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

    Constructors
    Constructor Description
    Match​(java.lang.String matchName, Server server)  
  • Method Summary

    Modifier and Type Method Description
    void addClient​(ServerClientHandler client)
    Adds a clientHandler to the clients list
    void deleteClient​(ServerClientHandler client)
    Removes the specified client from the clients list and the clients Map
    void deleteMatch()
    Delete the match closing all sockets and deleting it from the server reference list
    java.lang.String getMatchName()  
    int getPlayersNumber()  
    TurnManager getTurnManager()  
    protected void handleClientDisconnection​(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 server
    void handleLogin​(Message message, ServerClientHandler clientHandler)
    handles the login message registering the player to the server.
    boolean isGameRunning()
    returns true if the game is running
    boolean isTaken​(java.lang.String username)
    returns true if the the specified username is already taken by another client
    void lobbySetup​(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 match
    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
    void matchBroadcastUpdate​(Message message)
    sends broadcast phaseUpdate message
    void matchSingleUpdate​(Message message)
    sends phaseUpdate message only to the current player
    void sendBroadcast​(Message message)
    Sends the specified message to every connected client
    void sendToClient​(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

      public Match​(java.lang.String matchName, Server server)
  • Method Details

    • getPlayersNumber

      public int getPlayersNumber()
    • getMatchName

      public java.lang.String getMatchName()
    • lobbySetup

      public void lobbySetup​(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 match
      Parameters:
      message - should be MessageType.NUMBER_OF_PLAYERS || MessageType.LOGIN
    • handleLogin

      public void handleLogin​(Message message, ServerClientHandler clientHandler)
      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 login
      clientHandler - that wants to login
    • matchSingleUpdate

      public void matchSingleUpdate​(Message message)
      sends phaseUpdate message only to the current player
      Parameters:
      message - the phaseUpdate message (username can be null)
    • matchBroadcastUpdate

      public void matchBroadcastUpdate​(Message message)
      sends broadcast phaseUpdate message
      Parameters:
      message - the phaseUpdate message (username can be null)
    • addClient

      public void addClient​(ServerClientHandler client)
      Adds a clientHandler to the clients list
      Parameters:
      client - the ServerClientHandler to 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

      public void sendToClient​(Message message)
      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

      public void sendBroadcast​(Message message)
      Sends the specified message to every connected client
      Parameters:
      message - message to send
    • deleteClient

      public void deleteClient​(ServerClientHandler client)
      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

      public TurnManager getTurnManager()
    • isGameRunning

      public boolean isGameRunning()
      returns true if the game is running
      Returns:
      true if the game is running
    • handleClientDisconnection

      protected void handleClientDisconnection​(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 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