refactor: formated UserManager properly
This commit is contained in:
parent
274a85248f
commit
c24121b6d9
@ -16,10 +16,10 @@ import org.java_websocket.WebSocket;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** Class that manages users. It is meant as an extension to the {@link MarvelousServer} class. This is the first
|
||||
* place where messages are relayed to after they get received. This class is
|
||||
* responsible for handshakes, reconnects and WebSocket-to-Participant matching.
|
||||
* It is designed to be thread-safe. The Singleton of this class also contains a
|
||||
/**
|
||||
* Class that manages users. It is meant as an extension to the {@link MarvelousServer} class. This is the first place
|
||||
* where messages are relayed to after they get received. This class is responsible for handshakes, reconnects and
|
||||
* WebSocket-to-Participant matching. It is designed to be thread-safe. The Singleton of this class also contains a
|
||||
* {@link LobbyManager}, which manages the lobbys.
|
||||
*/
|
||||
public class UserManager {
|
||||
@ -37,8 +37,10 @@ public class UserManager {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** The {@link LobbyManager} associated with the {@link UserManager}. It is therefore a kind of extension
|
||||
* to the current singleton, and may of course not be called from anywhere else */
|
||||
/**
|
||||
* The {@link LobbyManager} associated with the {@link UserManager}. It is therefore a kind of extension to the
|
||||
* current singleton, and may of course not be called from anywhere else
|
||||
*/
|
||||
private final LobbyManager lobbyManager;
|
||||
|
||||
/** A set of users that aren't assigned to lobbies or character selection yet */
|
||||
@ -47,9 +49,9 @@ public class UserManager {
|
||||
/** A set of users that can reconnect if they wish to do so, and their matching Participants */
|
||||
private final HashMap<WebSocket, SUID> readyToReconnect;
|
||||
|
||||
/** A set of users that only have to send the
|
||||
* {@link uulm.teamname.marvelous.gamelibrary.messages.client.PlayerReadyMessage} to be assigned
|
||||
* to a lobby, containing WebSockets mapped to their user's usernames
|
||||
/**
|
||||
* A set of users that only have to send the {@link uulm.teamname.marvelous.gamelibrary.messages.client.PlayerReadyMessage}
|
||||
* to be assigned to a lobby, containing WebSockets mapped to their user's usernames
|
||||
*/
|
||||
private final HashMap<WebSocket, SUID> readyToConnect;
|
||||
|
||||
@ -88,9 +90,10 @@ public class UserManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on any received messages. The method checks the message for validity, and then relays it
|
||||
* accordingly. {@link HelloServerMessage HelloServerMessages} and {@link ReconnectMessage ReconnectMessages}
|
||||
* are handled in this component, whereby a handshake or reconnect is performed, respectively.
|
||||
* Called on any received messages. The method checks the message for validity, and then relays it accordingly.
|
||||
* {@link HelloServerMessage HelloServerMessages} and {@link ReconnectMessage ReconnectMessages} are handled in this
|
||||
* component, whereby a handshake or reconnect is performed, respectively.
|
||||
*
|
||||
* @param conn is the {@link WebSocket} that sent the message
|
||||
* @param message is the {@link String} sent by the connection
|
||||
*/
|
||||
@ -271,6 +274,7 @@ public class UserManager {
|
||||
|
||||
/**
|
||||
* Method to call when removing a user from the game, e.g. on player timeout, or end of match
|
||||
*
|
||||
* @param conn is the connection to close
|
||||
*/
|
||||
public void removeUser(WebSocket conn) {
|
||||
@ -291,11 +295,7 @@ public class UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called exclusively from {@link MarvelousServer} on closed connection.
|
||||
* @param conn
|
||||
* @param closedByRemote
|
||||
*/
|
||||
/** Method called exclusively from {@link MarvelousServer} on closed connection. */
|
||||
void disconnectUser(WebSocket conn, boolean closedByRemote) {
|
||||
// TODO: notify clients and such if the connection was in fact closed by the remote. Also remove participant
|
||||
synchronized (newUsers) {
|
||||
@ -308,6 +308,7 @@ public class UserManager {
|
||||
readyToReconnect.remove(conn);
|
||||
}
|
||||
synchronized (inGame) {
|
||||
if (inGame.containsKey(conn)) inGame.get(conn).clearConnection();
|
||||
inGame.remove(conn);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user