Added support for easy deployment to offsite server
This commit is contained in:
2
.idea/artifacts/Client_jar.xml
generated
2
.idea/artifacts/Client_jar.xml
generated
@@ -4,7 +4,7 @@
|
|||||||
<root id="root">
|
<root id="root">
|
||||||
<element id="archive" name="Client.jar">
|
<element id="archive" name="Client.jar">
|
||||||
<element id="directory" name="META-INF">
|
<element id="directory" name="META-INF">
|
||||||
<element id="file-copy" path="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" />
|
<element id="file-copy" path="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" output-file-name="singeleServerManifest.MF" />
|
||||||
</element>
|
</element>
|
||||||
<element id="module-output" name="Client" />
|
<element id="module-output" name="Client" />
|
||||||
</element>
|
</element>
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public class TicTacToe_Client extends Application {
|
|||||||
client.sendToServer("update");
|
client.sendToServer("update");
|
||||||
client.sendToServer(String.format("%f|%f", event.getX(), event.getY()));
|
client.sendToServer(String.format("%f|%f", event.getX(), event.getY()));
|
||||||
String gameState = client.getResponse();
|
String gameState = client.getResponse();
|
||||||
|
System.out.println(gameState);
|
||||||
if (gameState.length() == 9) {
|
if (gameState.length() == 9) {
|
||||||
drawBoard(gameState);
|
drawBoard(gameState);
|
||||||
if (!client.getGameEnded()) {
|
if (!client.getGameEnded()) {
|
||||||
@@ -114,16 +115,14 @@ public class TicTacToe_Client extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
client = new Client("localhost", 2589, "TestClient");
|
client = new Client("server", 2589, "Cato");
|
||||||
client.handshake();
|
client.handshake();
|
||||||
|
|
||||||
primaryStage.setTitle("TicTacToe");
|
primaryStage.setTitle("TicTacToe");
|
||||||
primaryStage.setResizable(false);
|
primaryStage.setResizable(false);
|
||||||
|
|
||||||
this.initializeGrid();
|
this.initializeGrid();
|
||||||
|
|
||||||
primaryStage.setScene(this.setScene());
|
primaryStage.setScene(this.setScene());
|
||||||
|
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
|
||||||
this.drawBoard(client.getGameState());
|
this.drawBoard(client.getGameState());
|
||||||
@@ -132,4 +131,5 @@ public class TicTacToe_Client extends Application {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,16 +34,16 @@ public class TicTacToe_Server {
|
|||||||
board = this.convertToNumbers(gameState);
|
board = this.convertToNumbers(gameState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int makeClientMove(String input) {
|
public boolean makeClientMove(String input) {
|
||||||
int column = Double.valueOf(input.split("\\|")[0]).intValue() / 300;
|
int column = Double.valueOf(input.split("\\|")[0]).intValue() / 300;
|
||||||
int row = Double.valueOf(input.split("\\|")[1]).intValue() / 300;
|
int row = Double.valueOf(input.split("\\|")[1]).intValue() / 300;
|
||||||
int index = column * 3 + row;
|
int index = column * 3 + row;
|
||||||
|
|
||||||
if (isLegalMove(column, row)) {
|
if (isLegalMove(column, row)) {
|
||||||
makeMoveOnBoard(index, 0);
|
makeMoveOnBoard(index, 0);
|
||||||
return 200;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return 404;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,16 +81,15 @@ public class MultiPlayerServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ticTacToe_gameloop() {
|
public void ticTacToe_gameloop() {
|
||||||
|
while(clients.size() == 2) {
|
||||||
for (Socket client : clients.values()) {
|
for (Socket client : clients.values()) {
|
||||||
try {
|
try {
|
||||||
while (!client.isClosed()) {
|
|
||||||
String message = instreams.get(client).readUTF();
|
String message = instreams.get(client).readUTF();
|
||||||
serverLogger.printLog(message, clientNames.get(client), LogType.Message);
|
serverLogger.printLog(message, clientNames.get(client), LogType.Message);
|
||||||
outstreams.get(client).writeInt(200);
|
outstreams.get(client).writeInt(200);
|
||||||
outstreams.get(client).flush();
|
outstreams.get(client).flush();
|
||||||
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
||||||
this.gameFlow(message, client);
|
this.gameFlow(message, client);
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
try {
|
try {
|
||||||
@@ -101,6 +100,7 @@ public class MultiPlayerServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void gameFlow(String input, Socket client) {
|
public void gameFlow(String input, Socket client) {
|
||||||
switch (input) {
|
switch (input) {
|
||||||
@@ -121,8 +121,8 @@ public class MultiPlayerServer {
|
|||||||
outstreams.get(client).writeInt(200);
|
outstreams.get(client).writeInt(200);
|
||||||
outstreams.get(client).flush();
|
outstreams.get(client).flush();
|
||||||
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
||||||
int verificationCode = ticTacToe_server.makeClientMove(position);
|
boolean isAllowed = ticTacToe_server.makeClientMove(position);
|
||||||
if (verificationCode == 200) {
|
if (isAllowed) {
|
||||||
String gameState = ticTacToe_server.getGameState();
|
String gameState = ticTacToe_server.getGameState();
|
||||||
outstreams.get(client).writeUTF(gameState);
|
outstreams.get(client).writeUTF(gameState);
|
||||||
outstreams.get(client).flush();
|
outstreams.get(client).flush();
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ public class SinglePlayerServer {
|
|||||||
outstreams.get(client).writeInt(200);
|
outstreams.get(client).writeInt(200);
|
||||||
outstreams.get(client).flush();
|
outstreams.get(client).flush();
|
||||||
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log);
|
||||||
int verificationCode = ticTacToe_server.makeClientMove(position);
|
boolean moveAllowed = ticTacToe_server.makeClientMove(position);
|
||||||
if (verificationCode == 200) {
|
if (moveAllowed) {
|
||||||
String gameState = ticTacToe_server.getGameState();
|
String gameState = ticTacToe_server.getGameState();
|
||||||
outstreams.get(client).writeUTF(gameState);
|
outstreams.get(client).writeUTF(gameState);
|
||||||
outstreams.get(client).flush();
|
outstreams.get(client).flush();
|
||||||
|
|||||||
7
deployment/multiplayer/buildMultiServer.sh
Executable file
7
deployment/multiplayer/buildMultiServer.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
cd /home/cato447/Code/ArcadeMachine/out/production/Server/
|
||||||
|
jar cmvf META-INF/multiServerManifest.MF multiServer.jar *
|
||||||
|
scp multiServer.jar root@server:/root
|
||||||
|
rm multiServer.jar
|
||||||
|
cd /home/cato447/Code/ArcadeMachine/deployment/multiplayer/
|
||||||
|
./startMultiServer.sh
|
||||||
2
deployment/multiplayer/startMultiServer.sh
Executable file
2
deployment/multiplayer/startMultiServer.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
ssh root@server ./startMultiServer.sh
|
||||||
7
deployment/singleplayer/buildSingleServer.sh
Executable file
7
deployment/singleplayer/buildSingleServer.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
cd /home/cato447/Code/ArcadeMachine/out/production/Server/
|
||||||
|
jar cmvf META-INF/MANIFEST.MF singleServer.jar *
|
||||||
|
scp singleServer.jar root@server:/root
|
||||||
|
rm singleServer.jar
|
||||||
|
cd /home/cato447/Code/ArcadeMachine/deployment/singleplayer/
|
||||||
|
./startSingleServer.sh
|
||||||
2
deployment/singleplayer/startSingleServer.sh
Executable file
2
deployment/singleplayer/startSingleServer.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
ssh root@server ./startSingleServer.sh
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Main-Class: client.networking.Client
|
Main-Class: Launcher
|
||||||
|
Class-Path: src.zip javafx-swt.jar javafx.web.jar javafx.base.jar javafx
|
||||||
|
.fxml.jar javafx.media.jar javafx.swing.jar javafx.controls.jar javafx.
|
||||||
|
graphics.jar
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Main-Class: networking.SinglePlayerServer
|
Main-Class: networking.SinglePlayerServer
|
||||||
|
|
||||||
|
|||||||
2
out/production/Server/META-INF/multiServerManifest.MF
Normal file
2
out/production/Server/META-INF/multiServerManifest.MF
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: networking.MultiPlayerServer
|
||||||
@@ -1,3 +1,2 @@
|
|||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Main-Class: networking.SinglePlayerServer
|
Main-Class: networking.SinglePlayerServer
|
||||||
|
|
||||||
Reference in New Issue
Block a user