Class NetworkHandlerRMI

java.lang.Object
it.polimi.ingsw.am13.client.network.rmi.NetworkHandlerRMI
All Implemented Interfaces:
NetworkHandler

public class NetworkHandlerRMI extends Object implements NetworkHandler
RMI implementation of NetworkHandler, which is used by the client to send messages to the server
  • Field Details

    • lobby

      private final LobbyRMIIF lobby
      The controller that manages all the games
    • player

      private PlayerLobby player
      The player associated to this network handler
    • controller

      private GameControllerRMIIF controller
      The controller of the match associated to this network handler
    • view

      private final View view
      The user interface
    • pingThread

      private Thread pingThread
      Thread sending periodically pings to server
  • Constructor Details

    • NetworkHandlerRMI

      public NetworkHandlerRMI(LobbyRMIIF lobby, View view)
      Initializes lobby and view
      Parameters:
      lobby - the controller that manages all the games
      view - the user interface
  • Method Details

    • getPlayer

      public PlayerLobby getPlayer()
      Specified by:
      getPlayer in interface NetworkHandler
      Returns:
      the current valid player associated to this NetworkHandler. Null is no valid player is currently associated.
    • getView

      public View getView()
      Returns:
      the user interface
    • setController

      public void setController(GameControllerRMIIF controller)
      Sets the controller to the passed parameter
      Parameters:
      controller - the controller of the match associated to this network handler
    • getRooms

      public void getRooms()
      Get the existing rooms
      Specified by:
      getRooms in interface NetworkHandler
    • createRoom

      public void createRoom(String nickname, Token token, int nPlayers)
      Create a room with the passed parameters
      Specified by:
      createRoom in interface NetworkHandler
      Parameters:
      nickname - of the player who is creating the room
      token - of the player who is creating the room
      nPlayers - of the room that is being created
    • joinRoom

      public void joinRoom(String nickname, Token token, int gameId)
      Make the player join the specified room
      Specified by:
      joinRoom in interface NetworkHandler
      Parameters:
      nickname - the nickname the client wants to join the room with
      token - chosen by the player who wants to join the room
      gameId - of the game that the client wants to join
    • reconnect

      public void reconnect(String nickname, Token token)
      Reconnect the passed player to an existing game he was previously part of
      Specified by:
      reconnect in interface NetworkHandler
      Parameters:
      nickname - of the player who wants to reconnect
      token - of the player who wants to reconnect
    • leaveRoom

      public void leaveRoom()
      Make the player leave the room he is currently part of
      Specified by:
      leaveRoom in interface NetworkHandler
    • playStarter

      public void playStarter(Side side)
      Play the starter card
      Specified by:
      playStarter in interface NetworkHandler
      Parameters:
      side - on which the starter card should be played
    • choosePersonalObjective

      public void choosePersonalObjective(CardObjectiveIF card)
      Choose the personal objective card
      Specified by:
      choosePersonalObjective in interface NetworkHandler
      Parameters:
      card - the chosen personal objective
    • playCard

      public void playCard(CardPlayableIF card, Coordinates coords, Side side)
      Play a card according to the parameters
      Specified by:
      playCard in interface NetworkHandler
      Parameters:
      card - the player wants to play
      coords - where the card should be played
      side - on which the card should be played
    • pickCard

      public void pickCard(CardPlayableIF card)
      Pick the passed card
      Specified by:
      pickCard in interface NetworkHandler
      Parameters:
      card - the player wants to pick
    • ping

      private void ping()
      Ping the server
    • startPing

      public void startPing()
      Starts the thread sending pings to server
      Specified by:
      startPing in interface NetworkHandler
    • stopPing

      public void stopPing()
      Stops the thread sending pings to server
      Specified by:
      stopPing in interface NetworkHandler
    • sendChatMessage

      public void sendChatMessage(List<PlayerLobby> receivers, String text)
      Send a chat message to the receivers (either a single player, or all the players)
      Specified by:
      sendChatMessage in interface NetworkHandler
      Parameters:
      receivers - of the chat message
      text - of the chat message