Commit b4231c51 authored by Alexandre Ducarne's avatar Alexandre Ducarne
Browse files

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

Feature/com/chat messages

See merge request !39
parents 0428bdff 569910af
......@@ -11,53 +11,53 @@ import main.java.server.ServerApp;
* </ul>
*/
public class Main {
/**
* Option used to launch server application
*/
private static final String SERVER_ARG_OPTION = "-server";
/**
* Option used to launch server application
*/
private static final String SERVER_ARG_OPTION = "-server";
/**
* Option used to launch client application
*/
private static final String CLIENT_ARG_OPTION = "-client";
/**
* Option used to launch client application
*/
private static final String CLIENT_ARG_OPTION = "-client";
/**
* Main Application entry point
*
* @param args
*/
public static void main(String[] args) {
/**
* If we have an argument, we look for which application to run (server or
* client)
*/
if (args.length > 0) {
if (args[0].equals(SERVER_ARG_OPTION)) {
runServerApp(args);
} else if (args[0].equals(CLIENT_ARG_OPTION)) {
runClientApp(args);
}
} else { // Default application is the client
runClientApp(args);
}
}
/**
* Main Application entry point
*
* @param args
*/
public static void main(String[] args) {
/**
* If we have an argument, we look for which application to run (server or
* client)
*/
if (args.length > 0) {
if (args[0].equals(SERVER_ARG_OPTION)) {
runServerApp(args);
} else if (args[0].equals(CLIENT_ARG_OPTION)) {
runClientApp(args);
}
} else { // Default application is the client
runClientApp(args);
}
}
/**
* Calls the main method of the server application
*
* @param args
*/
private static void runServerApp(String[] args) {
ServerApp.main(args);
}
/**
* Calls the main method of the server application
*
* @param args
*/
private static void runServerApp(String[] args) {
ServerApp.main(args);
}
/**
* Calls the main method of the client application
*
* @param args
*/
private static void runClientApp(String[] args) {
ClientApp.main(args);
}
/**
* Calls the main method of the client application
*
* @param args
*/
private static void runClientApp(String[] args) {
ClientApp.main(args);
}
}
package main.java.client;
import java.io.File;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.stage.Stage;
import main.java.client.data.DataCoreClient;
import main.java.client.game.GameCore;
import main.java.client.main.controller.MainControllerFX;
import main.java.client.main.controller.MainCore;
import main.java.client.network.ComCoreClient;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import java.io.File;
/**
* Main Client application
*/
@SpringBootApplication
public class ClientApp extends Application {
private static final Logger LOGGER = LogManager.getLogger(ClientApp.class);
private static ComCoreClient comCoreClient;
private static DataCoreClient dataCoreClient;
public static MainCore mainCore;
private static GameCore gameCore;
public static final String APPLICATION_NAME = "Othello";
public static final int APPLICATION_WIDTH = 889;
public static final int APPLICATION_HEIGHT = 500;
// css definition
private static final File cssFile = new File("src/baleine/client/main/ressources/main.css");
public static final String CSS_FILE_PATH = "file:///" + ClientApp.cssFile.getAbsolutePath().replace("\\", "/");
public static final String APPLICATION_NAME = "Othello";
public static final int APPLICATION_WIDTH = 889;
public static final int APPLICATION_HEIGHT = 500;
private static final Logger LOGGER = LogManager.getLogger(ClientApp.class);
// css definition
private static final File cssFile = new File("src/baleine/client/main/ressources/main.css");
public static final String CSS_FILE_PATH = "file:///" + ClientApp.cssFile.getAbsolutePath().replace("\\", "/");
public static MainCore mainCore;
private static ComCoreClient comCoreClient;
private static DataCoreClient dataCoreClient;
private static GameCore gameCore;
private ConfigurableApplicationContext springContext;
private Parent rootNode;
private FXMLLoader fxmlLoader;
/**
* Run the client app (JavaFX)
*
* @param args additional args
* @throws Exception TODO: remove once the Websocket is initialized in the
* proper class
*/
public static void main(String[] args) {
LOGGER.debug("ClientApp");
initCores();
// TODO: call this method once user is connected to a server in ihm main.
comCoreClient.initWebSocketConnection("localhost", 8080);
launch(args);
}
/**
* Run the client app (JavaFX)
*
* @param args additional args
* @throws Exception TODO: remove once the Websocket is initialized in the
* proper class
*/
public static void main(String[] args) {
LOGGER.debug("ClientApp");
launch(args);
}
private static void initCores() {
// Com Core
comCoreClient = new ComCoreClient();
private static void initCores() {
// IHM Game Core
gameCore = new GameCore();
// Data Core
dataCoreClient = new DataCoreClient();
// IHM Main Core
mainCore = new MainCore(new MainControllerFX());
// IHM Game Core
gameCore = new GameCore();
dataCoreClient = new DataCoreClient();
comCoreClient = new ComCoreClient();
// IHM Main Core
mainCore = new MainCore(new MainControllerFX());
// Set implementations
dataCoreClient.setDataToCom(comCoreClient.getDataToComClientImpl());
dataCoreClient.setDataToMain(mainCore.getDataToMainImpl());
dataCoreClient.setDataToGame(gameCore.getDataToGame());
comCoreClient.setComToDataClient(dataCoreClient.getClientComToDataImpl());
mainCore.setMainToData(dataCoreClient.getMainToDataImpl());
gameCore.setGameToData(dataCoreClient.getGameToDataImpl());
// TODO missing: gameCore.setGameToData(dataCoreClient.getDataToGameImpl());
}
// Set implementations
dataCoreClient.setDataToCom(comCoreClient.getDataToComClientImpl());
dataCoreClient.setDataToMain(mainCore.getDataToMainImpl());
dataCoreClient.setDataToGame(gameCore.getDataToGame());
comCoreClient.setComToDataClient(dataCoreClient.getClientComToDataImpl());
mainCore.setMainToData(dataCoreClient.getMainToDataImpl());
gameCore.setGameToData(dataCoreClient.getGameToDataImpl());
}
@Override
public void init() {
initCores();
comCoreClient.initWebSocketConnection("localhost", 8080);
}
@Override
public void start(Stage stage) throws Exception {
System.out.println(ClientApp.APPLICATION_NAME + " is starting...");
ClientApp.mainCore.getFX().initialize("../fxml/login.fxml", stage);
}
@Override
public void start(Stage stage) throws Exception {
System.out.println(ClientApp.APPLICATION_NAME + " is starting...");
ClientApp.mainCore.getFX().initialize("../fxml/login.fxml", stage);
}
}
package main.java.client.data;
import java.util.List;
import main.java.common.dataModel.*;
import main.java.common.interfaces.client.*;
import main.java.common.dataModel.Board;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Move;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IComToData;
import main.java.common.interfaces.client.IDataToCom;
import main.java.common.interfaces.client.IDataToGame;
import main.java.common.interfaces.client.IDataToMain;
import main.java.common.interfaces.client.IMainToData;
import java.util.List;
public class DataCoreClient {
private UserHeavy localUserHeavy;
private UserLight localUserLight;
private List<UserLight> listConnectedUsers;
private UserHeavy localUserHeavy;
private UserLight localUserLight;
private List<UserLight> listConnectedUsers;
private List<GameLight> listGameLight;
private List<GameLight> listGameLight;
private MainToDataImpl mainToDataImpl;
private ComToDataClientImpl comToDataClientImpl;
private GameToDataImpl gameToDataImpl;
private MainToDataImpl mainToDataImpl;
private ComToDataClientImpl comToDataClientImpl;
private GameToDataImpl gameToDataImpl;
private IDataToCom dataToCom;
private IDataToMain dataToMain;
private IDataToGame dataToGame;
private IDataToCom dataToCom;
private IDataToMain dataToMain;
private IDataToGame dataToGame;
public DataCoreClient() {
mainToDataImpl = new MainToDataImpl(this);
comToDataClientImpl = new ComToDataClientImpl(this);
gameToDataImpl = new GameToDataImpl(this);
}
public DataCoreClient() {
mainToDataImpl = new MainToDataImpl(this);
comToDataClientImpl = new ComToDataClientImpl(this);
gameToDataImpl = new GameToDataImpl(this);
}
public List<UserLight> getListConnectedUsers() {
return listConnectedUsers;
}
public List<UserLight> getListConnectedUsers() {
return listConnectedUsers;
}
public void setListConnectedUsers(List<UserLight> listConnectedUsers) {
this.listConnectedUsers = listConnectedUsers;
}
public void setListConnectedUsers(List<UserLight> listConnectedUsers) {
this.listConnectedUsers = listConnectedUsers;
}
public UserHeavy getLocalUserHeavy() {
return localUserHeavy;
}
public UserHeavy getLocalUserHeavy() {
return localUserHeavy;
}
public void setLocalUserHeavy(UserHeavy localUserHeavy) {
this.localUserHeavy = localUserHeavy;
}
public void setLocalUserHeavy(UserHeavy localUserHeavy) {
this.localUserHeavy = localUserHeavy;
}
public UserLight getLocalUserLight() {
return localUserLight;
}
public void setLocalUserLight(UserLight localUserLight) {
this.localUserLight = localUserLight;
}
public void setLocalUserLight(UserLight localUserLight) {
this.localUserLight = localUserLight;
}
public IComToData getClientComToDataImpl() {
return comToDataClientImpl;
}
public IComToData getClientComToDataImpl() {
return comToDataClientImpl;
}
public IMainToData getMainToDataImpl() {
return mainToDataImpl;
}
public IMainToData getMainToDataImpl() {
return mainToDataImpl;
}
public IDataToCom getDataToCom() {
return dataToCom;
}
public IDataToCom getDataToCom() {
return dataToCom;
}
public void setDataToCom(IDataToCom dataToCom) {
this.dataToCom = dataToCom;
}
public void setDataToCom(IDataToCom dataToCom) {
this.dataToCom = dataToCom;
}
public void setListGameLight(List<GameLight> listGameLight) {
this.listGameLight = listGameLight;
}
public List<GameLight> getListGameLight() {
return listGameLight;
}
public List<GameLight> getListGameLight() {
return listGameLight;
}
public void setListGameLight(List<GameLight> listGameLight) {
this.listGameLight = listGameLight;
}
private boolean isMoveValid(Move playerMove, Board boardGame) {
return false;
}
private boolean isMoveValid(Move playerMove, Board boardGame) {
return false;
}
public IDataToMain getDataToMain() {
return dataToMain;
}
public IDataToMain getDataToMain() {
return dataToMain;
}
public void setDataToMain(IDataToMain dataToMain) {
this.dataToMain = dataToMain;
}
public void setDataToMain(IDataToMain dataToMain) {
this.dataToMain = dataToMain;
}
public IDataToGame getDataToGame() {
return dataToGame;
}
public IDataToGame getDataToGame() {
return dataToGame;
}
public void setDataToGame(IDataToGame dataToGame) {
this.dataToGame = dataToGame;
}
public void setDataToGame(IDataToGame dataToGame) {
this.dataToGame = dataToGame;
}
public GameToDataImpl getGameToDataImpl() {
return gameToDataImpl;
}
public GameToDataImpl getGameToDataImpl() {
return gameToDataImpl;
}
}
package main.java.client.data;
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.UserZero;
import main.java.common.interfaces.client.IGameToData;
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
public class GameToDataImpl implements IGameToData {
DataCoreClient dataCoreClient;
DataCoreClient dataCoreClient;
public GameToDataImpl(DataCoreClient dataCoreClient) {
this.dataCoreClient = dataCoreClient;
}
public GameToDataImpl(DataCoreClient dataCoreClient) {
this.dataCoreClient = dataCoreClient;
}
@Override
public void playMove(int x, int y, UserZero u) {
@Override
public void playMove(int x, int y, UserZero u) {
}
}
@Override
public void getPlayer(UUID id) {
@Override
public void getPlayer(UUID id) {
}
}
@Override
public void newGameAvailable(GameLight gl) {
dataCoreClient.getDataToCom().addNewGameAvailable(gl);
}
@Override
public void newGameAvailable(GameLight gl) {
dataCoreClient.getDataToCom().addNewGameAvailable(gl);
}
@Override
public void askGame(UUID gameId, UUID userId) {
@Override
public void askGame(UUID gameId, UUID userId) {
}
}
@Override
public void newMessage(String m, UUID gameId) throws Exception {
dataCoreClient.getDataToCom().sendChatMessage(m, new Timestamp(new Date().getTime()),
dataCoreClient.getLocalUserHeavy().getId(), gameId);
}
@Override
public void newMessage(String m, UUID gameId) {
dataCoreClient.getDataToCom()
.sendChatMessage(
new Message(new Timestamp(new Date().getTime()),
m,
dataCoreClient.getLocalUserLight().convertToUserZero()), gameId);
}
}
package main.java.client.data;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javafx.stage.Stage;
import main.java.common.dataModel.*;
import main.java.common.interfaces.client.IMainToData;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
......@@ -11,209 +17,198 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javafx.stage.Stage;
import main.java.common.dataModel.GameHeavy;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.GameStatus;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IMainToData;
public class MainToDataImpl implements IMainToData {
DataCoreClient dataCoreClient;
public MainToDataImpl(DataCoreClient dataCoreClient) {
this.dataCoreClient = dataCoreClient;
}
public static void createUser(UserLight userLight, UserHeavy userHeavy) throws Exception {
String userFilePath = Configuration.SAVE_DIR + File.separator + userLight.getPseudo() + ".json";
File userFile = new File(userFilePath);
if (userFile.exists()) {
throw new Exception("This user already exists on this computer");
}
JsonObject userJson = new JsonObject();
userJson.addProperty("id", userLight.getId().toString());
userJson.addProperty("pseudo", userLight.getPseudo());
userJson.addProperty("lastName", userLight.getLastName());
userJson.addProperty("firstName", userLight.getFirstName());
if (userLight.getDateOfBirth() == null) {
userJson.addProperty("dateOfBirth", (String) null);
} else {
userJson.addProperty("dateOfBirth", new SimpleDateFormat("dd-MM-yyyy").format(userLight.getDateOfBirth()));
}
userJson.addProperty("avatarId", userLight.getAvatarId());
userJson.addProperty("playedGames", userLight.getPlayedGames());
userJson.addProperty("wonGames", userLight.getWonGames());
userJson.addProperty("password", userHeavy.getPassword());
userJson.addProperty("serverAddress", userHeavy.getServerAddress());
userJson.addProperty("serverPort", userHeavy.getServerPort());
userFile.getParentFile().mkdirs();
FileWriter fw = new FileWriter(userFilePath);
fw.write(userJson.toString());
fw.close();
}
@Override
public void selectGames(GameLight g) {
}
@Override
public void acceptanceAcquired(UUID u_id, Boolean validation) {
}
@Override
public Stage newGame(UserLight ul, Boolean spectatorsOk, Boolean chatOk, Boolean creatorPlayWhite, int limitMove,
Stage stageFx) {
GameLight gameCreated = new GameLight(UUID.randomUUID(), ul, null, GameStatus.PENDING, spectatorsOk, chatOk,
creatorPlayWhite, limitMove);
dataCoreClient.getDataToGame().getGameScreen(gameCreated, stageFx);
return stageFx;
}
@Override
public void updatedProfile(UserLight profile) {
}
@Override
public void requestToDataToSpecialGame(GameLight game, UserLight user, Stage stageFx) {
}
@Override
public void sendServerParams(String ip, int port) {
}
@Override
public ArrayList<GameLight> displaySavedGames(UUID id) {
return null;