diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java index 0e06955..66daa9d 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java @@ -117,8 +117,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * @param action The desired action */ public void notifyAll(NetworkEvent action) throws RemoteException { - for (IClientCallback cb : clients.values()) { - cb.onAction(action); + for (Map.Entry entry : clients.entrySet()) { + if(!action.getIsError() ||(action.getIsError()&& action.getUsername().equals(entry.getKey()))) + entry.getValue().onAction(action); } } diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java index 539416e..450b0d6 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java @@ -15,7 +15,13 @@ import java.util.concurrent.BlockingQueue; * It is also responsible to send events and game model updates back to the client. */ public class ClientHandler implements Runnable { - + /** + * The username of the connected client on this handler + */ + private final String username; + public String getUsername() { + return username; + } /** The TCP socket */ private Socket clientSocket; @@ -41,7 +47,8 @@ public class ClientHandler implements Runnable { * @param clientHandlers The shared list of all active client handlers * @param actionQueue The queue containing incoming events */ - public ClientHandler(Socket clientSocket, ObjectOutputStream out, ObjectInputStream in, List clientHandlers, BlockingQueue actionQueue) { + public ClientHandler(String username, Socket clientSocket, ObjectOutputStream out, ObjectInputStream in, List clientHandlers, BlockingQueue actionQueue) { + this.username=username; this.clientSocket = clientSocket; this.in = in; this.out = out; diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java index 55fd6a6..7ec3c05 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java @@ -115,7 +115,7 @@ public class TCPServer { clientSocket.getOutputStream().write((int) (1)); System.out.println("Accepted player: " + eventAddPlayer.getUsername()); - ClientHandler clientHandler = new ClientHandler(clientSocket, clientSend, clientReceive, clientHandlers, actionQueue); + ClientHandler clientHandler = new ClientHandler(eventAddPlayer.getUsername(),clientSocket, clientSend, clientReceive, clientHandlers, actionQueue); clientHandlers.add(clientHandler); ConnectedPlayers++; @@ -141,7 +141,10 @@ public class TCPServer { /** Sends an action to all TCP clients */ public void notifyAll(NetworkEvent event){ - clientHandlers.forEach((x) -> x.notifyEvent(event)); + clientHandlers.forEach((x) -> { + if(!event.getIsError()||(event.getIsError()&& event.getUsername().equals(x.getUsername()))) + x.notifyEvent(event); + }); }