Package io.sockit.gameserver.bot
Class Bot
java.lang.Object
io.sockit.gameserver.AbstractBot
io.sockit.gameserver.bot.Bot
public final class Bot extends AbstractBot
This class represents a Bot running on the server. It has methods to login the Bot to the Server, enter a game, fetch list of rooms, join a room, etc. Bots are instantiated in the setUpGame() method of the Game class
-
Field Summary
Fields Modifier and Type Field Description booleandebugEnabledindicates whether debug messages will be logged for this bot or notintlastErrorCode -
Constructor Summary
Constructors Constructor Description Bot()Creates a BotBot(boolean enableDebug)Creates a BotBot(BotTurnDelayType turnDelayType)Creates a BotBot(BotTurnDelayType turnDelayType, boolean enableDebug)creates a Bot -
Method Summary
Modifier and Type Method Description voidchangeAvtar(int avtarId)Attempts to Change the avtarId of this Botvoiddebug(String txt)Outputs a debug message if debug is enabled for this BotintgetAvtarId()Returns the avtarId of the botStringgetGameName()returns the Name of the game that this Bot is linked toJsonObjectgetGameUserData()Returns the Game Specific User Data of the BotRoomgetJoinedRoom()Returns the room joined by this bot or null if no room has been joinedvoidgetLocations()Fetches the list of game locations from the serverStringgetName()Returns the name of the BotPlayergetPlayer()Returns the player object associated with this Bot or null if the Bot is not seatedprotected StringgetPollData()Internal method.voidgetRooms(String location, RoomType roomType)Fetches the list of rooms from the serverStringgetSessionId()Returns the Bot sessionIdStringgetUserId()Returns the user ID of the Bot.booleanhasJoinedRoom()Checks if Bot has joined a room.booleanisActivePlayer()Checks if this Bot is an active player.booleanisCurTurn()Returns true if the current turn belongs to this Bot.booleanisGamePlayInProgress()Checks if Game play is in progress.booleanisLoggedIn()Returns whether this Bot is loggedIn to the server or notbooleanisSeated()Checks if this Bot is seated.booleanisSpectator()Checks if Bot is a spectator.voidjoinRoom(long roomId)Attempts to Make the Bot session join the specified room.voidleaveRoom()Attempts to leave the room.voidleaveSeat()Attempts to leave the seat in the room.voidlogIn(String name, int avtarId, String gameName)Attempts to Login a Bot onto server with emailId and starts a new sessionvoidlogOut()Attempts to Logout this bot from the servervoidplayAction(String action, JsonObject actionData)Attempts to Play an action.protected voidprocessCommand(String command, byte[] data)internal method.protected voidprocessCommand(String command, String data)internal method.voidrefreshRoomFromServer()Attempts to refresh the room state(data) from the servervoidsendBinaryMessage(String command, byte[] data)Attempts to sends a binary message to the servervoidsendJsonMessage(String command, JsonObject data)Attempts to Send a json message to the servervoidsendTxtMessage(String command, String data)Attempts to Send a text message to the servervoidsetBotEventListener(BotEventListener botEventListener)Sets the BotEventListener to which the bot's events/callbacks will be forwardedvoidtakeSeat(long roomId, int seatNo, JsonObject data)Attempts to take a seat in the room.Methods inherited from class io.sockit.gameserver.AbstractBot
closeSocket, forceInstanceLock, sendMesg, sendMesg
-
Field Details
-
lastErrorCode
public volatile int lastErrorCode -
debugEnabled
public final boolean debugEnabledindicates whether debug messages will be logged for this bot or not
-
-
Constructor Details
-
Bot
public Bot()Creates a Bot -
Bot
public Bot(boolean enableDebug)Creates a Bot- Parameters:
enableDebug- - specifies whether debug messages should be logged for this bot or not
-
Bot
Creates a Bot- Parameters:
turnDelayType- - specifies the turn delay type for this bot (fast, normal, slow or no delay)
-
Bot
creates a Bot- Parameters:
turnDelayType- - specifies the turn delay type for this bot (fast, normal, slow or no delay)enableDebug- - specifies whether debug messages should be logged for this bot or not
-
-
Method Details
-
logIn
Attempts to Login a Bot onto server with emailId and starts a new session- Parameters:
name- - the Bot nameavtarId- - the bot avatar IdgameName- - the game which should be linked with this Bot session on successful login - cannot be null
-
sendJsonMessage
Attempts to Send a json message to the server- Parameters:
command- - the message commanddata- - the message data as json
-
sendTxtMessage
Attempts to Send a text message to the server- Parameters:
command- - the message commanddata- - the message data as string
-
sendBinaryMessage
Attempts to sends a binary message to the server- Parameters:
command- - the message commanddata- - the message data as a byte array
-
getPollData
Internal method. Do not touch- Specified by:
getPollDatain classAbstractBot
-
changeAvtar
public void changeAvtar(int avtarId)Attempts to Change the avtarId of this Bot- Parameters:
avtarId- - the new avtar ID
-
logOut
public void logOut()Attempts to Logout this bot from the server -
getLocations
public void getLocations()Fetches the list of game locations from the server -
getRooms
Fetches the list of rooms from the server- Parameters:
location- - the location whose rooms should be fetchedroomType- - the room type - normal or fast
-
joinRoom
public void joinRoom(long roomId)Attempts to Make the Bot session join the specified room.- Parameters:
roomId- - the roomId of the room to join
-
refreshRoomFromServer
public void refreshRoomFromServer()Attempts to refresh the room state(data) from the server -
takeSeat
Attempts to take a seat in the room. Until the Bot is seated he/she remains a spectator and cannot take part in the game play. The seat numbers are numbered 1 to n.- Parameters:
roomId- - the roomId of the room to joinseatNo- - the seat number to sit on - starting from 1data- - additional data sent along with the take seat command to the server. For eg. in Poker this could be the chips to put on table
-
leaveSeat
public void leaveSeat()Attempts to leave the seat in the room. -
leaveRoom
public void leaveRoom()Attempts to leave the room. -
processCommand
internal method. Do not touch- Specified by:
processCommandin classAbstractBot- Parameters:
command- -data- -
-
processCommand
internal method. Do not touch- Specified by:
processCommandin classAbstractBot- Parameters:
command- -data- -
-
setBotEventListener
Sets the BotEventListener to which the bot's events/callbacks will be forwarded- Parameters:
botEventListener- - the BotEventListener that will handle the Bot's events/callbacks
-
getUserId
Returns the user ID of the Bot.- Returns:
- - the user ID of the bot
-
getSessionId
Returns the Bot sessionId- Returns:
- - Bot sessionId
-
getName
Returns the name of the Bot- Returns:
- - the name of the Bot
-
getAvtarId
public int getAvtarId()Returns the avtarId of the bot- Returns:
- - the avtarId of the bot
-
getGameName
returns the Name of the game that this Bot is linked to- Returns:
- - the Name of the game that this Bot is linked to
-
getGameUserData
Returns the Game Specific User Data of the Bot- Returns:
- - the Game Specific User Data of the Bot
-
isLoggedIn
public boolean isLoggedIn()Returns whether this Bot is loggedIn to the server or not- Returns:
- - true if this Bot is loggedIn to the server
-
getJoinedRoom
Returns the room joined by this bot or null if no room has been joined- Returns:
- - the room joined by this bot
-
hasJoinedRoom
public boolean hasJoinedRoom()Checks if Bot has joined a room. Returns true if this Bot has joined a room- Returns:
- - true if this Bot has joined a room
-
isSpectator
public boolean isSpectator()Checks if Bot is a spectator. Returns true if this Bot has joined a room and is a spectator- Returns:
- - true if this Bot has joined a room and is a spectator
-
isSeated
public boolean isSeated()Checks if this Bot is seated. Returns true if this Client is seated in a room.- Returns:
- - true if this Bot is seated in a room.
-
isGamePlayInProgress
public boolean isGamePlayInProgress()Checks if Game play is in progress. Returns true if this Bot has joined a room and Game play is in progress in the room.- Returns:
- - true if this Bot has joined a room and Game play is in progress in the room.
-
isActivePlayer
public boolean isActivePlayer()Checks if this Bot is an active player. Returns true if this Bot is seated in a room and is taking part in the current game play in the room..- Returns:
- - true if this Bot is seated in a room and is taking part in the current game play in the room..
-
getPlayer
Returns the player object associated with this Bot or null if the Bot is not seated- Returns:
- - the player object associated with this Bot or null if the Bot is not seated
-
isCurTurn
public boolean isCurTurn()Returns true if the current turn belongs to this Bot.- Returns:
- - true if the current turn belongs to this Boy.
-
playAction
public final void playAction(String action, JsonObject actionData) throws GamePlayNotInProgressExceptionAttempts to Play an action. Sends a playAction message to the Server.- Parameters:
action- - the action playedactionData- - the data associated with the action- Throws:
GamePlayNotInProgressException- - if GamePlay is not in progress
-
debug
Outputs a debug message if debug is enabled for this Bot- Parameters:
txt- - the debug message
-