Interface LobbyRMIIF

All Superinterfaces:
Remote
All Known Implementing Classes:
LobbyRMI

public interface LobbyRMIIF extends Remote
Interface representing lobby for the RMI connection. Hence this class is exposed to the network as RMI remote interface. The methods who allow players to join a room/game must receive a GameListenerClientRMI already instantiated, so that the server can use them to give update to the corresponding clients via RMI

Controller used to manage multiple games, that is to handle the lobby of players who are playing or are in a room willing to start a game.
It stores the server game listeners of players in all the rooms. A player joining the lobby can create a new room, setting the number of player for the future game to start, or can join an existing room. (In the moment they join/create a room, they decide their nickname and their token) Until game is not actually started, the players can be added and removed. If the room remains empty, it is automatically deleted.
When the right number of players is reached, the game automatically starts, adn the associated GameController is created. The players in the room are given the remote object GameControllerRMI via RMI update- The players who were in the room in that moment are so the definite ones for that game and they cannot change. All the rooms and the already started games are associated to a unique gameId.
  • Method Details

    • getRooms

      List<RoomIF> getRooms() throws RemoteException
      Returns:
      List of all rooms in the lobby, both the ones with game starter and not already started
      Throws:
      RemoteException
    • createRoom

      void createRoom(GameListenerClientRMIIF playerListener, int nPlayers) throws LobbyException, RemoteException
      Creates a new Room, for now populated only with the specified player. The gameId is automatically found as the next suitable gameId, hence it is different from the other ones created before by the lobby In case of success, the player who created the room is notified.
      Parameters:
      playerListener - Client listener of the first player who creates the game which will start in the future
      nPlayers - The number of players to start the game, chosen by the player who creates the room
      Throws:
      LobbyException - If the player has a nickName already chosen by another player in the lobby
      RemoteException
    • joinRoom

      void joinRoom(int gameId, GameListenerClientRMIIF playerListener) throws LobbyException, RemoteException
      Adds a players to an existing room, specified by the given gameId. In case of success, the players in that room are notified, and receive an update for the created gameController, too If the room with the newly joined players if full, it makes the game start (and notify the players of this).
      Parameters:
      gameId - Id of the room the player wants to join
      playerListener - Client listener of the player to add to that room
      Throws:
      LobbyException - If the player has a nickName already chosen by another player in the lobby, or if the room with the given gameId does not exist, or if it exists but the room is already full
      RemoteException
    • leaveRoom

      void leaveRoom(PlayerLobby player) throws LobbyException, RemoteException
      Removes a players from the existing room (specified by the given gameId) they joined. In case of success, it notifies the players in the room If the room becomes empty, it is automatically removed, as if it has never been created.
      Parameters:
      player - Player to remove from that room
      Throws:
      LobbyException - If the specified player is not in any existing rooms
      RemoteException
    • reconnectPlayer

      Reconnects a disconnected player for the already started game they took part in. Triggers the notification for other players, and the update for the gameController for the reconnected player.
      Parameters:
      playerListener - Client listener of the player to reconnect
      Throws:
      LobbyException - If the given player is not among players of any started game
      ConnectionException - If the player was already connected
      InvalidPlayerException - If the player is not among the players in the game
      GameStatusException - if any of the methods called directly or indirectly by this method are called in wrong game phase (generic error, should not happen)
      RemoteException