This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -45,6 +45,7 @@ public class ClientConnexion extends Connexion {
|
||||
|
||||
@Override
|
||||
public void visitPacket(DisconnectPacket packet) {
|
||||
this.client.disconnectReason = packet.getReason();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ public class Server {
|
||||
this.acceptThread.cancel();
|
||||
this.logicThread.cancel();
|
||||
for (ServerConnexion connexion : this.connexions) {
|
||||
connexion.nukeConnection();
|
||||
connexion.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user