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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for listeners that need to be informed when the user is changing zone. -
Field Summary
FieldsFields inherited from class marauroa.client.ClientFramework
netMan, TIMEOUT -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddDirection(Direction dir, boolean face)Add an active player movement direction.voidAdd a listener to be called when the player changes zone.booleanchooseCharacter(String character)After login allows you to choose a character to playvoidConnect to the server, and if our version is too outdated, display a message.booleanCheck if any direction key is in "pressed" state.static StendhalClientget()Get the client instance.Get the account name.games.stendhal.client.CachegetCache()Return the Cache instance.Get the character name.protected StringReturns the name of the game that this client implementsGet the game objects container.Get the RPObject of the user.Get the map layers.protected StringReturns the version number of the gamebooleanDetermine if we are in the middle of transferring new content that should suppress drawing during the transfer.booleankeyIsPressed(int keyCode)Check if a keyboard key is in the "pressed" state.protected voidonAvailableCharacterDetails(Map<String,RPObject> characters)It is called when we get the list of charactersprotected voidonAvailableCharacters(String[] characters)It is called when we get the list of charactersvoidonKeyPressed(int keyCode)Add a keypress to pressedStateKeys list.voidonKeyReleased(int keyCode)Remove a keypress from pressedStateKeys list.protected voidonPerception(MessageS2CPerception message)It is called when a perception arrives so you can choose how to apply the perception.protected voidonPreviousLogins(List<String> previousLogins)Call the client with a list of previous logins.protected voidonServerInfo(String[] info)It is called when we get the list of server information stringsprotected voidonTransfer(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.voidRelease the drawing semaphore.voidremoveDirection(Direction dir, boolean face)Remove a player movement direction.static voidSet the client instance tonull.voidSends a RPAction to serverstatic booleanserverVersionAtLeast(String required)Check if the connected server is of at least as recent as the specified version.voidsetAccountUsername(String username)Set the account name.voidsetCharacter(String character)Set the character name.voidsetSplashScreen(JFrame splash)Set the splash screen window.voidstop()Stop the player.booleanTry 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:ClientFrameworkReturns the name of the game that this client implements- Specified by:
getGameNamein classClientFramework- Returns:
- the name of the game that this client implements
-
getVersionNumber
Description copied from class:ClientFrameworkReturns the version number of the game- Specified by:
getVersionNumberin 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:ClientFrameworkIt is called when a perception arrives so you can choose how to apply the perception.- Specified by:
onPerceptionin classClientFramework- Parameters:
message- the perception message itself.
-
onTransferREQ
Description copied from class:ClientFrameworkis called before a content transfer is started.itemscontains 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:
onTransferREQin 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:
trueif more content is to be transfered.
-
onTransfer
Description copied from class:ClientFrameworkIt is called when we get a transfer of content- Specified by:
onTransferin classClientFramework- Parameters:
items- the transfered items.
-
onAvailableCharacters
Description copied from class:ClientFrameworkIt is called when we get the list of characters- Specified by:
onAvailableCharactersin classClientFramework- Parameters:
characters- the characters we have available at this account.
-
onAvailableCharacterDetails
Description copied from class:ClientFrameworkIt is called when we get the list of characters- Overrides:
onAvailableCharacterDetailsin classClientFramework- Parameters:
characters- the characters we have available at this account.
-
onServerInfo
Description copied from class:ClientFrameworkIt is called when we get the list of server information strings- Specified by:
onServerInfoin classClientFramework- Parameters:
info- the list of server strings with information.
-
onPreviousLogins
Description copied from class:ClientFrameworkCall the client with a list of previous logins.- Specified by:
onPreviousLoginsin 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:
trueif 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:ClientFrameworkAfter login allows you to choose a character to play- Overrides:
chooseCharacterin 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:
trueif the semaphore was acquired, otherwisefalse
-
connect
Connect to the server, and if our version is too outdated, display a message.- Overrides:
connectin classClientFramework- Parameters:
host- host nameport- host port- Throws:
IOException- in case of an input/output error
-
send
Description copied from class:ClientFrameworkSends a RPAction to server- Overrides:
sendin 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:
trueif the server is new enough, or the version is unknown,falseif 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
-