Package marauroa.client
Class ClientFramework
java.lang.Object
marauroa.client.ClientFramework
- Direct Known Subclasses:
StendhalClient
It is a wrapper over all the things that the client should do. You should
extend this class at your game.
- Author:
- miguel
-
Field Summary
Modifier and TypeFieldDescriptionprotected INetworkClientManagerInterface
We keep an instance of network manager to be able to communicate with server.static int
How long we should wait for connect. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
chooseCharacter(String character)
After login allows you to choose a character to playvoid
close()
Disconnect the socket and finish the network communications.void
Call this method to connect to server.void
connect(Proxy proxy, InetSocketAddress serverAddress)
Call this method to connect to server using a proxy-server inbetween.createAccount(String username, String password, String email)
Request server to create an account on server.createAccountWithToken(String username, String tokenType, String token)
Request server to create an account with token on server.createCharacter(String character, RPObject template)
Request server to create a character on server.boolean
Are we connected to the server?protected abstract String
Returns the name of the game that this client implementsprotected abstract String
Returns the version number of the gamevoid
Login to server using the given username and password.void
Login to server using the given username and password.void
loginWithToken(String username, String tokenType, String token)
Login to server using the given username and password.boolean
logout()
Request logout of serverboolean
loop(int delta)
Call this method to get and apply messagesprotected void
onAvailableCharacterDetails(Map<String,RPObject> characters)
It is called when we get the list of charactersprotected abstract void
onAvailableCharacters(String[] characters)
It is called when we get the list of charactersprotected abstract void
onPerception(MessageS2CPerception message)
It is called when a perception arrives so you can choose how to apply the perception.protected abstract void
onPreviousLogins(List<String> previousLogins)
Call the client with a list of previous logins.protected abstract void
onServerInfo(String[] info)
It is called when we get the list of server information stringsprotected abstract void
onTransfer(List<TransferContent> items)
It is called when we get a transfer of contentprotected abstract List<TransferContent>
onTransferREQ(List<TransferContent> items)
is called before a content transfer is started.void
resync()
Deprecated.void
Sends a RPAction to servervoid
sends a KeepAliveMessage, this is automatically done in game, but you may be required to call this method very five minutes in pre game.
-
Field Details
-
TIMEOUT
public static final int TIMEOUTHow long we should wait for connect.- See Also:
- Constant Field Values
-
netMan
We keep an instance of network manager to be able to communicate with server.
-
-
Constructor Details
-
ClientFramework
Constructor.- Parameters:
loggingProperties
- contains the name of the file that configure the logging system.
-
ClientFramework
public ClientFramework()Constructor.
-
-
Method Details
-
connect
Call this method to connect to server. This method just configure the connection, it doesn't send anything- Parameters:
host
- server host nameport
- server port number- Throws:
IOException
- if connection is not possible
-
connect
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 connectionserverAddress
- marauroa server (final destination)- Throws:
IOException
- if connection is not possible
-
resync
Deprecated.Request a synchronization with server. It shouldn't be needed now that we are using TCP. -
login
public void login(String username, String password) throws InvalidVersionException, TimeoutException, LoginFailedException, BannedAddressExceptionLogin to server using the given username and password.- Parameters:
username
- Player usernamepassword
- Player password- Throws:
InvalidVersionException
- if we are not using a compatible versionTimeoutException
- if timeout happens while waiting for the message.LoginFailedException
- if login is rejectedBannedAddressException
-
login
public void login(String username, String password, String seed) throws InvalidVersionException, TimeoutException, LoginFailedException, BannedAddressExceptionLogin to server using the given username and password.- Parameters:
username
- Player usernamepassword
- Player passwordseed
- preauthentication seed- Throws:
InvalidVersionException
- if we are not using a compatible versionTimeoutException
- if timeout happens while waiting for the message.LoginFailedException
- if login is rejectedBannedAddressException
-
loginWithToken
public void loginWithToken(String username, String tokenType, String token) throws InvalidVersionException, TimeoutException, LoginFailedException, BannedAddressExceptionLogin 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 versionTimeoutException
- if timeout happens while waiting for the message.LoginFailedException
- if login is rejectedBannedAddressException
-
chooseCharacter
public boolean chooseCharacter(String character) throws TimeoutException, InvalidVersionException, BannedAddressExceptionAfter 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 versionTimeoutException
- if timeout happens while waiting for the message.BannedAddressException
-
createAccount
public AccountResult createAccount(String username, String password, String email) throws TimeoutException, InvalidVersionException, BannedAddressExceptionRequest server to create an account on server.- Parameters:
username
- the player desired usernamepassword
- the player passwordemail
- player's email for notifications and/or password reset.- Returns:
- AccountResult
- Throws:
InvalidVersionException
- if we are not using a compatible versionTimeoutException
- if timeout happens while waiting for the message.BannedAddressException
-
createAccountWithToken
public AccountResult createAccountWithToken(String username, String tokenType, String token) throws TimeoutException, InvalidVersionException, BannedAddressExceptionRequest server to create an account with token on server.- Parameters:
username
- the player desired usernametokenType
- token typetoken
- authentication token (usually obtained from 3rd party).- Returns:
- AccountResult
- Throws:
InvalidVersionException
- if we are not using a compatible versionTimeoutException
- if timeout happens while waiting for the message.BannedAddressException
-
createCharacter
public CharacterResult createCharacter(String character, RPObject template) throws TimeoutException, InvalidVersionException, BannedAddressExceptionRequest server to create a character on server. You must have successfully logged into server before invoking this method.- Parameters:
character
- the character to createtemplate
- an object template to create the player avatar.- Returns:
- CharacterResult
- Throws:
InvalidVersionException
- if we are not using a compatible versionTimeoutException
- if timeout happens while waiting for the message.BannedAddressException
-
send
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 versionTimeoutException
- 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
It is called when a perception arrives so you can choose how to apply the perception.- Parameters:
message
- the perception message itself.
-
onTransferREQ
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
It is called when we get a transfer of content- Parameters:
items
- the transfered items.
-
onAvailableCharacters
It is called when we get the list of characters- Parameters:
characters
- the characters we have available at this account.
-
onAvailableCharacterDetails
It is called when we get the list of characters- Parameters:
characters
- the characters we have available at this account.
-
onServerInfo
It is called when we get the list of server information strings- Parameters:
info
- the list of server strings with information.
-
getGameName
Returns the name of the game that this client implements- Returns:
- the name of the game that this client implements
-
getVersionNumber
Returns the version number of the game- Returns:
- the version number of the game
-
onPreviousLogins
Call the client with a list of previous logins.- Parameters:
previousLogins
- a list of strings with the previous logins
-