mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merged with remote changes
This commit is contained in:
@@ -44,12 +44,12 @@ public class HeartbeatThread implements Runnable {
|
|||||||
* The delegate is notified if a player has disconnected
|
* The delegate is notified if a player has disconnected
|
||||||
*/
|
*/
|
||||||
private void sendHeartbeatToAllPlayers(){
|
private void sendHeartbeatToAllPlayers(){
|
||||||
|
try {
|
||||||
Message heartbeat = new Heartbeat(seqNum);
|
Message heartbeat = new Heartbeat(seqNum);
|
||||||
for (Player player : GameState.getPlayers()) {
|
for (Player player : GameState.getPlayers()) {
|
||||||
if (!player.getSocket().isConnected()) {
|
if (!player.getSocket().isConnected()) {
|
||||||
playerLostConnection(player);
|
playerLostConnection(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
player.getSocket().getOutputStream().write(heartbeat.getBuffer());
|
player.getSocket().getOutputStream().write(heartbeat.getBuffer());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -58,6 +58,9 @@ public class HeartbeatThread implements Runnable {
|
|||||||
}
|
}
|
||||||
updateDelegate();
|
updateDelegate();
|
||||||
seqNum++;
|
seqNum++;
|
||||||
|
} catch (NullPointerException ne) {
|
||||||
|
// TODO: 4/09/17 Just ignoring this at the moment. Caused by players getting removed elsewhere.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -234,7 +234,6 @@ public class GameClient {
|
|||||||
|
|
||||||
private void parsePackets() {
|
private void parsePackets() {
|
||||||
while (socketThread.getPacketQueue().peek() != null) {
|
while (socketThread.getPacketQueue().peek() != null) {
|
||||||
System.out.println("PARSING PACKET");
|
|
||||||
StreamPacket packet = socketThread.getPacketQueue().poll();
|
StreamPacket packet = socketThread.getPacketQueue().poll();
|
||||||
switch (packet.getType()) {
|
switch (packet.getType()) {
|
||||||
case RACE_STATUS:
|
case RACE_STATUS:
|
||||||
@@ -298,8 +297,6 @@ public class GameClient {
|
|||||||
case CHATTER_TEXT:
|
case CHATTER_TEXT:
|
||||||
Pair<Integer, String> playerIdMessagePair = StreamParser
|
Pair<Integer, String> playerIdMessagePair = StreamParser
|
||||||
.extractChatterText(packet);
|
.extractChatterText(packet);
|
||||||
|
|
||||||
System.out.println("playerIdMessagePair = " + playerIdMessagePair);
|
|
||||||
raceView.updateChatHistory(
|
raceView.updateChatHistory(
|
||||||
allBoatsMap.get(playerIdMessagePair.getKey()).getColour(),
|
allBoatsMap.get(playerIdMessagePair.getKey()).getColour(),
|
||||||
playerIdMessagePair.getValue()
|
playerIdMessagePair.getValue()
|
||||||
|
|||||||
@@ -574,7 +574,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
|||||||
yachtSelectionComboBox.setItems(
|
yachtSelectionComboBox.setItems(
|
||||||
FXCollections.observableArrayList(participants.values())
|
FXCollections.observableArrayList(participants.values())
|
||||||
);
|
);
|
||||||
//Null check is if the listener is fired but nothing selected
|
|
||||||
yachtSelectionComboBox.valueProperty().addListener((obs, lastSelection, selectedBoat) -> {
|
yachtSelectionComboBox.valueProperty().addListener((obs, lastSelection, selectedBoat) -> {
|
||||||
if (selectedBoat != null) {
|
if (selectedBoat != null) {
|
||||||
gameView.selectBoat(selectedBoat);
|
gameView.selectBoat(selectedBoat);
|
||||||
@@ -677,7 +676,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateChatHistory(Paint playerColour, String newMessage) {
|
public void updateChatHistory(Paint playerColour, String newMessage) {
|
||||||
// Platform.runLater(() -> chatHistory.appendText(newMessage + "\n\n"));
|
|
||||||
Platform.runLater(() -> chatHistory.addMessage(playerColour, newMessage));
|
Platform.runLater(() -> chatHistory.addMessage(playerColour, newMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,18 @@ public class ChatHistory extends ScrollPane {
|
|||||||
this.setMaxWidth(Double.MAX_VALUE);
|
this.setMaxWidth(Double.MAX_VALUE);
|
||||||
this.setVbarPolicy(ScrollBarPolicy.ALWAYS);
|
this.setVbarPolicy(ScrollBarPolicy.ALWAYS);
|
||||||
this.setHbarPolicy(ScrollBarPolicy.NEVER);
|
this.setHbarPolicy(ScrollBarPolicy.NEVER);
|
||||||
textFlow.getChildren().addListener((ListChangeListener<Node>) c -> {
|
//This makes the window auto scroll.
|
||||||
this.setVvalue(1.0);
|
textFlow.getChildren().addListener((ListChangeListener<Node>) c ->
|
||||||
});
|
this.setVvalue(1.0)
|
||||||
|
);
|
||||||
|
//This just makes it so that the ChatHistory is on focus it passes it off to the parent.
|
||||||
|
this.parentProperty().addListener((obs, old, parent) ->
|
||||||
|
this.focusedProperty().addListener((obsVal, oldVal, onFocus) -> {
|
||||||
|
if (onFocus) {
|
||||||
|
parent.requestFocus();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ Feature: SendChat
|
|||||||
Scenario: User send chat to another client
|
Scenario: User send chat to another client
|
||||||
Given The are two games running
|
Given The are two games running
|
||||||
When the user has pressed sends the message "Hello world" in a text box
|
When the user has pressed sends the message "Hello world" in a text box
|
||||||
Then the other client should recieve the message "Hello world"
|
Then the other client should receive the message "Hello world"
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ public class ChatCommandsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendFinishAsHost () {
|
public void sendFinishAsHost () {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
dcSent = false;
|
dcSent = false;
|
||||||
new GameState("localhost");
|
new GameState("localhost");
|
||||||
@@ -39,6 +44,7 @@ public class ChatCommandsTest {
|
|||||||
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
|
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
|
||||||
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
|
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
|
||||||
mst.terminate();
|
mst.terminate();
|
||||||
|
System.out.println("AY WE DID IT");
|
||||||
// host.setSocketToClose();
|
// host.setSocketToClose();
|
||||||
Assert.assertTrue(dcSent);
|
Assert.assertTrue(dcSent);
|
||||||
}
|
}
|
||||||
@@ -76,6 +82,11 @@ public class ChatCommandsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendSpeedAsHostValid () {
|
public void sendSpeedAsHostValid () {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
}
|
||||||
new GameState("localhost");
|
new GameState("localhost");
|
||||||
mst = new MainServerThread();
|
mst = new MainServerThread();
|
||||||
host = null;
|
host = null;
|
||||||
@@ -97,6 +108,7 @@ public class ChatCommandsTest {
|
|||||||
ie.printStackTrace();
|
ie.printStackTrace();
|
||||||
}
|
}
|
||||||
Assert.assertEquals(5.0, GameState.getSpeedMultiplier(), 0.00001);
|
Assert.assertEquals(5.0, GameState.getSpeedMultiplier(), 0.00001);
|
||||||
|
System.out.println("the thing " + GameState.getSpeedMultiplier());
|
||||||
mst.terminate();
|
mst.terminate();
|
||||||
// host.setSocketToClose();
|
// host.setSocketToClose();
|
||||||
try {
|
try {
|
||||||
@@ -111,6 +123,11 @@ public class ChatCommandsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendSpeedAsHostInvalid () {
|
public void sendSpeedAsHostInvalid () {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
}
|
||||||
new GameState("localhost");
|
new GameState("localhost");
|
||||||
mst = new MainServerThread();
|
mst = new MainServerThread();
|
||||||
host = null;
|
host = null;
|
||||||
@@ -134,6 +151,7 @@ public class ChatCommandsTest {
|
|||||||
mst.terminate();
|
mst.terminate();
|
||||||
// host.setSocketToClose();
|
// host.setSocketToClose();
|
||||||
Assert.assertEquals(1.0, GameState.getSpeedMultiplier(), 0.00001);
|
Assert.assertEquals(1.0, GameState.getSpeedMultiplier(), 0.00001);
|
||||||
|
System.out.println("value " + GameState.getSpeedMultiplier());
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
@@ -143,10 +161,12 @@ public class ChatCommandsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendCommandAsClient () {
|
public void sendCommandAsClient () {
|
||||||
new GameState("localhost");
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
}
|
||||||
mst = new MainServerThread();
|
mst = new MainServerThread();
|
||||||
host = null;
|
|
||||||
client = null;
|
|
||||||
try {
|
try {
|
||||||
host = new ClientToServerThread("localhost", 4942);
|
host = new ClientToServerThread("localhost", 4942);
|
||||||
try {
|
try {
|
||||||
@@ -189,13 +209,28 @@ public class ChatCommandsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void receiveFinishedAsClient () {
|
public void receiveFinishedAsClient () {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
}
|
||||||
new GameState("localhost");
|
new GameState("localhost");
|
||||||
dcSent = false;
|
dcSent = false;
|
||||||
mst = new MainServerThread();
|
mst = new MainServerThread();
|
||||||
host = null;
|
host = null;
|
||||||
try {
|
try {
|
||||||
host = new ClientToServerThread("localhost", 4942);
|
host = new ClientToServerThread("localhost", 4942);
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
}
|
||||||
client = new ClientToServerThread("localhost", 4942);
|
client = new ClientToServerThread("localhost", 4942);
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
}
|
||||||
client.addStreamObserver(() -> {
|
client.addStreamObserver(() -> {
|
||||||
while (client.getPacketQueue().peek() != null) {
|
while (client.getPacketQueue().peek() != null) {
|
||||||
StreamPacket packet = client.getPacketQueue().poll();
|
StreamPacket packet = client.getPacketQueue().poll();
|
||||||
@@ -204,6 +239,7 @@ public class ChatCommandsTest {
|
|||||||
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
|
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
|
||||||
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
|
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
|
||||||
mst.terminate();
|
mst.terminate();
|
||||||
|
System.out.println("TEST COMPLETE");
|
||||||
// client.setSocketToClose();
|
// client.setSocketToClose();
|
||||||
// host.setSocketToClose();
|
// host.setSocketToClose();
|
||||||
Assert.assertTrue(dcSent);
|
Assert.assertTrue(dcSent);
|
||||||
@@ -217,25 +253,26 @@ public class ChatCommandsTest {
|
|||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
// try {
|
||||||
Thread.sleep(100);
|
// Thread.sleep(100);
|
||||||
} catch (InterruptedException ie) {
|
// } catch (InterruptedException ie) {
|
||||||
ie.printStackTrace();
|
// ie.printStackTrace();
|
||||||
}
|
// }
|
||||||
mst.startGame();
|
// mst.startGame();
|
||||||
try {
|
// try {
|
||||||
Thread.sleep(100);
|
// Thread.sleep(100);
|
||||||
} catch (InterruptedException ie) {
|
// } catch (InterruptedException ie) {
|
||||||
ie.printStackTrace();
|
// ie.printStackTrace();
|
||||||
}
|
// }
|
||||||
host.sendChatterMessage("[time_prefix] <name_prefix> >finish");
|
host.sendChatterMessage("[time_prefix] <name_prefix> >finish");
|
||||||
dcSent = true;
|
dcSent = true;
|
||||||
try {
|
// try {
|
||||||
Thread.sleep(200);
|
// Thread.sleep(200);
|
||||||
} catch (InterruptedException ie) {
|
// } catch (InterruptedException ie) {
|
||||||
ie.printStackTrace();
|
// ie.printStackTrace();
|
||||||
}
|
// }
|
||||||
// host.setSocketToClose();
|
//// host.setSocketToClose();
|
||||||
|
// mst.terminate();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
|
|||||||
@@ -1,22 +1,10 @@
|
|||||||
package steps;
|
package steps;
|
||||||
|
|
||||||
import cucumber.api.PendingException;
|
|
||||||
import cucumber.api.java.en.Given;
|
import cucumber.api.java.en.Given;
|
||||||
import cucumber.api.java.en.Then;
|
import cucumber.api.java.en.Then;
|
||||||
import cucumber.api.java.en.When;
|
import cucumber.api.java.en.When;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import javafx.scene.layout.Pane;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import seng302.gameServer.GameStages;
|
|
||||||
import seng302.gameServer.GameState;
|
|
||||||
import seng302.gameServer.MainServerThread;
|
import seng302.gameServer.MainServerThread;
|
||||||
import seng302.gameServer.messages.BoatAction;
|
|
||||||
import seng302.model.ServerYacht;
|
|
||||||
import seng302.visualiser.ClientToServerThread;
|
|
||||||
import seng302.visualiser.GameClient;
|
import seng302.visualiser.GameClient;
|
||||||
import seng302.visualiser.controllers.StartScreenController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by kre39 on 7/08/17.
|
* Created by kre39 on 7/08/17.
|
||||||
@@ -44,7 +32,7 @@ public class SendChatSteps {
|
|||||||
// client1.getSocketThread().sendChatterMessage(arg1);
|
// client1.getSocketThread().sendChatterMessage(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Then("^the other client should recieve the message \"([^\"]*)\"$")
|
@Then("^the other client should receive the message \"([^\"]*)\"$")
|
||||||
public void the_other_client_should_recieve_the_message(String arg1) throws Throwable {
|
public void the_other_client_should_recieve_the_message(String arg1) throws Throwable {
|
||||||
// System.out.println(client2.getPacketQueue());
|
// System.out.println(client2.getPacketQueue());
|
||||||
// client2.setSocketToClose();
|
// client2.setSocketToClose();
|
||||||
|
|||||||
Reference in New Issue
Block a user