Package games.stendhal.client
Class StendhalClient
java.lang.Object
marauroa.client.ClientFramework
games.stendhal.client.StendhalClient
This class is the glue to Marauroa, it extends ClientFramework and allows us
to easily connect to an marauroa server and operate it easily.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Interface for listeners that need to be informed when the user is changing zone. -
Field Summary
Fields inherited from class marauroa.client.ClientFramework
netMan, TIMEOUT
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addDirection(Direction dir, boolean face)
Add an active player movement direction.void
Add a listener to be called when the player changes zone.boolean
chooseCharacter(String character)
After login allows you to choose a character to playvoid
Connect to the server, and if our version is too outdated, display a message.boolean
Check if any direction key is in "pressed" state.static StendhalClient
get()
Get the client instance.Get the account name.games.stendhal.client.Cache
getCache()
Return the Cache instance.Get the character name.protected String
Returns the name of the game that this client implementsGet the game objects container.Get the RPObject of the user.Get the map layers.protected String
Returns the version number of the gameboolean
Determine if we are in the middle of transferring new content that should suppress drawing during the transfer.boolean
keyIsPressed(int keyCode)
Check if a keyboard key is in the "pressed" state.protected void
onAvailableCharacterDetails(Map<String,RPObject> characters)
It is called when we get the list of charactersprotected void
onAvailableCharacters(String[] characters)
It is called when we get the list of charactersvoid
onKeyPressed(int keyCode)
Add a keypress to pressedStateKeys list.void
onKeyReleased(int keyCode)
Remove a keypress from pressedStateKeys list.protected void
onPerception(MessageS2CPerception message)
It is called when a perception arrives so you can choose how to apply the perception.protected void
onPreviousLogins(List<String> previousLogins)
Call the client with a list of previous logins.protected void
onServerInfo(String[] info)
It is called when we get the list of server information stringsprotected void
onTransfer(List<TransferContent> items)
It is called when we get a transfer of contentprotected List<TransferContent>
onTransferREQ(List<TransferContent> items)
is called before a content transfer is started.void
Release the drawing semaphore.void
removeDirection(Direction dir, boolean face)
Remove a player movement direction.static void
Set the client instance tonull
.void
Sends a RPAction to serverstatic boolean
serverVersionAtLeast(String required)
Check if the connected server is of at least as recent as the specified version.void
setAccountUsername(String username)
Set the account name.void
setCharacter(String character)
Set the character name.void
setSplashScreen(JFrame splash)
Set the splash screen window.void
stop()
Stop the player.boolean
Try to acquire the drawing semaphore.Methods inherited from class marauroa.client.ClientFramework
close, connect, createAccount, createAccountWithToken, createCharacter, getConnectionState, login, login, loginWithToken, logout, loop, resync, sendKeepAlive
-
Field Details
-
client
-
-
Method Details
-
get
Get the client instance.- Returns:
- client instance
-
resetClient
public static void resetClient()Set the client instance tonull
. -
getGameName
Description copied from class:ClientFramework
Returns the name of the game that this client implements- Specified by:
getGameName
in classClientFramework
- Returns:
- the name of the game that this client implements
-
getVersionNumber
Description copied from class:ClientFramework
Returns the version number of the game- Specified by:
getVersionNumber
in classClientFramework
- Returns:
- the version number of the game
-
getStaticGameLayers
Get the map layers.- Returns:
- map layers
-
getGameObjects
Get the game objects container.- Returns:
- game objects
-
onPerception
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 classClientFramework
- Parameters:
message
- the perception message itself.
-
onTransferREQ
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 classClientFramework
- Parameters:
items
- in this list by default all items.ack attributes are set to false;- Returns:
- the list of approved and rejected items.
-
addZoneChangeListener
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
Description copied from class:ClientFramework
It is called when we get a transfer of content- Specified by:
onTransfer
in classClientFramework
- Parameters:
items
- the transfered items.
-
onAvailableCharacters
Description copied from class:ClientFramework
It is called when we get the list of characters- Specified by:
onAvailableCharacters
in classClientFramework
- Parameters:
characters
- the characters we have available at this account.
-
onAvailableCharacterDetails
Description copied from class:ClientFramework
It is called when we get the list of characters- Overrides:
onAvailableCharacterDetails
in classClientFramework
- Parameters:
characters
- the characters we have available at this account.
-
onServerInfo
Description copied from class:ClientFramework
It is called when we get the list of server information strings- Specified by:
onServerInfo
in classClientFramework
- Parameters:
info
- the list of server strings with information.
-
onPreviousLogins
Description copied from class:ClientFramework
Call the client with a list of previous logins.- Specified by:
onPreviousLogins
in classClientFramework
- Parameters:
previousLogins
- a list of strings with the previous logins
-
addDirection
Add an active player movement direction.- Parameters:
dir
- The direction.face
- If to face direction only.- Returns:
true
if an action was sent, otherwisefalse
-
removeDirection
Remove a player movement direction.- Parameters:
dir
- The direction.face
- If to face direction only.
-
stop
public void stop()Stop the player. -
setAccountUsername
Set the account name.- Parameters:
username
- account name
-
getCharacter
Get the character name.- Returns:
- character name
-
setCharacter
Set the character name.- Parameters:
character
- name
-
setSplashScreen
Set the splash screen window. Used for transient windows.- Parameters:
splash
- first screen window
-
getAccountUsername
Get the account name.- Returns:
- account name
-
getCache
public games.stendhal.client.Cache getCache()Return the Cache instance.- Returns:
- cache
-
getPlayer
Get the RPObject of the user.- Returns:
- player object
-
chooseCharacter
public boolean chooseCharacter(String character) throws TimeoutException, InvalidVersionException, BannedAddressExceptionDescription copied from class:ClientFramework
After login allows you to choose a character to play- Overrides:
chooseCharacter
in classClientFramework
- 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 versionBannedAddressException
-
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, otherwisefalse
-
connect
Connect to the server, and if our version is too outdated, display a message.- Overrides:
connect
in classClientFramework
- Parameters:
host
- host nameport
- host port- Throws:
IOException
- in case of an input/output error
-
send
Description copied from class:ClientFramework
Sends a RPAction to server- Overrides:
send
in classClientFramework
- Parameters:
action
- the action to send to server.
-
serverVersionAtLeast
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
-