Added two methods to ClientHandler that send messages to multiple lobbies, this is needed for the gui interaction with multiple clients
This commit is contained in:
parent
fb730006f8
commit
460f4fb9ea
@ -1,7 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.helpers;
|
||||
|
||||
/**
|
||||
* This class contains all parameters for the PTGUI protocol message
|
||||
* This class contains parameters for the PTGUI protocol message
|
||||
*/
|
||||
public class GuiParameters {
|
||||
|
||||
@ -15,7 +15,7 @@ public class GuiParameters {
|
||||
public static final String listOfLobbies = "LOBBIES";
|
||||
|
||||
/**
|
||||
* Tells Gui, that what follows is a list of players (per Lobby?)
|
||||
* Tells Gui, that what follows is a list of players per Lobby
|
||||
*/
|
||||
public static final String listOfPLayers = "PLAYERS";
|
||||
|
||||
|
||||
@ -305,6 +305,35 @@ public class ClientHandler implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a given message to all connected client. The message has to already be protocol-formatted.
|
||||
*
|
||||
* @param msg the given message. Should already be protocol-formatted.
|
||||
*/
|
||||
public void sendMsgToAllClients(String msg) {
|
||||
for (ClientHandler client : connectedClients) {
|
||||
client.sendMsgToClient(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a Message to all clients in the same lobby. The message has to already be protocol-formatted.
|
||||
* @param msg the given message. Should already be protocol-formatted.
|
||||
*/
|
||||
public void sendMsgToClientsInLobby(String msg) {
|
||||
Lobby l = getLobby();
|
||||
if (l != null) {
|
||||
//System.out.println(msg); we can-comment this if you want lobby-announcements to print on the server console as well.
|
||||
for (ClientHandler client : l.getLobbyClients()) {
|
||||
client.sendMsgToClient(msg);
|
||||
}
|
||||
} else {
|
||||
LOGGER.debug("Could not send announcements; probably client isn't in a lobby."
|
||||
+ "Will send across all lobbies now.");
|
||||
sendMsgToAllClients(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a whisper message
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user