Created a new chat history class that allows for rich formatting of individual messages. Current implementation allows for bold and coloured text only. Has been manually tested. Fixed 3/5 chat command tests.

#implement #test #story[1246]
This commit is contained in:
Calum
2017-09-04 23:10:54 +12:00
parent 5026c568a7
commit 47f3f6e27d
9 changed files with 220 additions and 180 deletions
@@ -698,7 +698,6 @@ public class GameState implements Runnable {
public static void endRace () {
yachts.forEach((id, yacht) -> yacht.setBoatStatus(BoatStatus.FINISHED));
currentStage = GameStages.FINISHED;
System.out.println("FOR FUCKS SAKE YOU FUCKING DEGENERATE");
}
public static void setSpeedMultiplier (double multiplier) {
@@ -61,7 +61,6 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
//You should handle interrupts in some way, so that the thread won't keep on forever if you exit the app.
while (!terminated) {
System.out.println("CUNT GF" + GameState.getCurrentStage());
try {
Thread.sleep(1000 / CLIENT_UPDATES_PER_SECOND);
} catch (InterruptedException e) {
@@ -88,9 +87,8 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
//FINISHED
else if (GameState.getCurrentStage() == GameStages.FINISHED) {
broadcastMessage(makeRaceStatusMessage());
System.out.println("BUT I WAS HERE CUNTFACE");
try {
Thread.sleep(100); //Hackish fix to make sure all threads have broadcasted
Thread.sleep(1000); //Hackish fix to make sure all threads have sent closing RaceStatus
terminate();
} catch (InterruptedException ie) {
serverLog("Thread interrupted while waiting to terminate clients", 1);
@@ -102,7 +100,6 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
serverToClientThread.terminate();
}
serverSocket.close();
System.out.println("closed");
} catch (IOException e) {
System.out.println("IO error in server thread handler upon closing socket");
}
@@ -245,7 +242,6 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
for (Player player : GameState.getPlayers()) {
ServerYacht y = player.getYacht();
System.out.println(y.getBoatStatus());
BoatSubMessage m = new BoatSubMessage(y.getSourceId(), y.getBoatStatus(),
y.getLegNumber(),
0, 0, 1234L,
@@ -268,7 +264,6 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
raceStatus = RaceStatus.PREPARATORY;
}
} else if (GameState.getCurrentStage() == GameStages.FINISHED) {
System.out.println("WHAT THE FUCKING FUCK");
raceStatus = RaceStatus.TERMINATED;
} else {
raceStatus = RaceStatus.STARTED;
@@ -281,7 +276,6 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
}
public void terminate() {
System.out.println("done");
terminated = true;
}
@@ -386,9 +386,6 @@ public class ServerToClientThread implements Runnable, Observer {
Arrays.copyOfRange(chatterPayload, 3, 3 + chatterPayload.length)
);
String[] words = chatterText.split("\\s+");
for (String s : words) {
System.out.println(s);
}
if (words.length > 2 && isHost) {
switch (words[2].trim()) {
case ">speed":
@@ -396,19 +393,18 @@ public class ServerToClientThread implements Runnable, Observer {
GameState.setSpeedMultiplier(Double.valueOf(words[3]));
GameState.broadcastChatter(new ChatterMessage(
Byte.toUnsignedInt(chatterPayload[1]),
words[0] + "Host has set speed modifier to x" + words[3]
"SERVER: Speed modifier set to x" + words[3]
));
} catch (Exception e) {
logger.error("cannot parse >speed value");
}
return;
case ">finish":
System.out.println(words[2].trim());
GameState.endRace();
GameState.broadcastChatter(new ChatterMessage(
chatterPayload[1],
words[0] + "Host has ended the game"
"SERVER: Game will now finish"
));
GameState.endRace();
return;
}
}
@@ -26,7 +26,6 @@ import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Slider;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
@@ -50,6 +49,7 @@ import seng302.visualiser.controllers.annotations.ImportantAnnotationController;
import seng302.visualiser.controllers.annotations.ImportantAnnotationDelegate;
import seng302.visualiser.controllers.annotations.ImportantAnnotationsState;
import seng302.visualiser.fxObjects.BoatObject;
import seng302.visualiser.fxObjects.ChatHistory;
/**
* Controller class that manages the display of a race
@@ -63,7 +63,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
@FXML
private Button chatSend;
@FXML
private TextArea chatHistory;
private Pane chatHistoryHolder;
@FXML
private TextField chatInput;
@FXML
@@ -98,6 +98,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private GameView gameView;
private RaceState raceState;
private ChatHistory chatHistory;
private Timeline timerTimeline;
private Timer timer = new Timer();
private List<Series<String, Double>> sparkLineData = new ArrayList<>();
@@ -122,9 +124,19 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
chatInput.setText(chatInput.getText().substring(0, CHAT_LIMIT));
}
});
chatHistory.textProperty().addListener((obs, oldValue, newValue) -> {
chatHistory.setScrollTop(Double.MAX_VALUE);
});
chatHistory = new ChatHistory();
chatHistoryHolder.getChildren().addAll(chatHistory);
chatHistory.prefWidthProperty().bind(
chatHistoryHolder.widthProperty()
);
chatHistory.prefHeightProperty().bind(
chatHistoryHolder.heightProperty()
);
// chatHistory.setFitToWidth(true);
// chatHistory.setFitToHeight(true);
// chatHistory.textProperty().addListener((obs, oldValue, newValue) -> {
// chatHistory.setScrollTop(Double.MAX_VALUE);
// });
}
public void loadRace (
@@ -136,12 +148,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
this.markers = raceData.getCompoundMarks();
this.raceState = raceState;
initializeUpdateTimer();
initialiseFPSCheckBox();
initialiseAnnotationSlider();
initialiseBoatSelectionComboBox();
initialiseSparkLine();
raceState.getPlayerPositions().addListener((ListChangeListener<ClientYacht>) c -> {
while (c.next()) {
if (c.wasPermutated()) {
@@ -181,6 +187,12 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
gameView.enableZoom();
}
});
initializeUpdateTimer();
initialiseFPSCheckBox();
initialiseAnnotationSlider();
initialiseBoatSelectionComboBox();
initialiseSparkLine();
}
/**
@@ -665,7 +677,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
}
public void updateChatHistory(Paint playerColour, String newMessage) {
Platform.runLater(() -> chatHistory.appendText(newMessage + "\n\n"));
// Platform.runLater(() -> chatHistory.appendText(newMessage + "\n\n"));
Platform.runLater(() -> chatHistory.addMessage(playerColour, newMessage));
}
}
@@ -10,8 +10,6 @@ import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import seng302.gameServer.GameState;
import seng302.visualiser.GameClient;
/**
@@ -23,111 +21,32 @@ public class StartScreenController implements Initializable {
@FXML
private TextField ipTextField;
@FXML
private TextField portTextField;
@FXML
private GridPane startScreen2;
@FXML
private AnchorPane holder;
GameClient gameClient;
private GameClient gameClient;
public void initialize(URL url, ResourceBundle resourceBundle) {
// gameClient = new GameClient(holder);
}
//
// /**
// * Loads the fxml content into the parent pane
// * @param jfxUrl
// * @return the controller of the fxml
// */
// private Object setContentPane(String jfxUrl) {
// try {
// AnchorPane contentPane = (AnchorPane) startScreen2.getParent();
// contentPane.getChildren().removeAll();
// contentPane.getChildren().clear();
// contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
// FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(jfxUrl));
// contentPane.getChildren().addAll((Pane) fxmlLoader.load());
//
// return fxmlLoader.getController();
// } catch (IOException e) {
// e.printStackTrace();
// }
// return null;
// }
}
/**
* ATTEMPTS TO:
* Sets up a new game state with your IP address as designated as the host.
* Starts a thread to listen for incoming connections.
* Starts a client to server thread and connects to own ip.
* Switches to the lobby screen
* Creates an instance of GameClient and runs it as a host.
*/
@FXML
public void hostButtonPressed() {
// new GameState(getLocalHostIp());
gameClient = new GameClient(holder);
gameClient.runAsHost(getLocalHostIp(), 4942);
// try {
//// String ipAddress = InetAddress.getLocalHost().getHostAddress();
//// new GameState(ipAddress);
//// new MainServerThread();
//// ClientToServerThread clientToServerThread = new ClientToServerThread("localhost", 4950);
//// controller.setClientToServerThread(clientToServerThread);
// // get the lobby controller so that we can pass the game server thread to it
// new GameState(getLocalHostIp());
// MainServerThread mainServerThread = new MainServerThread();
//// ClientState.setHost(true);
// // host will connect and handshake to itself after setting up the server
// // TODO: 24/07/17 wmu16 - Make port number some static global type constant?
//// ClientToServerThread clientToServerThread = new ClientToServerThread(ClientState.getHostIp(), 4942);
//// ClientState.setConnectedToHost(true);
//// controller.setClientToServerThread(clientToServerThread);
// LobbyController lobbyController = (LobbyController) setContentPane("/views/LobbyView.fxml");
// lobbyController.setMainServerThread(mainServerThread);
// } catch (Exception e) {
// Alert alert = new Alert(AlertType.ERROR);
// alert.setHeaderText("Cannot host");
// alert.setContentText("Oops, failed to host, try to restart.");
// alert.showAndWait();
// e.printStackTrace();
// }
}
/**
* ATTEMPTS TO:
* Connect to an ip address and port using the ip and port specified on start screen.
* Starts a Client To Server Thread to maintain connection to host.
* Switch view to lobby view.
* Creates an instance of GameClient and runs it has a client.
*/
@FXML
public void connectButtonPressed() {
// TODO: 10/07/17 wmu16 - Finish function
gameClient = new GameClient(holder);
gameClient.runAsClient(ipTextField.getText().trim().toLowerCase(), 4942);
// try {
// String ipAddress = ipTextField.getText().trim().toLowerCase();
// Integer port = Integer.valueOf(portTextField.getText().trim());
//
//// ClientToServerThread clientToServerThread = new ClientToServerThread(ipAddress, port);
//// ClientState.setHost(false);
//// ClientState.setConnectedToHost(true);
//
//// controller.setClientToServerThread(clientToServerThread);
//// setContentPane("/views/LobbyView.fxml");
// } catch (Exception e) {
// Alert alert = new Alert(AlertType.ERROR);
// alert.setHeaderText("Cannot reach the host");
// alert.setContentText("Please check your host IP address.");
// alert.showAndWait();
// }
}
// public void setController(Controller controller) {
// this.controller = controller;
// }
/**
* Gets the local host ip address and sets this ip to ClientState.
@@ -162,7 +81,6 @@ public class StartScreenController implements Initializable {
if (ipAddress == null) {
System.out.println("[HOST] Cannot obtain local host ip address.");
}
// ClientState.setHostIp(ipAddress);
return ipAddress;
}
}
@@ -0,0 +1,59 @@
package seng302.visualiser.fxObjects;
import java.util.Arrays;
import javafx.collections.ListChangeListener;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.paint.Paint;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
/**
* Extension of a ScrollPane that contains a TextFlow. Has an addMessage() function to parse and
* display chatter text.
*/
public class ChatHistory extends ScrollPane {
private TextFlow textFlow = new TextFlow();
public ChatHistory() {
this.setContent(textFlow);
this.setFitToWidth(true);
this.setFitToHeight(true);
this.setMaxHeight(Double.MAX_VALUE);
this.setMaxWidth(Double.MAX_VALUE);
this.setVbarPolicy(ScrollBarPolicy.ALWAYS);
this.setHbarPolicy(ScrollBarPolicy.NEVER);
textFlow.getChildren().addListener((ListChangeListener<Node>) c -> {
this.setVvalue(1.0);
});
}
/**
* Adds a message to chat history. Messages should be either of the form:
* "[HH:MM:ss] \<player_name\>: \<message_text\>" or
* "SERVER: \<message_text\>"
* @param colour The colour of the user sending the message
* @param Text The chatter text message to be displayed
*/
public void addMessage (Paint colour, String Text) {
String[] words = Text.split(":");
if (words[0].trim().equals("SERVER")) {
Text text = new Text(Text + "\n\n");
text.setStyle("-fx-font-weight: bolder");
textFlow.getChildren().add(text);
} else {
Text timePlayer = new Text(
String.join(":", Arrays.copyOfRange(words, 0, 3)) + ":"
);
timePlayer.setStyle("-fx-font-weight: bold");
timePlayer.setFill(colour);
Text message = new Text(
String.join(":", Arrays.copyOfRange(words, 3, words.length)) + "\n\n"
);
message.wrappingWidthProperty().bind(this.widthProperty());
textFlow.getChildren().addAll(timePlayer, message);
}
}
}
+13 -32
View File
@@ -9,47 +9,29 @@
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="998.0" prefWidth="1530.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.RaceViewController">
<children>
<AnchorPane fx:id="basePane" layoutX="322.0" layoutY="130.0" prefHeight="998.0"
prefWidth="1281.0" style="-fx-background-color: skyblue;" AnchorPane.bottomAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<AnchorPane fx:id="basePane" layoutX="322.0" layoutY="130.0" prefHeight="998.0" prefWidth="1281.0" style="-fx-background-color: skyblue;" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<GridPane prefHeight="998.0" prefWidth="1281.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<GridPane prefHeight="998.0" prefWidth="1281.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="630.0" minWidth="10.0"
prefWidth="68.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1213.0" minWidth="10.0"
prefWidth="1213.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="630.0" minWidth="10.0" prefWidth="68.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1213.0" minWidth="10.0" prefWidth="1213.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="489.0" minHeight="1.0" prefHeight="24.0"
vgrow="SOMETIMES"/>
<RowConstraints maxHeight="997.0" minHeight="10.0" prefHeight="974.0"
vgrow="SOMETIMES"/>
<RowConstraints maxHeight="489.0" minHeight="1.0" prefHeight="24.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="997.0" minHeight="10.0" prefHeight="974.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<AnchorPane fx:id="contentAnchorPane" prefHeight="200.0" prefWidth="200.0"
GridPane.columnSpan="2" GridPane.rowSpan="2">
<AnchorPane fx:id="contentAnchorPane" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowSpan="2">
<children>
<AnchorPane layoutX="799.0" layoutY="770.0" prefHeight="214.0"
prefWidth="468.0">
<AnchorPane layoutX="799.0" layoutY="770.0" prefHeight="214.0" prefWidth="468.0">
<children>
<VBox prefHeight="214.0" prefWidth="468.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<VBox prefHeight="214.0" prefWidth="468.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<TextArea fx:id="chatHistory" editable="false"
focusTraversable="false" wrapText="true"
VBox.vgrow="ALWAYS"/>
<Pane fx:id="chatHistoryHolder" maxHeight="9.9999999999E10" maxWidth="1.7976931348623157E308" prefHeight="9.9999999999E10" />
<HBox VBox.vgrow="NEVER">
<children>
<TextField fx:id="chatInput"
focusTraversable="false" prefHeight="25.0"
HBox.hgrow="ALWAYS"/>
<Button fx:id="chatSend"
focusTraversable="false"
mnemonicParsing="false" text="Send"/>
<TextField fx:id="chatInput" focusTraversable="false" prefHeight="25.0" HBox.hgrow="ALWAYS" />
<Button fx:id="chatSend" focusTraversable="false" mnemonicParsing="false" text="Send" />
</children>
</HBox>
</children>
@@ -58,8 +40,7 @@
</AnchorPane>
</children>
</AnchorPane>
<Text fx:id="fpsDisplay" strokeType="OUTSIDE" strokeWidth="0.0" text="60 FPS"
GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
<Text fx:id="fpsDisplay" strokeType="OUTSIDE" strokeWidth="0.0" text="60 FPS" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
</children>
</GridPane>
</children>
@@ -0,0 +1 @@
Feature: Sending chatter packets over the web.
@@ -19,25 +19,28 @@ public class ChatCommandsTest {
// @Rule
// public Timeout globalTimeout = new Timeout(3, TimeUnit.SECONDS);
private boolean dcSent = false;
private ClientToServerThread client;
private ClientToServerThread host;
private MainServerThread mst;
@Test
public void sendFinishAsHost () {
try {
final MainServerThread mst = new MainServerThread();
final ClientToServerThread host = new ClientToServerThread("localhost", 4942);
dcSent = false;
new GameState("localhost");
mst = new MainServerThread();
host = new ClientToServerThread("localhost", 4942);
host.addStreamObserver(() -> {
while (host.getPacketQueue().peek() != null) {
StreamPacket packet = host.getPacketQueue().poll();
switch (packet.getType()) {
case RACE_STATUS:
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
System.out.println("yas");
System.out.println(rsd.getBoatData().get(0)[4]);
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
System.out.println("why tho");
System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAA");
mst.terminate();
host.setSocketToClose();
Assert.assertTrue(true);
// host.setSocketToClose();
Assert.assertTrue(dcSent);
}
break;
default:
@@ -45,13 +48,27 @@ public class ChatCommandsTest {
}
}
});
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.startGame();
try {
Thread.sleep(1000);
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
host.sendChatterMessage("[time_prefix] <name_prefix> >finish");
dcSent = true;
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
host = null;
client = null;
mst = null;
} catch (IOException ioe) {
ioe.printStackTrace();
}
@@ -59,76 +76,126 @@ public class ChatCommandsTest {
@Test
public void sendSpeedAsHostValid () {
MainServerThread mst = new MainServerThread();
ClientToServerThread host = null;
new GameState("localhost");
mst = new MainServerThread();
host = null;
try {
host = new ClientToServerThread("localhost", 4942);
} catch (IOException ioe) {
ioe.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.startGame();
host.sendChatterMessage("[time_prefix] <name_prefix> >speed 5.0");
try {
Thread.sleep(1000);
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.terminate();
host.setSocketToClose();
Assert.assertEquals(5.0, GameState.getSpeedMultiplier(), 0.00001);
mst.terminate();
// host.setSocketToClose();
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
host = null;
client = null;
mst = null;
}
@Test public void sendSpeedAsHostInvalid () {
MainServerThread mst = new MainServerThread();
ClientToServerThread host = null;
@Test
public void sendSpeedAsHostInvalid () {
new GameState("localhost");
mst = new MainServerThread();
host = null;
try {
host = new ClientToServerThread("localhost", 4942);
} catch (IOException ioe) {
ioe.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.startGame();
host.sendChatterMessage("[time_prefix] <name_prefix> >speed fdgdgdfg");
try {
Thread.sleep(1000);
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.terminate();
host.setSocketToClose();
// host.setSocketToClose();
Assert.assertEquals(1.0, GameState.getSpeedMultiplier(), 0.00001);
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
@Test
public void sendFinishAsClient () {
MainServerThread mst = new MainServerThread();
ClientToServerThread host = null;
ClientToServerThread client = null;
public void sendCommandAsClient () {
new GameState("localhost");
mst = new MainServerThread();
host = null;
client = null;
try {
host = new ClientToServerThread("localhost", 4942);
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
client = new ClientToServerThread("localhost", 4942);
System.out.println("done client and host assigning");
} catch (IOException ioe) {
ioe.printStackTrace();
}
mst.startGame();
client.sendChatterMessage("[time_prefix] <name_prefix> >speed 5.0");
try {
Thread.sleep(1000);
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.startGame();
try {
Thread.sleep(200);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
client.sendChatterMessage("[time_prefix] <name_prefix> >speed 5.0");
try {
Thread.sleep(200);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
Assert.assertEquals(1.0, GameState.getSpeedMultiplier(), 0.00001);
mst.terminate();
host.setSocketToClose();
client.setSocketToClose();
Assert.assertEquals(1.0, GameState.getSpeedMultiplier(), 0.00001);
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
@Test
public void receiveFinishedAsClient () {
MainServerThread mst = new MainServerThread();
ClientToServerThread host = null;
new GameState("localhost");
dcSent = false;
mst = new MainServerThread();
host = null;
try {
host = new ClientToServerThread("localhost", 4942);
ClientToServerThread client = new ClientToServerThread("localhost", 4942);
client = new ClientToServerThread("localhost", 4942);
client.addStreamObserver(() -> {
while (client.getPacketQueue().peek() != null) {
StreamPacket packet = client.getPacketQueue().poll();
@@ -137,8 +204,9 @@ public class ChatCommandsTest {
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
mst.terminate();
client.setSocketToClose();
Assert.assertTrue(true);
// client.setSocketToClose();
// host.setSocketToClose();
Assert.assertTrue(dcSent);
}
break;
default:
@@ -149,18 +217,29 @@ public class ChatCommandsTest {
} catch (IOException ioe) {
ioe.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.startGame();
try {
Thread.sleep(1000);
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
host.sendChatterMessage("[time_prefix] <name_prefix> >finish");
dcSent = true;
try {
Thread.sleep(1000);
Thread.sleep(200);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
// host.setSocketToClose();
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
host.setSocketToClose();
}
}