Further work on CommandExecuter and adjustments to NightServerProtocol.
This commit is contained in:
@@ -17,4 +17,5 @@
|
||||
* MSGRS: "Message received": Paramaters: a string detailing to the client that and what the server received as command.
|
||||
* SEROR: Server had an error. (used for debugging)
|
||||
* SPING: Ping from server to client;
|
||||
* NOCMD: Co command found.
|
||||
*/
|
||||
@@ -21,7 +21,7 @@ public class NightTrainProtocol {
|
||||
//Client Commands
|
||||
CRTGM, CHATA, CHATW, CHATG, LEAVG, JOING, VOTEG, QUITS, LISTP, CUSRN,CPING,
|
||||
//Server Responses
|
||||
MSGRS, SEROR, SPING;
|
||||
MSGRS, SEROR, SPING, NOCMD
|
||||
}
|
||||
|
||||
private static HashMap<String, NTtBCommands> initializeMapping(){
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.server.cmd.methods;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.protocol.NTtBFormatMsg;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.protocol.NightTrainProtocol.NTtBCommands;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This Class implements actually acting on the clients
|
||||
* messages.
|
||||
* This Class implements actually acting on the clients messages.
|
||||
*/
|
||||
public class CommandExecuter {
|
||||
|
||||
ClientHandler caller;
|
||||
private ClientHandler caller;
|
||||
private static String msgPrefix = "SERVER: ";
|
||||
|
||||
public static void execute(NTtBFormatMsg msg) {
|
||||
public void execute(NTtBFormatMsg msg) {
|
||||
switch (msg.getCommand()) {
|
||||
case CRTGM:
|
||||
break;
|
||||
@@ -55,19 +56,55 @@ public class CommandExecuter {
|
||||
case SPING:
|
||||
pongC();
|
||||
break;
|
||||
default:
|
||||
this.noCommand();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void wisper(String[] parameters) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
private void changeNickname(String[] parameters) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
private void quitServer() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
private void pongC() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
private void pongS() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
private void noCommand() {
|
||||
try {
|
||||
caller.getOut().write(msgPrefix + String.valueOf(NTtBCommands.NOCMD));
|
||||
} catch (IOException e) {
|
||||
System.out.println("IOException in noCommand() in CommandExecuter.java");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* boradcast chat message to everyone
|
||||
* @param parameters should only have one entry i.e.
|
||||
* parameters.length == 1
|
||||
* should be true;
|
||||
*
|
||||
* @param parameters should only have one entry i.e. parameters.length == 1 should be true;
|
||||
*/
|
||||
private static void broadcastClientMsg(String[] parameters) throws IOException {
|
||||
for(ClientHandler clients: ClientHandler.connectedClients) {
|
||||
clients.getOut().write(parameters[0]);
|
||||
private static void broadcastClientMsg(String[] parameters) {
|
||||
try {
|
||||
for (ClientHandler clients : ClientHandler.connectedClients) {
|
||||
clients.getOut().write(parameters[0]);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("IOEXCEPTION in CommandExecuter.java at broadcastClientMsg");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user