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() { private void startServer() {
try { try {
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
InetAddress localhost;
localhost = InetAddress.getLocalHost();
String ip = localhost.getHostAddress();
myServer = Network.createServer(port); myServer = Network.createServer(port);
initializeSerializables(); initializeSerializables();
myServer.start(); myServer.start();

View File

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