Package it.polimi.ingsw.eriantys.server
Class Server
java.lang.Object
java.lang.Thread
it.polimi.ingsw.eriantys.server.Server
- All Implemented Interfaces:
Runnable
This class represents the application server thread. It handles all the clients, instantiating
ClientConnection
objects for each of them, and exposes various methods-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
connect
(String username, ClientConnection connection) Handles a user connection by processing aHandshake
communication item.void
disconnect
(ClientConnection connection) Handles a user disconnection, causing an update on the internal state of the class.void
Processes the server-side end of the game.getConnection
(String username) A getter for the client connection instance of a user.void
handleMessage
(ConnectionMessage message) Handles a user request by processing aConnectionMessage
communication item.boolean
isConnected
(String username) A method to know if a user with a specified identifier exists or not.static void
The method is called to launch the server-side application.void
reconnect
(String username, int gameId, String passcode, ClientConnection connection) Handles a user reconnection by processing aReconnect
communication item.void
run()
void
sendHelp
(HelpRequest helpRequest) Handles the processing of aHelpRequest
communication item.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
name
- See Also:
-
-
Constructor Details
-
Server
Constructs aServer
object, starting theServerSocket
.- Parameters:
port
- the port number on which theServer
will run- Throws:
IOException
- if theServerSocket
could not be opened
-
-
Method Details
-
main
The method is called to launch the server-side application.- Parameters:
args
- the command line arguments
-
run
public void run() -
connect
Handles a user connection by processing aHandshake
communication item.- Parameters:
username
- the username requested by the clientconnection
- a reference to the client connection instance
-
reconnect
Handles a user reconnection by processing aReconnect
communication item.- Parameters:
username
- the username which has been chosen by the client prior to its disconnectiongameId
- the identifier of the game inside which the client was playing prior to its disconnectionpasscode
- the hexadecimal code which has been associated with the client by the disconnection handling infrastructureconnection
- a reference to the client connection instance
-
disconnect
Handles a user disconnection, causing an update on the internal state of the class.- Parameters:
connection
- a reference to the client connection instance
-
isConnected
A method to know if a user with a specified identifier exists or not.- Parameters:
username
- the target user- Returns:
true
if and only if aClientConnection
exists for the target username
-
getConnection
A getter for the client connection instance of a user.- Parameters:
username
- the target user- Returns:
- a reference to the client connection
- Throws:
NoConnectionException
- if no connection can be retrieved for the target player
-
handleMessage
Handles a user request by processing aConnectionMessage
communication item.- Parameters:
message
- the target message to process- Throws:
NoConnectionException
- if no connection can be retrieved for the target player
-
sendHelp
Handles the processing of aHelpRequest
communication item.- Parameters:
helpRequest
- the target request to process- Throws:
NoConnectionException
- if no connection can be retrieved for the target player
-
gameOver
Processes the server-side end of the game.- Parameters:
game
- the identifier of the game which has been endedplayers
- the list of usernames who played the game
-