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

Add classes and methods to handle ChatMessages

!! There is still no logic for generating endpoints per game !!
!! When this will be available, a refactor to connect it to server will be needed !!
- Modified interfaces to get Message directly and not string, user etc
- Add methods to send messages
parent e888d819
...@@ -18,6 +18,7 @@ public class ComCoreClient { ...@@ -18,6 +18,7 @@ public class ComCoreClient {
public ComCoreClient() { public ComCoreClient() {
dataToComClientImpl = new DataToComClientImpl(this); dataToComClientImpl = new DataToComClientImpl(this);
messageClientController = MessageClientController.getInstance(); messageClientController = MessageClientController.getInstance();
messageClientController.setComCore(this);
} }
/** /**
......
package main.java.client.network; package main.java.client.network;
import java.sql.Timestamp;
import java.util.UUID; import java.util.UUID;
import main.java.client.network.messages.clientToServer.ChatMessageToServerMessage; import main.java.client.network.messages.clientToServer.ChatMessageToServerMessage;
import main.java.client.network.messages.clientToServer.LoginUserToServerMessage; import main.java.client.network.messages.clientToServer.LoginUserToServerMessage;
import main.java.common.dataModel.GameLight; import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.Move; import main.java.common.dataModel.Move;
import main.java.common.dataModel.UserLight; import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IDataToCom; import main.java.common.interfaces.client.IDataToCom;
...@@ -30,7 +30,6 @@ public class DataToComClientImpl implements IDataToCom { ...@@ -30,7 +30,6 @@ public class DataToComClientImpl implements IDataToCom {
} }
/** /**
* @author cynthiasoimansoib
* This method is used when a client is trying to connect to the server. * This method is used when a client is trying to connect to the server.
* His informations are sent through WebSocket for him to be added to the server's * His informations are sent through WebSocket for him to be added to the server's
* list of users. * list of users.
...@@ -54,8 +53,8 @@ public class DataToComClientImpl implements IDataToCom { ...@@ -54,8 +53,8 @@ public class DataToComClientImpl implements IDataToCom {
} }
@Override @Override
public void sendChatMessage(String message, Timestamp time, UUID playerID, UUID gameID) { public void sendChatMessage(Message chatMessage, UUID gameID) {
ChatMessageToServerMessage msg = new ChatMessageToServerMessage(message, time, playerID, gameID); ChatMessageToServerMessage msg = new ChatMessageToServerMessage(chatMessage, gameID);
comCoreClient.getMessageClientController().sendChatMessageToServer(msg); comCoreClient.getMessageClientController().sendChatMessageToServer(msg);
} }
......
...@@ -13,8 +13,17 @@ public class MessageClientController { ...@@ -13,8 +13,17 @@ public class MessageClientController {
private static MessageClientController instance = new MessageClientController(); private static MessageClientController instance = new MessageClientController();
private WebSocketStompSessionHandler wsHandler; private WebSocketStompSessionHandler wsHandler;
private ComCoreClient comCore;
public ComCoreClient getComCore() {
return comCore;
}
public void setComCore(ComCoreClient comCore) {
this.comCore = comCore;
}
private MessageClientController() { private MessageClientController() {
} }
/** /**
......
package main.java.client.network.messages.clientToServer; package main.java.client.network.messages.clientToServer;
import java.sql.Timestamp;
import java.util.UUID; import java.util.UUID;
import main.java.common.dataModel.Message;
import main.java.common.message.MessageMeta; import main.java.common.message.MessageMeta;
import main.java.server.network.ComCoreServer; import main.java.server.network.ComCoreServer;
import main.java.server.network.MessageServerController; import main.java.server.network.MessageServerController;
...@@ -11,56 +11,46 @@ import main.java.server.network.MessageServerController; ...@@ -11,56 +11,46 @@ import main.java.server.network.MessageServerController;
* Message containing a chat message to send to the server. * Message containing a chat message to send to the server.
*/ */
public class ChatMessageToServerMessage extends MessageMeta { public class ChatMessageToServerMessage extends MessageMeta {
private String message; private Message chatMessage;
private Timestamp time; private UUID gameId;
private UUID playerID;
private UUID gameID;
public ChatMessageToServerMessage(Message chatMessage, UUID gameId) {
super();
this.chatMessage = chatMessage;
this.gameId = gameId;
}
public ChatMessageToServerMessage(String message, Timestamp time, UUID playerID, UUID gameID) { private ChatMessageToServerMessage() {
this.message = message; //NOP
this.time = time; }
this.playerID = playerID;
this.gameID = gameID;
}
public ChatMessageToServerMessage() { public Message getChatMessage() {
} return chatMessage;
}
@Override
public void processData() {
ComCoreServer comCore = MessageServerController.getInstance().getComCore();
comCore.getComToData().receiveNewChatMessage(message, time, playerID, gameID);
}
public String getMessage() { public void setChatMessage(Message chatMessage) {
return message; this.chatMessage = chatMessage;
} }
public void setMessage(String message) {
this.message = message;
}
public Timestamp getTime() { public UUID getGameId() {
return time; return gameId;
} }
public void setTime(Timestamp time) {
this.time = time;
}
public UUID getPlayerID() { public void setGameId(UUID gameId) {
return playerID; this.gameId = gameId;
} }
public void setPlayerID(UUID playerID) {
this.playerID = playerID;
}
public UUID getGameID() { @Override
return gameID; public void processData() {
} ComCoreServer comCore = MessageServerController.getInstance().getComCore();
comCore.getComToData().receiveNewChatMessage(this.chatMessage, this.gameId);
comCore.getMessageServerController().sendChatMessageToClients(this.chatMessage, this.gameId);
}
public void setGameID(UUID gameID) {
this.gameID = gameID;
}
} }
//
\ No newline at end of file
package main.java.common.interfaces.client; package main.java.common.interfaces.client;
import main.java.common.dataModel.GameLight; import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.Move; import main.java.common.dataModel.Move;
import main.java.common.dataModel.UserLight; import main.java.common.dataModel.UserLight;
...@@ -45,12 +46,11 @@ public interface IDataToCom { ...@@ -45,12 +46,11 @@ public interface IDataToCom {
/** /**
* Send a chat message. * Send a chat message.
* *
* @param message : the message * @param message : the data message to be sent
* @param time : the timestamp when the message was written
* @param playerID : the ID of the player sending the message
* @param gameID : the game in which the message was sent * @param gameID : the game in which the message was sent
*/ */
void sendChatMessage(String message, Timestamp time, UUID playerID, UUID gameID);
void sendChatMessage(Message chatMessage, UUID gameID);
/** /**
* Send a disconnecting request to the server. * Send a disconnecting request to the server.
......
...@@ -9,6 +9,7 @@ import main.java.common.dataModel.GameLight; ...@@ -9,6 +9,7 @@ import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message; import main.java.common.dataModel.Message;
import main.java.common.dataModel.Move; import main.java.common.dataModel.Move;
import main.java.common.dataModel.UserLight; import main.java.common.dataModel.UserLight;
import main.java.common.dataModel.UserZero;
/** /**
* This class is an interface which provides server methods to communicate from * This class is an interface which provides server methods to communicate from
...@@ -47,13 +48,11 @@ public interface IComToData { ...@@ -47,13 +48,11 @@ public interface IComToData {
/** /**
* Receive a new chat message to transfer it. * Receive a new chat message to transfer it.
* *
* @param message : the message to transfer * @param chatMessage : Data Message to transfer
* @param timestamp : the timestamp of the message
* @param userID : the UUID of the user sending the message
* @param gameID : the UUID of the game in which the message was sent * @param gameID : the UUID of the game in which the message was sent
* @return the message to transfer * @return the message to transfer
*/ */
Message receiveNewChatMessage(String message, Timestamp timestamp, UUID userID, UUID gameID) throws Exception; Message receiveNewChatMessage(Message chatMessage, UUID gameID);
/** /**
* Get all the participants (players & spectators) of a game. * Get all the participants (players & spectators) of a game.
......
package main.java.server.data; package main.java.server.data;
import java.util.ArrayList;
import java.util.UUID;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.Move;
import main.java.common.dataModel.UserLight;
import main.java.common.dataModel.*; import main.java.common.dataModel.*;
import main.java.common.interfaces.server.IComToData; import main.java.common.interfaces.server.IComToData;
...@@ -134,4 +141,10 @@ public class ComToDataServerImpl implements IComToData { ...@@ -134,4 +141,10 @@ public class ComToDataServerImpl implements IComToData {
dataCoreServer.getListConnectedUsers().set(index, userModified); dataCoreServer.getListConnectedUsers().set(index, userModified);
//dataCoreServer.getDataToCom().notifyListUserChange(); TO DISCUSS WITH COM //dataCoreServer.getDataToCom().notifyListUserChange(); TO DISCUSS WITH COM
} }
@Override
public Message receiveNewChatMessage(Message chatMessage, UUID gameID) {
// TODO Auto-generated method stub
return null;
}
} }
package main.java.server.network; package main.java.server.network;
import java.util.UUID;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import main.java.client.network.ComCoreClient; import main.java.common.dataModel.Message;
import main.java.client.network.WebSocketStompSessionHandler;
import main.java.client.network.WebSocketStompSessionInitializer;
import main.java.common.interfaces.server.IComToData; import main.java.common.interfaces.server.IComToData;
import main.java.common.interfaces.server.IDataToCom; import main.java.common.interfaces.server.IDataToCom;
...@@ -63,4 +63,8 @@ public class ComCoreServer { ...@@ -63,4 +63,8 @@ public class ComCoreServer {
WebSocketController wsController = new WebSocketController(); WebSocketController wsController = new WebSocketController();
messageServerController.setWsController(wsController); messageServerController.setWsController(wsController);
} }
public void sendChatMessage(Message message) {
}
} }
package main.java.server.network; package main.java.server.network;
import main.java.common.dataModel.Message;
import main.java.server.network.messages.serverToClient.NewUserAddedMessage; import main.java.server.network.messages.serverToClient.NewUserAddedMessage;
import main.java.server.network.messages.serverToClient.ServerStateOnConnectionMessage; import main.java.server.network.messages.serverToClient.ServerStateOnConnectionMessage;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
import main.java.server.network.messages.serverToClient.NewGameNotificationToClientMessage; import main.java.server.network.messages.serverToClient.NewGameNotificationToClientMessage;
/** /**
...@@ -71,7 +73,15 @@ public class MessageServerController { ...@@ -71,7 +73,15 @@ public class MessageServerController {
public void notifyNewUserAdded(NewUserAddedMessage message) { public void notifyNewUserAdded(NewUserAddedMessage message) {
wsController.sendMessage(message); wsController.sendMessage(message);
} }
/**
* 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 sendNewGameNotification(NewGameNotificationToClientMessage message) { public void sendNewGameNotification(NewGameNotificationToClientMessage message) {
wsController.sendMessage(message); wsController.sendMessage(message);
} }
......
package main.java.server.network.messages.serverToClient; package main.java.server.network.messages.serverToClient;
import main.java.client.network.MessageClientController;
import main.java.common.dataModel.Message; import main.java.common.dataModel.Message;
import main.java.common.message.MessageMeta; import main.java.common.message.MessageMeta;
...@@ -18,7 +19,7 @@ public class ChatMessageToClientMessage extends MessageMeta { ...@@ -18,7 +19,7 @@ public class ChatMessageToClientMessage extends MessageMeta {
@Override @Override
public void processData() { public void processData() {
// TODO: Implement MessageClientController.getInstance().getComCore().getComToDataClient().receiveChatMessage(this.message);
} }
public Message getMessage() { public Message getMessage() {
......
Supports Markdown
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