Commit 1fa865bd authored by Corentin-Boulanger's avatar Corentin-Boulanger Committed by alexandre.ducarne
Browse files

Begin refactor of messages process data

parent 6c0458e8
......@@ -2,6 +2,8 @@ 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.ServerStateOnConnectionMessage;
import java.util.Optional;
import main.java.client.network.messages.clientToServer.NewGameToServerMessage;
......@@ -14,7 +16,7 @@ public class MessageClientController {
private static MessageClientController instance = new MessageClientController();
private WebSocketStompSessionHandler wsHandler;
private ComCoreClient comCore;
public ComCoreClient getComCore() {
return comCore;
}
......@@ -53,6 +55,9 @@ public class MessageClientController {
wsHandler.sendMessage(message);
}
public void processData(MessageMeta message) {
}
void sendNewGameAvailableToServer(NewGameToServerMessage message) {
wsHandler.sendMessage(message);
}
......
......@@ -79,7 +79,7 @@ public class WebSocketStompSessionHandler extends StompSessionHandlerAdapter {
public void handleFrame(StompHeaders headers, Object payload) {
MessageMeta message = (MessageMeta) payload;
LOGGER.info("New server message received : " + message.toString());
message.processData();
MessageClientController.getInstance().processData(message);
}
}
......@@ -31,7 +31,6 @@ public class LoginUserToServerMessage extends MessageMeta {
@Override
public void processData() {
MessageServerController.getInstance().getComCore().getComToData().addAuthenticatedPlayer(this.userToAdd);
}
public UserLight getUserToAdd() {
......
......@@ -25,7 +25,11 @@ public class UserLight extends UserMeta {
super(id, pseudo);
}
public String getLastName() {
public UserLight() {
super();
}
public String getLastName() {
return lastName;
}
......
......@@ -11,6 +11,9 @@ abstract class UserMeta {
this.pseudo = pseudo;
}
public UserMeta() {
}
public UUID getId() {
return id;
}
......
package main.java.server.network;
import java.util.Optional;
import main.java.client.network.messages.clientToServer.LoginUserToServerMessage;
import main.java.common.message.MessageMeta;
import main.java.common.dataModel.Message;
import main.java.server.network.messages.serverToClient.NewUserAddedMessage;
import main.java.server.network.messages.serverToClient.ServerStateOnConnectionMessage;
......@@ -74,6 +78,14 @@ public class MessageServerController {
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());
}
}
/**
* 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
......
......@@ -39,6 +39,6 @@ public class WebSocketController {
@MessageMapping("/serverMessages")
public void onMessageReceived(MessageMeta message) {
LOGGER.info("New client message received : " + message.toString());
message.processData();
MessageServerController.getInstance().processData(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