Added some Documenting. Added some fields to ClientAttributes.java that might be useful in case we need this class.

This commit is contained in:
Sebastian Lenzlinger 2022-04-08 18:55:21 +02:00
parent d8692152b4
commit a10ea16d35
3 changed files with 33 additions and 6 deletions

View File

@ -23,9 +23,10 @@ public class CentralServerData {
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
//TODO which datastructures should be used here? //TODO which datastructures should be used here?
private Set<ClientHandler> clientsOnServer; //TODO Static or non static?
private List<Lobby> allLobbies; private static Set<ClientHandler> clientsOnServer;
private Map<Integer, Lobby> lobbyIDMap; private static List<Lobby> allLobbies;
private static Map<Integer, Lobby> lobbyIDMap;
public CentralServerData() { public CentralServerData() {
clientsOnServer = new HashSet<>(); clientsOnServer = new HashSet<>();
@ -67,7 +68,7 @@ public class CentralServerData {
public synchronized void removeClientFromLobby(ClientHandler client) { public synchronized void removeClientFromLobby(ClientHandler client) {
boolean foundAndRemoved = false; boolean foundAndRemoved = false;
for (Lobby l : allLobbies) { for (Lobby l : allLobbies) {
foundAndRemoved = l.getPlayers().remove(client); foundAndRemoved = l.removePlayer(client);
} }
LOGGER.debug("foundAndRemoved value: " + foundAndRemoved); LOGGER.debug("foundAndRemoved value: " + foundAndRemoved);
} }

View File

@ -1,10 +1,18 @@
package ch.unibas.dmi.dbis.cs108.sebaschi; package ch.unibas.dmi.dbis.cs108.sebaschi;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/** /**
* Attributes of a client visible to server. * Attributes of a client visible to server.
*/ */
public class ClientAttributes { public class ClientAttributes {
String name; public static final Logger LOGGER = LogManager.getLogger();
int id; public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
private String clientUserName;
private boolean loggedIn;
private boolean isInALobby;
private Lobby clientsLobby;
} }

View File

@ -127,4 +127,22 @@ public class Lobby {
} }
} }
/**
* Does what is says on the box. Needs to be called when a client disconnects for some reason and
* cannot reconnect. I.E. when the server closes the connection to that client, the client should
* be removed from the list.
*
* @param player that is to be removed
* @return true if a player was found and removed. Used for debugging.
*/
public synchronized boolean removePlayer(ClientHandler player) {
return this.getPlayers().remove(player);
}
public void broadcastToLounge(String msg) {
for (ClientHandler lounger : this.getPlayers()) {
}
}
} }