This commit is contained in:
2026-04-24 18:36:50 +02:00
parent 7833802187
commit b88b57e9d9
3 changed files with 8 additions and 11 deletions
@@ -2,7 +2,7 @@ package it.polimi.ingsw.gc14;
import java.util.ArrayList; import java.util.ArrayList;
public class LimitedList<String> extends ArrayList<String> { public class LimitedList<T> extends ArrayList<T> {
private int limit; private int limit;
private final Runnable action; private final Runnable action;
@@ -12,7 +12,7 @@ public class LimitedList<String> extends ArrayList<String> {
} }
@Override @Override
public boolean add(String element) { public boolean add(T element) {
boolean result = super.add(element); boolean result = super.add(element);
if (size() >= limit) { if (size() >= limit) {
action.run(); action.run();
@@ -20,7 +20,7 @@ public class LimitedList<String> extends ArrayList<String> {
return result; return result;
} }
public void setElement(int num) { public void setLimit(int num) {
this.limit=num; this.limit=num;
} }
@@ -54,7 +54,7 @@ public class RMIServer implements IGameServer {
{ {
Game game= new Game(preferredInt); Game game= new Game(preferredInt);
controller.setModel(game); controller.setModel(game);
playerList.setElement(preferredInt); playerList.setLimit(preferredInt);
} }
playerList.add(username); playerList.add(username);
clients.put(username, callback); clients.put(username, callback);
@@ -17,7 +17,7 @@ public class ServerLauncher {
GameController gameController; GameController gameController;
RMIServer serverRMI; RMIServer serverRMI;
TCPServer serverTCP; TCPServer serverTCP;
LimitedList players; static LimitedList<String> players;
@@ -59,8 +59,8 @@ public class ServerLauncher {
BlockingQueue<NetworkEvent> actionQueue = new LinkedBlockingQueue<>(); BlockingQueue<NetworkEvent> actionQueue = new LinkedBlockingQueue<>();
GameController gameController = new GameController(); GameController gameController = new GameController();
RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue); RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue, players);
TCPServer serverTCP = new TCPServer(gameController, 8080, actionQueue); TCPServer serverTCP = new TCPServer(gameController, 8080, actionQueue, players);
ServerLauncher launcher = new ServerLauncher(actionQueue, gameController, serverRMI, serverTCP); ServerLauncher launcher = new ServerLauncher(actionQueue, gameController, serverRMI, serverTCP);
launcher.run(); launcher.run();
@@ -68,10 +68,7 @@ public class ServerLauncher {
public void run() throws InterruptedException, RemoteException { public void run() throws InterruptedException, RemoteException {
// Aggiunge il primo player e imposta il numero di giocatori voluti serverRMI.notifyAll(gameController.getModel());
Game model = new Game(players.getLimit());
gameController.setModel(model);
serverRMI.notifyAll(model);
//serverTCP.broadcastUpdate(model); //serverTCP.broadcastUpdate(model);