Added missing stop Method for NetworkServer

This commit is contained in:
Finn
2025-12-11 10:32:05 +01:00
parent d95ff4c497
commit b267674b6f
2 changed files with 17 additions and 1 deletions

View File

@@ -6,7 +6,7 @@
<groupId>dev.unlegitdqrk</groupId> <groupId>dev.unlegitdqrk</groupId>
<artifactId>unlegitlibrary</artifactId> <artifactId>unlegitlibrary</artifactId>
<version>1.6.6</version> <version>1.6.7</version>
<url>https://unlegitdqrk.dev/</url> <url>https://unlegitdqrk.dev/</url>
<description>Just a big library</description> <description>Just a big library</description>

View File

@@ -95,6 +95,22 @@ public final class NetworkServer {
} }
} }
public boolean stop() {
for (ConnectionHandler connectionHandler : new ArrayList<>(connectionHandlers)) connectionHandler.disconnect();
incomingThread.interrupt();
try {
serverSocket.close();
serverSocket = null;
if (logger != null) logger.log("Server stopped");
else System.out.println("Server stopped");
return true;
} catch (Exception e) {
if (logger != null) logger.exception("Failed to stop", e);
else System.err.println("Failed to stop: " + e.getMessage());
return false;
}
}
private void incomingConnections() { private void incomingConnections() {
try { try {
while (!serverSocket.isClosed()) { while (!serverSocket.isClosed()) {