Skip to content

Commit

Permalink
Fix plugin API doc file name & add Resign plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaribz committed Jan 5, 2014
1 parent 1eda041 commit 89e0df7
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Components
help.
* [SPADS reference guide](doc/spadsDoc.html): HTML documentation of all SPADS
commands and settings (generated from help data files).
* [SPADS plugin API](doc/SpadsPluginApi.html): HTML documentation of the SPADS
* [SPADS plugin API](doc/spadsPluginApiDoc.html): HTML documentation of the SPADS
plugin API (generated from SPADS plugin API module)
* [Official SPADS plugins](plugins/officials): Official SPADS plugins sources.
* [SPADS plugins templates](plugins/templates): Templates for SPADS plugins
Expand Down Expand Up @@ -90,9 +90,9 @@ Documentation
be generated from any SPADS installation directory by using following
command (the pod2html.css file can be found [here](doc/pod2html.css)):

pod2html -css=pod2html.css --infile=SpadsPluginApi.pm --outfile=SpadsPluginApi.html
pod2html -css=pod2html.css --infile=SpadsPluginApi.pm --outfile=spadsPluginApiDoc.html

* Additional documentation can be found on [SPADS wiki](http://springrts.com/wiki/Hosting_Spring#SPADS).
* Additional documentation can be found on [SPADS wiki](http://springrts.com/wiki/SPADS).

Licensing
---------
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions plugins/officials/Resign/Resign.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
commandsFile:ResignCmd.conf
helpFile:ResignHelp.dat
164 changes: 164 additions & 0 deletions plugins/officials/Resign/Resign.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package Resign;

use strict;

use SpadsPluginApi;

no warnings 'redefine';

my $pluginVersion='0.1';
my $requiredSpadsVersion='0.11.18';

my %globalPluginParams = ( commandsFile => ['notNull'],
helpFile => ['notNull'] );
my %presetPluginParams;

sub getVersion { return $pluginVersion; }
sub getRequiredSpadsVersion { return $requiredSpadsVersion; }
sub getParams { return [\%globalPluginParams,\%presetPluginParams]; }

sub new {
my $class=shift;
my $self = {};
bless($self,$class);
addSpadsCommandHandler({resign => \&hSpadsResign});
slog("Plugin loaded (version $pluginVersion)",3);
return $self;
}

sub onUnload {
removeSpadsCommandHandler(['resign']);
slog("Plugin unloaded",3);
}

sub isNotAllowedToVote {
my ($user,$resignedPlayer)=@_;
my $autohost=getSpringInterface();
return 1 unless($autohost->getState() == 2);
my $p_runningBattle=getRunningBattle();
return 2 unless(exists $p_runningBattle->{users}->{$user}
&& defined $p_runningBattle->{users}->{$user}->{battleStatus}
&& $p_runningBattle->{users}->{$user}->{battleStatus}->{mode});
return 3 unless($p_runningBattle->{users}->{$user}->{battleStatus}->{team} == $p_runningBattle->{users}->{$resignedPlayer}->{battleStatus}->{team});
my $p_ahPlayer=$autohost->getPlayer($user);
return 4 unless(%{$p_ahPlayer} && $p_ahPlayer->{disconnectCause} == -1);
return 5 if($p_ahPlayer->{lost});
return 0;
}

sub hSpadsResign {
my ($source,$user,$p_params,$checkOnly)=@_;

my $autohost=getSpringInterface();
my $ahState=$autohost->getState();
if($ahState != 2) {
my $reason='game is not running';
if($ahState == 1) {
$reason='game has not started yet';
}elsif($ahState == 3) {
$reason='game is already over';
}
answer("Unable to resign, $reason!");
return 0;
}

my ($resignedPlayer,$isTeamResign);
if($#{$p_params} == -1) {
($resignedPlayer,$isTeamResign)=($user,1);
}elsif($#{$p_params} == 0) {
($resignedPlayer,$isTeamResign)=($p_params->[0],0);
}elsif($#{$p_params} == 1) {
if($p_params->[1] !~ /^team$/i) {
invalidSyntax($user,'resign');
return 0;
}
($resignedPlayer,$isTeamResign)=($p_params->[0],1);
}else{
invalidSyntax($user,'resign');
return 0;
}

my $p_runningBattle=getRunningBattle();
my @bPlayers=grep {defined $p_runningBattle->{users}->{$_}->{battleStatus} && $p_runningBattle->{users}->{$_}->{battleStatus}->{mode}} (keys %{$p_runningBattle->{users}});

if($#{$p_params} == -1) {
if(! grep {$resignedPlayer eq $_} @bPlayers) {
answer('Only players are allowed to resign!');
return 0;
}
}else{
my $p_playerFound=::cleverSearch($resignedPlayer,\@bPlayers);
if(! @{$p_playerFound}) {
answer("Unable to resign \"$resignedPlayer\", player not found!");
return 0;
}elsif($#{$p_playerFound} > 0) {
answer("Unable to resign \"$resignedPlayer\", ambiguous command! (multiple matches)");
return 0;
}
$resignedPlayer=$p_playerFound->[0];
}

if($checkOnly) {
my $notAllowed=isNotAllowedToVote($user,$resignedPlayer);
if($notAllowed) {
if($notAllowed == 2) {
answer("Only players are allowed to vote for resign!");
}elsif($notAllowed == 3) {
answer("Only the players from same team are allowed to vote for resign!");
}elsif($notAllowed == 4) {
answer("Only connected players are allowed to vote for resign!");
}elsif($notAllowed == 5) {
answer("Only the players who didn't loose yet are allowed to vote for resign!");
}
return 0;
}
}

my @playersToResign;
if($isTeamResign) {
my @resignablePlayers;
foreach my $bPlayer (@bPlayers) {
my $p_ahPlayer=$autohost->getPlayer($bPlayer);
push(@resignablePlayers,$bPlayer) if(%{$p_ahPlayer} && $p_ahPlayer->{disconnectCause} == -1 && $p_ahPlayer->{lost} == 0);
}
@playersToResign=grep {$p_runningBattle->{users}->{$_}->{battleStatus}->{team} == $p_runningBattle->{users}->{$resignedPlayer}->{battleStatus}->{team}} @resignablePlayers;
if(! @playersToResign) {
answer("Unable to resign ally team of $resignedPlayer, no resignable player found!");
return 0;
}
}else{
my $p_ahPlayer=$autohost->getPlayer($resignedPlayer);
if(! %{$p_ahPlayer} || $p_ahPlayer->{disconnectCause} != -1) {
answer("Unable to resign $resignedPlayer, player not connected!");
return 0;
}
if($p_ahPlayer->{lost}) {
answer("Unable to resign $resignedPlayer, player has already lost!");
return 0;
}
@playersToResign=($resignedPlayer);
}

return "resign $resignedPlayer".($isTeamResign?' TEAM':'') if($checkOnly);

foreach my $playerToResign (@playersToResign) {
$autohost->sendChatMessage('/specbynum '.($autohost->getPlayer($playerToResign)->{playerNb}));
}

if($#playersToResign > 0) {
sayBattleAndGame('Resigned '.($#playersToResign+1)." players (by $user)");
}else{
sayBattleAndGame("Resigned player $playersToResign[0] (by $user)");
}
}

sub onVoteRequest {
my ($self,$source,$user,$p_command,$p_remainingVoters)=@_;
return 1 unless($p_command->[0] eq 'resign');
foreach my $remainingVoter (keys %{$p_remainingVoters}) {
delete($p_remainingVoters->{$remainingVoter}) if(isNotAllowedToVote($remainingVoter,$p_command->[1]));
}
return 1;
}

1;
39 changes: 39 additions & 0 deletions plugins/officials/Resign/ResignCmd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#?source:status:gameState|directLevel:voteLevel

################################################################################
#
# Input fields description:
# -------------------------
#
# source: source of the command call (string)
# pv -> pv message to AutoHost
# chan -> message in AutoHost channel
# battle -> message in battle lobby
# game -> in game message
#
# status: status of the client calling the command (string)
# playing -> player currently playing in game
# player -> player in battle lobby and/or in game
# spec -> spectator in battle lobby
# outside -> user outside battle
#
# gameState: game state (string)
# running -> game is currently running
# stopped -> no game running
#
################################################################################
#
# Output fields description:
# --------------------------
#
# directLevel:
# AutoHost access level required for calling command directly (integer)
#
# voteLevel:
# AutoHost access level required for calling command through vote (integer)
#
################################################################################

[resign]
:playing:running|100:10
::running|100:
5 changes: 5 additions & 0 deletions plugins/officials/Resign/ResignHelp.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[resign]
!resign [<playerName> [TEAM]] - resigns a player or an entire ally team if "TEAM" is provided
"!resign joe" resigns the player named joe
"!resign joe TEAM" resigns joe's ally team
"!resign" resigns your entire ally team (same as "!resign <yourName> TEAM")

0 comments on commit 89e0df7

Please sign in to comment.