Package it.polimi.ingsw.network.server
Class Match
java.lang.Object
it.polimi.ingsw.network.server.Match
public class Match
extends java.lang.Object
This class contains reference to all the clientHandlers in order to manage at an high level of abstraction
the message sending process and the client disconnections inside of a match.
A match is a game room that can be created or joined by players using it's unique Id. Once the game has started
the match is no longer accessible by players. If a player disconnects from a match others can still play
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidaddClient(ServerClientHandler client)Adds a clientHandler to the clients listvoiddeleteClient(ServerClientHandler client)Removes the specified client from the clients list and the clients MapvoiddeleteMatch()Delete the match closing all sockets and deleting it from the server reference listjava.lang.StringgetMatchName()intgetPlayersNumber()TurnManagergetTurnManager()protected voidhandleClientDisconnection(ServerClientHandler disconnectedClient)If the game is not running this method deletes the client Sends to Client a disconnected message if the disconnection is caused by the servervoidhandleLogin(Message message, ServerClientHandler clientHandler)handles the login message registering the player to the server.booleanisGameRunning()returns true if the game is runningbooleanisTaken(java.lang.String username)returns true if the the specified username is already taken by another clientvoidlobbySetup(Message message)manages client interaction in the lobby creation phase if the message sender is the first player send him a message if he isn't the first player this methods tells all the other clients that a new player connected if all the players required are logged this method will start the matchjava.util.List<java.lang.String>loggedPlayers()Returns a list of the logged players in the match NOTE: if a player disconnects he is considered still logged if he actually logged in successfullyvoidmatchBroadcastUpdate(Message message)sends broadcast phaseUpdate messagevoidmatchSingleUpdate(Message message)sends phaseUpdate message only to the current playervoidsendBroadcast(Message message)Sends the specified message to every connected clientvoidsendToClient(Message message)Sends the specified message.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Match
-
-
Method Details
-
getPlayersNumber
public int getPlayersNumber() -
getMatchName
public java.lang.String getMatchName() -
lobbySetup
manages client interaction in the lobby creation phase if the message sender is the first player send him a message if he isn't the first player this methods tells all the other clients that a new player connected if all the players required are logged this method will start the match- Parameters:
message- should beMessageType.NUMBER_OF_PLAYERS || MessageType.LOGIN
-
handleLogin
handles the login message registering the player to the server. Sends a message to the client with feedback on the login procedure (E.g. login successful or login error). Also handles reconnection if the login message is sent by a player that has disconnected during the game- Parameters:
message- login message sent by the client that wants to loginclientHandler- that wants to login
-
matchSingleUpdate
sends phaseUpdate message only to the current player- Parameters:
message- the phaseUpdate message (username can be null)
-
matchBroadcastUpdate
sends broadcast phaseUpdate message- Parameters:
message- the phaseUpdate message (username can be null)
-
addClient
Adds a clientHandler to the clients list- Parameters:
client- theServerClientHandlerto be added
-
isTaken
public boolean isTaken(java.lang.String username)returns true if the the specified username is already taken by another client- Parameters:
username- the username whose availability is to be checked- Returns:
- true if the username is already taken
-
sendToClient
Sends the specified message. If username is null sends broadcast, otherwise sends only to the client associated with the username- Parameters:
message- the message to be sent
-
sendBroadcast
Sends the specified message to every connected client- Parameters:
message- message to send
-
deleteClient
Removes the specified client from the clients list and the clients Map- Parameters:
client- the clientHandler to be removed
-
loggedPlayers
public java.util.List<java.lang.String> loggedPlayers()Returns a list of the logged players in the match NOTE: if a player disconnects he is considered still logged if he actually logged in successfully- Returns:
- the logged players list
-
getTurnManager
-
isGameRunning
public boolean isGameRunning()returns true if the game is running- Returns:
- true if the game is running
-
handleClientDisconnection
If the game is not running this method deletes the client Sends to Client a disconnected message if the disconnection is caused by the server- Parameters:
disconnectedClient- the clientHandler that disconnected or that needs to be disconnected
-
deleteMatch
public void deleteMatch()Delete the match closing all sockets and deleting it from the server reference list
-