com.realtime.crossfire.jxclient.server.crossfire
Class DefaultCrossfireServerConnection

java.lang.Object
  extended by com.realtime.crossfire.jxclient.server.server.DefaultServerConnection
      extended by com.realtime.crossfire.jxclient.server.crossfire.DefaultCrossfireServerConnection
All Implemented Interfaces:
CrossfireServerConnection, ServerConnection

public class DefaultCrossfireServerConnection
extends DefaultServerConnection
implements CrossfireServerConnection

Default implementation of CrossfireServerConnection.


Field Summary
private static byte[] ACCOUNT_ADD_PLAYER_PREFIX
          The command prefix for the "accountaddplayer" command.
private static byte[] ACCOUNT_LOGIN_PREFIX
          The command prefix for the "accountlogin" command.
private static byte[] ACCOUNT_NEW_PREFIX
          The command prefix for the "accountnew" command.
private static byte[] ACCOUNT_PLAY_PREFIX
          The command prefix for the "accountplay" command.
private  java.lang.String accountName
          The account name.
private static int ACL_CLASS
          Parameter type in the "accountplayers" command.
private static int ACL_FACE
          Parameter type in the "accountplayers" command.
private static int ACL_FACE_NUM
          Parameter type in the "accountplayers" command.
private static int ACL_LEVEL
          Parameter type in the "accountplayers" command.
private static int ACL_MAP
          Parameter type in the "accountplayers" command.
private static int ACL_NAME
          Parameter type in the "accountplayers" command.
private static int ACL_PARTY
          Parameter type in the "accountplayers" command.
private static int ACL_RACE
          Parameter type in the "accountplayers" command.
private static byte[] ADDME_PREFIX
          The command prefix for the "addme" command.
private static byte[] APPLY_PREFIX
          The command prefix for the "apply" command.
private static byte[] ASKFACE_PREFIX
          The command prefix for the "askface" command.
private  java.nio.ByteBuffer byteBuffer
          A byte buffer using writeBuffer to store the data.
private  ClientSocketListener clientSocketListener
          The ClientSocketListener attached to the server socket.
private  ClientSocketState clientSocketState
          The current connection state.
private static byte[] CREATE_PLAYER_PREFIX
          The command prefix for the "createplayer" command.
private  java.util.Collection<CrossfireAccountListener> crossfireAccountListeners
          The CrossfireAccountListeners to be notified.
private  java.util.Collection<CrossfireComcListener> crossfireComcListeners
          The CrossfireComcListeners to be notified.
private  java.util.Collection<CrossfireExpTableListener> crossfireExpTableListeners
          The CrossfireExpTableListeners to be notified.
private  java.util.Collection<CrossfireFaceListener> crossfireFaceListeners
          The CrossfireFaceListeners to be notified.
private  java.util.Collection<CrossfireFailureListener> crossfireFailureListeners
          The CrossfireFailureListeners to be notified.
private  java.util.Collection<CrossfireMusicListener> crossfireMusicListeners
          The CrossfireMusicListeners to be notified.
private  java.util.Collection<CrossfirePickupListener> crossfirePickupListeners
          The CrossfirePickupListeners to be notified.
private  java.util.Collection<CrossfireServerConnectionListener> crossfireServerConnectionListeners
          The CrossfireServerConnectionListeners to notify.
private  java.util.Collection<CrossfireSkillInfoListener> crossfireSkillInfoListeners
          The CrossfireSkillInfoListeners to be notified.
private  java.util.Collection<CrossfireSoundListener> crossfireSoundListeners
          The CrossfireSoundListeners to be notified.
private  java.util.Collection<CrossfireSpellListener> crossfireSpellListeners
          The CrossfireSpellListeners to be notified.
private  java.util.Collection<CrossfireStatsListener> crossfireStatsListeners
          The CrossfireStatsListeners to be notified.
private  java.util.Collection<CrossfireTickListener> crossfireTickListeners
          The CrossfireTickListeners to be notified.
private  java.util.Collection<CrossfireUpdateFaceListener> crossfireUpdateFaceListeners
          The CrossfireUpdateFaceListeners to be notified.
private  java.util.Collection<CrossfireUpdateItemListener> crossfireUpdateItemListeners
          The CrossfireUpdateItemListeners to be notified.
private  java.util.Collection<CrossfireUpdateMapListener> crossfireUpdateMapListeners
          The CrossfireUpdateMapListeners to be notified.
private  int currentMapHeight
          The currently active map height.
private  int currentMapWidth
          The currently active map width.
private  int currentNumLookObjects
          The currently active number of ground view objects.
private  DebugWriter debugProtocol
          The appender to write protocol commands to.
private static int DEFAULT_MAP_HEIGHT
          The default map height when no "setup mapsize" command has been sent.
private static int DEFAULT_MAP_WIDTH
          The default map width when no "setup mapsize" command has been sent.
private static int DEFAULT_NUM_LOOK_OBJECTS
          The default number of ground objects when no "setup num_look_objects" command has been sent.
private  java.util.Collection<CrossfireDrawextinfoListener> drawextinfoListeners
          The CrossfireDrawextinfoListeners to be notified.
private  java.util.Collection<CrossfireDrawinfoListener> drawinfoListeners
          The CrossfireDrawinfoListeners to be notified.
private static byte[] EXAMINE_PREFIX
          The command prefix for the "examine" command.
private static int FACE_COLOR_MASK
          Bitmask in magic map information to extract the color information of a tile.
private static int FACE_FLOOR
          Bitmask in magic map information to denote a floor tile.
private static int FACE_WALL
          Bitmask in magic map information to denote a wall tile.
private static byte[] LOCK_PREFIX
          The command prefix for the "lock" command.
private  int loginMethod
          The login method version supported by the server we're connected to.
private static byte[] LOOKAT_PREFIX
          The command prefix for the "lookat" command.
private  java.util.Collection<CrossfireMagicmapListener> magicmapListeners
          The CrossfireMagicmapListeners to be notified of received magicmap commands.
private static byte[] MARK_PREFIX
          The command prefix for the "mark" command.
private static byte[] MOVE_PREFIX
          The command prefix for the "move" command.
private static byte[] NCOM_PREFIX
          The command prefix for the "ncom" command.
private  int packet
          The packet id for the next "ncom" command to send.
private static java.util.regex.Pattern PATTERN_DOT
          Pattern to split a string by ":".
private  int pendingMapHeight
          The map height that is being negotiated with the server.
private  int pendingMapWidth
          The map width that is being negotiated with the server.
private  int pendingNumLookObjects
          The number of ground view objects being negotiated with the server.
private  int preferredMapHeight
          The map height in tiles that is negotiated with the server.
private  int preferredMapWidth
          The map width in tiles that is negotiated with the server.
private  int preferredNumLookObjects
          The number of ground view objects to be negotiated with the server.
private  java.util.Collection<CrossfireQueryListener> queryListeners
          The CrossfireQueryListeners to be notified.
private  java.util.Collection<ReceivedPacketListener> receivedPacketListeners
          The ReceivedPacketListeners to be notified.
private  java.lang.Object redrawSemaphore
          The semaphore used to synchronized map model updates and map view redraws.
private static byte[] REPLY_PREFIX
          The command prefix for the "reply" command.
private static byte[] REQUESTINFO_PREFIX
          The command prefix for the "requestinfo" command.
private  java.util.Collection<SentReplyListener> sentReplyListeners
          The SentReplyListeners to be notified.
private static byte[] SETUP_PREFIX
          The command prefix for the "setup" command.
private static byte[] TOGGLEEXTENDEDTEXT_PREFIX
          The command prefix for the "toggleextendedtext" command.
private static java.nio.charset.Charset UTF8
          The Charset used for parsing or encoding strings received from or sent to the Crossfire server.
private  java.lang.String version
          The version information to send when connecting to the server.
private static byte[] VERSION_PREFIX
          The command prefix for the "version" command.
private  byte[] writeBuffer
          Buffer to build commands to send.
 
Constructor Summary
DefaultCrossfireServerConnection(java.lang.Object redrawSemaphore, DebugWriter debugProtocol, java.lang.String version)
          Creates a new instance.
 
Method Summary
 void addCrossfireAccountListener(CrossfireAccountListener listener)
          Adds a listener to be notified about account events.
 void addCrossfireComcListener(CrossfireComcListener listener)
          Adds a listener to be notified about received comc commands.
 void addCrossfireDrawextinfoListener(CrossfireDrawextinfoListener listener)
          Adds a new listener monitoring the drawextinfo S->C messages.
 void addCrossfireDrawinfoListener(CrossfireDrawinfoListener listener)
          Adds a new listener monitoring the drawinfo S->C messages.
 void addCrossfireExpTableListener(CrossfireExpTableListener crossfireExpTableListener)
          Adds a listener to be notified about received experience table changes.
 void addCrossfireFaceListener(CrossfireFaceListener listener)
          Adds a listener to be notified about received face commands.
 void addCrossfireFailureListener(CrossfireFailureListener listener)
          Adds a listener to be notified of failure messages.
 void addCrossfireMagicmapListener(CrossfireMagicmapListener listener)
          Adds a listener from the list of objects listening to magicmap messages.
 void addCrossfireMusicListener(CrossfireMusicListener listener)
          Adds a listener to be notified about received music commands.
 void addCrossfirePickupListener(CrossfirePickupListener listener)
          Adds a listener to be notified about received "pickup" messages.
 void addCrossfireQueryListener(CrossfireQueryListener listener)
          Adds a new listener monitoring the query S->C messages.
 void addCrossfireServerConnectionListener(CrossfireServerConnectionListener listener)
          Adds a listener to be notified about connection progress.
 void addCrossfireSkillInfoListener(CrossfireSkillInfoListener listener)
          Adds a listener to be notified about received skill info changes.
 void addCrossfireSoundListener(CrossfireSoundListener listener)
          Adds a listener to be notified about received sound commands.
 void addCrossfireSpellListener(CrossfireSpellListener listener)
          Adds a listener to be notified about received spell commands.
 void addCrossfireStatsListener(CrossfireStatsListener crossfireStatsListener)
          Adds a listener to be notified about stats changes.
 void addCrossfireTickListener(CrossfireTickListener listener)
          Adds a listener to be notified about tick changes.
 void addCrossfireUpdateFaceListener(CrossfireUpdateFaceListener listener)
          Add a listener to be notified about face image changes.
 void addCrossfireUpdateItemListener(CrossfireUpdateItemListener crossfireUpdateItemListener)
          Adds a listener to be notified about item changes.
 void addCrossfireUpdateMapListener(CrossfireUpdateMapListener listener)
          Adds a listener to be notified about map changes.
 void addPacketWatcherListener(ReceivedPacketListener listener)
          Adds a listener to be notified about received packets.
 void addSentReplyListener(SentReplyListener listener)
          Adds a listener to be notified about sent reply packets.
private  void clearFailure()
          Inform the various failure listeners that they can clean the last displayed failure.
private  void cmdMap2Coordinate(java.nio.ByteBuffer packet, int x, int y)
          Processes the payload data for a map2 coordinate command.
private  void cmdMap2CoordinateClearSpace(int x, int y, int len)
          Processes the payload data for a map2 coordinate "clear_space" sub-command.
private  void cmdMap2CoordinateDarkness(java.nio.ByteBuffer packet, int x, int y, int len)
          Processes the payload data for a map2 coordinate "darkness" sub-command.
private  void cmdMap2CoordinateLayer(java.nio.ByteBuffer packet, int x, int y, int len, int layer)
          Processes the payload data for a map2 coordinate "layer" sub-command.
private  void cmdMap2CoordinateLayer3(java.nio.ByteBuffer packet, int x, int y, int layer, int face)
          Processes the additional payload data for a map2 coordinate "layer" sub-command having 4 bytes payload.
private  void cmdMap2CoordinateLayer4(java.nio.ByteBuffer packet, int x, int y, int layer, int face)
          Processes the additional payload data for a map2 coordinate "layer" sub-command having 4 bytes payload.
private  void cmdReplyinfo(java.lang.String infoType, java.nio.ByteBuffer packet)
          Handles the replyinfo server to client command.
 void connect(java.lang.String hostname, int port)
          Attempts to connect the client to a server.
private  void connected()
          Called after the server connection has been established.
 void drawextinfo(int color, int type, int subtype, java.lang.String message)
          Pretends that a drawextinfo message has been received.
 void drawInfo(java.lang.String message, int color)
          Pretends that a drawinfo message has been received.
 void drawInfoSetDebugMode(boolean printMessageTypes)
          Enables or disables printing of message types.
private static java.lang.String extractCommand(java.nio.ByteBuffer packet)
          Returns the command string for a received packet.
private  void fireNewMap()
          Notifies all listeners that a "newmap" command has been received.
 java.lang.String getAccountName()
          Returns the current account name.
private static int getInt1(java.nio.ByteBuffer byteBuffer)
          Extracts and removes a 1 byte integer from a ByteBuffer at it's current position.
private static int getInt2(java.nio.ByteBuffer byteBuffer)
          Extracts and removes a 2 byte integer from a ByteBuffer at it's current position.
private static int getInt4(java.nio.ByteBuffer byteBuffer)
          Extracts and removes a 4 byte integer from a ByteBuffer at it's current position.
private static long getInt8(java.nio.ByteBuffer byteBuffer)
          Extracts and removes an 8 byte integer from a ByteBuffer at it's current position.
 int getMapHeight()
          Returns the map height in tiles.
 int getMapWidth()
          Returns the map width in tiles.
private static java.lang.String getString(java.nio.ByteBuffer byteBuffer, int len)
          Extracts and removes a string from a ByteBuffer at it's current position.
private static java.lang.String hexDump(java.nio.ByteBuffer byteBuffer)
          Returns a hex-dump of a ByteBuffer.
private  void negotiateMapSize(int mapWidth, int mapHeight)
          Requests a change of the map size from the server.
private  void negotiateNumLookObjects(int numLookObjects)
          Requests a change of the number of ground objects from the server.
private static java.lang.String newString(java.nio.ByteBuffer byteBuffer, int start, int len)
          Extracts a string from a ByteBuffer range.
private  void notifyPacketWatcherListenersAscii(java.nio.ByteBuffer packet, int args)
          Notifies all ReceivedPacketListeners about a packet having ascii parameters.
private  void notifyPacketWatcherListenersEmpty(java.lang.String command)
          Notifies all ReceivedPacketListeners about an empty packet.
private  void notifyPacketWatcherListenersIntArray(java.nio.ByteBuffer packet, int args)
          Notifies all ReceivedPacketListeners about a packet having an array of int values as parameters.
private  void notifyPacketWatcherListenersMixed(java.nio.ByteBuffer packet, int args)
          Notifies all ReceivedPacketListeners about a packet having mixed parameters.
private  void notifyPacketWatcherListenersNoData(java.nio.ByteBuffer packet, int args)
          Notifies all ReceivedPacketListeners about a packet having unknown parameters.
private  void notifyPacketWatcherListenersShortArray(java.nio.ByteBuffer packet, int args)
          Notifies all ReceivedPacketListeners about a packet having an array of short values as parameters.
private  void notifyPacketWatcherListenersShortInt(java.nio.ByteBuffer packet, int args)
          Notifies all ReceivedPacketListeners about a packet having a short and an in value as parameters.
private  void notifyPacketWatcherListenersStats(int stat, java.lang.Object... args)
          Notifies all ReceivedPacketListeners about a packet having stat parameters.
private static int parseDigit(byte ch)
          Parses a character into an integer.
private  void processAccountPlayers(java.nio.ByteBuffer packet)
          Processes an 'accountplayers' server command.
private  void processAddmeFailed(java.nio.ByteBuffer packet)
          Processes an 'account_failed' server command.
private  void processAddmeSuccess(java.nio.ByteBuffer packet)
          Processes an 'account_success' server command.
private  void processAddSpell(java.nio.ByteBuffer packet)
          Processes an 'addspell' server command.
private  void processAnim(java.nio.ByteBuffer packet)
          Processes an 'anim' server command.
private  void processComc(java.nio.ByteBuffer packet)
          Processes a 'comc' server command.
private  void processDelInv(java.nio.ByteBuffer packet)
          Processes a 'delinv' server command.
private  void processDelItem(java.nio.ByteBuffer packet)
          Processes a 'delitem' server command.
private  void processDelSpell(java.nio.ByteBuffer packet)
          Processes a 'delspell' server command.
private  void processDrawExtInfo(java.nio.ByteBuffer packet)
          Processes a 'drawextinfo' server command.
private  void processDrawInfo(java.nio.ByteBuffer packet)
          Processes a 'drawinfo' server command.
private  void processExpTableReplyinfo(java.nio.ByteBuffer packet)
          Processes a "replyinfo exp_table" block.
private  void processExtendedInfoSet(java.nio.ByteBuffer packet)
          Processes an 'ExtendedInfoSet' server command.
private  void processExtendedTextSet(java.nio.ByteBuffer packet)
          Processes an 'ExtendedTextSet' server command.
private  void processFace2(java.nio.ByteBuffer packet)
          Processes a 'face2' server command.
private  void processFailure(java.nio.ByteBuffer packet)
          Processes a 'failure' server command.
private  void processGoodbye(java.nio.ByteBuffer packet)
          Processes a 'goodbye' server command.
private  void processImage2(java.nio.ByteBuffer packet)
          Processes an 'image2' server command.
private static void processImageInfoReplyinfo(java.nio.ByteBuffer packet)
          Processes a "replyinfo image_info" block.
private  void processItem2(java.nio.ByteBuffer packet)
          Processes an 'item2' server command.
private  void processMagicMap(java.nio.ByteBuffer packet)
          Processes a 'magicmap' server command.
private  void processMap2(java.nio.ByteBuffer packet)
          Processes a 'map2' server command.
private  void processMapExtended(java.nio.ByteBuffer packet)
          Processes a 'mapextended' server command.
private  void processMusic(java.nio.ByteBuffer packet)
          Processes a 'music' server command.
private  void processNewMap(java.nio.ByteBuffer packet)
          Processes a 'newmap' server command.
private  void processPacket(java.nio.ByteBuffer packet)
          Processes a received packet.
private  void processPickup(java.nio.ByteBuffer packet)
          Processes a 'pickup' server command.
private  void processPlayer(java.nio.ByteBuffer packet)
          Processes a 'pickup' server command.
private  void processQuery(java.nio.ByteBuffer packet)
          Processes a 'pickup' server command.
private  void processReplyInfo(java.nio.ByteBuffer packet)
          Processes a 'replyinfo' server command.
private  void processSetup(java.nio.ByteBuffer packet)
          Processes a 'replyinfo' server command.
private  void processSkillInfoReplyinfo(java.nio.ByteBuffer packet)
          Processes a "replyinfo skill_info" block.
private  void processSmooth(java.nio.ByteBuffer packet)
          Processes a 'smooth' server command.
private  void processSound(java.nio.ByteBuffer packet)
          Processes a 'sound' server command.
private  void processSound2(java.nio.ByteBuffer packet)
          Processes a 'sound2' server command.
private  void processStats(java.nio.ByteBuffer packet)
          Processes a 'stats' server command.
private  void processTick(java.nio.ByteBuffer packet)
          Processes a 'tick' server command.
private  void processUpdItem(java.nio.ByteBuffer packet)
          Processes an 'upditem' server command.
private  void processUpdSpell(java.nio.ByteBuffer packet)
          Processes an 'updspell' server command.
private  void processVersion(java.nio.ByteBuffer packet)
          Processes a 'version' server command.
private  void putDecimal(int value)
          Appends an integer in decimal ASCII representation to byteBuffer.
 void removeCrossfireAccountListener(CrossfireAccountListener listener)
          Removes a listener to be notified about account events.
 void removeCrossfireDrawextinfoListener(CrossfireDrawextinfoListener listener)
          Removes the given listener from the list of objects listening to the drawextinfo S->C messages.
 void removeCrossfireDrawinfoListener(CrossfireDrawinfoListener listener)
          Removes the given listener from the list of objects listening to the drawinfo S->C messages.
 void removeCrossfireFailureListener(CrossfireFailureListener listener)
          Removes a listener to be notified of failure messages.
 void removeCrossfireMagicmapListener(CrossfireMagicmapListener listener)
          Removes a listener from the list of objects listening to magicmap messages.
 void removeCrossfirePickupListener(CrossfirePickupListener listener)
          Removes a listener to be notified about received "pickup" messages.
 void removeCrossfireQueryListener(CrossfireQueryListener listener)
          Removes the given listener from the list of objects listening to the query S->C messages.
 void removeCrossfireSkillInfoListener(CrossfireSkillInfoListener listener)
          Removes a listener to be notified about received skill info changes.
 void removeCrossfireUpdateItemListener(CrossfireUpdateItemListener crossfireUpdateItemListener)
          Removes a listener to be notified about item changes.
 void removePacketWatcherListener(ReceivedPacketListener listener)
          Removes a listener to be notified about received packets.
 void removeSentReplyListener(SentReplyListener listener)
          Removes a listener to be notified about sent reply packets.
 void sendAccountCharacterCreate(java.lang.String login, java.lang.String password)
          Sends a request to create a new character associated to the account.
 void sendAccountCreate(java.lang.String login, java.lang.String password)
          Sends a request to create a new account.
 void sendAccountLink(int force, java.lang.String login, java.lang.String password)
          Sends a request to add an existing character to an account.
 void sendAccountLogin(java.lang.String login, java.lang.String password)
          Asks for an account login.
 void sendAccountPlay(java.lang.String name)
          Sends a request to play a character from an account.
 void sendAddme()
          Sends an "addme" command to the server.
 void sendApply(int tag)
          Sends an "apply" command to the server.
 void sendAskface(int num)
          Sends an "askface" command to the server.
 void sendExamine(int tag)
          Sends an "examine" command to the server.
 void sendLock(boolean val, int tag)
          Sends a "lock" command to the server.
 void sendLookat(int dx, int dy)
          Sends a "lookat" command to the server.
 void sendMark(int tag)
          Sends a "mark" command to the server.
 void sendMove(int to, int tag, int nrof)
          Sends a "move" command to the server.
 int sendNcom(int repeat, java.lang.String command)
          Sends a "ncom" command to the server.
 void sendReply(java.lang.String text)
          Sends a "reply" command to the server.
 void sendRequestinfo(java.lang.String infoType)
          Sends a "requestinfo" command to the server.
 void sendSetup(java.lang.String... options)
          Sends a "setup" command to the server.
 void sendToggleextendedtext(int... types)
          Sends a "toggleextendedtext" command to the server.
 void sendVersion(int csval, int scval, java.lang.String vinfo)
          Sends a "version" command to the server.
private  void setClientSocketState(ClientSocketState prevState, ClientSocketState nextState)
          Updates the clientSocketState.
private  void setCurrentMapSize(int currentMapWidth, int currentMapHeight)
          Sets the current map size as negotiated with the server.
private  void setCurrentNumLookObjects(int currentNumLookObjects)
          Sets the current ground view objects as negotiated with the server.
 void setPreferredMapSize(int preferredMapWidth, int preferredMapHeight)
          Sets the preferred map size.
 void setPreferredNumLookObjects(int preferredNumLookObjects)
          Sets the maximum number of objects in the ground view.
 
Methods inherited from class com.realtime.crossfire.jxclient.server.server.DefaultServerConnection
addClientSocketListener, disconnect, removeClientSocketListener, start, stop, writePacket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
start, stop
 
Methods inherited from interface com.realtime.crossfire.jxclient.server.server.ServerConnection
addClientSocketListener, disconnect, removeClientSocketListener
 

Field Detail

ACCOUNT_ADD_PLAYER_PREFIX

@NotNull
private static final byte[] ACCOUNT_ADD_PLAYER_PREFIX
The command prefix for the "accountaddplayer" command.


ACCOUNT_LOGIN_PREFIX

@NotNull
private static final byte[] ACCOUNT_LOGIN_PREFIX
The command prefix for the "accountlogin" command.


ACCOUNT_NEW_PREFIX

@NotNull
private static final byte[] ACCOUNT_NEW_PREFIX
The command prefix for the "accountnew" command.


ACCOUNT_PLAY_PREFIX

@NotNull
private static final byte[] ACCOUNT_PLAY_PREFIX
The command prefix for the "accountplay" command.


accountName

@Nullable
private java.lang.String accountName
The account name. Set to null if no account name is known.


ACL_CLASS

private static final int ACL_CLASS
Parameter type in the "accountplayers" command.

See Also:
Constant Field Values

ACL_FACE

private static final int ACL_FACE
Parameter type in the "accountplayers" command.

See Also:
Constant Field Values

ACL_FACE_NUM

private static final int ACL_FACE_NUM
Parameter type in the "accountplayers" command.

See Also:
Constant Field Values

ACL_LEVEL

private static final int ACL_LEVEL
Parameter type in the "accountplayers" command.

See Also:
Constant Field Values

ACL_MAP

private static final int ACL_MAP
Parameter type in the "accountplayers" command.

See Also:
Constant Field Values

ACL_NAME

private static final int ACL_NAME
Parameter type in the "accountplayers" command.

See Also:
Constant Field Values

ACL_PARTY

private static final int ACL_PARTY
Parameter type in the "accountplayers" command.

See Also:
Constant Field Values

ACL_RACE

private static final int ACL_RACE
Parameter type in the "accountplayers" command.

See Also:
Constant Field Values

ADDME_PREFIX

@NotNull
private static final byte[] ADDME_PREFIX
The command prefix for the "addme" command.


APPLY_PREFIX

@NotNull
private static final byte[] APPLY_PREFIX
The command prefix for the "apply" command.


ASKFACE_PREFIX

@NotNull
private static final byte[] ASKFACE_PREFIX
The command prefix for the "askface" command.


byteBuffer

@NotNull
private final java.nio.ByteBuffer byteBuffer
A byte buffer using writeBuffer to store the data.


clientSocketListener

@NotNull
private final ClientSocketListener clientSocketListener
The ClientSocketListener attached to the server socket.


clientSocketState

@NotNull
private ClientSocketState clientSocketState
The current connection state.


CREATE_PLAYER_PREFIX

@NotNull
private static final byte[] CREATE_PLAYER_PREFIX
The command prefix for the "createplayer" command.


crossfireAccountListeners

@NotNull
private final java.util.Collection<CrossfireAccountListener> crossfireAccountListeners
The CrossfireAccountListeners to be notified.


crossfireComcListeners

@NotNull
private final java.util.Collection<CrossfireComcListener> crossfireComcListeners
The CrossfireComcListeners to be notified.


crossfireExpTableListeners

@NotNull
private final java.util.Collection<CrossfireExpTableListener> crossfireExpTableListeners
The CrossfireExpTableListeners to be notified.


crossfireFaceListeners

@NotNull
private final java.util.Collection<CrossfireFaceListener> crossfireFaceListeners
The CrossfireFaceListeners to be notified.


crossfireFailureListeners

@NotNull
private final java.util.Collection<CrossfireFailureListener> crossfireFailureListeners
The CrossfireFailureListeners to be notified.


crossfireMusicListeners

@NotNull
private final java.util.Collection<CrossfireMusicListener> crossfireMusicListeners
The CrossfireMusicListeners to be notified.


crossfirePickupListeners

@NotNull
private final java.util.Collection<CrossfirePickupListener> crossfirePickupListeners
The CrossfirePickupListeners to be notified.


crossfireServerConnectionListeners

@NotNull
private final java.util.Collection<CrossfireServerConnectionListener> crossfireServerConnectionListeners
The CrossfireServerConnectionListeners to notify.


crossfireSkillInfoListeners

@NotNull
private final java.util.Collection<CrossfireSkillInfoListener> crossfireSkillInfoListeners
The CrossfireSkillInfoListeners to be notified.


crossfireSoundListeners

@NotNull
private final java.util.Collection<CrossfireSoundListener> crossfireSoundListeners
The CrossfireSoundListeners to be notified.


crossfireSpellListeners

@NotNull
private final java.util.Collection<CrossfireSpellListener> crossfireSpellListeners
The CrossfireSpellListeners to be notified.


crossfireStatsListeners

@NotNull
private final java.util.Collection<CrossfireStatsListener> crossfireStatsListeners
The CrossfireStatsListeners to be notified.


crossfireTickListeners

@NotNull
private final java.util.Collection<CrossfireTickListener> crossfireTickListeners
The CrossfireTickListeners to be notified.


crossfireUpdateFaceListeners

@NotNull
private final java.util.Collection<CrossfireUpdateFaceListener> crossfireUpdateFaceListeners
The CrossfireUpdateFaceListeners to be notified.


crossfireUpdateItemListeners

@NotNull
private final java.util.Collection<CrossfireUpdateItemListener> crossfireUpdateItemListeners
The CrossfireUpdateItemListeners to be notified.


crossfireUpdateMapListeners

@NotNull
private final java.util.Collection<CrossfireUpdateMapListener> crossfireUpdateMapListeners
The CrossfireUpdateMapListeners to be notified.


currentMapHeight

private int currentMapHeight
The currently active map height.


currentMapWidth

private int currentMapWidth
The currently active map width.


currentNumLookObjects

private int currentNumLookObjects
The currently active number of ground view objects.


debugProtocol

@Nullable
private final DebugWriter debugProtocol
The appender to write protocol commands to. May be null to not write anything.


DEFAULT_MAP_HEIGHT

private static final int DEFAULT_MAP_HEIGHT
The default map height when no "setup mapsize" command has been sent.

See Also:
Constant Field Values

DEFAULT_MAP_WIDTH

private static final int DEFAULT_MAP_WIDTH
The default map width when no "setup mapsize" command has been sent.

See Also:
Constant Field Values

DEFAULT_NUM_LOOK_OBJECTS

private static final int DEFAULT_NUM_LOOK_OBJECTS
The default number of ground objects when no "setup num_look_objects" command has been sent.

See Also:
Constant Field Values

drawextinfoListeners

@NotNull
private final java.util.Collection<CrossfireDrawextinfoListener> drawextinfoListeners
The CrossfireDrawextinfoListeners to be notified.


drawinfoListeners

@NotNull
private final java.util.Collection<CrossfireDrawinfoListener> drawinfoListeners
The CrossfireDrawinfoListeners to be notified.


EXAMINE_PREFIX

@NotNull
private static final byte[] EXAMINE_PREFIX
The command prefix for the "examine" command.


FACE_COLOR_MASK

private static final int FACE_COLOR_MASK
Bitmask in magic map information to extract the color information of a tile.

See Also:
Constant Field Values

FACE_FLOOR

private static final int FACE_FLOOR
Bitmask in magic map information to denote a floor tile.

See Also:
Constant Field Values

FACE_WALL

private static final int FACE_WALL
Bitmask in magic map information to denote a wall tile.

See Also:
Constant Field Values

LOCK_PREFIX

@NotNull
private static final byte[] LOCK_PREFIX
The command prefix for the "lock" command.


loginMethod

private int loginMethod
The login method version supported by the server we're connected to.


LOOKAT_PREFIX

@NotNull
private static final byte[] LOOKAT_PREFIX
The command prefix for the "lookat" command.


magicmapListeners

@NotNull
private final java.util.Collection<CrossfireMagicmapListener> magicmapListeners
The CrossfireMagicmapListeners to be notified of received magicmap commands.


MARK_PREFIX

@NotNull
private static final byte[] MARK_PREFIX
The command prefix for the "mark" command.


MOVE_PREFIX

@NotNull
private static final byte[] MOVE_PREFIX
The command prefix for the "move" command.


NCOM_PREFIX

@NotNull
private static final byte[] NCOM_PREFIX
The command prefix for the "ncom" command.


packet

private int packet
The packet id for the next "ncom" command to send.


PATTERN_DOT

@NotNull
private static final java.util.regex.Pattern PATTERN_DOT
Pattern to split a string by ":".


pendingMapHeight

private int pendingMapHeight
The map height that is being negotiated with the server. Set to 0 when not negotiating.


pendingMapWidth

private int pendingMapWidth
The map width that is being negotiated with the server. Set to 0 when not negotiating.


pendingNumLookObjects

private int pendingNumLookObjects
The number of ground view objects being negotiated with the server. Set to 0 when not negotiating.


preferredMapHeight

private int preferredMapHeight
The map height in tiles that is negotiated with the server.


preferredMapWidth

private int preferredMapWidth
The map width in tiles that is negotiated with the server.


preferredNumLookObjects

private int preferredNumLookObjects
The number of ground view objects to be negotiated with the server.


queryListeners

@NotNull
private final java.util.Collection<CrossfireQueryListener> queryListeners
The CrossfireQueryListeners to be notified.


receivedPacketListeners

@NotNull
private final java.util.Collection<ReceivedPacketListener> receivedPacketListeners
The ReceivedPacketListeners to be notified.


redrawSemaphore

@NotNull
private final java.lang.Object redrawSemaphore
The semaphore used to synchronized map model updates and map view redraws.


REPLY_PREFIX

@NotNull
private static final byte[] REPLY_PREFIX
The command prefix for the "reply" command.


REQUESTINFO_PREFIX

@NotNull
private static final byte[] REQUESTINFO_PREFIX
The command prefix for the "requestinfo" command.


sentReplyListeners

@NotNull
private final java.util.Collection<SentReplyListener> sentReplyListeners
The SentReplyListeners to be notified.


SETUP_PREFIX

@NotNull
private static final byte[] SETUP_PREFIX
The command prefix for the "setup" command.


TOGGLEEXTENDEDTEXT_PREFIX

@NotNull
private static final byte[] TOGGLEEXTENDEDTEXT_PREFIX
The command prefix for the "toggleextendedtext" command.


UTF8

@NotNull
private static final java.nio.charset.Charset UTF8
The Charset used for parsing or encoding strings received from or sent to the Crossfire server.


version

@NotNull
private final java.lang.String version
The version information to send when connecting to the server.


VERSION_PREFIX

@NotNull
private static final byte[] VERSION_PREFIX
The command prefix for the "version" command.


writeBuffer

@NotNull
private final byte[] writeBuffer
Buffer to build commands to send. It is shared between all sendXxx() functions. It is used to synchronize these functions.

Constructor Detail

DefaultCrossfireServerConnection

public DefaultCrossfireServerConnection(@NotNull
                                        java.lang.Object redrawSemaphore,
                                        @Nullable
                                        DebugWriter debugProtocol,
                                        @NotNull
                                        java.lang.String version)
                                 throws java.io.IOException
Creates a new instance.

Parameters:
redrawSemaphore - the semaphore used to synchronized map model updates and map view redraws
debugProtocol - tf non-null, write all protocol commands to this writer
version - the version information to send to the server when connecting
Throws:
java.io.IOException - if an internal error occurs
Method Detail

addCrossfireAccountListener

public void addCrossfireAccountListener(@NotNull
                                        CrossfireAccountListener listener)
Adds a listener to be notified about account events.

Specified by:
addCrossfireAccountListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add.

addCrossfireComcListener

public void addCrossfireComcListener(@NotNull
                                     CrossfireComcListener listener)
Adds a listener to be notified about received comc commands.

Specified by:
addCrossfireComcListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireDrawextinfoListener

public void addCrossfireDrawextinfoListener(@NotNull
                                            CrossfireDrawextinfoListener listener)
Adds a new listener monitoring the drawextinfo S->C messages.

Specified by:
addCrossfireDrawextinfoListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove

addCrossfireDrawinfoListener

public void addCrossfireDrawinfoListener(@NotNull
                                         CrossfireDrawinfoListener listener)
Adds a new listener monitoring the drawinfo S->C messages.

Specified by:
addCrossfireDrawinfoListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove

addCrossfireExpTableListener

public void addCrossfireExpTableListener(@NotNull
                                         CrossfireExpTableListener crossfireExpTableListener)
Adds a listener to be notified about received experience table changes.

Specified by:
addCrossfireExpTableListener in interface CrossfireServerConnection
Parameters:
crossfireExpTableListener - the listener to add

addCrossfireFaceListener

public void addCrossfireFaceListener(@NotNull
                                     CrossfireFaceListener listener)
Adds a listener to be notified about received face commands.

Specified by:
addCrossfireFaceListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireFailureListener

public void addCrossfireFailureListener(@NotNull
                                        CrossfireFailureListener listener)
Adds a listener to be notified of failure messages.

Specified by:
addCrossfireFailureListener in interface CrossfireServerConnection
Parameters:
listener - listener to add.

addCrossfireMagicmapListener

public void addCrossfireMagicmapListener(@NotNull
                                         CrossfireMagicmapListener listener)
Adds a listener from the list of objects listening to magicmap messages.

Specified by:
addCrossfireMagicmapListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireMusicListener

public void addCrossfireMusicListener(@NotNull
                                      CrossfireMusicListener listener)
Adds a listener to be notified about received music commands.

Specified by:
addCrossfireMusicListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfirePickupListener

public void addCrossfirePickupListener(@NotNull
                                       CrossfirePickupListener listener)
Adds a listener to be notified about received "pickup" messages.

Specified by:
addCrossfirePickupListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireQueryListener

public void addCrossfireQueryListener(@NotNull
                                      CrossfireQueryListener listener)
Adds a new listener monitoring the query S->C messages.

Specified by:
addCrossfireQueryListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove

addCrossfireServerConnectionListener

public void addCrossfireServerConnectionListener(@NotNull
                                                 CrossfireServerConnectionListener listener)
Adds a listener to be notified about connection progress.

Specified by:
addCrossfireServerConnectionListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireSkillInfoListener

public void addCrossfireSkillInfoListener(@NotNull
                                          CrossfireSkillInfoListener listener)
Adds a listener to be notified about received skill info changes.

Specified by:
addCrossfireSkillInfoListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireSoundListener

public void addCrossfireSoundListener(@NotNull
                                      CrossfireSoundListener listener)
Adds a listener to be notified about received sound commands.

Specified by:
addCrossfireSoundListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireSpellListener

public void addCrossfireSpellListener(@NotNull
                                      CrossfireSpellListener listener)
Adds a listener to be notified about received spell commands.

Specified by:
addCrossfireSpellListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireStatsListener

public void addCrossfireStatsListener(@NotNull
                                      CrossfireStatsListener crossfireStatsListener)
Adds a listener to be notified about stats changes.

Specified by:
addCrossfireStatsListener in interface CrossfireServerConnection
Parameters:
crossfireStatsListener - the listener to add

addCrossfireTickListener

public void addCrossfireTickListener(@NotNull
                                     CrossfireTickListener listener)
Adds a listener to be notified about tick changes.

Specified by:
addCrossfireTickListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireUpdateFaceListener

public void addCrossfireUpdateFaceListener(@NotNull
                                           CrossfireUpdateFaceListener listener)
Add a listener to be notified about face image changes.

Specified by:
addCrossfireUpdateFaceListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addCrossfireUpdateItemListener

public void addCrossfireUpdateItemListener(@NotNull
                                           CrossfireUpdateItemListener crossfireUpdateItemListener)
Adds a listener to be notified about item changes.

Specified by:
addCrossfireUpdateItemListener in interface CrossfireServerConnection
Parameters:
crossfireUpdateItemListener - the listener to add

addCrossfireUpdateMapListener

public void addCrossfireUpdateMapListener(@NotNull
                                          CrossfireUpdateMapListener listener)
Adds a listener to be notified about map changes.

Specified by:
addCrossfireUpdateMapListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addPacketWatcherListener

public void addPacketWatcherListener(@NotNull
                                     ReceivedPacketListener listener)
Adds a listener to be notified about received packets.

Specified by:
addPacketWatcherListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

addSentReplyListener

public void addSentReplyListener(@NotNull
                                 SentReplyListener listener)
Adds a listener to be notified about sent reply packets.

Specified by:
addSentReplyListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

clearFailure

private void clearFailure()
Inform the various failure listeners that they can clean the last displayed failure.


cmdMap2Coordinate

private void cmdMap2Coordinate(@NotNull
                               java.nio.ByteBuffer packet,
                               int x,
                               int y)
                        throws UnknownCommandException
Processes the payload data for a map2 coordinate command.

Parameters:
packet - the packet contents
x - the x-coordinate of the currently processed square
y - the y-coordinate of the currently processed square
Throws:
UnknownCommandException - if the command cannot be parsed

cmdMap2CoordinateClearSpace

private void cmdMap2CoordinateClearSpace(int x,
                                         int y,
                                         int len)
                                  throws UnknownCommandException
Processes the payload data for a map2 coordinate "clear_space" sub-command.

Parameters:
x - the x-coordinate of the currently processed square
y - the y-coordinate of the currently processed square
len - the payload length
Throws:
UnknownCommandException - if the command cannot be parsed

cmdMap2CoordinateDarkness

private void cmdMap2CoordinateDarkness(@NotNull
                                       java.nio.ByteBuffer packet,
                                       int x,
                                       int y,
                                       int len)
                                throws UnknownCommandException
Processes the payload data for a map2 coordinate "darkness" sub-command.

Parameters:
packet - the packet contents
x - the x-coordinate of the currently processed square
y - the y-coordinate of the currently processed square
len - the payload length
Throws:
UnknownCommandException - if the command cannot be parsed

cmdMap2CoordinateLayer

private void cmdMap2CoordinateLayer(@NotNull
                                    java.nio.ByteBuffer packet,
                                    int x,
                                    int y,
                                    int len,
                                    int layer)
                             throws UnknownCommandException
Processes the payload data for a map2 coordinate "layer" sub-command.

Parameters:
packet - the packet contents
x - the x-coordinate of the currently processed square
y - the y-coordinate of the currently processed square
len - the payload length
layer - the layer to update
Throws:
UnknownCommandException - if the command cannot be parsed

cmdMap2CoordinateLayer3

private void cmdMap2CoordinateLayer3(@NotNull
                                     java.nio.ByteBuffer packet,
                                     int x,
                                     int y,
                                     int layer,
                                     int face)
                              throws UnknownCommandException
Processes the additional payload data for a map2 coordinate "layer" sub-command having 4 bytes payload.

Parameters:
packet - the packet contents
face - the face number
x - the x-coordinate of the currently processed square
y - the y-coordinate of the currently processed square
layer - the layer to update
Throws:
UnknownCommandException - if the command cannot be parsed

cmdMap2CoordinateLayer4

private void cmdMap2CoordinateLayer4(@NotNull
                                     java.nio.ByteBuffer packet,
                                     int x,
                                     int y,
                                     int layer,
                                     int face)
                              throws UnknownCommandException
Processes the additional payload data for a map2 coordinate "layer" sub-command having 4 bytes payload.

Parameters:
packet - the packet contents
face - the face number
x - the x-coordinate of the currently processed square
y - the y-coordinate of the currently processed square
layer - the layer to update
Throws:
UnknownCommandException - if the command cannot be parsed

cmdReplyinfo

private void cmdReplyinfo(@NotNull
                          java.lang.String infoType,
                          java.nio.ByteBuffer packet)
                   throws java.io.IOException
Handles the replyinfo server to client command.

Parameters:
infoType - the info_type parameter
packet - the packet payload data
Throws:
java.io.IOException - if an I/O error occurs

connect

public void connect(@NotNull
                    java.lang.String hostname,
                    int port)
Attempts to connect the client to a server.

Specified by:
connect in interface ServerConnection
Overrides:
connect in class DefaultServerConnection
Parameters:
hostname - the hostname to connect to
port - the port to connect to

connected

private void connected()
Called after the server connection has been established.


drawextinfo

public void drawextinfo(int color,
                        int type,
                        int subtype,
                        java.lang.String message)
Pretends that a drawextinfo message has been received.

Specified by:
drawextinfo in interface CrossfireServerConnection
Parameters:
color - the color
type - the message type
subtype - the message subtype
message - the message

drawInfo

public void drawInfo(@NotNull
                     java.lang.String message,
                     int color)
Pretends that a drawinfo message has been received.

Specified by:
drawInfo in interface CrossfireServerConnection
Parameters:
message - the message
color - the color

drawInfoSetDebugMode

public void drawInfoSetDebugMode(boolean printMessageTypes)
Enables or disables printing of message types.

Specified by:
drawInfoSetDebugMode in interface CrossfireServerConnection
Parameters:
printMessageTypes - whether to enable or disable message types

extractCommand

private static java.lang.String extractCommand(@NotNull
                                               java.nio.ByteBuffer packet)
Returns the command string for a received packet.

Parameters:
packet - the packet contents
Returns:
the command string

fireNewMap

private void fireNewMap()
Notifies all listeners that a "newmap" command has been received.


getAccountName

@Nullable
public java.lang.String getAccountName()
Returns the current account name.

Specified by:
getAccountName in interface CrossfireServerConnection
Returns:
the current account name or null

getInt1

private static int getInt1(@NotNull
                           java.nio.ByteBuffer byteBuffer)
Extracts and removes a 1 byte integer from a ByteBuffer at it's current position.

Parameters:
byteBuffer - the byte buffer
Returns:
the integer

getInt2

private static int getInt2(@NotNull
                           java.nio.ByteBuffer byteBuffer)
Extracts and removes a 2 byte integer from a ByteBuffer at it's current position.

Parameters:
byteBuffer - the byte buffer
Returns:
the integer

getInt4

private static int getInt4(@NotNull
                           java.nio.ByteBuffer byteBuffer)
Extracts and removes a 4 byte integer from a ByteBuffer at it's current position.

Parameters:
byteBuffer - the byte buffer
Returns:
the integer

getInt8

private static long getInt8(@NotNull
                            java.nio.ByteBuffer byteBuffer)
Extracts and removes an 8 byte integer from a ByteBuffer at it's current position.

Parameters:
byteBuffer - the byte buffer
Returns:
the integer

getMapHeight

public int getMapHeight()
Returns the map height in tiles.

Specified by:
getMapHeight in interface CrossfireServerConnection
Returns:
the map height

getMapWidth

public int getMapWidth()
Returns the map width in tiles.

Specified by:
getMapWidth in interface CrossfireServerConnection
Returns:
the map width

getString

private static java.lang.String getString(java.nio.ByteBuffer byteBuffer,
                                          int len)
Extracts and removes a string from a ByteBuffer at it's current position.

Parameters:
byteBuffer - the byte buffer
len - the length of the string
Returns:
the string

hexDump

@NotNull
private static java.lang.String hexDump(@NotNull
                                                java.nio.ByteBuffer byteBuffer)
Returns a hex-dump of a ByteBuffer.

Parameters:
byteBuffer - the byte buffer
Returns:
the hex-dump

negotiateMapSize

private void negotiateMapSize(int mapWidth,
                              int mapHeight)
Requests a change of the map size from the server.

Parameters:
mapWidth - the map width to request
mapHeight - the map height to request

negotiateNumLookObjects

private void negotiateNumLookObjects(int numLookObjects)
Requests a change of the number of ground objects from the server.

Parameters:
numLookObjects - the number of ground objects to request

newString

private static java.lang.String newString(java.nio.ByteBuffer byteBuffer,
                                          int start,
                                          int len)
Extracts a string from a ByteBuffer range.

Parameters:
byteBuffer - the byte buffer
start - the start index of the string
len - the length of the string
Returns:
the string

notifyPacketWatcherListenersAscii

private void notifyPacketWatcherListenersAscii(@NotNull
                                               java.nio.ByteBuffer packet,
                                               int args)
Notifies all ReceivedPacketListeners about a packet having ascii parameters.

Parameters:
packet - the packet contents
args - the start index into packet of the packet's arguments

notifyPacketWatcherListenersEmpty

private void notifyPacketWatcherListenersEmpty(@NotNull
                                               java.lang.String command)
Notifies all ReceivedPacketListeners about an empty packet.

Parameters:
command - the command string

notifyPacketWatcherListenersIntArray

private void notifyPacketWatcherListenersIntArray(@NotNull
                                                  java.nio.ByteBuffer packet,
                                                  int args)
Notifies all ReceivedPacketListeners about a packet having an array of int values as parameters.

Parameters:
packet - the packet contents
args - the start index into packet of the packet's arguments

notifyPacketWatcherListenersMixed

private void notifyPacketWatcherListenersMixed(@NotNull
                                               java.nio.ByteBuffer packet,
                                               int args)
Notifies all ReceivedPacketListeners about a packet having mixed parameters.

Parameters:
packet - the packet contents
args - the start index into packet of the packet's arguments

notifyPacketWatcherListenersNoData

private void notifyPacketWatcherListenersNoData(@NotNull
                                                java.nio.ByteBuffer packet,
                                                int args)
Notifies all ReceivedPacketListeners about a packet having unknown parameters.

Parameters:
packet - the packet contents
args - the start index into packet of the packet's arguments

notifyPacketWatcherListenersShortArray

private void notifyPacketWatcherListenersShortArray(@NotNull
                                                    java.nio.ByteBuffer packet,
                                                    int args)
Notifies all ReceivedPacketListeners about a packet having an array of short values as parameters.

Parameters:
packet - the packet contents
args - the start index into packet of the packet's arguments

notifyPacketWatcherListenersShortInt

private void notifyPacketWatcherListenersShortInt(@NotNull
                                                  java.nio.ByteBuffer packet,
                                                  int args)
Notifies all ReceivedPacketListeners about a packet having a short and an in value as parameters.

Parameters:
packet - the packet contents
args - the start index into packet of the packet's arguments

notifyPacketWatcherListenersStats

private void notifyPacketWatcherListenersStats(int stat,
                                               @NotNull
                                               java.lang.Object... args)
Notifies all ReceivedPacketListeners about a packet having stat parameters.

Parameters:
stat - the stat value
args - the stat arguments depending on type and stat

parseDigit

private static int parseDigit(byte ch)
                       throws UnknownCommandException
Parses a character into an integer.

Parameters:
ch - the character to parse
Returns:
the integer representing the character
Throws:
UnknownCommandException - if ch is not a digit

processAccountPlayers

private void processAccountPlayers(@NotNull
                                   java.nio.ByteBuffer packet)
                            throws UnknownCommandException
Processes an 'accountplayers' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processAddmeFailed

private void processAddmeFailed(@NotNull
                                java.nio.ByteBuffer packet)
Processes an 'account_failed' server command.

Parameters:
packet - the packet's payload

processAddmeSuccess

private void processAddmeSuccess(@NotNull
                                 java.nio.ByteBuffer packet)
Processes an 'account_success' server command.

Parameters:
packet - the packet's payload

processAddSpell

private void processAddSpell(@NotNull
                             java.nio.ByteBuffer packet)
Processes an 'addspell' server command.

Parameters:
packet - the packet's payload

processAnim

private void processAnim(@NotNull
                         java.nio.ByteBuffer packet)
                  throws UnknownCommandException
Processes an 'anim' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processComc

private void processComc(@NotNull
                         java.nio.ByteBuffer packet)
                  throws UnknownCommandException
Processes a 'comc' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processDelInv

private void processDelInv(@NotNull
                           java.nio.ByteBuffer packet)
                    throws UnknownCommandException
Processes a 'delinv' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processDelItem

private void processDelItem(@NotNull
                            java.nio.ByteBuffer packet)
                     throws UnknownCommandException
Processes a 'delitem' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processDelSpell

private void processDelSpell(@NotNull
                             java.nio.ByteBuffer packet)
                      throws UnknownCommandException
Processes a 'delspell' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processDrawExtInfo

private void processDrawExtInfo(@NotNull
                                java.nio.ByteBuffer packet)
                         throws UnknownCommandException
Processes a 'drawextinfo' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processDrawInfo

private void processDrawInfo(@NotNull
                             java.nio.ByteBuffer packet)
                      throws UnknownCommandException
Processes a 'drawinfo' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processExpTableReplyinfo

private void processExpTableReplyinfo(@NotNull
                                      java.nio.ByteBuffer packet)
Processes a "replyinfo exp_table" block.

Parameters:
packet - the packet to process

processExtendedInfoSet

private void processExtendedInfoSet(@NotNull
                                    java.nio.ByteBuffer packet)
Processes an 'ExtendedInfoSet' server command.

Parameters:
packet - the packet's payload

processExtendedTextSet

private void processExtendedTextSet(@NotNull
                                    java.nio.ByteBuffer packet)
Processes an 'ExtendedTextSet' server command.

Parameters:
packet - the packet's payload

processFace2

private void processFace2(@NotNull
                          java.nio.ByteBuffer packet)
Processes a 'face2' server command.

Parameters:
packet - the packet's payload

processFailure

private void processFailure(@NotNull
                            java.nio.ByteBuffer packet)
Processes a 'failure' server command.

Parameters:
packet - the packet's payload

processGoodbye

private void processGoodbye(@NotNull
                            java.nio.ByteBuffer packet)
                     throws UnknownCommandException
Processes a 'goodbye' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processImage2

private void processImage2(@NotNull
                           java.nio.ByteBuffer packet)
                    throws UnknownCommandException
Processes an 'image2' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processImageInfoReplyinfo

private static void processImageInfoReplyinfo(@NotNull
                                              java.nio.ByteBuffer packet)
                                       throws java.io.IOException
Processes a "replyinfo image_info" block.

Parameters:
packet - the packet to process
Throws:
java.io.IOException - if the packet cannot be parsed

processItem2

private void processItem2(@NotNull
                          java.nio.ByteBuffer packet)
                   throws UnknownCommandException
Processes an 'item2' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processMagicMap

private void processMagicMap(@NotNull
                             java.nio.ByteBuffer packet)
                      throws UnknownCommandException
Processes a 'magicmap' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processMap2

private void processMap2(@NotNull
                         java.nio.ByteBuffer packet)
                  throws UnknownCommandException
Processes a 'map2' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processMapExtended

private void processMapExtended(@NotNull
                                java.nio.ByteBuffer packet)
Processes a 'mapextended' server command.

Parameters:
packet - the packet's payload

processMusic

private void processMusic(@NotNull
                          java.nio.ByteBuffer packet)
Processes a 'music' server command.

Parameters:
packet - the packet's payload

processNewMap

private void processNewMap(@NotNull
                           java.nio.ByteBuffer packet)
                    throws UnknownCommandException
Processes a 'newmap' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processPacket

private void processPacket(@NotNull
                           java.nio.ByteBuffer packet)
                    throws UnknownCommandException
Processes a received packet. This function does not avoid buffer underflow exceptions when reading data from the packet. Instead, a try...catch clause is used to detect invalid packets.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet cannot be parsed

processPickup

private void processPickup(@NotNull
                           java.nio.ByteBuffer packet)
                    throws UnknownCommandException
Processes a 'pickup' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processPlayer

private void processPlayer(@NotNull
                           java.nio.ByteBuffer packet)
                    throws UnknownCommandException
Processes a 'pickup' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processQuery

private void processQuery(@NotNull
                          java.nio.ByteBuffer packet)
                   throws UnknownCommandException
Processes a 'pickup' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processReplyInfo

private void processReplyInfo(@NotNull
                              java.nio.ByteBuffer packet)
                       throws UnknownCommandException
Processes a 'replyinfo' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processSetup

private void processSetup(@NotNull
                          java.nio.ByteBuffer packet)
                   throws UnknownCommandException
Processes a 'replyinfo' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processSkillInfoReplyinfo

private void processSkillInfoReplyinfo(@NotNull
                                       java.nio.ByteBuffer packet)
                                throws java.io.IOException
Processes a "replyinfo skill_info" block.

Parameters:
packet - the packet to process
Throws:
java.io.IOException - if the packet cannot be parsed

processSmooth

private void processSmooth(@NotNull
                           java.nio.ByteBuffer packet)
                    throws UnknownCommandException
Processes a 'smooth' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processSound

private void processSound(@NotNull
                          java.nio.ByteBuffer packet)
                   throws UnknownCommandException
Processes a 'sound' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processSound2

private void processSound2(@NotNull
                           java.nio.ByteBuffer packet)
                    throws UnknownCommandException
Processes a 'sound2' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processStats

private void processStats(@NotNull
                          java.nio.ByteBuffer packet)
                   throws UnknownCommandException
Processes a 'stats' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processTick

private void processTick(@NotNull
                         java.nio.ByteBuffer packet)
                  throws UnknownCommandException
Processes a 'tick' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processUpdItem

private void processUpdItem(@NotNull
                            java.nio.ByteBuffer packet)
                     throws UnknownCommandException
Processes an 'upditem' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processUpdSpell

private void processUpdSpell(@NotNull
                             java.nio.ByteBuffer packet)
                      throws UnknownCommandException
Processes an 'updspell' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

processVersion

private void processVersion(@NotNull
                            java.nio.ByteBuffer packet)
                     throws UnknownCommandException
Processes a 'version' server command.

Parameters:
packet - the packet's payload
Throws:
UnknownCommandException - if the packet is invalid.

putDecimal

private void putDecimal(int value)
Appends an integer in decimal ASCII representation to byteBuffer.

Parameters:
value - the value to append

removeCrossfireAccountListener

public void removeCrossfireAccountListener(@NotNull
                                           CrossfireAccountListener listener)
Removes a listener to be notified about account events.

Specified by:
removeCrossfireAccountListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove.

removeCrossfireDrawextinfoListener

public void removeCrossfireDrawextinfoListener(@NotNull
                                               CrossfireDrawextinfoListener listener)
Removes the given listener from the list of objects listening to the drawextinfo S->C messages.

Specified by:
removeCrossfireDrawextinfoListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove

removeCrossfireDrawinfoListener

public void removeCrossfireDrawinfoListener(@NotNull
                                            CrossfireDrawinfoListener listener)
Removes the given listener from the list of objects listening to the drawinfo S->C messages.

Specified by:
removeCrossfireDrawinfoListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove

removeCrossfireFailureListener

public void removeCrossfireFailureListener(@NotNull
                                           CrossfireFailureListener listener)
Removes a listener to be notified of failure messages.

Specified by:
removeCrossfireFailureListener in interface CrossfireServerConnection
Parameters:
listener - listener to be removed.

removeCrossfireMagicmapListener

public void removeCrossfireMagicmapListener(@NotNull
                                            CrossfireMagicmapListener listener)
Removes a listener from the list of objects listening to magicmap messages.

Specified by:
removeCrossfireMagicmapListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove

removeCrossfirePickupListener

public void removeCrossfirePickupListener(@NotNull
                                          CrossfirePickupListener listener)
Removes a listener to be notified about received "pickup" messages.

Specified by:
removeCrossfirePickupListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove

removeCrossfireQueryListener

public void removeCrossfireQueryListener(@NotNull
                                         CrossfireQueryListener listener)
Removes the given listener from the list of objects listening to the query S->C messages.

Specified by:
removeCrossfireQueryListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove

removeCrossfireSkillInfoListener

public void removeCrossfireSkillInfoListener(@NotNull
                                             CrossfireSkillInfoListener listener)
Removes a listener to be notified about received skill info changes.

Specified by:
removeCrossfireSkillInfoListener in interface CrossfireServerConnection
Parameters:
listener - the listener to remove

removeCrossfireUpdateItemListener

public void removeCrossfireUpdateItemListener(@NotNull
                                              CrossfireUpdateItemListener crossfireUpdateItemListener)
Removes a listener to be notified about item changes.

Specified by:
removeCrossfireUpdateItemListener in interface CrossfireServerConnection
Parameters:
crossfireUpdateItemListener - the listener to remove

removePacketWatcherListener

public void removePacketWatcherListener(@NotNull
                                        ReceivedPacketListener listener)
Removes a listener to be notified about received packets.

Specified by:
removePacketWatcherListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

removeSentReplyListener

public void removeSentReplyListener(@NotNull
                                    SentReplyListener listener)
Removes a listener to be notified about sent reply packets.

Specified by:
removeSentReplyListener in interface CrossfireServerConnection
Parameters:
listener - the listener to add

sendAccountCharacterCreate

public void sendAccountCharacterCreate(@NotNull
                                       java.lang.String login,
                                       @NotNull
                                       java.lang.String password)
Sends a request to create a new character associated to the account.

Specified by:
sendAccountCharacterCreate in interface CrossfireServerConnection
Parameters:
login - the character's name
password - the character's password

sendAccountCreate

public void sendAccountCreate(@NotNull
                              java.lang.String login,
                              @NotNull
                              java.lang.String password)
Sends a request to create a new account.

Specified by:
sendAccountCreate in interface CrossfireServerConnection
Parameters:
login - the account login
password - the account password

sendAccountLink

public void sendAccountLink(int force,
                            @NotNull
                            java.lang.String login,
                            @NotNull
                            java.lang.String password)
Sends a request to add an existing character to an account.

Specified by:
sendAccountLink in interface CrossfireServerConnection
Parameters:
force - 0 to allow failure, 1 to force in certain situations
login - the character's login
password - the character's password

sendAccountLogin

public void sendAccountLogin(@NotNull
                             java.lang.String login,
                             @NotNull
                             java.lang.String password)
Asks for an account login.

Specified by:
sendAccountLogin in interface CrossfireServerConnection
Parameters:
login - the account login
password - the account password

sendAccountPlay

public void sendAccountPlay(@NotNull
                            java.lang.String name)
Sends a request to play a character from an account.

Specified by:
sendAccountPlay in interface CrossfireServerConnection
Parameters:
name - the character's name to play

sendAddme

public void sendAddme()
Sends an "addme" command to the server.

Specified by:
sendAddme in interface CrossfireServerConnection

sendApply

public void sendApply(int tag)
Sends an "apply" command to the server.

Specified by:
sendApply in interface CrossfireServerConnection
Parameters:
tag - the item to apply

sendAskface

public void sendAskface(int num)
Sends an "askface" command to the server.

Specified by:
sendAskface in interface CrossfireServerConnection
Parameters:
num - the face to query

sendExamine

public void sendExamine(int tag)
Sends an "examine" command to the server.

Specified by:
sendExamine in interface CrossfireServerConnection
Parameters:
tag - the item to examine

sendLock

public void sendLock(boolean val,
                     int tag)
Sends a "lock" command to the server.

Specified by:
sendLock in interface CrossfireServerConnection
Parameters:
val - whether to lock the item
tag - the item to lock

sendLookat

public void sendLookat(int dx,
                       int dy)
Sends a "lookat" command to the server.

Specified by:
sendLookat in interface CrossfireServerConnection
Parameters:
dx - the x-coordinate in tiles, relative to the player
dy - the y-coordinate in tiles, relative to the player

sendMark

public void sendMark(int tag)
Sends a "mark" command to the server.

Specified by:
sendMark in interface CrossfireServerConnection
Parameters:
tag - the item to mark

sendMove

public void sendMove(int to,
                     int tag,
                     int nrof)
Sends a "move" command to the server.

Specified by:
sendMove in interface CrossfireServerConnection
Parameters:
to - the destination location
tag - the item to move
nrof - the number of items to move

sendNcom

public int sendNcom(int repeat,
                    @NotNull
                    java.lang.String command)
Sends a "ncom" command to the server.

Specified by:
sendNcom in interface CrossfireServerConnection
Parameters:
repeat - the repeat count
command - the command
Returns:
the packet id

sendReply

public void sendReply(@NotNull
                      java.lang.String text)
Sends a "reply" command to the server.

Specified by:
sendReply in interface CrossfireServerConnection
Parameters:
text - the text to reply

sendRequestinfo

public void sendRequestinfo(@NotNull
                            java.lang.String infoType)
Sends a "requestinfo" command to the server.

Specified by:
sendRequestinfo in interface CrossfireServerConnection
Parameters:
infoType - the info type to request

sendSetup

public void sendSetup(@NotNull
                      java.lang.String... options)
Sends a "setup" command to the server.

Specified by:
sendSetup in interface CrossfireServerConnection
Parameters:
options - the option/value pairs to send

sendToggleextendedtext

public void sendToggleextendedtext(@NotNull
                                   int... types)
Sends a "toggleextendedtext" command to the server.

Specified by:
sendToggleextendedtext in interface CrossfireServerConnection
Parameters:
types - the types to request

sendVersion

public void sendVersion(int csval,
                        int scval,
                        @NotNull
                        java.lang.String vinfo)
Sends a "version" command to the server.

Specified by:
sendVersion in interface CrossfireServerConnection
Parameters:
csval - the client version number
scval - the server version number
vinfo - the client identification string

setClientSocketState

private void setClientSocketState(@NotNull
                                  ClientSocketState prevState,
                                  @NotNull
                                  ClientSocketState nextState)
Updates the clientSocketState.

Parameters:
prevState - the expected current state
nextState - the next state

setCurrentMapSize

private void setCurrentMapSize(int currentMapWidth,
                               int currentMapHeight)
Sets the current map size as negotiated with the server.

Parameters:
currentMapWidth - the new map width
currentMapHeight - the new map height

setCurrentNumLookObjects

private void setCurrentNumLookObjects(int currentNumLookObjects)
Sets the current ground view objects as negotiated with the server.

Parameters:
currentNumLookObjects - the number of objects

setPreferredMapSize

public void setPreferredMapSize(int preferredMapWidth,
                                int preferredMapHeight)
Sets the preferred map size.

Specified by:
setPreferredMapSize in interface CrossfireServerConnection
Parameters:
preferredMapWidth - the preferred map width in tiles; must be odd
preferredMapHeight - the preferred map height in tiles; must be odd

setPreferredNumLookObjects

public void setPreferredNumLookObjects(int preferredNumLookObjects)
Sets the maximum number of objects in the ground view. Must not be called in connected state.

Specified by:
setPreferredNumLookObjects in interface CrossfireServerConnection
Parameters:
preferredNumLookObjects - the number of objects