Class StendhalClient

java.lang.Object
marauroa.client.ClientFramework
games.stendhal.client.StendhalClient

public class StendhalClient extends ClientFramework
This class is the glue to Marauroa, it extends ClientFramework and allows us to easily connect to an marauroa server and operate it easily.
  • Field Details

  • Method Details

    • get

      public static StendhalClient get()
      Get the client instance.
      Returns:
      client instance
    • resetClient

      public static void resetClient()
      Set the client instance to null.
    • getGameName

      protected String getGameName()
      Description copied from class: ClientFramework
      Returns the name of the game that this client implements
      Specified by:
      getGameName in class ClientFramework
      Returns:
      the name of the game that this client implements
    • getVersionNumber

      protected String getVersionNumber()
      Description copied from class: ClientFramework
      Returns the version number of the game
      Specified by:
      getVersionNumber in class ClientFramework
      Returns:
      the version number of the game
    • getStaticGameLayers

      public StaticGameLayers getStaticGameLayers()
      Get the map layers.
      Returns:
      map layers
    • getGameObjects

      public GameObjects getGameObjects()
      Get the game objects container.
      Returns:
      game objects
    • onPerception

      protected void onPerception(MessageS2CPerception message)
      Description copied from class: ClientFramework
      It is called when a perception arrives so you can choose how to apply the perception.
      Specified by:
      onPerception in class ClientFramework
      Parameters:
      message - the perception message itself.
    • onTransferREQ

      protected List<TransferContent> onTransferREQ(List<TransferContent> items)
      Description copied from class: ClientFramework
      is called before a content transfer is started. items contains a list of names and timestamp. That information can be used to decide if a transfer from server is needed. By setting attribute ack to true in a TransferContent it will be acknowledged. All acknowledges items in the returned List, will be transfered by server.
      Specified by:
      onTransferREQ in class ClientFramework
      Parameters:
      items - in this list by default all items.ack attributes are set to false;
      Returns:
      the list of approved and rejected items.
    • addZoneChangeListener

      public void addZoneChangeListener(StendhalClient.ZoneChangeListener listener)
      Add a listener to be called when the player changes zone.
      Parameters:
      listener - added listener
    • isInTransfer

      public boolean isInTransfer()
      Determine if we are in the middle of transferring new content that should suppress drawing during the transfer.
      Returns:
      true if more content is to be transfered.
    • onTransfer

      protected void onTransfer(List<TransferContent> items)
      Description copied from class: ClientFramework
      It is called when we get a transfer of content
      Specified by:
      onTransfer in class ClientFramework
      Parameters:
      items - the transfered items.
    • onAvailableCharacters

      protected void onAvailableCharacters(String[] characters)
      Description copied from class: ClientFramework
      It is called when we get the list of characters
      Specified by:
      onAvailableCharacters in class ClientFramework
      Parameters:
      characters - the characters we have available at this account.
    • onAvailableCharacterDetails

      protected void onAvailableCharacterDetails(Map<String,​RPObject> characters)
      Description copied from class: ClientFramework
      It is called when we get the list of characters
      Overrides:
      onAvailableCharacterDetails in class ClientFramework
      Parameters:
      characters - the characters we have available at this account.
    • onServerInfo

      protected void onServerInfo(String[] info)
      Description copied from class: ClientFramework
      It is called when we get the list of server information strings
      Specified by:
      onServerInfo in class ClientFramework
      Parameters:
      info - the list of server strings with information.
    • onPreviousLogins

      protected void onPreviousLogins(List<String> previousLogins)
      Description copied from class: ClientFramework
      Call the client with a list of previous logins.
      Specified by:
      onPreviousLogins in class ClientFramework
      Parameters:
      previousLogins - a list of strings with the previous logins
    • addDirection

      public boolean addDirection(Direction dir, boolean face)
      Add an active player movement direction.
      Parameters:
      dir - The direction.
      face - If to face direction only.
      Returns:
      true if an action was sent, otherwise false
    • removeDirection

      public void removeDirection(Direction dir, boolean face)
      Remove a player movement direction.
      Parameters:
      dir - The direction.
      face - If to face direction only.
    • stop

      public void stop()
      Stop the player.
    • setAccountUsername

      public void setAccountUsername(String username)
      Set the account name.
      Parameters:
      username - account name
    • getCharacter

      public String getCharacter()
      Get the character name.
      Returns:
      character name
    • setCharacter

      public void setCharacter(String character)
      Set the character name.
      Parameters:
      character - name
    • setSplashScreen

      public void setSplashScreen(JFrame splash)
      Set the splash screen window. Used for transient windows.
      Parameters:
      splash - first screen window
    • getAccountUsername

      public String getAccountUsername()
      Get the account name.
      Returns:
      account name
    • getCache

      public games.stendhal.client.Cache getCache()
      Return the Cache instance.
      Returns:
      cache
    • getPlayer

      public RPObject getPlayer()
      Get the RPObject of the user.
      Returns:
      player object
    • chooseCharacter

      public boolean chooseCharacter(String character) throws TimeoutException, InvalidVersionException, BannedAddressException
      Description copied from class: ClientFramework
      After login allows you to choose a character to play
      Overrides:
      chooseCharacter in class ClientFramework
      Parameters:
      character - name of the character we want to play with.
      Returns:
      true if choosing character is successful.
      Throws:
      TimeoutException - if timeout happens while waiting for the message.
      InvalidVersionException - if we are not using a compatible version
      BannedAddressException
    • releaseDrawingSemaphore

      public void releaseDrawingSemaphore()
      Release the drawing semaphore.
    • tryAcquireDrawingSemaphore

      public boolean tryAcquireDrawingSemaphore()
      Try to acquire the drawing semaphore.
      Returns:
      true if the semaphore was acquired, otherwise false
    • connect

      public void connect(String host, int port) throws IOException
      Connect to the server, and if our version is too outdated, display a message.
      Overrides:
      connect in class ClientFramework
      Parameters:
      host - host name
      port - host port
      Throws:
      IOException - in case of an input/output error
    • send

      public void send(RPAction action)
      Description copied from class: ClientFramework
      Sends a RPAction to server
      Overrides:
      send in class ClientFramework
      Parameters:
      action - the action to send to server.
    • serverVersionAtLeast

      public static boolean serverVersionAtLeast(String required)
      Check if the connected server is of at least as recent as the specified version.
      Parameters:
      required - string representation of required server version
      Returns:
      true if the server is new enough, or the version is unknown, false if the server is older than the required version
    • keyIsPressed

      public boolean keyIsPressed(int keyCode)
      Check if a keyboard key is in the "pressed" state.
      Parameters:
      keyCode - The integer code for the key
      Returns:
      true if code is found in pressedStateKeys list
    • directionKeyIsPressed

      public boolean directionKeyIsPressed()
      Check if any direction key is in "pressed" state.
      Returns:
      Direction key found in pressedStateKeys list
    • onKeyPressed

      public void onKeyPressed(int keyCode)
      Add a keypress to pressedStateKeys list.
      Parameters:
      keyCode - Key to add
    • onKeyReleased

      public void onKeyReleased(int keyCode)
      Remove a keypress from pressedStateKeys list.
      Parameters:
      keyCode - Key to remove