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 {
public ComCoreClient() {
dataToComClientImpl = new DataToComClientImpl(this);
messageClientController = MessageClientController.getInstance();
messageClientController.setComCore(this);
}
/**
......
package main.java.client.network;
import java.sql.Timestamp;
import java.util.UUID;
import main.java.client.network.messages.clientToServer.ChatMessageToServerMessage;
import main.java.client.network.messages.clientToServer.LoginUserToServerMessage;
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.interfaces.client.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.
* His informations are sent through WebSocket for him to be added to the server's
* list of users.
......@@ -54,8 +53,8 @@ public class DataToComClientImpl implements IDataToCom {
}
@Override
public void sendChatMessage(String message, Timestamp time, UUID playerID, UUID gameID) {
ChatMessageToServerMessage msg = new ChatMessageToServerMessage(message, time, playerID, gameID);
public void sendChatMessage(Message chatMessage, UUID gameID) {
ChatMessageToServerMessage msg = new ChatMessageToServerMessage(chatMessage, gameID);
comCoreClient.getMessageClientController().sendChatMessageToServer(msg);
}
......
......@@ -13,8 +13,17 @@ public class MessageClientController {
private static MessageClientController instance = new MessageClientController();
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;
import java.sql.Timestamp;
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;
......@@ -11,56 +11,46 @@ import main.java.server.network.MessageServerController;
* Message containing a chat message to send to the server.
*/
public class ChatMessageToServerMessage extends MessageMeta {
private String message;
private Timestamp time;
private UUID playerID;
private UUID gameID;
private Message chatMessage;
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) {
this.message = message;
this.time = time;
this.playerID = playerID;
this.gameID = gameID;
}
private ChatMessageToServerMessage() {
//NOP
}
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() {
return message;
}
public void setChatMessage(Message chatMessage) {
this.chatMessage = chatMessage;
}
public void setMessage(String message) {
this.message = message;
}
public Timestamp getTime() {
return time;
}
public UUID getGameId() {
return gameId;
}
public void setTime(Timestamp time) {
this.time = time;
}
public UUID getPlayerID() {
return playerID;
}
public void setGameId(UUID gameId) {
this.gameId = gameId;
}
public void setPlayerID(UUID playerID) {
this.playerID = playerID;
}
public UUID getGameID() {
return gameID;
}
@Override
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;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.Move;
import main.java.common.dataModel.UserLight;
......@@ -45,12 +46,11 @@ public interface IDataToCom {
/**
* Send a chat message.
*
* @param message : the message
* @param time : the timestamp when the message was written
* @param playerID : the ID of the player sending the message
* @param message : the data message to be 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.
......
......@@ -9,6 +9,7 @@ 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.UserZero;
/**
* This class is an interface which provides server methods to communicate from
......@@ -47,13 +48,11 @@ public interface IComToData {
/**
* Receive a new chat message to transfer it.
*
* @param message : the message to transfer
* @param timestamp : the timestamp of the message
* @param userID : the UUID of the user sending the message
* @param chatMessage : Data Message to transfer
* @param gameID : the UUID of the game in which the message was sent
* @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.
......
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.interfaces.server.IComToData;
......@@ -134,4 +141,10 @@ public class ComToDataServerImpl implements IComToData {
dataCoreServer.getListConnectedUsers().set(index, userModified);
//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;
import java.util.UUID;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import main.java.client.network.ComCoreClient;
import main.java.client.network.WebSocketStompSessionHandler;
import main.java.client.network.WebSocketStompSessionInitializer;
import main.java.common.dataModel.Message;
import main.java.common.interfaces.server.IComToData;
import main.java.common.interfaces.server.IDataToCom;
......@@ -63,4 +63,8 @@ public class ComCoreServer {
WebSocketController wsController = new WebSocketController();
messageServerController.setWsController(wsController);
}
public void sendChatMessage(Message message) {
}
}
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.ServerStateOnConnectionMessage;
import java.util.Optional;
import java.util.UUID;
import main.java.server.network.messages.serverToClient.NewGameNotificationToClientMessage;
/**
......@@ -71,7 +73,15 @@ public class MessageServerController {
public void notifyNewUserAdded(NewUserAddedMessage 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) {
wsController.sendMessage(message);
}
......
package main.java.server.network.messages.serverToClient;
import main.java.client.network.MessageClientController;
import main.java.common.dataModel.Message;
import main.java.common.message.MessageMeta;
......@@ -18,7 +19,7 @@ public class ChatMessageToClientMessage extends MessageMeta {
@Override
public void processData() {
// TODO: Implement
MessageClientController.getInstance().getComCore().getComToDataClient().receiveChatMessage(this.message);
}
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