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, Jon Åslund

Field Summary
private  int actionId
          Description of the Field
private  Client cl
          Description of the Field
private  int connectionstatus
          Description of the Field
private  DataInputExchangeHandler DEHInput
          Description of the Field
private  DataOutputExchangeHandler DEHOutput
          Description of the Field
private static int DISCONNECTED
          Description of the Field
private static int HANDSHAKING
          Description of the Field
private  boolean joined
          Description of the Field
private static int JOINED
          Description of the Field
private  ServerConnection sc
          Description of the Field
 
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)
          Description of the Method
 StringTokenizer getAvailableRoles()
          asks the server which roles are available for this client to join as
 Image getMap()
          Called by the client when it wants to get the whole map
 Dimension getMapSize()
          Called by the client when it wants to know the size of the map
 Point getMapUpperLeft()
          Called by the client to get the coordinates of the upper left corner of the 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, registerNatives, toString, wait, wait, wait
 

Field Detail

sc

private ServerConnection sc
Description of the Field

cl

private Client cl
Description of the Field

joined

private boolean joined
Description of the Field

DEHInput

private DataInputExchangeHandler DEHInput
Description of the Field

DEHOutput

private DataOutputExchangeHandler DEHOutput
Description of the Field

actionId

private int actionId
Description of the Field

connectionstatus

private int connectionstatus
Description of the Field

DISCONNECTED

private static final int DISCONNECTED
Description of the Field

HANDSHAKING

private static final int HANDSHAKING
Description of the Field

JOINED

private static final int JOINED
Description of the Field
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 StringTokenizer getAvailableRoles()
asks the server which roles are available for this client to join as
Specified by:
getAvailableRoles in interface Server
Returns:
The AvailableRoles value

getMapUpperLeft

public Point getMapUpperLeft()
Called by the client to get the coordinates of the upper left corner of the map
Specified by:
getMapUpperLeft in interface Server
Returns:
The MapUpperLeft value

getMapSize

public Dimension getMapSize()
Called by the client when it wants to know the size of the map
Specified by:
getMapSize in interface Server
Returns:
The MapSize value

getMap

public Image 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)
Description of the Method
Specified by:
doAction in interface Server
Parameters:
pieceHandle - Description of Parameter
a - Description of Parameter
Returns:
Description of the Returned Value

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