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.*;
|
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
|
* Class that manages users. It is meant as an extension to the {@link MarvelousServer} class. This is the first place
|
||||||
* responsible for handshakes, reconnects and WebSocket-to-Participant matching.
|
* where messages are relayed to after they get received. This class is responsible for handshakes, reconnects and
|
||||||
* It is designed to be thread-safe. The Singleton of this class also contains a
|
* 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.
|
* {@link LobbyManager}, which manages the lobbys.
|
||||||
*/
|
*/
|
||||||
public class UserManager {
|
public class UserManager {
|
||||||
@ -37,8 +37,10 @@ public class UserManager {
|
|||||||
return instance;
|
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;
|
private final LobbyManager lobbyManager;
|
||||||
|
|
||||||
/** A set of users that aren't assigned to lobbies or character selection yet */
|
/** 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 */
|
/** A set of users that can reconnect if they wish to do so, and their matching Participants */
|
||||||
private final HashMap<WebSocket, SUID> readyToReconnect;
|
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
|
* A set of users that only have to send the {@link uulm.teamname.marvelous.gamelibrary.messages.client.PlayerReadyMessage}
|
||||||
* to a lobby, containing WebSockets mapped to their user's usernames
|
* to be assigned to a lobby, containing WebSockets mapped to their user's usernames
|
||||||
*/
|
*/
|
||||||
private final HashMap<WebSocket, SUID> readyToConnect;
|
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
|
* Called on any received messages. The method checks the message for validity, and then relays it accordingly.
|
||||||
* accordingly. {@link HelloServerMessage HelloServerMessages} and {@link ReconnectMessage ReconnectMessages}
|
* {@link HelloServerMessage HelloServerMessages} and {@link ReconnectMessage ReconnectMessages} are handled in this
|
||||||
* are handled in this component, whereby a handshake or reconnect is performed, respectively.
|
* component, whereby a handshake or reconnect is performed, respectively.
|
||||||
|
*
|
||||||
* @param conn is the {@link WebSocket} that sent the message
|
* @param conn is the {@link WebSocket} that sent the message
|
||||||
* @param message is the {@link String} sent by the connection
|
* @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
|
* 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
|
* @param conn is the connection to close
|
||||||
*/
|
*/
|
||||||
public void removeUser(WebSocket conn) {
|
public void removeUser(WebSocket conn) {
|
||||||
@ -291,11 +295,7 @@ public class UserManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Method called exclusively from {@link MarvelousServer} on closed connection. */
|
||||||
* Method called exclusively from {@link MarvelousServer} on closed connection.
|
|
||||||
* @param conn
|
|
||||||
* @param closedByRemote
|
|
||||||
*/
|
|
||||||
void disconnectUser(WebSocket conn, boolean closedByRemote) {
|
void disconnectUser(WebSocket conn, boolean closedByRemote) {
|
||||||
// TODO: notify clients and such if the connection was in fact closed by the remote. Also remove participant
|
// TODO: notify clients and such if the connection was in fact closed by the remote. Also remove participant
|
||||||
synchronized (newUsers) {
|
synchronized (newUsers) {
|
||||||
@ -308,6 +308,7 @@ public class UserManager {
|
|||||||
readyToReconnect.remove(conn);
|
readyToReconnect.remove(conn);
|
||||||
}
|
}
|
||||||
synchronized (inGame) {
|
synchronized (inGame) {
|
||||||
|
if (inGame.containsKey(conn)) inGame.get(conn).clearConnection();
|
||||||
inGame.remove(conn);
|
inGame.remove(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user