Added support for easy deployment to offsite server

This commit is contained in:
2021-02-28 05:01:54 +01:00
parent 81c17b2cc1
commit bc0345f061
13 changed files with 65 additions and 44 deletions

View File

@@ -81,22 +81,22 @@ public class MultiPlayerServer {
}
public void ticTacToe_gameloop() {
for (Socket client : clients.values()) {
try {
while (!client.isClosed()) {
String message = instreams.get(client).readUTF();
serverLogger.printLog(message, clientNames.get(client), LogType.Message);
outstreams.get(client).writeInt(200);
outstreams.get(client).flush();
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
this.gameFlow(message, client);
}
} catch (IOException e) {
e.printStackTrace();
while(clients.size() == 2) {
for (Socket client : clients.values()) {
try {
client.close();
} catch (IOException ioException) {
ioException.printStackTrace();
String message = instreams.get(client).readUTF();
serverLogger.printLog(message, clientNames.get(client), LogType.Message);
outstreams.get(client).writeInt(200);
outstreams.get(client).flush();
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
this.gameFlow(message, client);
} catch (IOException e) {
e.printStackTrace();
try {
client.close();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
}
@@ -121,8 +121,8 @@ public class MultiPlayerServer {
outstreams.get(client).writeInt(200);
outstreams.get(client).flush();
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
int verificationCode = ticTacToe_server.makeClientMove(position);
if (verificationCode == 200) {
boolean isAllowed = ticTacToe_server.makeClientMove(position);
if (isAllowed) {
String gameState = ticTacToe_server.getGameState();
outstreams.get(client).writeUTF(gameState);
outstreams.get(client).flush();

View File

@@ -121,8 +121,8 @@ public class SinglePlayerServer {
outstreams.get(client).writeInt(200);
outstreams.get(client).flush();
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
int verificationCode = ticTacToe_server.makeClientMove(position);
if (verificationCode == 200) {
boolean moveAllowed = ticTacToe_server.makeClientMove(position);
if (moveAllowed) {
String gameState = ticTacToe_server.getGameState();
outstreams.get(client).writeUTF(gameState);
outstreams.get(client).flush();