Commit 569910af authored by alexandre.ducarne's avatar alexandre.ducarne
Browse files

Rebase

parent 1bc6ae89
...@@ -11,53 +11,53 @@ import main.java.server.ServerApp; ...@@ -11,53 +11,53 @@ import main.java.server.ServerApp;
* </ul> * </ul>
*/ */
public class Main { public class Main {
/** /**
* Option used to launch server application * Option used to launch server application
*/ */
private static final String SERVER_ARG_OPTION = "-server"; private static final String SERVER_ARG_OPTION = "-server";
/** /**
* Option used to launch client application * Option used to launch client application
*/ */
private static final String CLIENT_ARG_OPTION = "-client"; private static final String CLIENT_ARG_OPTION = "-client";
/** /**
* Main Application entry point * Main Application entry point
* *
* @param args * @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
/** /**
* If we have an argument, we look for which application to run (server or * If we have an argument, we look for which application to run (server or
* client) * client)
*/ */
if (args.length > 0) { if (args.length > 0) {
if (args[0].equals(SERVER_ARG_OPTION)) { if (args[0].equals(SERVER_ARG_OPTION)) {
runServerApp(args); runServerApp(args);
} else if (args[0].equals(CLIENT_ARG_OPTION)) { } else if (args[0].equals(CLIENT_ARG_OPTION)) {
runClientApp(args); runClientApp(args);
} }
} else { // Default application is the client } else { // Default application is the client
runClientApp(args); runClientApp(args);
} }
} }
/** /**
* Calls the main method of the server application * Calls the main method of the server application
* *
* @param args * @param args
*/ */
private static void runServerApp(String[] args) { private static void runServerApp(String[] args) {
ServerApp.main(args); ServerApp.main(args);
} }
/** /**
* Calls the main method of the client application * Calls the main method of the client application
* *
* @param args * @param args
*/ */
private static void runClientApp(String[] args) { private static void runClientApp(String[] args) {
ClientApp.main(args); ClientApp.main(args);
} }
} }
package main.java.client.data; 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 java.util.List;
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;
public class DataCoreClient { public class DataCoreClient {
private UserHeavy localUserHeavy; private UserHeavy localUserHeavy;
private UserLight localUserLight; private UserLight localUserLight;
private List<UserLight> listConnectedUsers; private List<UserLight> listConnectedUsers;
private List<GameLight> listGameLight; private List<GameLight> listGameLight;
private MainToDataImpl mainToDataImpl; private MainToDataImpl mainToDataImpl;
private ComToDataClientImpl comToDataClientImpl; private ComToDataClientImpl comToDataClientImpl;
private GameToDataImpl gameToDataImpl; private GameToDataImpl gameToDataImpl;
private IDataToCom dataToCom; private IDataToCom dataToCom;
private IDataToMain dataToMain; private IDataToMain dataToMain;
private IDataToGame dataToGame; private IDataToGame dataToGame;
public DataCoreClient() { public DataCoreClient() {
mainToDataImpl = new MainToDataImpl(this); mainToDataImpl = new MainToDataImpl(this);
comToDataClientImpl = new ComToDataClientImpl(this); comToDataClientImpl = new ComToDataClientImpl(this);
gameToDataImpl = new GameToDataImpl(this); gameToDataImpl = new GameToDataImpl(this);
} }
public List<UserLight> getListConnectedUsers() { public List<UserLight> getListConnectedUsers() {
return listConnectedUsers; return listConnectedUsers;
} }
public void setListConnectedUsers(List<UserLight> listConnectedUsers) { public void setListConnectedUsers(List<UserLight> listConnectedUsers) {
this.listConnectedUsers = listConnectedUsers; this.listConnectedUsers = listConnectedUsers;
} }
public UserHeavy getLocalUserHeavy() { public UserHeavy getLocalUserHeavy() {
return localUserHeavy; return localUserHeavy;
} }
public void setLocalUserHeavy(UserHeavy localUserHeavy) { public void setLocalUserHeavy(UserHeavy localUserHeavy) {
this.localUserHeavy = localUserHeavy; this.localUserHeavy = localUserHeavy;
} }
public UserLight getLocalUserLight() { public UserLight getLocalUserLight() {
return localUserLight; return localUserLight;
} }
public void setLocalUserLight(UserLight localUserLight) { public void setLocalUserLight(UserLight localUserLight) {
this.localUserLight = localUserLight; this.localUserLight = localUserLight;
} }
public IComToData getClientComToDataImpl() { public IComToData getClientComToDataImpl() {
return comToDataClientImpl; return comToDataClientImpl;
} }
public IMainToData getMainToDataImpl() { public IMainToData getMainToDataImpl() {
return mainToDataImpl; return mainToDataImpl;
} }
public IDataToCom getDataToCom() { public IDataToCom getDataToCom() {
return dataToCom; return dataToCom;
} }
public void setDataToCom(IDataToCom dataToCom) { public void setDataToCom(IDataToCom dataToCom) {
this.dataToCom = dataToCom; this.dataToCom = dataToCom;
} }
public void setListGameLight(List<GameLight> listGameLight) { public List<GameLight> getListGameLight() {
this.listGameLight = listGameLight; return listGameLight;
} }
public List<GameLight> getListGameLight() { public void setListGameLight(List<GameLight> listGameLight) {
return listGameLight; this.listGameLight = listGameLight;
} }
private boolean isMoveValid(Move playerMove, Board boardGame) { private boolean isMoveValid(Move playerMove, Board boardGame) {
return false; return false;
} }
public IDataToMain getDataToMain() { public IDataToMain getDataToMain() {
return dataToMain; return dataToMain;
} }
public void setDataToMain(IDataToMain dataToMain) { public void setDataToMain(IDataToMain dataToMain) {
this.dataToMain = dataToMain; this.dataToMain = dataToMain;
} }
public IDataToGame getDataToGame() { public IDataToGame getDataToGame() {
return dataToGame; return dataToGame;
} }
public void setDataToGame(IDataToGame dataToGame) { public void setDataToGame(IDataToGame dataToGame) {
this.dataToGame = dataToGame; this.dataToGame = dataToGame;
} }
public GameToDataImpl getGameToDataImpl() { public GameToDataImpl getGameToDataImpl() {
return gameToDataImpl; return gameToDataImpl;
} }
} }
package main.java.client.data; 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.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.UserZero; import main.java.common.dataModel.UserZero;
import main.java.common.interfaces.client.IGameToData; import main.java.common.interfaces.client.IGameToData;
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
public class GameToDataImpl implements IGameToData { public class GameToDataImpl implements IGameToData {
DataCoreClient dataCoreClient; DataCoreClient dataCoreClient;
public GameToDataImpl(DataCoreClient dataCoreClient) { public GameToDataImpl(DataCoreClient dataCoreClient) {
this.dataCoreClient = dataCoreClient; this.dataCoreClient = dataCoreClient;
} }
@Override @Override
public void playMove(int x, int y, UserZero u) { public void playMove(int x, int y, UserZero u) {
} }
@Override @Override
public void getPlayer(UUID id) { public void getPlayer(UUID id) {
} }
@Override @Override
public void newGameAvailable(GameLight gl) { public void newGameAvailable(GameLight gl) {
dataCoreClient.getDataToCom().addNewGameAvailable(gl); dataCoreClient.getDataToCom().addNewGameAvailable(gl);
} }
@Override @Override
public void askGame(UUID gameId, UUID userId) { public void askGame(UUID gameId, UUID userId) {
} }
@Override @Override
public void newMessage(String m, UUID gameId) throws Exception { public void newMessage(String m, UUID gameId) {
dataCoreClient.getDataToCom().sendChatMessage(m, new Timestamp(new Date().getTime()), dataCoreClient.getDataToCom()
dataCoreClient.getLocalUserHeavy().getId(), gameId); .sendChatMessage(
} new Message(new Timestamp(new Date().getTime()),
m,
dataCoreClient.getLocalUserLight().convertToUserZero()), gameId);
}
} }
package main.java.client.data; 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.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
...@@ -11,209 +17,198 @@ import java.util.ArrayList; ...@@ -11,209 +17,198 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.UUID; 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 { public class MainToDataImpl implements IMainToData {
DataCoreClient dataCoreClient; DataCoreClient dataCoreClient;
public MainToDataImpl(DataCoreClient dataCoreClient) { public MainToDataImpl(DataCoreClient dataCoreClient) {
this.dataCoreClient = dataCoreClient; this.dataCoreClient = dataCoreClient;
} }
public static void createUser(UserLight userLight, UserHeavy userHeavy) throws Exception { public static void createUser(UserLight userLight, UserHeavy userHeavy) throws Exception {
String userFilePath = Configuration.SAVE_DIR + File.separator + userLight.getPseudo() + ".json"; String userFilePath = Configuration.SAVE_DIR + File.separator + userLight.getPseudo() + ".json";
File userFile = new File(userFilePath); File userFile = new File(userFilePath);
if (userFile.exists()) { if (userFile.exists()) {
throw new Exception("This user already exists on this computer"); throw new Exception("This user already exists on this computer");
} }
JsonObject userJson = new JsonObject(); JsonObject userJson = new JsonObject();
userJson.addProperty("id", userLight.getId().toString()); userJson.addProperty("id", userLight.getId().toString());
userJson.addProperty("pseudo", userLight.getPseudo()); userJson.addProperty("pseudo", userLight.getPseudo());
userJson.addProperty("lastName", userLight.getLastName()); userJson.addProperty("lastName", userLight.getLastName());
userJson.addProperty("firstName", userLight.getFirstName()); userJson.addProperty("firstName", userLight.getFirstName());
if (userLight.getDateOfBirth() == null) { if (userLight.getDateOfBirth() == null) {
userJson.addProperty("dateOfBirth", (String) null); userJson.addProperty("dateOfBirth", (String) null);
} else { } else {
userJson.addProperty("dateOfBirth", new SimpleDateFormat("dd-MM-yyyy").format(userLight.getDateOfBirth())); userJson.addProperty("dateOfBirth", new SimpleDateFormat("dd-MM-yyyy").format(userLight.getDateOfBirth()));
} }
userJson.addProperty("avatarId", userLight.getAvatarId()); userJson.addProperty("avatarId", userLight.getAvatarId());
userJson.addProperty("playedGames", userLight.getPlayedGames()); userJson.addProperty("playedGames", userLight.getPlayedGames());
userJson.addProperty("wonGames", userLight.getWonGames()); userJson.addProperty("wonGames", userLight.getWonGames());
userJson.addProperty("password", userHeavy.getPassword()); userJson.addProperty("password", userHeavy.getPassword());
userJson.addProperty("serverAddress", userHeavy.getServerAddress()); userJson.addProperty("serverAddress", userHeavy.getServerAddress());
userJson.addProperty("serverPort", userHeavy.getServerPort()); userJson.addProperty("serverPort", userHeavy.getServerPort());
userFile.getParentFile().mkdirs(); userFile.getParentFile().mkdirs();
FileWriter fw = new FileWriter(userFilePath); FileWriter fw = new FileWriter(userFilePath);
fw.write(userJson.toString()); fw.write(userJson.toString());
fw.close(); fw.close();
} }
@Override @Override
public void selectGames(GameLight g) { public void selectGames(GameLight g) {
} }
@Override @Override
public void acceptanceAcquired(UUID u_id, Boolean validation) { public void acceptanceAcquired(UUID u_id, Boolean validation) {
} }
@Override @Override
public Stage newGame(UserLight ul, Boolean spectatorsOk, Boolean chatOk, Boolean creatorPlayWhite, int limitMove, public Stage newGame(UserLight ul, Boolean spectatorsOk, Boolean chatOk, Boolean creatorPlayWhite, int limitMove,
Stage stageFx) { Stage stageFx) {
GameLight gameCreated = new GameLight(UUID.randomUUID(), ul, null, GameStatus.PENDING, spectatorsOk, chatOk, GameLight gameCreated = new GameLight(UUID.randomUUID(), ul, null, GameStatus.PENDING, spectatorsOk, chatOk,
creatorPlayWhite, limitMove); creatorPlayWhite, limitMove);
dataCoreClient.getDataToGame().getGameScreen(gameCreated, stageFx); dataCoreClient.getDataToGame().getGameScreen(gameCreated, stageFx);
return stageFx; return stageFx;
} }
@Override @Override
public void updatedProfile(UserLight profile) { public void updatedProfile(UserLight profile) {
} }
@Override @Override
public void requestToDataToSpecialGame(GameLight game, UserLight user, Stage stageFx) { public void requestToDataToSpecialGame(GameLight game, UserLight user, Stage stageFx) {
} }
@Override @Override
public void sendServerParams(String ip, int port) { public void sendServerParams(String ip, int port) {
} }
@Override @Override
public ArrayList<GameLight> displaySavedGames(UUID id) { public ArrayList<GameLight> displaySavedGames(UUID id) {
return null; return null;
} }
@Override @Override
public GameHeavy getSavedGame(UUID id) { public GameHeavy getSavedGame(UUID id) {
return null; return null;
} }
@Override @Override
public void sendUserInfo(String pseudo, String lastName, String firstName, Date dateOfBirth, int avatarId, public void sendUserInfo(String pseudo, String lastName, String firstName, Date dateOfBirth, int avatarId,
String password) throws Exception { String password) throws Exception {
if (lastName == null || firstName == null || password == null) { if (lastName == null || firstName == null || password == null) {
throw new Exception("One or more required field is empty"); throw new Exception("One or more required field is empty");
} }
UUID id = UUID.randomUUID(); UUID id = UUID.randomUUID();
createUser(new UserLight(id, pseudo, lastName, firstName, dateOfBirth, avatarId, 0, 0), createUser(new UserLight(id, pseudo, lastName, firstName, dateOfBirth, avatarId, 0, 0),
new UserHeavy(id, pseudo, password, null, null, null)); new UserHeavy(id, pseudo, password, null, null, null));
} }
@Override @Override
public void downloadUserProfile(String filePath) { public void downloadUserProfile(String filePath) {
} }
@Override @Override
public void updateProfile(UserLight profileLight, UserHeavy profileHeavy) throws Exception { public void updateProfile(UserLight profileLight, UserHeavy profileHeavy) throws Exception {
String userFilePath = Configuration.SAVE_DIR + File.separator + dataCoreClient.getLocalUserHeavy().getPseudo()