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 boolean
debugEnabled
indicates whether debug messages will be logged for this bot or notint
lastErrorCode
-
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 void
changeAvtar(int avtarId)
Attempts to Change the avtarId of this Botvoid
debug(String txt)
Outputs a debug message if debug is enabled for this Botint
getAvtarId()
Returns the avtarId of the botString
getGameName()
returns the Name of the game that this Bot is linked toJsonObject
getGameUserData()
Returns the Game Specific User Data of the BotRoom
getJoinedRoom()
Returns the room joined by this bot or null if no room has been joinedvoid
getLocations()
Fetches the list of game locations from the serverString
getName()
Returns the name of the BotPlayer
getPlayer()
Returns the player object associated with this Bot or null if the Bot is not seatedprotected String
getPollData()
Internal method.void
getRooms(String location, RoomType roomType)
Fetches the list of rooms from the serverString
getSessionId()
Returns the Bot sessionIdString
getUserId()
Returns the user ID of the Bot.boolean
hasJoinedRoom()
Checks if Bot has joined a room.boolean
isActivePlayer()
Checks if this Bot is an active player.boolean
isCurTurn()
Returns true if the current turn belongs to this Bot.boolean
isGamePlayInProgress()
Checks if Game play is in progress.boolean
isLoggedIn()
Returns whether this Bot is loggedIn to the server or notboolean
isSeated()
Checks if this Bot is seated.boolean
isSpectator()
Checks if Bot is a spectator.void
joinRoom(long roomId)
Attempts to Make the Bot session join the specified room.void
leaveRoom()
Attempts to leave the room.void
leaveSeat()
Attempts to leave the seat in the room.void
logIn(String name, int avtarId, String gameName)
Attempts to Login a Bot onto server with emailId and starts a new sessionvoid
logOut()
Attempts to Logout this bot from the servervoid
playAction(String action, JsonObject actionData)
Attempts to Play an action.protected void
processCommand(String command, byte[] data)
internal method.protected void
processCommand(String command, String data)
internal method.void
refreshRoomFromServer()
Attempts to refresh the room state(data) from the servervoid
sendBinaryMessage(String command, byte[] data)
Attempts to sends a binary message to the servervoid
sendJsonMessage(String command, JsonObject data)
Attempts to Send a json message to the servervoid
sendTxtMessage(String command, String data)
Attempts to Send a text message to the servervoid
setBotEventListener(BotEventListener botEventListener)
Sets the BotEventListener to which the bot's events/callbacks will be forwardedvoid
takeSeat(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:
getPollData
in 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:
processCommand
in classAbstractBot
- Parameters:
command
- -data
- -
-
processCommand
internal method. Do not touch- Specified by:
processCommand
in 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
-