public void chat(String message) { message = message.substring(5); if (isServer) { for (ServerService s : services) s.sendMessageToClients( "chat " + gameData.getPlayerName() + " " + gameData.getPlayerSide() + " " + message); parseChatMessage( "chat " + gameData.getPlayerName() + " " + gameData.getPlayerSide() + " " + message); } if (!isServer) requestToServer.println( "chat " + gameData.getPlayerName() + " " + gameData.getPlayerSide() + " " + message); }
public void parseChatMessage(String response) { int counter = 0; String side = null; String playerName = null; String chatMessage = null; response = response.substring(5); StringTokenizer st = new StringTokenizer(response); while (st.hasMoreElements()) { if (counter > 1) break; if (counter == 0) playerName = st.nextToken(); if (counter == 1) side = st.nextToken(); counter++; } chatMessage = response.substring(playerName.length() + side.length() + 2); if (playerName.equals(gameData.getPlayerName())) playerName = "Me"; String finalString = playerName + " (" + side + ") says: " + chatMessage; mw.v.enqueEvent(new CustomEvent(CustomEvent.CHAT_MESSAGE, finalString)); }