more stable connexion
Some checks failed
Linux arm64 / Build (push) Failing after 5m1s

This commit is contained in:
2025-01-26 14:54:46 +01:00
parent e51cc23459
commit 47dc35ebfa
7 changed files with 64 additions and 12 deletions

View File

@@ -16,6 +16,8 @@ public class Client {
public final Signal onDisconnect = new Signal();
public final Signal onClosed = new Signal();
String disconnectReason = null;
public Client(String address, short port) throws UnknownHostException, IOException {
this.clientConnection = new ClientConnexion(address, port, this);
this.game = new Game();
@@ -39,6 +41,10 @@ public class Client {
return game;
}
public String getDisconnectReason() {
return disconnectReason;
}
public void forceDisconnect() {
this.onClosed.emit();
stop();

View File

@@ -45,6 +45,7 @@ public class ClientConnexion extends Connexion {
@Override
public void visitPacket(DisconnectPacket packet) {
this.client.disconnectReason = packet.getReason();
close();
}

View File

@@ -49,6 +49,7 @@ public class Server {
this.acceptThread.cancel();
this.logicThread.cancel();
for (ServerConnexion connexion : this.connexions) {
connexion.nukeConnection();
connexion.close();
}
}

View File

@@ -33,7 +33,7 @@ public class ServerConnexion extends Connexion {
public void nukeConnection() {
if (player != null) {
sendPacket(new DisconnectPacket("Server stopped"));
sendPacket(new DisconnectPacket("Le serveur a été fermé !"));
this.server.broadcastPacket(new PlayerLeavePacket(player.getId()));
this.server.getGame().removePlayer(player.getId());
}