Updated 'MdgaServer' class.

Updated the 'MdgaServer' class by adding the 'shutdown' message to it.
This commit is contained in:
Daniel Grigencha
2024-12-02 23:23:56 +01:00
parent 838f59b9aa
commit 1f64676d31

View File

@@ -296,4 +296,21 @@ public void broadcast(ServerMessage message) {
public void disconnectClient(int id) {
this.myServer.getConnection(id).close("");
}
/**
* This method will be used to shut down the server.
* It will iterate threw all connections of myServer attribute and check if they are equal to null. If not they will
* be closed. After that the myServer attribute will be closed and this program will be exited with the exit code 0.
*/
@Override
public void shutdown() {
for (HostedConnection client : this.myServer.getConnections()) {
if (client != null) {
client.close("Host closed the server.");
}
}
this.myServer.close();
this.exit(0);
}
}