Added functionality to automatically select a server

- Added functionality on the DiscoveryServer to return a random server to the player
- Added elements to the UI to support auto-selecting a server
- Added client side code to request a random server

Tags: #story[1281]
This commit is contained in:
Michael Rausch
2017-09-26 01:14:02 +13:00
parent d0844e861d
commit 9cfb3b9e5d
8 changed files with 119 additions and 15 deletions
@@ -27,6 +27,7 @@ import seng302.discoveryServer.DiscoveryServer;
import seng302.gameServer.ServerDescription;
import seng302.discoveryServer.util.ServerListing;
import seng302.discoveryServer.DiscoveryServerClient;
import seng302.gameServer.messages.RoomCodeRequest;
import seng302.utilities.Sounds;
import seng302.visualiser.ServerListener;
import seng302.visualiser.ServerListenerDelegate;
@@ -58,6 +59,8 @@ public class ServerListController implements Initializable, ServerListenerDelega
private JFXButton roomConnectButton;
@FXML
private JFXTextField roomNumber;
@FXML
private JFXButton autoSelectGame;
//---------FXML END---------//
private Label noServersFound;
@@ -101,6 +104,29 @@ public class ServerListController implements Initializable, ServerListenerDelega
textField.getValidators().add(validator);
}
autoSelectGame.setOnMouseReleased(e -> {
try {
ServerListing listing = new DiscoveryServerClient().getRandomServer();
if (listing == null){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setHeaderText("Error finding game");
alert.setContentText("No servers are up");
alert.showAndWait();
}
else{
ViewManager.getInstance().getGameClient().runAsClient(listing.getAddress(), listing.getPortNumber());
}
} catch (Exception e1) {
e1.printStackTrace();
logger.error("Error getting listing");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setHeaderText("Error finding game");
alert.setContentText("Couldn't contact matchmaking server");
alert.showAndWait();
}
});
/*
// Validating the hostname
HostNameFieldValidator hostNameValidator = new HostNameFieldValidator();