megamek.client
Class Client

java.lang.Object
  extended by megamek.client.Client
All Implemented Interfaces:
IClientCommandHandler
Direct Known Subclasses:
BotClient

public class Client
extends java.lang.Object
implements IClientCommandHandler

This class is instanciated for each client and for each bot running on that client. non-local clients are not also instantiated on the local server.


Field Summary
 java.util.Map<java.lang.String,Client> bots
           
static java.lang.String CLIENT_COMMAND
           
 IGame game
           
 int local_pn
           
 java.lang.String phaseReport
           
 java.lang.String roundReport
           
 
Constructor Summary
Client(java.lang.String name, java.lang.String host, int port)
          Construct a client which will try to connect.
 
Method Summary
 void addCloseClientListener(CloseClientListener l)
          Adds the specified close client listener to receive close client events.
 boolean canUnloadStranded()
          Can I unload entities stranded on immobile transports?
 void changePhase(IGame.Phase phase)
          Changes the game phase, and the displays that go along with it.
protected  void changeTurnIndex(int index)
          Change whose turn it is.
 boolean connect()
          Attempt to connect to the specified host
 void deploy(int id, Coords c, int nFacing, int elevation)
          Maintain backwards compatability.
 void deploy(int id, Coords c, int nFacing, int elevation, java.util.List<Entity> loadedUnits, boolean assaultDrop)
          Deploy an entity at the given coordinates, with the given facing, and starting with the given units already loaded.
 void die()
          Shuts down threads and sockets
protected  void disconnected()
          The client has become disconnected from the server
protected  void flushConn()
          send all buffered packets on their way this should be called after everything which causes us to wait for a reply.
 java.util.Enumeration<java.lang.String> getAllCommandNames()
           
 java.util.Vector<Coords> getArtilleryAutoHit()
          Get hexes designated for automatic artillery hits.
 IBoard getBoard()
          Shortcut to game.board
 ClientCommand getCommand(java.lang.String commandName)
          Returns the command associated with the specified name
 java.util.Enumeration<Entity> getEntities()
          Returns an enumeration of the entities in game.entities
 Entity getEntity(int id)
           
 int getFirstDeployableEntityNum()
          Returns the number of the first deployable entity
 int getFirstEntityNum()
          Returns the number of first selectable entity
 java.lang.String getHost()
           
 Player getLocalPlayer()
          Return the local player
 MapSettings getMapSettings()
           
 GameTurn getMyTurn()
           
 java.lang.String getName()
           
 int getNextDeployableEntityNum(int entityId)
          Returns the number of the next deployable entity
 int getNextEntityNum(int entityId)
          Returns the number of the next selectable entity after the one given
 Player getPlayer(int idx)
          Returns the individual player assigned the index parameter.
 java.util.Enumeration<Player> getPlayers()
          Return an enumeration of the players in the game
 int getPort()
           
 java.util.Enumeration<Entity> getSelectedEntities(EntitySelector selector)
          Returns an Enumeration of the entities that match the selection criteria.
protected  void handlePacket(Packet c)
           
 boolean isMyTurn()
          is it my turn?
 void moveEntity(int id, MovePath md)
          Send movement data for the given entity to the server.
protected  void receiveAttack(Packet c)
          Loads entity firing data from the data in the net command
protected  void receiveBoard(Packet c)
          Loads the board from the data in the net command.
protected  void receiveBuildingCollapse(Packet packet)
           
protected  void receiveBuildingUpdateCF(Packet packet)
           
protected  void receiveDeployMinefields(Packet packet)
           
protected  void receiveEntities(Packet c)
          Loads the entities from the data in the net command.
protected  void receiveEntityAdd(Packet packet)
           
protected  void receiveEntityRemove(Packet packet)
           
protected  void receiveEntityUpdate(Packet c)
          Loads entity update data from the data in the net command.
protected  void receiveEntityVisibilityIndicator(Packet packet)
           
protected  void receivePlayerInfo(Packet c)
          Receives player information from the message packet.
protected  void receiveRemoveMinefield(Packet packet)
           
 java.lang.String receiveReport(java.util.Vector<Report> v)
           
protected  void receiveRevealMinefield(Packet packet)
           
protected  void receiveSendingMinefields(Packet packet)
           
protected  void receiveTurns(Packet packet)
          Loads the turn list from the data in the packet
protected  void receiveUpdateMinefields(Packet packet)
           
 void registerCommand(ClientCommand command)
          Registers a new command in the client command table
 void retrieveServerInfo()
          wtf is this?
 java.lang.String runCommand(java.lang.String cmd)
           
 java.lang.String runCommand(java.lang.String[] args)
          Runs the command
protected  void send(Packet packet)
          send the message to the server
 void sendAddEntity(Entity entity)
          Sends an "add entity" packet
 void sendAddSquadron(java.util.Vector<Entity> fighters)
          Sends an "add squadron" packet This is not working, don't use it
 void sendAmmoChange(int nEntity, int nWeapon, int nAmmo)
          Send mode-change data to the server
 void sendArtyAutoHitHexes(java.util.Vector<Coords> hexes)
          Sends a "set Artillery Autohit Hexes" packet
 void sendAttackData(int aen, java.util.Vector<EntityAction> attacks)
          Send a weapon fire command to the server.
 void sendCalledShotChange(int nEntity, int nEquip)
          Send called shot change data to the server
 void sendChat(java.lang.String message)
          Broadcast a general chat message from the local player
 void sendCustomInit(Player player)
          Sends an "update custom initiative" packet
 void sendDeleteEntity(int id)
          Sends a "delete entity" packet
 void sendDeployMinefields(java.util.Vector<Minefield> minefields)
          Sends an "deploy minefields" packet
 void sendDone(boolean done)
          Sends a "player done" message to the server.
 void sendGameOptions(java.lang.String password, java.util.Vector<IBasicOption> options)
          Send the game options to the server
 void sendLoadGame(java.io.File f)
          sends a load game file to the server
 void sendMapDimensions(MapSettings settings)
          Send the new map dimensions to the server
 void sendMapSettings(MapSettings settings)
          Send the new map selection to the server
 void sendModeChange(int nEntity, int nEquip, int nMode)
          Send mode-change data to the server
 void sendPlanetaryConditions(PlanetaryConditions conditions)
          Send the planetary Conditions to the server
 void sendPlayerInfo()
          Sends the info associated with the local player.
 void sendRerollInitiativeRequest()
          Sends a "reroll initiative" message to the server.
 void sendSystemModeChange(int nEntity, int nSystem, int nMode)
          Send system mode-change data to the server
 void sendUnloadStranded(int[] entityIds)
          Send command to unload stranded entities to the server
 void sendUpdateEntity(Entity entity)
          Sends an "update entity" packet
 void setName(java.lang.String newN)
           
protected  void updateConnection()
          call this once to update the connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLIENT_COMMAND

public static final java.lang.String CLIENT_COMMAND
See Also:
Constant Field Values

local_pn

public int local_pn

game

public IGame game

phaseReport

public java.lang.String phaseReport

roundReport

public java.lang.String roundReport

bots

public java.util.Map<java.lang.String,Client> bots
Constructor Detail

Client

public Client(java.lang.String name,
              java.lang.String host,
              int port)
Construct a client which will try to connect. If the connection fails, it will alert the player, free resources and hide the frame.

Parameters:
name - the player name for this client
host - the hostname
port - the host port
Method Detail

updateConnection

protected void updateConnection()
call this once to update the connection


connect

public boolean connect()
Attempt to connect to the specified host


die

public void die()
Shuts down threads and sockets


disconnected

protected void disconnected()
The client has become disconnected from the server


getArtilleryAutoHit

public java.util.Vector<Coords> getArtilleryAutoHit()
Get hexes designated for automatic artillery hits.


getPlayers

public java.util.Enumeration<Player> getPlayers()
Return an enumeration of the players in the game


getEntity

public Entity getEntity(int id)

getPlayer

public Player getPlayer(int idx)
Returns the individual player assigned the index parameter.


getLocalPlayer

public Player getLocalPlayer()
Return the local player


getSelectedEntities

public java.util.Enumeration<Entity> getSelectedEntities(EntitySelector selector)
Returns an Enumeration of the entities that match the selection criteria.


getFirstEntityNum

public int getFirstEntityNum()
Returns the number of first selectable entity


getNextEntityNum

public int getNextEntityNum(int entityId)
Returns the number of the next selectable entity after the one given


getFirstDeployableEntityNum

public int getFirstDeployableEntityNum()
Returns the number of the first deployable entity


getNextDeployableEntityNum

public int getNextDeployableEntityNum(int entityId)
Returns the number of the next deployable entity


getBoard

public IBoard getBoard()
Shortcut to game.board


getEntities

public java.util.Enumeration<Entity> getEntities()
Returns an enumeration of the entities in game.entities


getMapSettings

public MapSettings getMapSettings()

changePhase

public void changePhase(IGame.Phase phase)
Changes the game phase, and the displays that go along with it.


addCloseClientListener

public void addCloseClientListener(CloseClientListener l)
Adds the specified close client listener to receive close client events. This is used by external programs running megamek

Parameters:
l - the game listener.

retrieveServerInfo

public void retrieveServerInfo()
wtf is this? waits for 5 seconds just for nothing?? - itmo fixed this to be a bit more sensible..


isMyTurn

public boolean isMyTurn()
is it my turn?


getMyTurn

public GameTurn getMyTurn()

canUnloadStranded

public boolean canUnloadStranded()
Can I unload entities stranded on immobile transports?


sendUnloadStranded

public void sendUnloadStranded(int[] entityIds)
Send command to unload stranded entities to the server


changeTurnIndex

protected void changeTurnIndex(int index)
Change whose turn it is.


sendModeChange

public void sendModeChange(int nEntity,
                           int nEquip,
                           int nMode)
Send mode-change data to the server


sendCalledShotChange

public void sendCalledShotChange(int nEntity,
                                 int nEquip)
Send called shot change data to the server


sendSystemModeChange

public void sendSystemModeChange(int nEntity,
                                 int nSystem,
                                 int nMode)
Send system mode-change data to the server


sendAmmoChange

public void sendAmmoChange(int nEntity,
                           int nWeapon,
                           int nAmmo)
Send mode-change data to the server


moveEntity

public void moveEntity(int id,
                       MovePath md)
Send movement data for the given entity to the server.


deploy

public void deploy(int id,
                   Coords c,
                   int nFacing,
                   int elevation)
Maintain backwards compatability.

Parameters:
id - - the int ID of the deployed entity
c - - the Coords where the entity should be deployed
nFacing - - the int direction the entity should face

deploy

public void deploy(int id,
                   Coords c,
                   int nFacing,
                   int elevation,
                   java.util.List<Entity> loadedUnits,
                   boolean assaultDrop)
Deploy an entity at the given coordinates, with the given facing, and starting with the given units already loaded.

Parameters:
id - - the int ID of the deployed entity
c - - the Coords where the entity should be deployed
nFacing - - the int direction the entity should face
loadedUnits - - a List of units that start the game being transported byt the deployed entity.
assaultDrop - - true if deployment is an assault drop

sendAttackData

public void sendAttackData(int aen,
                           java.util.Vector<EntityAction> attacks)
Send a weapon fire command to the server.


sendGameOptions

public void sendGameOptions(java.lang.String password,
                            java.util.Vector<IBasicOption> options)
Send the game options to the server


sendMapSettings

public void sendMapSettings(MapSettings settings)
Send the new map selection to the server


sendMapDimensions

public void sendMapDimensions(MapSettings settings)
Send the new map dimensions to the server


sendPlanetaryConditions

public void sendPlanetaryConditions(PlanetaryConditions conditions)
Send the planetary Conditions to the server


sendChat

public void sendChat(java.lang.String message)
Broadcast a general chat message from the local player


sendDone

public void sendDone(boolean done)
Sends a "player done" message to the server.


sendRerollInitiativeRequest

public void sendRerollInitiativeRequest()
Sends a "reroll initiative" message to the server.


sendPlayerInfo

public void sendPlayerInfo()
Sends the info associated with the local player.


sendAddEntity

public void sendAddEntity(Entity entity)
Sends an "add entity" packet


sendAddSquadron

public void sendAddSquadron(java.util.Vector<Entity> fighters)
Sends an "add squadron" packet This is not working, don't use it


sendDeployMinefields

public void sendDeployMinefields(java.util.Vector<Minefield> minefields)
Sends an "deploy minefields" packet


sendArtyAutoHitHexes

public void sendArtyAutoHitHexes(java.util.Vector<Coords> hexes)
Sends a "set Artillery Autohit Hexes" packet


sendUpdateEntity

public void sendUpdateEntity(Entity entity)
Sends an "update entity" packet


sendCustomInit

public void sendCustomInit(Player player)
Sends an "update custom initiative" packet


sendDeleteEntity

public void sendDeleteEntity(int id)
Sends a "delete entity" packet


sendLoadGame

public void sendLoadGame(java.io.File f)
sends a load game file to the server


receivePlayerInfo

protected void receivePlayerInfo(Packet c)
Receives player information from the message packet.


receiveTurns

protected void receiveTurns(Packet packet)
Loads the turn list from the data in the packet


receiveBoard

protected void receiveBoard(Packet c)
Loads the board from the data in the net command.


receiveEntities

protected void receiveEntities(Packet c)
Loads the entities from the data in the net command.


receiveEntityUpdate

protected void receiveEntityUpdate(Packet c)
Loads entity update data from the data in the net command.


receiveEntityAdd

protected void receiveEntityAdd(Packet packet)

receiveEntityRemove

protected void receiveEntityRemove(Packet packet)

receiveEntityVisibilityIndicator

protected void receiveEntityVisibilityIndicator(Packet packet)

receiveDeployMinefields

protected void receiveDeployMinefields(Packet packet)

receiveSendingMinefields

protected void receiveSendingMinefields(Packet packet)

receiveRevealMinefield

protected void receiveRevealMinefield(Packet packet)

receiveRemoveMinefield

protected void receiveRemoveMinefield(Packet packet)

receiveUpdateMinefields

protected void receiveUpdateMinefields(Packet packet)

receiveBuildingUpdateCF

protected void receiveBuildingUpdateCF(Packet packet)

receiveBuildingCollapse

protected void receiveBuildingCollapse(Packet packet)

receiveAttack

protected void receiveAttack(Packet c)
Loads entity firing data from the data in the net command


receiveReport

public java.lang.String receiveReport(java.util.Vector<Report> v)

send

protected void send(Packet packet)
send the message to the server


flushConn

protected void flushConn()
send all buffered packets on their way this should be called after everything which causes us to wait for a reply. For example "done" button presses etc. to make stuff more efficient, this should only be called after a batch of packets is sent,not separately for each packet


handlePacket

protected void handlePacket(Packet c)

getName

public java.lang.String getName()

getPort

public int getPort()

getHost

public java.lang.String getHost()

setName

public void setName(java.lang.String newN)

runCommand

public java.lang.String runCommand(java.lang.String cmd)
Parameters:
text - a client command with CLIENT_COMMAND prepended.

runCommand

public java.lang.String runCommand(java.lang.String[] args)
Runs the command

Parameters:
args - the command and it's arguments with the CLIENT_COMMAND already removed, and the string tokenized.

registerCommand

public void registerCommand(ClientCommand command)
Registers a new command in the client command table

Specified by:
registerCommand in interface IClientCommandHandler

getCommand

public ClientCommand getCommand(java.lang.String commandName)
Returns the command associated with the specified name

Specified by:
getCommand in interface IClientCommandHandler

getAllCommandNames

public java.util.Enumeration<java.lang.String> getAllCommandNames()
Specified by:
getAllCommandNames in interface IClientCommandHandler