mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user