mooore stuff
Some checks failed
Linux arm64 / Build (push) Failing after 5m5s

This commit is contained in:
2025-01-26 13:46:23 +01:00
parent caf7011f08
commit e51cc23459
20 changed files with 395 additions and 65 deletions

View File

@@ -5,6 +5,8 @@ import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;
import game.Game;
import game.Player;
import network.protocol.Packet;
public class Server {
@@ -13,6 +15,8 @@ public class Server {
final List<ServerConnexion> connexions;
private final ServerAcceptThread acceptThread;
private final ServerLogicThread logicThread;
private final Game game;
private int nextPlayerId = 0;
public Server(short port) throws IOException {
this.serverSocket = new ServerSocket(port);
@@ -21,6 +25,7 @@ public class Server {
this.acceptThread.start();
this.logicThread = new ServerLogicThread(this);
this.logicThread.start();
this.game = new Game();
}
public void broadcastPacket(Packet packet) {
@@ -32,8 +37,9 @@ public class Server {
public void update() {
for (var it = connexions.iterator(); it.hasNext();) {
ServerConnexion connexion = it.next();
if(!connexion.update()) {
if (!connexion.update()) {
connexion.close();
connexion.nukeConnection();
it.remove();
}
}
@@ -47,4 +53,15 @@ public class Server {
}
}
public Player addPlayer(String pseudo) {
Player p = new Player(nextPlayerId, pseudo);
this.game.addPlayer(p);
nextPlayerId++;
return p;
}
public Game getGame() {
return game;
}
}