Class ClientFramework

java.lang.Object
marauroa.client.ClientFramework
Direct Known Subclasses:
StendhalClient

public abstract class ClientFramework extends Object
It is a wrapper over all the things that the client should do. You should extend this class at your game.
Author:
miguel
  • Field Details

  • Constructor Details

    • ClientFramework

      public ClientFramework(String loggingProperties)
      Constructor.
      Parameters:
      loggingProperties - contains the name of the file that configure the logging system.
    • ClientFramework

      public ClientFramework()
      Constructor.
  • Method Details

    • connect

      public void connect(String host, int port) throws IOException
      Call this method to connect to server. This method just configure the connection, it doesn't send anything
      Parameters:
      host - server host name
      port - server port number
      Throws:
      IOException - if connection is not possible
    • connect

      public void connect(Proxy proxy, InetSocketAddress serverAddress) throws IOException
      Call this method to connect to server using a proxy-server inbetween. This method just configure the connection, it doesn't send anything.
      Parameters:
      proxy - proxy server to use for the connection
      serverAddress - marauroa server (final destination)
      Throws:
      IOException - if connection is not possible
    • resync

      @Deprecated public void resync()
      Deprecated.
      Request a synchronization with server. It shouldn't be needed now that we are using TCP.
    • login

      Login to server using the given username and password.
      Parameters:
      username - Player username
      password - Player password
      Throws:
      InvalidVersionException - if we are not using a compatible version
      TimeoutException - if timeout happens while waiting for the message.
      LoginFailedException - if login is rejected
      BannedAddressException
    • login

      public void login(String username, String password, String seed) throws InvalidVersionException, TimeoutException, LoginFailedException, BannedAddressException
      Login to server using the given username and password.
      Parameters:
      username - Player username
      password - Player password
      seed - preauthentication seed
      Throws:
      InvalidVersionException - if we are not using a compatible version
      TimeoutException - if timeout happens while waiting for the message.
      LoginFailedException - if login is rejected
      BannedAddressException
    • loginWithToken

      public void loginWithToken(String username, String tokenType, String token) throws InvalidVersionException, TimeoutException, LoginFailedException, BannedAddressException
      Login to server using the given username and password.
      Parameters:
      username - player username (may be null)
      tokenType - type of token (may be null)
      token - authentication token
      Throws:
      InvalidVersionException - if we are not using a compatible version
      TimeoutException - if timeout happens while waiting for the message.
      LoginFailedException - if login is rejected
      BannedAddressException
    • chooseCharacter

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

      public AccountResult createAccount(String username, String password, String email) throws TimeoutException, InvalidVersionException, BannedAddressException
      Request server to create an account on server.
      Parameters:
      username - the player desired username
      password - the player password
      email - player's email for notifications and/or password reset.
      Returns:
      AccountResult
      Throws:
      InvalidVersionException - if we are not using a compatible version
      TimeoutException - if timeout happens while waiting for the message.
      BannedAddressException
    • createAccountWithToken

      public AccountResult createAccountWithToken(String username, String tokenType, String token) throws TimeoutException, InvalidVersionException, BannedAddressException
      Request server to create an account with token on server.
      Parameters:
      username - the player desired username
      tokenType - token type
      token - authentication token (usually obtained from 3rd party).
      Returns:
      AccountResult
      Throws:
      InvalidVersionException - if we are not using a compatible version
      TimeoutException - if timeout happens while waiting for the message.
      BannedAddressException
    • createCharacter

      public CharacterResult createCharacter(String character, RPObject template) throws TimeoutException, InvalidVersionException, BannedAddressException
      Request server to create a character on server. You must have successfully logged into server before invoking this method.
      Parameters:
      character - the character to create
      template - an object template to create the player avatar.
      Returns:
      CharacterResult
      Throws:
      InvalidVersionException - if we are not using a compatible version
      TimeoutException - if timeout happens while waiting for the message.
      BannedAddressException
    • send

      public void send(RPAction action)
      Sends a RPAction to server
      Parameters:
      action - the action to send to server.
    • logout

      Request logout of server
      Returns:
      true if we have successfully logout or false if server rejects to logout our player and maintain it on game world.
      Throws:
      InvalidVersionException - if we are not using a compatible version
      TimeoutException - if timeout happens while waiting for the message.
      BannedAddressException
    • close

      public void close()
      Disconnect the socket and finish the network communications.
    • loop

      public boolean loop(int delta)
      Call this method to get and apply messages
      Parameters:
      delta - unused
      Returns:
      true if new messages were received.
    • sendKeepAlive

      public void sendKeepAlive()
      sends a KeepAliveMessage, this is automatically done in game, but you may be required to call this method very five minutes in pre game.
    • getConnectionState

      public boolean getConnectionState()
      Are we connected to the server?
      Returns:
      true unless it is sure that we are disconnected
    • onPerception

      protected abstract void onPerception(MessageS2CPerception message)
      It is called when a perception arrives so you can choose how to apply the perception.
      Parameters:
      message - the perception message itself.
    • onTransferREQ

      protected abstract List<TransferContent> onTransferREQ(List<TransferContent> items)
      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.
      Parameters:
      items - in this list by default all items.ack attributes are set to false;
      Returns:
      the list of approved and rejected items.
    • onTransfer

      protected abstract void onTransfer(List<TransferContent> items)
      It is called when we get a transfer of content
      Parameters:
      items - the transfered items.
    • onAvailableCharacters

      protected abstract void onAvailableCharacters(String[] characters)
      It is called when we get the list of characters
      Parameters:
      characters - the characters we have available at this account.
    • onAvailableCharacterDetails

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

      protected abstract void onServerInfo(String[] info)
      It is called when we get the list of server information strings
      Parameters:
      info - the list of server strings with information.
    • getGameName

      protected abstract String getGameName()
      Returns the name of the game that this client implements
      Returns:
      the name of the game that this client implements
    • getVersionNumber

      protected abstract String getVersionNumber()
      Returns the version number of the game
      Returns:
      the version number of the game
    • onPreviousLogins

      protected abstract void onPreviousLogins(List<String> previousLogins)
      Call the client with a list of previous logins.
      Parameters:
      previousLogins - a list of strings with the previous logins