Class DefaultCrossfireServerConnection

java.lang.Object
com.realtime.crossfire.jxclient.server.crossfire.AbstractCrossfireServerConnection
com.realtime.crossfire.jxclient.server.crossfire.DefaultCrossfireServerConnection
All Implemented Interfaces:
AskfaceQueue, CrossfireServerConnection, ServerConnection

public class DefaultCrossfireServerConnection extends AbstractCrossfireServerConnection
Default implementation of CrossfireServerConnection.
  • Constructor Details

    • DefaultCrossfireServerConnection

      public DefaultCrossfireServerConnection(@NotNull @NotNull Model model, @Nullable @Nullable DebugWriter debugProtocol, @NotNull @NotNull String version) throws IOException
      Creates a new instance.
      Parameters:
      model - the model instance to update
      debugProtocol - if non-null, write all protocol commands to this writer
      version - the version information to send to the server when connecting
      Throws:
      IOException - if an internal error occurs
  • Method Details

    • setCrossfireUpdateMapListener

      public void setCrossfireUpdateMapListener(@NotNull @NotNull CrossfireUpdateMapListener listener)
      Description copied from interface: CrossfireServerConnection
      Sets a listener to be notified about map changes. At most one such listener may be set.
      Parameters:
      listener - the listener
    • start

      public void start()
      Description copied from interface: CrossfireServerConnection
      Starts operation.
    • stop

      public void stop() throws InterruptedException
      Description copied from interface: CrossfireServerConnection
      Stops operation.
      Throws:
      InterruptedException - if stopping was interrupted
    • addCrossfireMapScrollListener

      public void addCrossfireMapScrollListener(@NotNull @NotNull CrossfireMapScrollListener listener)
      Description copied from interface: CrossfireServerConnection
      Registers a listener to be called whenever the map was scolled.
      Parameters:
      listener - the listener
    • sendAccountLogin

      public void sendAccountLogin(@NotNull @NotNull String login, @NotNull @NotNull String password)
      Description copied from interface: CrossfireServerConnection
      Asks for an account login.
      Parameters:
      login - the account login
      password - the account password
    • sendAddme

      public void sendAddme()
      Description copied from interface: CrossfireServerConnection
      Sends an "addme" command to the server.
    • sendApply

      public void sendApply(int tag)
      Description copied from interface: CrossfireServerConnection
      Sends an "apply" command to the server.
      Parameters:
      tag - the item to apply
    • sendAskface

      public void sendAskface(int faceNum)
      Description copied from interface: AskfaceQueue
      Sends an "askface" command.
      Parameters:
      faceNum - the face number to request
    • addFaceReceivedListener

      public void addFaceReceivedListener(@NotNull @NotNull AskfaceFaceQueueListener listener)
      Description copied from interface: AskfaceQueue
      Registers a listener to be called whenever a face has been received.
      Parameters:
      listener - the listener
    • sendExamine

      public void sendExamine(int tag)
      Description copied from interface: CrossfireServerConnection
      Sends an "examine" command to the server.
      Parameters:
      tag - the item to examine
    • sendLock

      public void sendLock(boolean val, int tag)
      Description copied from interface: CrossfireServerConnection
      Sends a "lock" command to the server.
      Parameters:
      val - whether to lock the item
      tag - the item to lock
    • sendLookat

      public void sendLookat(int dx, int dy)
      Description copied from interface: CrossfireServerConnection
      Sends a "lookat" command to the server.
      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)
      Description copied from interface: CrossfireServerConnection
      Sends a "mark" command to the server.
      Parameters:
      tag - the item to mark
    • sendMove

      public void sendMove(int to, int tag, int nrof)
      Description copied from interface: CrossfireServerConnection
      Sends a "move" command to the server.
      Parameters:
      to - the destination location
      tag - the item to move
      nrof - the number of items to move
    • sendNcom

      public int sendNcom(int repeat, @NotNull @NotNull String command)
      Description copied from interface: CrossfireServerConnection
      Sends a "ncom" command to the server.
      Parameters:
      repeat - the repeat count
      command - the command
      Returns:
      the packet id
    • sendRawString

      public void sendRawString(@NotNull @NotNull String command)
      Description copied from interface: CrossfireServerConnection
      Sends an arbitrary string command to the server.
      Parameters:
      command - the command
    • sendReply

      public void sendReply(@NotNull @NotNull String text)
      Description copied from interface: CrossfireServerConnection
      Sends a "reply" command to the server.
      Parameters:
      text - the text to reply
    • sendRequestinfo

      public void sendRequestinfo(@NotNull @NotNull String infoType)
      Description copied from interface: CrossfireServerConnection
      Sends a "requestinfo" command to the server.
      Parameters:
      infoType - the info type to request
    • sendSetup

      public void sendSetup(@NotNull @NotNull String... options)
      Description copied from interface: CrossfireServerConnection
      Sends a "setup" command to the server.
      Parameters:
      options - the option/value pairs to send
    • sendToggleextendedtext

      public void sendToggleextendedtext(@NotNull @org.jetbrains.annotations.NotNull int... types)
      Description copied from interface: CrossfireServerConnection
      Sends a "toggleextendedtext" command to the server.
      Parameters:
      types - the types to request
    • sendVersion

      public void sendVersion(int csval, int scval, @NotNull @NotNull String vinfo)
      Description copied from interface: CrossfireServerConnection
      Sends a "version" command to the server.
      Parameters:
      csval - the client version number
      scval - the server version number
      vinfo - the client identification string
    • setPreferredMapSize

      public void setPreferredMapSize(int preferredMapWidth, int preferredMapHeight)
      Description copied from interface: CrossfireServerConnection
      Sets the preferred map size.
      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)
      Description copied from interface: CrossfireServerConnection
      Sets the maximum number of objects in the ground view. Must not be called in connected state.
      Parameters:
      preferredNumLookObjects - the number of objects
    • getAccountName

      @Nullable public @Nullable String getAccountName()
      Description copied from interface: CrossfireServerConnection
      Returns the current account name.
      Returns:
      the current account name or null
    • connect

      public void connect(@NotNull @NotNull String hostname, int port)
      Description copied from interface: ServerConnection
      Attempts to connect the client to a server.
      Parameters:
      hostname - the hostname to connect to
      port - the port to connect to
    • disconnect

      public void disconnect(@NotNull @NotNull String reason)
      Description copied from interface: ServerConnection
      Disconnects from the server. Does nothing if not connected.
      Parameters:
      reason - the reason for the disconnect
    • addClientSocketListener

      public void addClientSocketListener(@NotNull @NotNull ClientSocketListener clientSocketListener)
      Description copied from interface: ServerConnection
      Adds a ClientSocketListener to notify.
      Parameters:
      clientSocketListener - the client socket listener to add
    • removeClientSocketListener

      public void removeClientSocketListener(@NotNull @NotNull ClientSocketListener clientSocketListener)
      Description copied from interface: ServerConnection
      Removes a ClientSocketListener to notify.
      Parameters:
      clientSocketListener - the client socket listener to remove
    • sendAccountPlay

      public void sendAccountPlay(@NotNull @NotNull String name)
      Description copied from interface: CrossfireServerConnection
      Sends a request to play a character from an account.
      Parameters:
      name - the character's name to play
    • sendAccountLink

      public void sendAccountLink(int force, @NotNull @NotNull String login, @NotNull @NotNull String password)
      Description copied from interface: CrossfireServerConnection
      Sends a request to add an existing character to an account.
      Parameters:
      force - 0 to allow failure, 1 to force in certain situations
      login - the character's login
      password - the character's password
    • sendAccountCreate

      public void sendAccountCreate(@NotNull @NotNull String login, @NotNull @NotNull String password)
      Description copied from interface: CrossfireServerConnection
      Sends a request to create a new account.
      Parameters:
      login - the account login
      password - the account password
    • sendAccountCharacterCreate

      public void sendAccountCharacterCreate(@NotNull @NotNull String login, @NotNull @NotNull String password, @NotNull @NotNull Collection<String> attributes)
      Description copied from interface: CrossfireServerConnection
      Sends a request to create a new character associated to the account.
      Parameters:
      login - the character's name
      password - the character's password
      attributes - the character attributes
    • sendAccountPassword

      public void sendAccountPassword(@NotNull @NotNull String currentPassword, @NotNull @NotNull String newPassword)
      Description copied from interface: CrossfireServerConnection
      Sends a request to change the account's password.
      Parameters:
      currentPassword - current account password
      newPassword - new account password
    • getCurrentNumLookObjects

      public int getCurrentNumLookObjects()
      Returns the currently negotiated setup value of "num_look_objects".
      Returns:
      the current size of the ground view
    • waitForCurrentNumLookObjectsValid

      public void waitForCurrentNumLookObjectsValid() throws InterruptedException
      Waits until getCurrentNumLookObjects() is stable. This function returns as soon as the negotiation with the Crossfire server is complete.
      Throws:
      InterruptedException - if the current thread was interrupted