simple.server.SimpleServerCLI Maven / Gradle / Ivy
The newest version!
package simple.server;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import marauroa.common.crypto.Hash;
import marauroa.common.game.RPObject;
import marauroa.server.game.db.AccountDAO;
import marauroa.server.game.db.DAORegister;
import org.openide.util.Lookup;
import simple.common.game.ClientObjectInterface;
import simple.server.core.action.ActionProvider;
import simple.server.core.engine.IRPWorld;
import simple.server.core.engine.SimpleRPZone;
import simple.server.core.entity.RPEntityInterface;
import simple.server.core.event.api.IRPEvent;
import simple.server.core.tool.Tool;
import simple.server.extension.MarauroaServerExtension;
/**
* This provides a command line interface with the server.
*
* @author Javier A. Ortiz Bultrón [email protected]
*/
class SimpleServerCLI extends Thread {
private static final Logger LOG
= Logger.getLogger(SimpleServerCLI.class.getSimpleName());
private BufferedReader input;
public SimpleServerCLI() {
super("Simple Server CLI");
}
@Override
public void run() {
try {
LOG.info("Starting Simple Server CLI...");
input = new BufferedReader(new InputStreamReader(System.in));
String line;
line = input.readLine();
while (!line.equals("")) {
processInput(line.trim());
line = input.readLine();
}
} catch (IOException ex) {
LOG.log(Level.SEVERE, null, ex);
}
}
private void processInput(String line) {
StringTokenizer st = new StringTokenizer(line, " ");
while (st.hasMoreTokens()) {
String token = st.nextToken();
String temp;//Used to hold temporary values
switch (token) {
case "help":
LOG.info("Valid commands include: create, delete, quit, show.");
break;
case "quit":
LOG.info("Are you sure you want to quit? (Y/N)");
try {
line = input.readLine();
OUTER:
while (!line.trim().toLowerCase().equals("")) {
switch (line) {
case "y":
SimpleServer.server.finish();
LOG.info("Server stopped!");
System.exit(0);
break;
case "n":
break OUTER;
default:
LOG.info("Invalid option. Are you sure you want"
+ " to quit? (Y/N)");
line = input.readLine();
break;
}
}
} catch (IOException ex) {
LOG.log(Level.SEVERE, null, ex);
}
break;
case "create":
if (st.hasMoreTokens()) {
temp = st.nextToken();
switch (temp) {
case "account":
processCreateAccountCommand(st);
break;
case "zone":
processCreateZoneCommand(st);
break;
default:
LOG.log(Level.WARNING, "Unknown parameter: {0}", temp);
}
} else {
LOG.warning("Missing parameters for create command!\n"
+ "Usage: create