Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## gecco.communication.client
Class ServerAmbassador

    java.lang.Object
      gecco.communication.client.ServerAmbassador

All Implemented Interfaces:
  Server

public class ServerAmbassador
extends Object
implements Server

This is the class that implements gecco.client.Server, and is the only part of the communication the client knows of.

Author:
  Niklas Hallenfur, Karl Hasselström, Jon Åslund

Constructor Summary
`ServerAmbassador(Client cl)`

Method Summary
`void` | `abortAction(long actionId)` Called by the client when it wants a unit to abort an action
`boolean` | `connect(String host, int port)` tries to connect to the server returns false if failed to connect
`void` | `connectionLost()` Called whenever a communication error occurs.
`void` | `disconnect()` Called by the client when it wants to disconnect
`long` | `doAction(int pieceHandle, Action a)` Called by the client when it wants a unit to perform an action.
`Set` | `getAvailableRoles()` asks the server which roles are available for this client to join as
`BufferedImage` | `getMap()` Called by the client when it wants to get the whole map
`boolean` | `joinAsRole(String role)` Tells the server that the client wants to join the game.
`void` | `startGame()` Called by the client when it is ready to receive messages from the server

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ServerAmbassador

    public ServerAmbassador(Client cl)

Parameters:
  `cl` - The object that implements gecco.client.Client, and the only part of the client that the communication part is aware of

Method Detail

### getAvailableRoles

    public Set getAvailableRoles()

  asks the server which roles are available for this client to join as

  Specified by:
    `getAvailableRoles` in interface `Server`
  Returns:
    The AvailableRoles value

### getMap

    public BufferedImage getMap()

  Called by the client when it wants to get the whole map

  Specified by:
    `getMap` in interface `Server`
  Returns:
    The Map value

### connect

    public boolean connect(String host,
                           int port)

  tries to connect to the server returns false if failed to connect

  Specified by:
    `connect` in interface `Server`
  Parameters:
    `host` - The name of the host where to find the server
    `port` - The port number to connect to
  Returns:
    Description of the Returned Value

### joinAsRole

    public boolean joinAsRole(String role)

  Tells the server that the client wants to join the game.

  Specified by:
    `joinAsRole` in interface `Server`
  Parameters:
    `role` - The role this client wants to join as
  Returns:
    Description of the Returned Value

### connectionLost

    public void connectionLost()

  Called whenever a communication error occurs. Kills the Thread that checks for incoming and outgoing messages, and tells the client that the connection i lost

### doAction

    public long doAction(int pieceHandle,
                         Action a)

  Called by the client when it wants a unit to perform an action. Checks the target type, and creates an ActionMessage of the appropriate type, and adds it to the send queue.

  Specified by:
    `doAction` in interface `Server`
  Parameters:
    `pieceHandle` - Description of Parameter
    `a` - Description of Parameter
  Returns:
    A unique id for the action, or -1 if the action couldn't be sent.

### abortAction

    public void abortAction(long actionId)

  Called by the client when it wants a unit to abort an action

  Specified by:
    `abortAction` in interface `Server`
  Parameters:
    `actionId` - Description of Parameter

### disconnect

    public void disconnect()

  Called by the client when it wants to disconnect

  Specified by:
    `disconnect` in interface `Server`

### startGame

    public void startGame()

  Called by the client when it is ready to receive messages from the server

  Specified by:
    `startGame` in interface `Server`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD