Skip to content

Commit

Permalink
introduce ForceCloseBattleCommandProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
hoijui committed Jan 18, 2011
1 parent 32e60a7 commit 77f69d8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 24 deletions.
24 changes: 0 additions & 24 deletions src/main/java/com/springrts/tasserver/TASServer.java
Expand Up @@ -607,30 +607,6 @@ public boolean tryToExecCommand(String command, Client client) {
}

tryToExecCommand(Misc.makeSentence(commands, 2), targetClient);
} else if (commands[0].equals("FORCECLOSEBATTLE")) {
if (client.getAccount().getAccess().compareTo(Account.Access.ADMIN) < 0) {
return false;
}
if (commands.length != 2) {
return false;
}

int battleID;
try {
battleID = Integer.parseInt(commands[1]);
} catch (NumberFormatException e) {
client.sendLine("SERVERMSG Invalid BattleID!");
return false;
}

Battle bat = context.getBattles().getBattleByID(battleID);
if (bat == null) {
client.sendLine("SERVERMSG Error: unknown BATTLE_ID!");
return false;
}

context.getBattles().closeBattleAndNotifyAll(bat);

} else if (commands[0].equals("MUTE")) {
if (client.getAccount().getAccess().compareTo(Account.Access.PRIVILEGED) < 0) {
return false;
Expand Down
Expand Up @@ -30,6 +30,7 @@
import com.springrts.tasserver.commands.impl.EnableRegisterCommandProcessor;
import com.springrts.tasserver.commands.impl.FindIpCommandProcessor;
import com.springrts.tasserver.commands.impl.FloodLevelCommandProcessor;
import com.springrts.tasserver.commands.impl.ForceCloseBattleCommandProcessor;
import com.springrts.tasserver.commands.impl.ForceStopServerCommandProcessor;
import com.springrts.tasserver.commands.impl.ForgeMessageCommandProcessor;
import com.springrts.tasserver.commands.impl.GetAccountAccessCommandProcessor;
Expand Down Expand Up @@ -146,6 +147,7 @@ public void init() {
commandProcessorClasses.add(ForgeMessageCommandProcessor.class);
commandProcessorClasses.add(GetIpCommandProcessor.class);
commandProcessorClasses.add(GetInGameTimeCommandProcessor.class);
commandProcessorClasses.add(ForceCloseBattleCommandProcessor.class);

try {
load(commandProcessorClasses);
Expand Down
@@ -0,0 +1,66 @@
/*
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;

/**
* @author hoijui
*/
@SupportedCommand("FORCECLOSEBATTLE")
public class ForceCloseBattleCommandProcessor extends AbstractCommandProcessor {

public ForceCloseBattleCommandProcessor() {
super(1, 1, Account.Access.ADMIN);
}

@Override
public boolean process(Client client, List<String> args)
throws CommandProcessingException
{
boolean checksOk = super.process(client, args);
if (!checksOk) {
return false;
}

int battleID;
try {
battleID = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
client.sendLine("SERVERMSG Invalid BattleID!");
return false;
}

Battle bat = getContext().getBattles().getBattleByID(battleID);
if (bat == null) {
client.sendLine("SERVERMSG Error: unknown BATTLE_ID!");
return false;
}

getContext().getBattles().closeBattleAndNotifyAll(bat);

return true;
}
}

0 comments on commit 77f69d8

Please sign in to comment.