Commit e6fad37c authored by Cynthia SOIMANSOIB's avatar Cynthia SOIMANSOIB Committed by alexandre.ducarne
Browse files

Updated code to put logic of message processing into message controller.

This way, no need for comCoreClient into Server when processing message
and vice versa.
parent 1fa865bd
......@@ -3,6 +3,7 @@ package main.java.client.network;
import main.java.client.network.messages.clientToServer.ChatMessageToServerMessage;
import main.java.client.network.messages.clientToServer.LoginUserToServerMessage;
import main.java.common.message.MessageMeta;
import main.java.server.network.messages.serverToClient.ChatMessageToClientMessage;
import main.java.server.network.messages.serverToClient.ServerStateOnConnectionMessage;
import java.util.Optional;
......@@ -55,20 +56,23 @@ public class MessageClientController {
wsHandler.sendMessage(message);
}
public void processData(MessageMeta message) {
}
void sendNewGameAvailableToServer(NewGameToServerMessage message) {
wsHandler.sendMessage(message);
}
/**
* Send a ChatMessageToServerMessage to the server
*
*
* @param message the message to send
*/
public void sendChatMessageToServer(ChatMessageToServerMessage message) {
// TODO send to the correct game by retrieving message.gameID
wsHandler.sendMessage(message);
}
public void processData(MessageMeta message) {
switch(message.getClass().toString()) {
case "ChatMessageToClientMessage" :
ChatMessageToClientMessage chatMessage = (ChatMessageToClientMessage) message;
this.comCore.getComToDataClient().receiveChatMessage(chatMessage.getMessage());
}
}
}
......@@ -4,8 +4,6 @@ import java.util.UUID;
import main.java.common.dataModel.Message;
import main.java.common.message.MessageMeta;
import main.java.server.network.ComCoreServer;
import main.java.server.network.MessageServerController;
/**
* Message containing a chat message to send to the server.
......@@ -47,9 +45,6 @@ public class ChatMessageToServerMessage extends MessageMeta {
@Override
public void processData() {
ComCoreServer comCore = MessageServerController.getInstance().getComCore();
comCore.getComToData().receiveNewChatMessage(this.chatMessage, this.gameId);
comCore.getMessageServerController().sendChatMessageToClients(this.chatMessage, this.gameId);
}
}
......
package main.java.server.network;
import java.util.Optional;
import java.util.UUID;
import main.java.client.network.messages.clientToServer.ChatMessageToServerMessage;
import main.java.client.network.messages.clientToServer.LoginUserToServerMessage;
import main.java.common.message.MessageMeta;
import main.java.server.network.messages.serverToClient.ChatMessageToClientMessage;
import main.java.common.dataModel.Message;
import main.java.server.network.messages.serverToClient.NewUserAddedMessage;
import main.java.server.network.messages.serverToClient.ServerStateOnConnectionMessage;
......@@ -77,22 +80,25 @@ public class MessageServerController {
public void notifyNewUserAdded(NewUserAddedMessage message) {
wsController.sendMessage(message);
}
public void processData(MessageMeta message) {
switch(message.getClass().toString()) {
case "LoginUserToServerMessage":
LoginUserToServerMessage msg = (LoginUserToServerMessage) message;
MessageServerController.getInstance().getComCore().getComToData().addAuthenticatedPlayer(msg.getUserToAdd());
LoginUserToServerMessage loginMessage = (LoginUserToServerMessage) message;
MessageServerController.getInstance().getComCore().getComToData().addAuthenticatedPlayer(loginMessage.getUserToAdd());
break;
case "ChatMessageToServerMessage":
ChatMessageToServerMessage chatMessage = (ChatMessageToServerMessage) message;
comCore.getComToData().receiveNewChatMessage(chatMessage.getChatMessage(), chatMessage.getGameId());
this.sendChatMessageToClients(new ChatMessageToClientMessage(chatMessage.getChatMessage()), chatMessage.getGameId());
break;
}
}
/**
* Use the gameId to find endpoint of all connected clients to this game chatroom and
* sends message to the endpoint for them to receive the message
* */
public void sendChatMessageToClients(Message chatMessage, UUID gameId) {
// In this class send message to the game endpoint
}
public void sendChatMessageToClients(ChatMessageToClientMessage chatMessage, UUID gameId) {
//FIXME : when handling roomchat available, handle it to send chat message only on this chat room
wsController.sendMessage(chatMessage);
}
public void sendNewGameNotification(NewGameNotificationToClientMessage message) {
wsController.sendMessage(message);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment