# Class RmiServer

java.lang.Object
java.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
it.polimi.ingsw.is25am31.network.rmi.server.RmiServer

All Implemented Interfaces:
  `VirtualServer`, `Serializable`, `Remote`

public class RmiServer extends UnicastRemoteObject implements VirtualServer
The RmiServer class is an implementation of the VirtualServer interface, extending UnicastRemoteObject. It serves as a remote server that listens for client connections and processes requests to interact with game mechanics. The server communicates with a ControllerManager to delegate and manage client operations.

See Also:
  - Serialized Form

- ## Field Summary

  ### Fields inherited from class java.rmi.server.RemoteObject

  `ref`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RmiServer(ControllerManager controllerManager)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `abandonRace(UUID clientId)`
  Handles a request to abandon the race.
  `void`
  `attachComponent(Component component, int x, int y, UUID clientId)`
  Handles a request to attach specified component on player's ship at specified coordinates
  `static void`
  `bind(ControllerManager controllerManager)`
  `void`
  `connect(VirtualView client)`
  Handles a connection request
  `void`
  `createGame(UUID clientId)`
  Requests the server to create a new game instance.
  `void`
  `drawCard(UUID clientId)`
  Handles request to draw a card from the deck.
  `void`
  `drawFaceDownComponent(UUID clientId)`
  Handles a request to draw a component from face down components,
  `void`
  `drawFaceUpComponent(int id, UUID clientId)`
  Handles a request to draw a face up component.
  `void`
  `drawFromReserved(int index, UUID clientId)`
  Handles a request to draw a component from reserved components
  `void`
  `endAssemblePhase(UUID clientId)`
  Handles a request to end assembling phase
  `void`
  `endCrewPlacingPhase(UUID clientId)`
  Handles a request to end crew placing phase
  `void`
  `getFaceUpComponentList(UUID clientId)`
  Handles a request to see face up components list
  `void`
  `getSubDeck(UUID clientId, int index)`
  Handles a request to see sub deck in specified index.
  `void`
  `increment(UUID clientId)`
  Increments a counter used to trace clients' disconnections.
  `void`
  `joinGame(UUID clientId, int game)`
  Requests the server to join an existing game.
  `void`
  `leaveGame(UUID clientId)`
  Handles request to leave game
  `void`
  `ping(UUID clientId)`
  Sends a ping to the server for connection testing.
  `void`
  `placeCrewMember(UUID clientId, int x, int y, AlienColor type)`
  Handles a request to place crew members/alien of specified type in cabin in specified coordinates of the ship of the player
  `void`
  `placeRocket(UUID clientId, int position)`
  Handles a request to place player's rocket in specified position.
  `void`
  `putDownComponent(Component component, UUID clientId)`
  Handles a request to put down a component
  `void`
  `removeComponent(UUID clientId, int x, int y)`
  Requests the server to remove a component from the client's ship at specified coordinates.
  `void`
  `rollDice(UUID clientId)`
  Handles a request to roll dice.
  `void`
  `setCardContext(UUID clientId, Map<String,Object> context)`
  Handles request to set card context (performing an operation that the player may/must do right before card effect is applied)
  `void`
  `setEffectContext(UUID clientId, Map<String,Object> context)`
  Handles a request to apply card effect
  `void`
  `setGameLevel(UUID clientId, int level)`
  Handles request to set game level
  `void`
  `setMaxPlayers(UUID clientId, int userNumber)`
  Handles request to set max players
  `void`
  `setNickname(String nickname, UUID clientId)`
  Handles request to set nickname.
  `void`
  `showShip(UUID clientId, String nickname)`
  Requests the server to send the ship of a specific player to the requesting client.
  `void`
  `startFinalHourGlass(UUID clientId)`
  Requests the server to start the final hourglass timer.
  `void`
  `startHourGlass(UUID clientId)`
  Requests the server to start a standard hourglass timer.
  `void`
  `viewGame(UUID clientId)`
  Requests the server to send the list of available games that the client can join.

  ### Methods inherited from class java.rmi.server.UnicastRemoteObject

  `clone, exportObject, exportObject, exportObject, exportObject, exportObject, unexportObject`

  ### Methods inherited from class java.rmi.server.RemoteServer

  `getClientHost, getLog, setLog`

  ### Methods inherited from class java.rmi.server.RemoteObject

  `equals, getRef, hashCode, toString, toStub`

  ### Methods inherited from class java.lang.Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### RmiServer

    public RmiServer(ControllerManager controllerManager) throws RemoteException
    Throws:
      `RemoteException`

- ## Method Details

  - ### bind

    public static void bind(ControllerManager controllerManager) throws RemoteException, UnknownHostException
    Throws:
      `RemoteException`
      `UnknownHostException`

  - ### connect

    public void connect(VirtualView client) throws Exception
    Handles a connection request
    Specified by:
      `connect` in interface `VirtualServer`
    Parameters:
      `client` - client to call the remote methods on
    Throws:
      `Exception`

  - ### createGame

    public void createGame(UUID clientId) throws Exception
    Description copied from interface: `VirtualServer`
    Requests the server to create a new game instance.
    Specified by:
      `createGame` in interface `VirtualServer`
    Parameters:
      `clientId` - The ID of the client creating the game.
    Throws:
      `Exception`

  - ### viewGame

    public void viewGame(UUID clientId) throws Exception
    Description copied from interface: `VirtualServer`
    Requests the server to send the list of available games that the client can join.
    Specified by:
      `viewGame` in interface `VirtualServer`
    Parameters:
      `clientId` - The ID of the client.
    Throws:
      `Exception`

  - ### joinGame

    public void joinGame(UUID clientId, int game) throws Exception
    Description copied from interface: `VirtualServer`
    Requests the server to join an existing game.
    Specified by:
      `joinGame` in interface `VirtualServer`
    Parameters:
      `clientId` - The ID of the client joining the game.
      `game` - The ID of the game to join.
    Throws:
      `Exception`

  - ### ping

    public void ping(UUID clientId) throws RemoteException
    Description copied from interface: `VirtualServer`
    Sends a ping to the server for connection testing.
    Specified by:
      `ping` in interface `VirtualServer`
    Parameters:
      `clientId` - The ID of the client sending the ping.
    Throws:
      `RemoteException`

  - ### increment

    public void increment(UUID clientId) throws Exception
    Description copied from interface: `VirtualServer`
    Increments a counter used to trace clients' disconnections.
    Specified by:
      `increment` in interface `VirtualServer`
    Parameters:
      `clientId` - the ID of the client whose value needs to be incremented
    Throws:
      `Exception` - if the increment operation fails or if the client ID is invalid

  - ### setMaxPlayers

    public void setMaxPlayers(UUID clientId, int userNumber) throws Exception
    Handles request to set max players
    Specified by:
      `setMaxPlayers` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
      `userNumber` - number of players required to start the game
    Throws:
      `Exception`

  - ### setGameLevel

    public void setGameLevel(UUID clientId, int level) throws Exception
    Handles request to set game level
    Specified by:
      `setGameLevel` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
      `level` - level of the game
    Throws:
      `Exception`

  - ### leaveGame

    public void leaveGame(UUID clientId) throws Exception
    Handles request to leave game
    Specified by:
      `leaveGame` in interface `VirtualServer`
    Parameters:
      `clientId` - id of the client leaving the game
    Throws:
      `Exception`

  - ### setNickname

    public void setNickname(String nickname, UUID clientId) throws Exception
    Handles request to set nickname.
    Specified by:
      `setNickname` in interface `VirtualServer`
    Parameters:
      `nickname` - nickname the player wants to set
      `clientId` - id of the player's client
    Throws:
      `Exception`

  - ### drawCard

    public void drawCard(UUID clientId) throws Exception
    Handles request to draw a card from the deck.
    Specified by:
      `drawCard` in interface `VirtualServer`
    Parameters:
      `clientId` - The ID of the client.
    Throws:
      `Exception`

  - ### drawFaceDownComponent

    public void drawFaceDownComponent(UUID clientId) throws Exception
    Handles a request to draw a component from face down components,
    Specified by:
      `drawFaceDownComponent` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception`

  - ### putDownComponent

    public void putDownComponent(Component component, UUID clientId) throws Exception
    Handles a request to put down a component
    Specified by:
      `putDownComponent` in interface `VirtualServer`
    Parameters:
      `component` - component to be put back
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception`

  - ### getFaceUpComponentList

    public void getFaceUpComponentList(UUID clientId) throws Exception
    Handles a request to see face up components list
    Specified by:
      `getFaceUpComponentList` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception`

  - ### drawFaceUpComponent

    public void drawFaceUpComponent(int id, UUID clientId) throws Exception
    Handles a request to draw a face up component.
    Specified by:
      `drawFaceUpComponent` in interface `VirtualServer`
    Parameters:
      `id` - component's id
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception` - if either specified component is not in face up components list or someone else already took it

  - ### startHourGlass

    public void startHourGlass(UUID clientId) throws Exception
    Description copied from interface: `VirtualServer`
    Requests the server to start a standard hourglass timer.
    Specified by:
      `startHourGlass` in interface `VirtualServer`
    Parameters:
      `clientId` - The ID of the client.
    Throws:
      `Exception`

  - ### startFinalHourGlass

    public void startFinalHourGlass(UUID clientId) throws Exception
    Description copied from interface: `VirtualServer`
    Requests the server to start the final hourglass timer.
    Specified by:
      `startFinalHourGlass` in interface `VirtualServer`
    Parameters:
      `clientId` - The ID of the client.
    Throws:
      `Exception`

  - ### drawFromReserved

    public void drawFromReserved(int index, UUID clientId) throws Exception
    Handles a request to draw a component from reserved components
    Specified by:
      `drawFromReserved` in interface `VirtualServer`
    Parameters:
      `index` - index of the component that the player wants to draw
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception`

  - ### attachComponent

    public void attachComponent(Component component, int x, int y, UUID clientId) throws Exception
    Handles a request to attach specified component on player's ship at specified coordinates
    Specified by:
      `attachComponent` in interface `VirtualServer`
    Parameters:
      `component` - component to be attached to the ship
      `x` - row to place the component on
      `y` - column to place the component on
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception`

  - ### removeComponent

    public void removeComponent(UUID clientId, int x, int y) throws Exception
    Description copied from interface: `VirtualServer`
    Requests the server to remove a component from the client's ship at specified coordinates.
    Specified by:
      `removeComponent` in interface `VirtualServer`
    Parameters:
      `clientId` - The ID of the client.
      `x` - The row of the component to remove.
      `y` - The column of the component to remove.
    Throws:
      `Exception`

  - ### setCardContext

    public void setCardContext(UUID clientId, Map<String,Object> context) throws Exception
    Handles request to set card context (performing an operation that the player may/must do right before card effect is applied)
    Specified by:
      `setCardContext` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
      `context` - parameters used to set card context (actions done immediately before card effect resolution)
    Throws:
      `Exception`

  - ### setEffectContext

    public void setEffectContext(UUID clientId, Map<String,Object> context) throws Exception
    Handles a request to apply card effect
    Specified by:
      `setEffectContext` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
      `context` - parameters used for card effect resolution
    Throws:
      `Exception`

  - ### endAssemblePhase

    public void endAssemblePhase(UUID clientId) throws Exception
    Handles a request to end assembling phase
    Specified by:
      `endAssemblePhase` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception`

  - ### placeRocket

    public void placeRocket(UUID clientId, int position) throws Exception
    Handles a request to place player's rocket in specified position.
    Specified by:
      `placeRocket` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
      `position` - integer representing the position from which the player wants to start
    Throws:
      `Exception`

  - ### endCrewPlacingPhase

    public void endCrewPlacingPhase(UUID clientId) throws Exception
    Handles a request to end crew placing phase
    Specified by:
      `endCrewPlacingPhase` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception`

  - ### placeCrewMember

    public void placeCrewMember(UUID clientId, int x, int y, AlienColor type) throws Exception
    Handles a request to place crew members/alien of specified type in cabin in specified coordinates of the ship of the player
    Specified by:
      `placeCrewMember` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
      `x` - row of the cabin
      `y` - column of the cabin
      `type` - 1 for humans, 2 for brown alien, 3 for purple alien
    Throws:
      `Exception`

  - ### showShip

    public void showShip(UUID clientId, String nickname) throws Exception
    Description copied from interface: `VirtualServer`
    Requests the server to send the ship of a specific player to the requesting client.
    Specified by:
      `showShip` in interface `VirtualServer`
    Parameters:
      `clientId` - The ID of the client requesting to view the ship.
      `nickname` - The nickname of the player whose ship is to be shown.
    Throws:
      `Exception`

  - ### rollDice

    public void rollDice(UUID clientId) throws Exception
    Handles a request to roll dice.
    Specified by:
      `rollDice` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception` - if player can't roll dice

  - ### getSubDeck

    public void getSubDeck(UUID clientId, int index) throws Exception
    Handles a request to see sub deck in specified index.
    Specified by:
      `getSubDeck` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
      `index` - index of sub deck requested
    Throws:
      `Exception`

  - ### abandonRace

    public void abandonRace(UUID clientId) throws Exception
    Handles a request to abandon the race.
    Specified by:
      `abandonRace` in interface `VirtualServer`
    Parameters:
      `clientId` - UUID of the client calling the method
    Throws:
      `Exception`