Package megamek.client
Class Client
java.lang.Object
megamek.client.AbstractClient
megamek.client.Client
- All Implemented Interfaces:
IClient
- Direct Known Subclasses:
BotClient,HeadlessClient
This class is instantiated for each client and for each bot running on that client. non-local clients are not also
instantiated on the local server.
-
Nested Class Summary
Nested classes/interfaces inherited from class megamek.client.AbstractClient
AbstractClient.ConnectionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final GameThe game state object: this object is not ever replaced during a game, only updated.Fields inherited from class megamek.client.AbstractClient
awaitingSave, bots, connected, connection, connectionListener, connThread, disconnectFlag, host, iconCache, localPlayerNumber, log, name, phaseReport, port, roundReport, unitNameTracker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcacheImgTag(Entity entity) Hashtable for storing img tags containing base64Text src.booleanCan I unload entities stranded on immobile transports?voidchangePhase(GamePhase phase) Changes the game phase, and the displays that go along with it.protected voidchangeTurnIndex(int index, int prevPlayerId) Change whose turn it is.voiddeploy(int id, Coords coords, int boardId, int nFacing, int elevation, List<Entity> loadedUnits, boolean assaultDrop) Deploy an entity at the given coordinates, with the given facing, and starting with the given units already loaded.getBoard()Shortcut to game.boardgetBoard(int boardId) Returns the board with the given boardId or null if the game does not have a board of that boardId.Returns an enumeration of the entities in game.entitiesgetEntity(int id) intReturns the number of the first deployable entityintReturns the number of first selectable entitygetGame()Returns the game of this client as a game-type independent IGame.intgetNextDeployableEntityNum(int entityId) Returns the number of the next deployable entityintgetNextEntityNum(int entityId) Returns the number of the next selectable entity after the one givenintgetPrevEntityNum(int entityId) Returns the number of the previous selectable entity after the one givengetSelectedEntities(EntitySelector selector) Returns an Enumeration of the entities that match the selection criteria.protected booleanhandleGameSpecificPacket(Packet packet) Handles any Packets that are specific to the game type (TW, AS...).booleanisMyTurn()voidmoveEntity(int id, MovePath md) Send movement data for the given entity to the server.protected voidreceiveAttack(Packet packet) Loads entity firing data from the data in the net commandprotected voidreceiveBuildingAdd(Packet packet) protected voidreceiveBuildingCollapse(Packet packet) protected voidreceiveBuildingRemove(Packet packet) protected voidreceiveBuildingUpdate(Packet packet) protected voidreceiveDeployMinefields(Packet packet) protected voidreceiveEntities(Packet packet) Loads the entities from the data in the net command.protected voidreceiveEntitiesUpdate(Packet packet) Update multiple entities from the server.protected voidreceiveEntityRemove(Packet packet) protected voidreceiveEntityUpdate(Packet packet) Loads entity update data from the data in the net command.protected voidprotected voidreceiveForcesDelete(Packet packet) Receives a server packet commanding deletion of forces.protected voidreceiveForceUpdate(Packet packet) Receives a force-related update containing affected forces and affected entitiesprotected voidreceiveIlluminatedHexes(Packet packet) protected voidreceiveRemoveMinefield(Packet packet) receiveReport(List<Report> reports) protected voidreceiveRevealMinefield(Packet packet) protected voidreceiveSendingMinefields(Packet packet) protected voidreceiveTurns(Packet packet) Loads the turn list from the data in the packetprotected voidreceiveUpdateCutHexes(Packet packet) protected voidreceiveUpdateGroundObjects(Packet packet) protected voidprotected voidreceiveUpdateMinefields(Packet packet) voidsendActivateHidden(int nEntity, GamePhase phase) Send activate hidden data to the servervoidsendAddEntitiesToForce(Collection<Entity> entities, int forceId) Sends a packet instructing the server to add the given entities to the given force.voidsendAddEntity(List<Entity> entities) Sends an "add entity" packet that contains a collection of Entity objects.voidsendAddForce(Force force, Collection<Entity> entities) Sends an "Add force" packetvoidsendAddSquadron(FighterSquadron fighterSquadron, Collection<Integer> fighterIds) Sends an "add squadron" packetvoidsendAmmoChange(int entityId, int weaponId, int ammoId, int ammoCarrierId, int reason) Send ammo-change data to the server.voidsendAMSAssignCFRResponse(int[] waaIndex) voidsendAPDSAssignCFRResponse(Integer waaIndex) voidsendArtyAutoHitHexes(List<BoardLocation> hexes) Sends a "set Artillery AutoHit Hexes" packetvoidsendAssignForceFull(Collection<Force> forceList, int newOwnerId) Sends a packet instructing the server to add the given entities to the given force.voidsendAttackData(int aen, Vector<EntityAction> attacks) Send a weapon fire command to the server.protected voidHook invoked when the server greets this client, allowing a bot client to push its behavior settings to the server.voidsendBuildTrain(int tractorId, List<Integer> trailerIds) Sends a "build train" packet, connecting a tractor and several trailers in one operation.voidsendCalledShotChange(int entityId, int equipmentNum, int calledShot) Send called shot change data to the server.voidsendChangeOwner(Collection<Entity> entities, int newOwnerId) Sends a packet containing multiple entity updates.voidsendChangeTeam(Vector<Player> players, int newTeamId) Sends a packet containing multiple entity updates.voidsendChargeLevelChange(int nEntity, int nEquip, int nChargeLevel) Send charge-change data to the servervoidsendCustomInit(Player player) Deprecated, for removal: This API element is subject to removal in a future version.voidsendDamageEdit(DamageEditSpec spec) Sends a gamemaster's damage editor edits for the server to apply to its own copy of the unit.voidsendDeleteEntities(List<Integer> ids) Sends an update to the server to delete the entities of the given ids.voidsendDeleteEntity(int id) Sends a "delete entity" packetvoidsendDeleteForces(List<Force> toDelete) Sends a packet to the Server requesting to delete the given forces.voidsendDeployBridge(int entityId, int equipNum) Declares that the given unit is deploying one of its Bridge-Layer (AVLB) bridges (TM p.242 / TW).voidsendDeployFortifications(Vector<BoardLocation> fortifiedHexes) Sends a "deploy fortifications" packet carrying the hex locations the player is fortifying.voidsendDeployGroundObjects(Map<Coords, List<ICarryable>> groundObjects) Sends an updated state of ground objects (i.e.voidsendDeploymentUnload(Entity loader, Entity loaded) Sends an "update entity" packetvoidsendDeployMinefields(Vector<Minefield> minefields) Sends an "deploy minefields" packetvoidvoidsendEntityWeaponOrderUpdate(Entity entity) voidsendExplodeBuilding(DemolitionCharge charge) voidsendForceParent(Collection<Force> forceList, int newParentId) Sends the given forces to the server to be made top-level forces.voidsendGameOptions(String password, Vector<IBasicOption> options) Send the game options to the servervoidsendGhostTargetAction(int sourceEntityId, int equipmentId, int targetEntityId) Send a ghost target action to the server (Standard mode, TO:AR rules).voidsendHiddenPBSCFRResponse(Vector<EntityAction> attacks) voidsendLoadEntity(int id, int loaderId, int bayNumber) Sends a "load entity" packetvoidsendLoadGame(File f) sends a load game file to the servervoidAsks the server to build the game board from the current map settings and broadcast it to all clients while still in the lobby, so that all players can see the battlefield that will actually be played.voidsendMapDimensions(MapSettings settings) Send the new map dimensions to the servervoidsendMapSettings(MapSettings settings) Send the new map selection to the servervoidsendModeChange(int nEntity, int nEquip, int nMode) Send mode-change data to the servervoidsendMountFacingChange(int nEntity, int nEquip, int nFacing) Send mount-facing-change data to the servervoidsendNovaChange(int id, String net) Send a Nova CEWS update packetvoidsendPlanetaryConditions(PlanetaryConditions conditions) Send the planetary Conditions to the servervoidsendPlayerPickedPassThrough(Integer targetId, Integer attackerId, Coords pos) For ground to air attacks, the ground unit targets the closest hex in the air units flight path.voidsendPrePhaseData(int aen) Send s done with prephase turnvoidSends a "reroll initiative" message to the server.voidReset round deployment packetvoidsendSensorChange(int nEntity, int nSensor) Send sensor-change data to the servervoidsendSinksChange(int nEntity, int activeSinks) Send sinks-change data to the servervoidsendSpecialHexDisplayAppend(Coords c, int boardId, SpecialHexDisplay shd) voidsendSpecialHexDisplayDelete(Coords c, int boardId, SpecialHexDisplay shd) voidsendSystemModeChange(int nEntity, int nSystem, int nMode) Deprecated, for removal: This API element is subject to removal in a future version.voidsendTAGTargetCFRResponse(int index) voidsendTelemissileTargetCFRResponse(int index) voidsendTowEntity(int id, int tractorId) Sends a "tow entity" packetvoidsendUnitAbandonmentAnnouncement(int entityId) Sends a unit abandonment announcement to the server.voidsendUnloadStranded(int... entityIds) Send command to unload stranded entities to the servervoidsendUpdateEntity(Collection<Entity> entities) Sends a packet containing multiple entity updates.voidsendUpdateEntity(Entity entity) Sends an "update entity" packetvoidsendUpdateForce(Collection<Force> changedForces) Sends an "Update force" packetvoidsendUpdateForce(Collection<Force> changedForces, Collection<Entity> changedEntities) Sends an "Update force" packetvoidsendVariableRangeTargetingModeChange(int entityId, VariableRangeTargetingMode mode) Send a Variable Range Targeting mode change packet (BMM pg.voidsetSkillGenerator(AbstractSkillGenerator skillGenerator) Methods inherited from class megamek.client.AbstractClient
addCloseClientListener, checkDuplicateNamesDuringAdd, connect, correctName, die, disconnected, fireSaveCompleted, flushConn, getBots, getHost, getLocalPlayerNumber, getName, getPort, handleGameIndependentPacket, handlePacket, initGameLog, isAwaitingSave, isBot, isConnected, keepGameLog, memDump, possiblyWriteToLog, receivePlayerInfo, receiveUnitReplace, send, sendArtilleryRevealPreference, sendChat, sendDone, sendNextPlayer, sendPause, sendPlayerInfo, sendPlayerInfo, sendServerChat, sendUnpause, setAwaitingSave, setLocalPlayerNumber, setName, setSaveCompletionCallback, updateConnectionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface megamek.client.IClient
getBotClient, getInGameObject, getInGameObjects, getLocalPlayer, getPlayer, isLocalBot, playerExists
-
Field Details
-
game
The game state object: this object is not ever replaced during a game, only updated. A reference can therefore be cached by other objects.
-
-
Constructor Details
-
Client
-
-
Method Details
-
getGame
Description copied from interface:IClientReturns the game of this client as a game-type independent IGame. Note that the game object is only updated, not replaced and a reference to it can therefore be kept.- Returns:
- The game of this client
-
getEntity
-
getSelectedEntities
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 -
getPrevEntityNum
public int getPrevEntityNum(int entityId) Returns the number of the previous 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
Shortcut to game.board -
getBoard
Returns the board with the given boardId or null if the game does not have a board of that boardId. Shortcut to game.getBoard(int).- Parameters:
boardId- The board's ID- Returns:
- The board with the given ID
- See Also:
-
getEntitiesVector
Returns an enumeration of the entities in game.entities -
getMapSettings
-
changePhase
Changes the game phase, and the displays that go along with it.- Overrides:
changePhasein classAbstractClient- Parameters:
phase- the phase switching from.
-
isMyTurn
public boolean isMyTurn()- Returns:
- True when the currently active turn is a turn for the local player
-
getMyTurn
-
receiveTurns
Loads the turn list from the data in the packet- Throws:
InvalidPacketDataException
-
canUnloadStranded
public boolean canUnloadStranded()Can I unload entities stranded on immobile transports? -
deploy
public void deploy(int id, Coords coords, int boardId, int nFacing, int elevation, 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 ID of the deployed entitycoords- the Coords where the entity should be deployednFacing- the direction the entity should faceloadedUnits- a List of units that start the game being transported by the deployed entity.assaultDrop- true if deployment is an assault drop
-
sendPlayerPickedPassThrough
For ground to air attacks, the ground unit targets the closest hex in the air units flight path. In the case of several equidistant hexes, the attacker gets to choose. This method updates the server with the users choice.- Parameters:
targetId- The target IDattackerId- The attacker Entity IDpos- The selected hex
-
sendAttackData
Send a weapon fire command to the server. -
sendPrePhaseData
public void sendPrePhaseData(int aen) Send s done with prephase turn -
sendGhostTargetAction
public void sendGhostTargetAction(int sourceEntityId, int equipmentId, int targetEntityId) Send a ghost target action to the server (Standard mode, TO:AR rules). The server performs the Piloting+3 roll and derives friendliness from entity ownership.- Parameters:
sourceEntityId- the entity generating the ghost targetequipmentId- the equipment number on the source entitytargetEntityId- the entity being targeted
-
sendGameOptions
Send the game options to the server -
sendMapSettings
Send the new map selection to the server -
sendMapDimensions
Send the new map dimensions to the server -
sendPlanetaryConditions
Send the planetary Conditions to the server -
sendLobbyBoardGenerationRequest
public void sendLobbyBoardGenerationRequest()Asks the server to build the game board from the current map settings and broadcast it to all clients while still in the lobby, so that all players can see the battlefield that will actually be played. -
sendRerollInitiativeRequest
public void sendRerollInitiativeRequest()Sends a "reroll initiative" message to the server. -
sendResetRoundDeployment
public void sendResetRoundDeployment()Reset round deployment packet -
sendEntityWeaponOrderUpdate
-
sendAddEntity
Sends an "add entity" packet that contains a collection of Entity objects. -
sendAddSquadron
Sends an "add squadron" packet -
sendDeployMinefields
Sends an "deploy minefields" packet -
sendDeployFortifications
Sends a "deploy fortifications" packet carrying the hex locations the player is fortifying. -
sendDeployGroundObjects
Sends an updated state of ground objects (i.e. cargo etc.) -
sendArtyAutoHitHexes
Sends a "set Artillery AutoHit Hexes" packet -
sendUpdateEntity
Sends an "update entity" packet -
sendUpdateEntity
Sends a packet containing multiple entity updates. Should only be used in the lobby phase. -
sendDamageEdit
Sends a gamemaster's damage editor edits for the server to apply to its own copy of the unit. UnlikesendUpdateEntity(Entity)this carries only the edited values, so the server's unit keeps every piece of state the editor does not touch. -
sendChangeOwner
Sends a packet containing multiple entity updates. Should only be used in the lobby phase. -
sendDeploymentUnload
Sends an "update entity" packet -
sendDeleteEntity
public void sendDeleteEntity(int id) Sends a "delete entity" packet -
sendDeleteEntities
Sends an update to the server to delete the entities of the given ids. -
sendLoadEntity
public void sendLoadEntity(int id, int loaderId, int bayNumber) Sends a "load entity" packet -
sendTowEntity
public void sendTowEntity(int id, int tractorId) Sends a "tow entity" packet -
sendBuildTrain
Sends a "build train" packet, connecting a tractor and several trailers in one operation. The server validates the whole chain and applies it in full or not at all, so a rejected request leaves every unit unattached.- Parameters:
tractorId- the powered tractor that will head the traintrailerIds- the trailers to hitch behind it, ordered front to back
-
sendExplodeBuilding
-
receiveEntities
Loads the entities from the data in the net command.- Throws:
InvalidPacketDataException
-
receiveForceUpdate
Receives a force-related update containing affected forces and affected entities- Throws:
InvalidPacketDataException
-
receiveForcesDelete
Receives a server packet commanding deletion of forces. Only valid in the lobby phase.- Throws:
InvalidPacketDataException
-
receiveEntityUpdate
Loads entity update data from the data in the net command.- Throws:
InvalidPacketDataException
-
receiveEntitiesUpdate
Update multiple entities from the server. Used only in the lobby phase.- Throws:
InvalidPacketDataException
-
receiveEntityRemove
- Throws:
InvalidPacketDataException
-
receiveEntityVisibilityIndicator
- Throws:
InvalidPacketDataException
-
receiveUpdateGroundObjects
- Throws:
InvalidPacketDataException
-
receiveUpdateIndustrialElevators
-
receiveDeployMinefields
- Throws:
InvalidPacketDataException
-
receiveSendingMinefields
- Throws:
InvalidPacketDataException
-
receiveIlluminatedHexes
- Throws:
InvalidPacketDataException
-
receiveUpdateCutHexes
- Throws:
InvalidPacketDataException
-
receiveRevealMinefield
- Throws:
InvalidPacketDataException
-
receiveRemoveMinefield
- Throws:
InvalidPacketDataException
-
receiveUpdateMinefields
- Throws:
InvalidPacketDataException
-
receiveBuildingAdd
- Throws:
InvalidPacketDataException
-
receiveBuildingUpdate
- Throws:
InvalidPacketDataException
-
receiveBuildingRemove
- Throws:
InvalidPacketDataException
-
receiveBuildingCollapse
- Throws:
InvalidPacketDataException
-
receiveAttack
Loads entity firing data from the data in the net command- Throws:
InvalidPacketDataException
-
receiveReport
-
cacheImgTag
Hashtable for storing img tags containing base64Text src. -
sendNovaChange
Send a Nova CEWS update packet -
sendVariableRangeTargetingModeChange
Send a Variable Range Targeting mode change packet (BMM pg. 86). Mode changes are applied at the start of the next round.- Parameters:
entityId- the ID of the entity changing modesmode- the new VariableRangeTargetingMode to apply next round
-
sendUnitAbandonmentAnnouncement
public void sendUnitAbandonmentAnnouncement(int entityId) Sends a unit abandonment announcement to the server. For Meks (TacOps:AR p.165): Must be prone and shutdown. For Vehicles (TacOps): Can be abandoned anytime. The abandonment will execute during the End Phase of the following turn.- Parameters:
entityId- the ID of the unit announcing abandonment
-
sendSpecialHexDisplayAppend
-
sendSpecialHexDisplayDelete
-
sendBotSettingsToServer
protected void sendBotSettingsToServer()Hook invoked when the server greets this client, allowing a bot client to push its behavior settings to the server. Non-bot clients have no settings to send, so this default implementation does nothing; bot clients override it. -
handleGameSpecificPacket
Description copied from class:AbstractClientHandles any Packets that are specific to the game type (TW, AS...). When implementing this, make sure that this doesn't do duplicate actions withAbstractClient.handleGameIndependentPacket(Packet)- but packets may be handled in both methods (all packets traverse both methods).When making changes, do not forget to update Precognition which is a Client clone but unfortunately not a subclass.
- Specified by:
handleGameSpecificPacketin classAbstractClient- Parameters:
packet- The packet to handle- Returns:
- True when the packet has been handled
-
sendDominoCFRResponse
-
sendAMSAssignCFRResponse
public void sendAMSAssignCFRResponse(int[] waaIndex) -
sendAPDSAssignCFRResponse
-
sendHiddenPBSCFRResponse
-
sendTelemissileTargetCFRResponse
public void sendTelemissileTargetCFRResponse(int index) -
sendTAGTargetCFRResponse
public void sendTAGTargetCFRResponse(int index) -
getAvailableMapSizes
-
sendForceParent
Sends the given forces to the server to be made top-level forces. -
sendChangeTeam
Sends a packet containing multiple entity updates. Should only be used in the lobby phase. -
sendUpdateForce
Sends an "Update force" packet -
sendUpdateForce
Sends an "Update force" packet -
sendAddEntitiesToForce
Sends a packet instructing the server to add the given entities to the given force. The server will handle this; the client does not have to implement the change. -
sendAssignForceFull
Sends a packet instructing the server to add the given entities to the given force. The server will handle this; the client does not have to implement the change. -
sendDeleteForces
Sends a packet to the Server requesting to delete the given forces. -
sendAddForce
Sends an "Add force" packet -
sendCustomInit
Deprecated, for removal: This API element is subject to removal in a future version.Sends an "update custom initiative" packet -
getSkillGenerator
-
setSkillGenerator
-
sendUnloadStranded
public void sendUnloadStranded(int... entityIds) Send command to unload stranded entities to the server -
changeTurnIndex
protected void changeTurnIndex(int index, int prevPlayerId) Change whose turn it is. -
sendModeChange
public void sendModeChange(int nEntity, int nEquip, int nMode) Send mode-change data to the server -
sendChargeLevelChange
public void sendChargeLevelChange(int nEntity, int nEquip, int nChargeLevel) Send charge-change data to the server -
sendDeployBridge
public void sendDeployBridge(int entityId, int equipNum) Declares that the given unit is deploying one of its Bridge-Layer (AVLB) bridges (TM p.242 / TW). The server validates eligibility and computes the target hex (directly in front, along the unit's facing); the bridge is placed at the end of the following turn if the unit stays stationary.- Parameters:
entityId- the unit declaring the deploymentequipNum- the equipment index of the specific bridgelayer to deploy (a unit may carry more than one)
-
sendMountFacingChange
public void sendMountFacingChange(int nEntity, int nEquip, int nFacing) Send mount-facing-change data to the server -
sendCalledShotChange
public void sendCalledShotChange(int entityId, int equipmentNum, int calledShot) Send called shot change data to the server.- Parameters:
entityId- the id of the entity whose weapon is changingequipmentNum- the equipment number of the weaponcalledShot- the new called shot, one of theCalledShotCALLED_ constants
-
sendSystemModeChange
@Deprecated(since="0.51.0", forRemoval=true) public void sendSystemModeChange(int nEntity, int nSystem, int nMode) Deprecated, for removal: This API element is subject to removal in a future version.Send system mode-change data to the server -
sendAmmoChange
public void sendAmmoChange(int entityId, int weaponId, int ammoId, int ammoCarrierId, int reason) Send ammo-change data to the server.- Parameters:
entityId- the unit that owns the weapon being reloadedweaponId- the equipment number of the weapon on that unitammoId- the equipment number of the ammo bin on the carrying unitammoCarrierId- the unit that owns the ammo bin. This is the same as entityId unless the bin belongs to a directly connected trailer sharing ammo with this unit.reason- the report message id explaining the change, or 0 for no report
-
sendSensorChange
public void sendSensorChange(int nEntity, int nSensor) Send sensor-change data to the server -
sendSinksChange
public void sendSinksChange(int nEntity, int activeSinks) Send sinks-change data to the server -
sendActivateHidden
Send activate hidden data to the server -
moveEntity
Send movement data for the given entity to the server. -
sendLoadGame
sends a load game file to the server
-