Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Calum
2017-09-28 16:17:27 +13:00
11 changed files with 134 additions and 79 deletions
@@ -19,7 +19,7 @@ import java.util.Timer;
import java.util.TimerTask;
public class DiscoveryServerClient {
private final Integer UPDATE_INTERVAL_MS = 700;
private final Integer UPDATE_INTERVAL_MS = 1000;
private static String roomCode = null;
private Timer serverListingUpdateTimer;
@@ -26,6 +26,7 @@ import seng302.utilities.GeoUtility;
public class MainServerThread implements Runnable, ClientConnectionDelegate {
private static final int PORT = 4942;
private static int selectedPort = PORT;
private static final Integer CLIENT_UPDATES_PER_SECOND = 60;
private Logger logger = LoggerFactory.getLogger(MainServerThread.class);
private boolean terminated;
@@ -40,7 +41,8 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
public MainServerThread() {
new GameState();
try {
serverSocket = new ServerSocket(PORT);
serverSocket = new ServerSocket(0);
selectedPort = serverSocket.getLocalPort();
} catch (IOException e) {
logger.trace("IO error in server thread handler upon trying to make new server socket",
0);
@@ -66,7 +68,7 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
.setMapName(regattaXMLData.getCourseName())
.setCapacity(capacity)
.setNumberOfPlayers(numPlayers - 1)
.registerGame(PORT, regattaXMLData.getRegattaName());
.registerGame(selectedPort, regattaXMLData.getRegattaName());
} catch (IOException e) {
logger.warn("Could not register server");
}
@@ -346,4 +348,8 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
public boolean hasStarted() {
return hasStarted;
}
public int getPortNumber() {
return selectedPort;
}
}
@@ -143,7 +143,7 @@ public class GameClient {
}
try {
startClientToServerThread("localhost", 4942);
startClientToServerThread("localhost", server.getPortNumber());
} catch (IOException e) {
showConnectionError("Cannot connect to server as host");
}
@@ -177,9 +177,11 @@ public class GameClient {
this.lobbyController = ViewManager.getInstance().goToLobby(false);
lobbyController.setPortNumber(""+server.getPortNumber());
ViewManager.getInstance().setPlayerList(clientLobbyList);
return new ServerDescription(serverName, regattaData.getCourseName(), GameState.getNumberOfPlayers(), GameState.getCapacity(),
"localhost", 4942);
"localhost", server.getPortNumber());
}
private void tearDownConnection() {
@@ -35,7 +35,7 @@ public class MapMaker {
private XMLGenerator xmlGenerator = new XMLGenerator();
private List<String> maps = new ArrayList<>(
Arrays.asList("default.xml", "horseshoe.xml", "loop.xml", "madagascar.xml"));
Arrays.asList("default.xml", "horseshoe.xml", "loop.xml", "madagascar.xml", "waiheke.xml"));
public static MapMaker getInstance() {
if (instance == null) {
@@ -71,6 +71,8 @@ public class LobbyController implements Initializable {
@FXML
private Label roomLabel;
@FXML
private Label portNumber;
@FXML
private Pane speedTokenPane, handlingTokenPane, windWalkerTokenPane, bumperTokenPane, randomTokenPane;
//---------FXML END---------//
@@ -85,6 +87,8 @@ public class LobbyController implements Initializable {
@Override
public void initialize(URL location, ResourceBundle resources) {
roomLabel.setText("");
portNumber.setText("");
this.playerBoats = ViewManager.getInstance().getGameClient().getAllBoatsMap();
if (this.playersColor == null) {
@@ -376,4 +380,8 @@ public class LobbyController implements Initializable {
public void setRoomCode(String roomCode) {
roomLabel.setText("Room: " + roomCode);
}
public void setPortNumber(String p){
portNumber.setText("Port: " + p);
}
}
+61
View File
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<RaceDefinition>
<CourseName>Waiheke</CourseName>
<CentralLat>-36.80008</CentralLat>
<CentralLng>175.012225</CentralLng>
<MaxPlayers>10</MaxPlayers>
<Marks>
<CompoundMark CompoundMarkID="1">
<Mark Lat="-36.79512" Lng="175.0116"/>
<Mark Lat="-36.79468" Lng="175.01312"/>
</CompoundMark>
<CompoundMark CompoundMarkID="2">
<Mark Lat="-36.80069" Lng="175.01495"/>
</CompoundMark>
<CompoundMark CompoundMarkID="3">
<Mark Lat="-36.79892" Lng="175.01832"/>
<Mark Lat="-36.79988" Lng="175.01913"/>
</CompoundMark>
<CompoundMark CompoundMarkID="4">
<Mark Lat="-36.80064" Lng="175.01171"/>
<Mark Lat="-36.80186" Lng="175.0124"/>
</CompoundMark>
<CompoundMark CompoundMarkID="5">
<Mark Lat="-36.79579" Lng="175.01194"/>
<Mark Lat="-36.79545" Lng="175.01349"/>
</CompoundMark>
</Marks>
<Course>
<OpeningSegment>
<Corner CompoundMarkID="1" Rounding="PS"/>
<Corner CompoundMarkID="2" Rounding="P"/>
</OpeningSegment>
<RepeatingSegment>
<Corner CompoundMarkID="3" Rounding="SP"/>
<Corner CompoundMarkID="4" Rounding="PS"/>
</RepeatingSegment>
<ClosingSegment>
<Corner CompoundMarkID="5" Rounding="PS"/>
</ClosingSegment>
</Course>
<CourseLimit>
<Limit Lat="-36.7938" Lng="175.01194"/>
<Limit Lat="-36.79411" Lng="175.01555"/>
<Limit Lat="-36.79765" Lng="175.01898"/>
<Limit Lat="-36.79909" Lng="175.02149"/>
<Limit Lat="-36.80163" Lng="175.02014"/>
<Limit Lat="-36.80292" Lng="175.0175"/>
<Limit Lat="-36.80325" Lng="175.01008"/>
<Limit Lat="-36.80107" Lng="175.0089"/>
<Limit Lat="-36.79567" Lng="175.00961"/>
</CourseLimit>
</RaceDefinition>
+46 -68
View File
@@ -66,6 +66,11 @@
<GridPane.margin>
<Insets right="20.0" top="10.0" />
</GridPane.margin>
</Label>
<Label fx:id="portNumber" text="Port: 4191" GridPane.columnIndex="2" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
<GridPane.margin>
<Insets right="20.0" top="-15.0" />
</GridPane.margin>
</Label>
</children>
<columnConstraints>
@@ -80,12 +85,9 @@
</GridPane>
<GridPane GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" maxWidth="-Infinity" minWidth="-Infinity"
prefWidth="115.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308"
minWidth="337.0" prefWidth="430.0"/>
<ColumnConstraints hgrow="NEVER" maxWidth="350.0" minWidth="350.0"
prefWidth="350.0"/>
<ColumnConstraints hgrow="NEVER" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="115.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="337.0" prefWidth="430.0" />
<ColumnConstraints hgrow="NEVER" maxWidth="350.0" minWidth="350.0" prefWidth="350.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="SOMETIMES" />
@@ -110,116 +112,92 @@
<Insets bottom="15.0" left="7.0" right="7.0" top="15.0" />
</GridPane.margin>
</AnchorPane>
<GridPane prefHeight="370.0" prefWidth="189.0" styleClass="tokenGridView"
vgap="5.0">
<GridPane prefHeight="370.0" prefWidth="189.0" styleClass="tokenGridView" vgap="5.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Tokens"
GridPane.halignment="CENTER">
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Tokens" GridPane.halignment="CENTER">
<font>
<Font name="System Bold" size="18.0"/>
<Font name="System Bold" size="18.0" />
</font>
</Text>
<StackPane prefHeight="150.0" prefWidth="200.0"
GridPane.rowIndex="1">
<StackPane prefHeight="150.0" prefWidth="200.0" GridPane.rowIndex="1">
<children>
<Label alignment="BOTTOM_CENTER" text="Speed"
StackPane.alignment="BOTTOM_CENTER">
<Label alignment="BOTTOM_CENTER" text="Speed" StackPane.alignment="BOTTOM_CENTER">
<font>
<Font size="12.0"/>
<Font size="12.0" />
</font>
<padding>
<Insets bottom="5.0"/>
<Insets bottom="5.0" />
</padding>
</Label>
<Pane fx:id="speedTokenPane" prefHeight="999.0"
prefWidth="200.0" styleClass="tokenView"/>
<Pane fx:id="speedTokenPane" prefHeight="999.0" prefWidth="200.0" styleClass="tokenView" />
</children>
</StackPane>
<StackPane prefHeight="150.0" prefWidth="200.0"
GridPane.rowIndex="2">
<StackPane prefHeight="150.0" prefWidth="200.0" GridPane.rowIndex="2">
<children>
<Label alignment="BOTTOM_CENTER" text="Handling"
StackPane.alignment="BOTTOM_CENTER">
<Label alignment="BOTTOM_CENTER" text="Handling" StackPane.alignment="BOTTOM_CENTER">
<font>
<Font size="12.0"/>
<Font size="12.0" />
</font>
<padding>
<Insets bottom="5.0"/>
<Insets bottom="5.0" />
</padding>
</Label>
<Pane fx:id="handlingTokenPane" prefHeight="999.0"
prefWidth="200.0" styleClass="tokenView"/>
<Pane fx:id="handlingTokenPane" prefHeight="999.0" prefWidth="200.0" styleClass="tokenView" />
</children>
</StackPane>
<StackPane prefHeight="150.0" prefWidth="200.0"
GridPane.rowIndex="3">
<StackPane prefHeight="150.0" prefWidth="200.0" GridPane.rowIndex="3">
<children>
<Label alignment="BOTTOM_CENTER" text="Wind Walker"
StackPane.alignment="BOTTOM_CENTER">
<Label alignment="BOTTOM_CENTER" text="Wind Walker" StackPane.alignment="BOTTOM_CENTER">
<font>
<Font size="12.0"/>
<Font size="12.0" />
</font>
<padding>
<Insets bottom="5.0"/>
<Insets bottom="5.0" />
</padding>
</Label>
<Pane fx:id="windWalkerTokenPane" prefHeight="999.0"
prefWidth="200.0" styleClass="tokenView"/>
<Pane fx:id="windWalkerTokenPane" prefHeight="999.0" prefWidth="200.0" styleClass="tokenView" />
</children>
</StackPane>
<StackPane prefHeight="150.0" prefWidth="200.0"
GridPane.rowIndex="4">
<StackPane prefHeight="150.0" prefWidth="200.0" GridPane.rowIndex="4">
<children>
<Label alignment="BOTTOM_CENTER" text="Bumper"
StackPane.alignment="BOTTOM_CENTER">
<Label alignment="BOTTOM_CENTER" text="Bumper" StackPane.alignment="BOTTOM_CENTER">
<font>
<Font size="12.0"/>
<Font size="12.0" />
</font>
<padding>
<Insets bottom="5.0"/>
<Insets bottom="5.0" />
</padding>
</Label>
<Pane fx:id="bumperTokenPane" prefHeight="999.0"
prefWidth="200.0" styleClass="tokenView"/>
<Pane fx:id="bumperTokenPane" prefHeight="999.0" prefWidth="200.0" styleClass="tokenView" />
</children>
</StackPane>
<StackPane prefHeight="150.0" prefWidth="200.0"
GridPane.rowIndex="5">
<StackPane prefHeight="150.0" prefWidth="200.0" GridPane.rowIndex="5">
<children>
<Label alignment="BOTTOM_CENTER" text="Random"
StackPane.alignment="BOTTOM_CENTER">
<Label alignment="BOTTOM_CENTER" text="Random" StackPane.alignment="BOTTOM_CENTER">
<font>
<Font size="12.0"/>
<Font size="12.0" />
</font>
<padding>
<Insets bottom="5.0"/>
<Insets bottom="5.0" />
</padding>
</Label>
<Pane fx:id="randomTokenPane" prefHeight="999.0"
prefWidth="60.0" styleClass="tokenView"/>
<Pane fx:id="randomTokenPane" prefHeight="999.0" prefWidth="60.0" styleClass="tokenView" />
</children>
</StackPane>
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="80.0" minWidth="80.0"
prefWidth="80.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="80.0" minWidth="80.0" prefWidth="80.0" />
</columnConstraints>
<padding>
<Insets bottom="15.0" left="15.0" right="7.0" top="15.0"/>
<Insets bottom="15.0" left="15.0" right="7.0" top="15.0" />
</padding>
<rowConstraints>
<RowConstraints maxHeight="116.0" minHeight="0.0" prefHeight="40.0"
vgrow="NEVER"/>
<RowConstraints maxHeight="285.0" minHeight="-Infinity"
prefHeight="60.0" vgrow="SOMETIMES"/>
<RowConstraints maxHeight="285.0" minHeight="-Infinity"
prefHeight="60.0" vgrow="SOMETIMES"/>
<RowConstraints maxHeight="141.0" minHeight="-Infinity"
prefHeight="60.0" vgrow="SOMETIMES"/>
<RowConstraints maxHeight="285.0" minHeight="-Infinity"
prefHeight="60.0" vgrow="SOMETIMES"/>
<RowConstraints maxHeight="285.0" minHeight="-Infinity"
prefHeight="60.0" vgrow="SOMETIMES"/>
<RowConstraints maxHeight="116.0" minHeight="0.0" prefHeight="40.0" vgrow="NEVER" />
<RowConstraints maxHeight="285.0" minHeight="-Infinity" prefHeight="60.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="285.0" minHeight="-Infinity" prefHeight="60.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="141.0" minHeight="-Infinity" prefHeight="60.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="285.0" minHeight="-Infinity" prefHeight="60.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="285.0" minHeight="-Infinity" prefHeight="60.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
@@ -236,7 +214,7 @@
</GridPane>
</children>
<stylesheets>
<URL value="@../css/Master.css"/>
<URL value="@../css/LobbyView.css"/>
<URL value="@../css/Master.css" />
<URL value="@../css/LobbyView.css" />
</stylesheets>
</StackPane>
@@ -12,7 +12,7 @@ public class DisconnectionTest {
@Test
public void testServerDisconnection () throws Exception {
MainServerThread serverThread = new MainServerThread();
ClientToServerThread clientThread = new ClientToServerThread("localhost", 4942);
ClientToServerThread clientThread = new ClientToServerThread("localhost", serverThread.getPortNumber());
Thread.sleep(1000);
clientThread.addDisconnectionListener(message -> Assert.assertTrue(message != null));
serverThread.terminate();
@@ -20,7 +20,7 @@ public class RegularPacketsTest {
public void setup() throws Exception {
new GameState();
serverThread = new MainServerThread();
clientThread = new ClientToServerThread("localhost", 4942);
clientThread = new ClientToServerThread("localhost", serverThread.getPortNumber());
GameState.setCurrentStage(GameStages.RACING);
}
+2 -2
View File
@@ -45,7 +45,7 @@ public class SendChatSteps {
} catch (InterruptedException ie) {
ie.printStackTrace();
}
host = new ClientToServerThread("localhost", 4942);
host = new ClientToServerThread("localhost", mst.getPortNumber());
host.addStreamObserver(() -> {
while (host.getPacketQueue().peek() != null) {
StreamPacket packet = host.getPacketQueue().poll();
@@ -68,7 +68,7 @@ public class SendChatSteps {
} catch (InterruptedException ie) {
ie.printStackTrace();
}
client = new ClientToServerThread("localhost", 4942);
client = new ClientToServerThread("localhost", mst.getPortNumber());
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
+1 -1
View File
@@ -44,7 +44,7 @@ public class ToggleSailSteps {
} catch (InterruptedException ie) {
ie.printStackTrace();
}
client = new ClientToServerThread("localhost", 4942);
client = new ClientToServerThread("localhost", mst.getPortNumber());
try {
Thread.sleep(100);
} catch (InterruptedException ie) {