gecco.communication.server
Class ClientAmbassador

java.lang.Object
  |
  +--gecco.communication.server.ClientAmbassador
All Implemented Interfaces:
Client

public class ClientAmbassador
extends Object
implements Client

The class that implements gecco.server.core.Client, and the only part of the communication package that the server needs to know about

Author:
Niklas Hallenfur, Henrik Hägerström, Jon Åslund

Field Summary
private  byte[] initialMapRGB
          Description of the Field
private  Dimension mapSize
          Description of the Field
private  Vector roledefs
          Description of the Field
private  Hashtable roles
          Description of the Field
private  Server server
          Description of the Field
 
Constructor Summary
ClientAmbassador(Vector rd, Server server, int port)
          Initiates the ServerAmbassador, and also starts a Thread that listens for incoming clients
 
Method Summary
 boolean acceptRole(String role)
          Called by NewClientListener when it wants to check if the role a client wants to join as, is a legal role
 void actionCompleted(String role, int actionHandle, String unitMessage)
          Description of the Method
 void actionFailed(String role, int actionHandle, String errorMessage)
          Description of the Method
 void addClient(ClientConnection c)
          Called by NewClientListener when it has received a legal join request from a client
 void automatonHasState(String role, int x, int y, Color color)
          Description of the Method
 void automatonInvisible(String role, int x, int y)
          Description of the Method
 void automatonsHasState(String role, List pointObjects, List colors)
          Description of the Method
 void automatonsInvisible(String role, List pointObjects)
          Description of the Method
 void connectionLost(String role, int id)
          Description of the Method
 int getAvailableId(String role)
          Called by NewClientListener when it is about to add a client, and wants to know what id the client should have.
 byte[] getMap()
          Gets the Map attribute of the ClientAmbassador object
 Dimension getMapSize()
          Gets the MapSize attribute of the ClientAmbassador object
 int getNumberOfClients()
          returns the number of clients that are connected as any role
 int getNumberOfClients(String role)
          returns the number of clients that are connected as 'role' at the moment.
 Map getUnitTypeIcons()
          Gets the UnitTypeIcons attribute of the ClientAmbassador object
 String rolesLeft()
          Called by NewClientListener when a client has asked for the available roles.
 void unitActionBlocked(String role, int handle, ActionDefinition action, boolean isBlocked)
          Description of the Method
 void unitDeleted(String role, int handle)
          Description of the Method
 void unitInvisible(String role, int handle)
          Description of the Method
 void unitMessage(String role, int unitHandle, String message)
          Description of the Method
 void unitMoved(String role, int handle, double newX, double newY)
          Description of the Method
 void unitPropertyChanged(String role, int handle, String key, String newValue)
          Description of the Method
 void unitVisible(String role, int handle, String name, String type, double x, double y, Set unblockedActions, Set blockedActions, Map properties)
          Here follows the implementation of the methods in interface gecco.server.core.Client.
 String whoIsConnected()
          returns a String with the names of all connected clients
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

roles

private Hashtable roles
Description of the Field

roledefs

private Vector roledefs
Description of the Field

server

private Server server
Description of the Field

initialMapRGB

private byte[] initialMapRGB
Description of the Field

mapSize

private Dimension mapSize
Description of the Field
Constructor Detail

ClientAmbassador

public ClientAmbassador(Vector rd,
                        Server server,
                        int port)
Initiates the ServerAmbassador, and also starts a Thread that listens for incoming clients
Parameters:
rd - A vector containing RoleDefinition objects, used to create the appropriate number of RoleConnectoions, and to keep track of what roles are still available to join as
server - The server from the communication parts point of view
port - The port at which to listen for incoming connections from clients.
Method Detail

getNumberOfClients

public int getNumberOfClients(String role)
returns the number of clients that are connected as 'role' at the moment.
Parameters:
role - Description of Parameter
Returns:
The NumberOfClients value

getNumberOfClients

public int getNumberOfClients()
returns the number of clients that are connected as any role
Returns:
The NumberOfClients value

getAvailableId

public int getAvailableId(String role)
Called by NewClientListener when it is about to add a client, and wants to know what id the client should have. returns a id that is unused by clients of role 'role'
Parameters:
role - Description of Parameter
Returns:
The AvailableId value

getMapSize

public Dimension getMapSize()
Gets the MapSize attribute of the ClientAmbassador object
Returns:
The MapSize value

getMap

public byte[] getMap()
Gets the Map attribute of the ClientAmbassador object
Returns:
The Map value

getUnitTypeIcons

public Map getUnitTypeIcons()
Gets the UnitTypeIcons attribute of the ClientAmbassador object
Returns:
The UnitTypeIcons value

addClient

public void addClient(ClientConnection c)
Called by NewClientListener when it has received a legal join request from a client
Parameters:
c - The object that represents the connection to the client to join.

acceptRole

public boolean acceptRole(String role)
Called by NewClientListener when it wants to check if the role a client wants to join as, is a legal role
Parameters:
role - Description of Parameter
Returns:
Description of the Returned Value

whoIsConnected

public String whoIsConnected()
returns a String with the names of all connected clients
Returns:
Description of the Returned Value

rolesLeft

public String rolesLeft()
Called by NewClientListener when a client has asked for the available roles. returns the available roles as a String, with the roles separated by spaces
Returns:
Description of the Returned Value

connectionLost

public void connectionLost(String role,
                           int id)
Description of the Method
Parameters:
role - Description of Parameter
id - Description of Parameter

unitVisible

public void unitVisible(String role,
                        int handle,
                        String name,
                        String type,
                        double x,
                        double y,
                        Set unblockedActions,
                        Set blockedActions,
                        Map properties)
Here follows the implementation of the methods in interface gecco.server.core.Client. For details, see gecco.server.core.Client.
Specified by:
unitVisible in interface Client
Parameters:
role - Description of Parameter
handle - Description of Parameter
name - Description of Parameter
type - Description of Parameter
x - Description of Parameter
y - Description of Parameter
unblockedActions - Description of Parameter
blockedActions - Description of Parameter
properties - Description of Parameter

unitInvisible

public void unitInvisible(String role,
                          int handle)
Description of the Method
Specified by:
unitInvisible in interface Client
Parameters:
role - Description of Parameter
handle - Description of Parameter

unitDeleted

public void unitDeleted(String role,
                        int handle)
Description of the Method
Specified by:
unitDeleted in interface Client
Parameters:
role - Description of Parameter
handle - Description of Parameter

unitMoved

public void unitMoved(String role,
                      int handle,
                      double newX,
                      double newY)
Description of the Method
Specified by:
unitMoved in interface Client
Parameters:
role - Description of Parameter
handle - Description of Parameter
newX - Description of Parameter
newY - Description of Parameter

unitPropertyChanged

public void unitPropertyChanged(String role,
                                int handle,
                                String key,
                                String newValue)
Description of the Method
Specified by:
unitPropertyChanged in interface Client
Parameters:
role - Description of Parameter
handle - Description of Parameter
key - Description of Parameter
newValue - Description of Parameter

unitActionBlocked

public void unitActionBlocked(String role,
                              int handle,
                              ActionDefinition action,
                              boolean isBlocked)
Description of the Method
Specified by:
unitActionBlocked in interface Client
Parameters:
role - Description of Parameter
handle - Description of Parameter
action - Description of Parameter
isBlocked - Description of Parameter

automatonHasState

public void automatonHasState(String role,
                              int x,
                              int y,
                              Color color)
Description of the Method
Specified by:
automatonHasState in interface Client
Parameters:
role - Description of Parameter
x - Description of Parameter
y - Description of Parameter
color - Description of Parameter

automatonInvisible

public void automatonInvisible(String role,
                               int x,
                               int y)
Description of the Method
Specified by:
automatonInvisible in interface Client
Parameters:
role - Description of Parameter
x - Description of Parameter
y - Description of Parameter

actionCompleted

public void actionCompleted(String role,
                            int actionHandle,
                            String unitMessage)
Description of the Method
Specified by:
actionCompleted in interface Client
Parameters:
role - Description of Parameter
actionHandle - Description of Parameter
unitMessage - Description of Parameter

actionFailed

public void actionFailed(String role,
                         int actionHandle,
                         String errorMessage)
Description of the Method
Specified by:
actionFailed in interface Client
Parameters:
role - Description of Parameter
actionHandle - Description of Parameter
errorMessage - Description of Parameter

automatonsHasState

public void automatonsHasState(String role,
                               List pointObjects,
                               List colors)
Description of the Method
Specified by:
automatonsHasState in interface Client
Parameters:
role - Description of Parameter
pointObjects - Description of Parameter
colors - Description of Parameter

automatonsInvisible

public void automatonsInvisible(String role,
                                List pointObjects)
Description of the Method
Specified by:
automatonsInvisible in interface Client
Parameters:
role - Description of Parameter
pointObjects - Description of Parameter

unitMessage

public void unitMessage(String role,
                        int unitHandle,
                        String message)
Description of the Method
Specified by:
unitMessage in interface Client
Parameters:
role - Description of Parameter
unitHandle - Description of Parameter
message - Description of Parameter