# Class SocketServerHandler

java.lang.Object
it.polimi.ingsw.is25am31.network.socket.client.SocketServerHandler

All Implemented Interfaces:
  `VirtualServer`, `Remote`

public class SocketServerHandler extends Object implements VirtualServer
The `SocketServerHandler` class acts as a client-side proxy for the server in a socket-based communication. It implements the `VirtualServer` interface, allowing the client to invoke "remote" methods that are then serialized as command objects and sent to the actual server via an `ObjectOutputStream`. This class handles the serialization and sending of various client-to-server messages.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SocketServerHandler(ObjectOutputStream out)`
  Constructs a new `SocketServerHandler`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `abandonRace(UUID clientId)`
  Sends a command to the server for a client to abandon the race.
  `void`
  `attachComponent(Component component, int x, int y, UUID clientId)`
  Sends a command to the server for a client to attach a component at specified coordinates.
  `void`
  `connect(VirtualView client)`
  This method is part of the `VirtualServer` interface but is not directly used in the current socket communication model for connecting.
  `void`
  `createGame(UUID clientId)`
  Sends a command to the server for a client to create a new game.
  `void`
  `drawCard(UUID clientId)`
  Sends a command to the server for a client to draw a card.
  `void`
  `drawFaceDownComponent(UUID clientId)`
  Sends a command to the server for a client to draw a face-down component.
  `void`
  `drawFaceUpComponent(int index, UUID clientId)`
  Sends a command to the server for a client to draw a face-up component at a specific index.
  `void`
  `drawFromReserved(int index, UUID clientId)`
  Sends a command to the server for a client to draw from the reserved components at a specific index.
  `void`
  `endAssemblePhase(UUID clientId)`
  Sends a command to the server to signal the end of the assemble phase for a client.
  `void`
  `endCrewPlacingPhase(UUID clientId)`
  Sends a command to the server to signal the end of the crew placing phase for a client.
  `void`
  `getFaceUpComponentList(UUID clientId)`
  Sends a command to the server to request the list of face-up components.
  `void`
  `getSubDeck(UUID clientId, int index)`
  Sends a command to the server to get a sub-deck from the game.
  `void`
  `increment(UUID clientId)`
  Sends an increment command to the server.
  `void`
  `joinGame(UUID clientId, int game)`
  Sends a command to the server for a client to join a specific game.
  `void`
  `leaveGame(UUID clientId)`
  Sends a command to the server for a client to leave the current game.
  `void`
  `ping(UUID clientId)`
  Sends a ping command to the server to test connectivity.
  `void`
  `placeCrewMember(UUID clientId, int x, int y, AlienColor a)`
  Sends a command to the server for a client to place a crew member at specified coordinates with a specific color (if it's an alien).
  `void`
  `placeRocket(UUID clientId, int position)`
  Sends a command to the server for a client to place a rocket at a specific position.
  `void`
  `putDownComponent(Component component, UUID clientId)`
  Sends a command to the server for a client to put down a component.
  `void`
  `removeComponent(UUID clientId, int x, int y)`
  Sends a command to the server to remove a component at specified coordinates.
  `void`
  `rollDice(UUID clientId)`
  Sends a command to the server for a client to roll the dice.
  `void`
  `setCardContext(UUID clientId, Map<String,Object> context)`
  Sends a command to the server to set the context for a card operation.
  `void`
  `setEffectContext(UUID clientId, Map<String,Object> context)`
  Sends a command to the server to set the context for an effect resolution.
  `void`
  `setGameLevel(UUID clientId, int level)`
  Sends a command to the server to set the game level.
  `void`
  `setMaxPlayers(UUID clientId, int maxPlayers)`
  Sends a command to the server to set the maximum number of players for a game.
  `void`
  `setNickname(String nickname, UUID clientId)`
  Sends a command to the server to set a client's nickname.
  `void`
  `showShip(UUID clientId, String nickname)`
  Sends a command to the server to request showing a ship belonging to a specific player.
  `void`
  `startFinalHourGlass(UUID clientId)`
  Sends a command to the server to start the final hourglass timer.
  `void`
  `startHourGlass(UUID clientId)`
  Sends a command to the server to start an hourglass timer.
  `void`
  `viewGame(UUID clientId)`
  Sends a command to the server for a client to view available games.

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

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SocketServerHandler

    public SocketServerHandler(ObjectOutputStream out)
    Constructs a new `SocketServerHandler`.
    Parameters:
      `out` - The `ObjectOutputStream` used to send command objects to the server.

- ## Method Details

  - ### connect

    public void connect(VirtualView client)
    This method is part of the `VirtualServer` interface but is not directly used in the current socket communication model for connecting.
    Specified by:
      `connect` in interface `VirtualServer`
    Parameters:
      `client` - The `VirtualView` instance of the client. (Not used for sending a command)

  - ### leaveGame

    public void leaveGame(UUID clientId) throws IOException
    Sends a command to the server for a client to leave the current game.
    Specified by:
      `leaveGame` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting to leave.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### drawCard

    public void drawCard(UUID clientId) throws IOException
    Sends a command to the server for a client to draw a card.
    Specified by:
      `drawCard` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting to draw a card.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### drawFaceDownComponent

    public void drawFaceDownComponent(UUID clientId) throws IOException
    Sends a command to the server for a client to draw a face-down component.
    Specified by:
      `drawFaceDownComponent` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting to draw a face-down component.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### drawFaceUpComponent

    public void drawFaceUpComponent(int index, UUID clientId) throws IOException
    Sends a command to the server for a client to draw a face-up component at a specific index.
    Specified by:
      `drawFaceUpComponent` in interface `VirtualServer`
    Parameters:
      `index` - The index of the face-up component to draw.
      `clientId` - The `UUID` of the client requesting to draw the component.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### attachComponent

    public void attachComponent(Component component, int x, int y, UUID clientId) throws IOException
    Sends a command to the server for a client to attach a component at specified coordinates.
    Specified by:
      `attachComponent` in interface `VirtualServer`
    Parameters:
      `component` - The `Component` to be attached.
      `x` - The line to attach the component on.
      `y` - The column to attach the component on.
      `clientId` - The `UUID` of the client performing the action.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### setNickname

    public void setNickname(String nickname, UUID clientId) throws IOException
    Sends a command to the server to set a client's nickname.
    Specified by:
      `setNickname` in interface `VirtualServer`
    Parameters:
      `nickname` - The desired nickname for the client.
      `clientId` - The `UUID` of the client setting the nickname.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### setCardContext

    public void setCardContext(UUID clientId, Map<String,Object> context) throws IOException
    Sends a command to the server to set the context for a card operation. This context can contain various parameters needed for a card's effect.
    Specified by:
      `setCardContext` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client providing the context.
      `context` - A `Map` containing key-value pairs representing the card context.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### setEffectContext

    public void setEffectContext(UUID clientId, Map<String,Object> context) throws IOException
    Sends a command to the server to set the context for an effect resolution. This context can contain various parameters needed for resolving an effect.
    Specified by:
      `setEffectContext` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client providing the context.
      `context` - A `Map` containing key-value pairs representing the effect context.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### endAssemblePhase

    public void endAssemblePhase(UUID clientId) throws IOException
    Sends a command to the server to signal the end of the assemble phase for a client.
    Specified by:
      `endAssemblePhase` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client ending the assemble phase.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### setMaxPlayers

    public void setMaxPlayers(UUID clientId, int maxPlayers) throws IOException
    Sends a command to the server to set the maximum number of players for a game. This is typically done by the game creator.
    Specified by:
      `setMaxPlayers` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client setting the maximum players.
      `maxPlayers` - The maximum number of players allowed in the game.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### setGameLevel

    public void setGameLevel(UUID clientId, int level) throws IOException
    Sends a command to the server to set the game level. This is typically done by the game creator.
    Specified by:
      `setGameLevel` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client setting the game level.
      `level` - The desired game level.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### showShip

    public void showShip(UUID clientId, String nickname) throws IOException
    Sends a command to the server to request showing a ship belonging to a specific player.
    Specified by:
      `showShip` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting the action.
      `nickname` - The nickname of the player whose ship is to be shown.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### rollDice

    public void rollDice(UUID clientId) throws IOException
    Sends a command to the server for a client to roll the dice.
    Specified by:
      `rollDice` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting to roll the dice.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### putDownComponent

    public void putDownComponent(Component component, UUID clientId) throws IOException
    Sends a command to the server for a client to put down a component.
    Specified by:
      `putDownComponent` in interface `VirtualServer`
    Parameters:
      `component` - The `Component` to be put down.
      `clientId` - The `UUID` of the client performing the action.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### getFaceUpComponentList

    public void getFaceUpComponentList(UUID clientId) throws IOException
    Sends a command to the server to request the list of face-up components.
    Specified by:
      `getFaceUpComponentList` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting the list.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### drawFromReserved

    public void drawFromReserved(int index, UUID clientId) throws IOException
    Sends a command to the server for a client to draw from the reserved components at a specific index.
    Specified by:
      `drawFromReserved` in interface `VirtualServer`
    Parameters:
      `index` - The index in the reserved components from which to draw.
      `clientId` - The `UUID` of the client performing the action.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### removeComponent

    public void removeComponent(UUID clientId, int x, int y) throws IOException
    Sends a command to the server to remove a component at specified coordinates.
    Specified by:
      `removeComponent` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting the action.
      `x` - The X-coordinate of the component to remove.
      `y` - The Y-coordinate of the component to remove.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### getSubDeck

    public void getSubDeck(UUID clientId, int index) throws IOException
    Sends a command to the server to get a sub-deck from the game.
    Specified by:
      `getSubDeck` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting the sub-deck.
      `index` - The index of the sub-deck to retrieve.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### placeRocket

    public void placeRocket(UUID clientId, int position) throws IOException
    Sends a command to the server for a client to place a rocket at a specific position.
    Specified by:
      `placeRocket` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client performing the action.
      `position` - The position where the rocket is to be placed.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### endCrewPlacingPhase

    public void endCrewPlacingPhase(UUID clientId) throws IOException
    Sends a command to the server to signal the end of the crew placing phase for a client.
    Specified by:
      `endCrewPlacingPhase` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client ending the phase.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### placeCrewMember

    public void placeCrewMember(UUID clientId, int x, int y, AlienColor a) throws IOException
    Sends a command to the server for a client to place a crew member at specified coordinates with a specific color (if it's an alien).
    Specified by:
      `placeCrewMember` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client performing the action.
      `x` - The row where the crew member is placed.
      `y` - The column where the crew member is placed.
      `a` - The `AlienColor` of the crew member.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### startHourGlass

    public void startHourGlass(UUID clientId) throws IOException
    Sends a command to the server to start an hourglass timer.
    Specified by:
      `startHourGlass` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client initiating the hourglass.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### startFinalHourGlass

    public void startFinalHourGlass(UUID clientId) throws IOException
    Sends a command to the server to start the final hourglass timer.
    Specified by:
      `startFinalHourGlass` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client initiating the final hourglass.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### abandonRace

    public void abandonRace(UUID clientId) throws IOException
    Sends a command to the server for a client to abandon the race.
    Specified by:
      `abandonRace` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client abandoning the race.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### ping

    public void ping(UUID clientId) throws IOException
    Sends a ping command to the server to test connectivity.
    Specified by:
      `ping` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client sending the ping.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### increment

    public void increment(UUID clientId) throws IOException
    Sends an increment command to the server. (Specific use case for a game mechanic or test).
    Specified by:
      `increment` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting the increment.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### createGame

    public void createGame(UUID clientId) throws IOException
    Sends a command to the server for a client to create a new game.
    Specified by:
      `createGame` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client creating the game.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### viewGame

    public void viewGame(UUID clientId) throws IOException
    Sends a command to the server for a client to view available games.
    Specified by:
      `viewGame` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting to view games.
    Throws:
      `IOException` - If an I/O error occurs during communication.

  - ### joinGame

    public void joinGame(UUID clientId, int game) throws IOException
    Sends a command to the server for a client to join a specific game.
    Specified by:
      `joinGame` in interface `VirtualServer`
    Parameters:
      `clientId` - The `UUID` of the client requesting to join the game.
      `game` - The integer ID of the game to join.
    Throws:
      `IOException` - If an I/O error occurs during communication.