-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce JoinBattle & LeaveBattle command-processors
- Loading branch information
Showing
5 changed files
with
174 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/com/springrts/tasserver/commands/impl/JoinBattleDenyCommandProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright (c) 2010 Robin Vobruba <robin.vobruba@derisk.ch> | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.springrts.tasserver.commands.impl; | ||
|
||
|
||
import com.springrts.tasserver.Account; | ||
import com.springrts.tasserver.Battle; | ||
import com.springrts.tasserver.Client; | ||
import com.springrts.tasserver.Misc; | ||
import com.springrts.tasserver.commands.AbstractCommandProcessor; | ||
import com.springrts.tasserver.commands.CommandProcessingException; | ||
import com.springrts.tasserver.commands.SupportedCommand; | ||
import java.util.List; | ||
|
||
/** | ||
* Sent by client in response to a JOINBATTLEREQUEST command in order to prevent | ||
* the user from joining the battle. | ||
* @author hoijui | ||
*/ | ||
@SupportedCommand("JOINBATTLEDENY") | ||
public class JoinBattleDenyCommandProcessor extends AbstractCommandProcessor { | ||
|
||
public JoinBattleDenyCommandProcessor() { | ||
super(1, ARGS_MAX_NOCHECK, Account.Access.NORMAL); | ||
} | ||
|
||
@Override | ||
public boolean process(Client client, List<String> args) | ||
throws CommandProcessingException | ||
{ | ||
boolean checksOk = super.process(client, args); | ||
if (!checksOk) { | ||
return false; | ||
} | ||
|
||
if (client.getBattleID() == Battle.NO_BATTLE_ID) { | ||
return false; | ||
} | ||
|
||
Battle bat = getContext().getBattles().getBattleByID(client.getBattleID()); | ||
if (bat == null) { | ||
return false; | ||
} | ||
|
||
// only the founder can deny a battle join | ||
if (bat.getFounder() != client) { | ||
return false; | ||
} | ||
|
||
String username = args.get(0); | ||
Client joiningClient = getContext().getClients().getClient(username); | ||
if (joiningClient == null) { | ||
return false; | ||
} | ||
if (joiningClient.getRequestedBattleID() != client.getBattleID()) { | ||
return false; | ||
} | ||
joiningClient.setRequestedBattleID(Battle.NO_BATTLE_ID); | ||
if(args.size() > 1) { | ||
String reason = Misc.makeSentence(args, 1); | ||
joiningClient.sendLine("JOINBATTLEFAILED Denied by battle founder - " + reason); | ||
} else { | ||
joiningClient.sendLine("JOINBATTLEFAILED Denied by battle founder"); | ||
} | ||
|
||
return true; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/com/springrts/tasserver/commands/impl/LeaveBattleCommandProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright (c) 2010 Robin Vobruba <robin.vobruba@derisk.ch> | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.springrts.tasserver.commands.impl; | ||
|
||
|
||
import com.springrts.tasserver.Account; | ||
import com.springrts.tasserver.Battle; | ||
import com.springrts.tasserver.Client; | ||
import com.springrts.tasserver.commands.AbstractCommandProcessor; | ||
import com.springrts.tasserver.commands.CommandProcessingException; | ||
import com.springrts.tasserver.commands.SupportedCommand; | ||
import java.util.List; | ||
|
||
/** | ||
* Sent by the client when he leaves a battle. | ||
* Also sent by a founder of the battle when he closes the battle. | ||
* @author hoijui | ||
*/ | ||
@SupportedCommand("LEAVEBATTLE") | ||
public class LeaveBattleCommandProcessor extends AbstractCommandProcessor { | ||
|
||
public LeaveBattleCommandProcessor() { | ||
super(0, 0, Account.Access.NORMAL); | ||
} | ||
|
||
@Override | ||
public boolean process(Client client, List<String> args) | ||
throws CommandProcessingException | ||
{ | ||
boolean checksOk = super.process(client, args); | ||
if (!checksOk) { | ||
return false; | ||
} | ||
|
||
if (client.getBattleID() == Battle.NO_BATTLE_ID) { | ||
// this may happen when client sent the LEAVEBATTLE command | ||
// right after he was kicked from the battle, for example. | ||
return false; | ||
} | ||
Battle bat = getContext().getBattles().getBattleByID(client.getBattleID()); | ||
getContext().getBattles().verify(bat); | ||
|
||
// automatically checks if the client is a founder and closes the battle | ||
getContext().getBattles().leaveBattle(client, bat); | ||
|
||
return true; | ||
} | ||
} |