Commit d37a5448 authored by Cynthia Soimansoib's avatar Cynthia Soimansoib
Browse files

Merge branch 'feature/com/refactorGameListMessage' into 'int/v2'

Implement use case "retrieve game list" from server

See merge request !43
parents 2e072a54 6b900a54
package main.java.client.data;
import main.java.common.dataModel.*;
import main.java.common.interfaces.client.IComToData;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import main.java.client.network.MessageClientController;
import main.java.common.dataModel.Board;
import main.java.common.dataModel.GameHeavy;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IComToData;
import main.java.server.network.messages.serverToClient.GameListMessage;
public class ComToDataClientImpl implements IComToData {
DataCoreClient dataCoreClient;
......
......@@ -3,6 +3,7 @@ package main.java.client.data;
import main.java.common.dataModel.*;
import main.java.common.interfaces.client.*;
import java.util.ArrayList;
import java.util.List;
public class DataCoreClient {
......@@ -24,6 +25,9 @@ public class DataCoreClient {
mainToDataImpl = new MainToDataImpl(this);
comToDataClientImpl = new ComToDataClientImpl(this);
gameToDataImpl = new GameToDataImpl(this);
listConnectedUsers = new ArrayList<UserLight>();
listGameLight = new ArrayList<GameLight>();
}
public List<UserLight> getListConnectedUsers() {
......
package main.java.client.network;
import java.util.UUID;
import main.java.client.network.messages.clientToServer.ChatMessageToServerMessage;
import main.java.client.network.messages.clientToServer.LoginUserToServerMessage;
import main.java.client.network.messages.clientToServer.NewGameToServerMessage;
import main.java.client.network.messages.clientToServer.RequestGameListMessage;
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;
import java.util.UUID;
public class DataToComClientImpl implements IDataToCom {
......@@ -84,5 +85,13 @@ public class DataToComClientImpl implements IDataToCom {
// TODO Auto-generated method stub
}
/**
* Resquest the game list to the server
*/
@Override
public void getServerGameList() {
RequestGameListMessage message = new RequestGameListMessage();
MessageClientController.getInstance().sendRequestGameList(message);
}
}
package main.java.client.network;
import java.util.Optional;
import main.java.client.network.messages.clientToServer.ChatMessageToServerMessage;
import main.java.client.network.messages.clientToServer.LoginUserToServerMessage;
import main.java.client.network.messages.clientToServer.NewGameToServerMessage;
import main.java.client.network.messages.clientToServer.RequestGameListMessage;
import main.java.common.message.MessageMeta;
import main.java.server.network.messages.serverToClient.ChatMessageToClientMessage;
import main.java.server.network.messages.serverToClient.NewUserAddedMessage;
import main.java.server.network.messages.serverToClient.GameListMessage;
import main.java.server.network.messages.serverToClient.ServerStateOnConnectionMessage;
import java.util.Optional;
/**
* Class handling message sending & receiving
*/
......@@ -71,6 +73,25 @@ public class MessageClientController {
wsHandler.sendMessage(message);
}
/**
* Send a RequestGameListMessage to the server
*
* @param message the message to send
*/
public void sendRequestGameList(RequestGameListMessage message) {
wsHandler.sendMessage(message);
}
/**
* Send a GameListMessage to the server
*
* @param message the message to send
*/
public void sendGameListToData(GameListMessage message) {
wsHandler.sendMessage(message);
}
public void processData(MessageMeta message) {
switch (message.getClass().getSimpleName()) {
case "ChatMessageToClientMessage":
......@@ -86,6 +107,12 @@ public class MessageClientController {
case "NewUserAddedMessage":
NewUserAddedMessage newUserMessage = (NewUserAddedMessage) message;
this.comCore.getComToDataClient().addNewUser(newUserMessage.getUserToAdd());
break;
case "GameListMessage":
GameListMessage gameListMessage = (GameListMessage) message;
this.comCore.getComToDataClient().forwardGames(gameListMessage.getGameLights());
break;
}
}
}
package main.java.client.network.messages.clientToServer;
import main.java.common.message.MessageMeta;
/**
* Message containing a login request to send to the server.
*/
public class RequestGameListMessage extends MessageMeta {
public RequestGameListMessage() {
// TODO
}
@Override
public void processData() {
}
}
......@@ -89,4 +89,9 @@ public interface IDataToCom {
* @param move : the move to send
*/
void sendMove(Move move);
/**
* Get the list of games from the server
*/
void getServerGameList();
}
......@@ -45,4 +45,11 @@ public interface IDataToCom {
*/
void sendNewUserLists(UserLight playerToNotify, ArrayList<UserLight> playersOnline, ArrayList<GameLight> gamesOnline);
/**
* Send the game list to the Com module
*
* @param gameLights the game list to send
*/
void sendGameList(ArrayList<GameLight> gameLights);
}
package main.java.server.network;
import java.util.ArrayList;
import main.java.common.dataModel.Board;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.server.IDataToCom;
import main.java.server.network.messages.serverToClient.GameListMessage;
import main.java.server.network.messages.serverToClient.NewGameNotificationToClientMessage;
import main.java.server.network.messages.serverToClient.ServerStateOnConnectionMessage;
import java.util.ArrayList;
public class DataToComServerImpl implements IDataToCom {
private ComCoreServer comCoreServer;
......@@ -44,5 +45,11 @@ public class DataToComServerImpl implements IDataToCom {
MessageServerController.getInstance().sendListsToNewUser(message);
comCoreServer.getMessageServerController().sendListsToNewUser(message);
}
@Override
public void sendGameList(ArrayList<GameLight> gameLights) {
GameListMessage message = new GameListMessage(gameLights);
MessageServerController.getInstance().sendGameList(message);
}
}
package main.java.server.network;
import java.util.List;
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.dataModel.GameLight;
import main.java.common.dataModel.UserLight;
import main.java.common.message.MessageMeta;
import main.java.server.network.messages.serverToClient.ChatMessageToClientMessage;
import main.java.server.network.messages.serverToClient.GameListMessage;
import main.java.server.network.messages.serverToClient.NewGameNotificationToClientMessage;
import main.java.server.network.messages.serverToClient.NewUserAddedMessage;
import main.java.server.network.messages.serverToClient.ServerStateOnConnectionMessage;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
/**
* Class handling sending & receiving messages from clients
*/
......@@ -110,6 +111,12 @@ public class MessageServerController {
this.sendChatMessageToClients(new ChatMessageToClientMessage(chatMessage.getChatMessage()),
chatMessage.getGameId());
break;
case "RequestGameListMessage":
ComCoreServer comCore = MessageServerController.getInstance().getComCore();
GameListMessage gameListMessage = new GameListMessage(comCore.getComToData().getListGames());
MessageServerController.getInstance().sendGameList(gameListMessage);
break;
}
}
......@@ -121,4 +128,13 @@ public class MessageServerController {
public void sendNewGameNotification(NewGameNotificationToClientMessage message) {
wsController.sendToAll(message);
}
/**
* Send a GameListMessage to clients
*
* @param message the message to send
*/
public void sendGameList(GameListMessage message) {
wsController.sendToAll(message);
}
}
package main.java.server.network.messages.serverToClient;
import java.util.List;
import main.java.common.dataModel.GameLight;
import main.java.common.message.MessageMeta;
public class GameListMessage extends MessageMeta {
private List<GameLight> gameLights;
public GameListMessage(List<GameLight> gameLights) {
this.gameLights = gameLights;
}
public GameListMessage() {
}
@Override
public void processData() {
}
public List<GameLight> getGameLights() {
return gameLights;
}
public void setGameLights(List<GameLight> gameLights) {
this.gameLights = gameLights;
}
}
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