fixed server join logic

This commit is contained in:
Fleischer Hanno
2024-12-01 22:33:30 +01:00
parent 7a0a3589a5
commit 92be52b62a
2 changed files with 5 additions and 6 deletions

View File

@@ -68,9 +68,7 @@ public void run() {
private void startServer() {
try {
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
InetAddress localhost;
localhost = InetAddress.getLocalHost();
String ip = localhost.getHostAddress();
myServer = Network.createServer(port);
initializeSerializables();
myServer.start();

View File

@@ -126,7 +126,7 @@ private void tryHost() {
private void tryJoin() {
int port = 0;
String ip = joinDialog.getIpt();
String portText = hostDialog.getPort();
String portText = joinDialog.getPort();
try {
// Validate the port
@@ -134,9 +134,10 @@ private void tryJoin() {
if (port < 1 || port > 65535) {
throw new IllegalArgumentException("Invalid port");
}
joinDialog.setPortNumber(port);
// Validate the IP address
if (isValidIpAddress(ip)) {
joinDialog.setHostname(ip);
app.getModelSynchronize().setName(startDialog.getName());
app.getModelSynchronize().setJoin(ip, port);
joinDialog.connectToServer();
@@ -146,7 +147,7 @@ private void tryJoin() {
// Invalid input, fall through to reset
}
hostDialog.resetPort();
joinDialog.resetPort();
joinDialog.resetIp();
app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT);
}