better network structure
Some checks failed
Linux arm64 / Build (push) Has been cancelled

This commit is contained in:
2025-01-23 22:24:23 +01:00
parent 5e99cd92df
commit bfe98a2cf0
22 changed files with 248 additions and 93 deletions

View File

@@ -5,21 +5,43 @@ import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;
import network.protocol.Packet;
public class Server {
final ServerSocket serverSocket;
final List<ServerConnexion> connexions;
private final ServerThread thread;
private final ServerAcceptThread acceptThread;
private final ServerLogicThread logicThread;
public Server(short port) throws IOException {
this.serverSocket = new ServerSocket(port);
this.connexions = new ArrayList<>();
this.thread = new ServerThread(this);
this.thread.start();
this.acceptThread = new ServerAcceptThread(this);
this.acceptThread.start();
this.logicThread = new ServerLogicThread(this);
this.logicThread.start();
}
public void broadcastPacket(Packet packet) {
for (ServerConnexion connexion : this.connexions) {
connexion.sendPacket(packet);
}
}
public void update() {
for (var it = connexions.iterator(); it.hasNext();) {
ServerConnexion connexion = it.next();
if(!connexion.update()) {
connexion.close();
it.remove();
}
}
}
public void stop() {
this.thread.cancel();
this.acceptThread.cancel();
this.logicThread.cancel();
for (ServerConnexion connexion : this.connexions) {
connexion.close();
}