Package io.sockit.gameserver
Class Room
java.lang.Object
io.sockit.gameserver.Room
- All Implemented Interfaces:
Comparable<Room>
public abstract class Room extends Object implements Comparable<Room>
This class is the super class for all Game Rooms. It has methods to start gamePlay, iterate players, etc. The seats in the room are like a rounded queue such that the next seat after the last seat will be the first seat. The Game developer should extend this class and override the various event/callback methods such as
onRoomJoined(), onSeatTaken(), beforeGameStarted()
, etc. to provide the game logic. See example below
public class TicTacToeRoom extends Room{
CellState[] grid;
public TicTacToeRoom(Game game, String roomName, RoomType roomType, int turnDurationInSecs, int delayAfterGameEnded, boolean enableDebug) {
super(game, roomName, roomType, 2, turnDurationInSecs, delayAfterGameEnded, enableDebug);
grid = new CellState[9];
Arrays.fill(grid, CellState.unmarked);
}
{@literal @}Override
protected Player newPlayer(Session session, int seatNo, JsonObject jo) {
return new TicTacToePlayer(session, seatNo);
}
{@literal @}Override
protected void resetData() {
Arrays.fill(grid, CellState.unmarked);
}
{@literal @}Override
protected JsonObject prepareJsonForClient() {
JsonObjectBuilder json =Json.createObjectBuilder();
JsonArrayBuilder jsonGrid = Json.createArrayBuilder();
for(int counter=0; counter < grid.length; counter++){
jsonGrid.add(grid[counter].toString());
}
json.add("grid", jsonGrid);
return json.build();
}
{@literal @}Override
protected void onPlayerAction(Player player, String action, JsonObject data, boolean isOutOfTurn) {
if(isOutOfTurn){
return;
}
if(action.equals("cellClicked")){
int cellIndex = data.getInt("cellIndex");
if(cellIndex > 8 || cellIndex < 0){
this.invalidateAction("Cell Dosen't exist", null);
return;
}
JsonObjectBuilder sendData = Json.createObjectBuilder();
if(grid[cellIndex] != CellState.unmarked){
sendData.add("cellIndex", cellIndex);
sendData.add("cellValue", grid[cellIndex].toString());
this.invalidateAction("Can't Click That!", sendData.build());
return;
}
TicTacToePlayer ticTacToePlayer = (TicTacToePlayer) player;
grid[cellIndex] = ticTacToePlayer.playerToken;
sendData.add("cellIndex", cellIndex);
sendData.add("cellValue", grid[cellIndex].toString());
this.actionPlayed("cellIndex", sendData.build());
}
}
//.......
}
-
Field Summary
Fields Modifier and Type Field Description boolean
debugEnabled
whether logging of debug messages is enabled for this player or notGame
game
The Game to which this room belongsint
minNoOfPlayersForGame
the min number of players required to start a new game.Long
roomId
the room ID.String
roomName
the room name.RoomType
roomType
the room type. -
Constructor Summary
Constructors Modifier Constructor Description protected
Room(Game game, String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, int delayAfterGameEndedInSecs)
Creates a room.protected
Room(Game game, String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, int delayAfterGameEndedInSecs, boolean enableDebug)
Creates a roomprotected
Room(Game game, String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, int delayAfterGameEndedInSecs, boolean enableDebug, int minNoOfPlayersForGame)
-
Method Summary
Modifier and Type Method Description void
actionPlayed(String playerAction, JsonObject actionData)
Sends turnPlayed or outOfTurnPlayed event/message to clients.int
activeBotPlayerCount()
The number of bot players active in the current game play - (i.e number of bot players who have not exited the game play)int
activeNonBotPlayerCount()
The number of non bot players active in the current game play.int
activePlayerCount()
The number of players active (i.e.protected void
afterGamePlayEnded()
Event-Handler/Callback called after game play has ended and endGamePlay message has been sent to clients.protected Player
afterGamePlayStarted()
Event-Handler/Callback called after new game play message is sent - should return the first turn playerprotected void
afterRoomDestroyed()
Event-Handler/Callback called after Room is Destroyed and destroyed event/message is sent to clients.protected void
afterSeatLeft(Player player, boolean isCurTurnPlayer, int noOfActivePlayers, boolean isLeavingRoom, boolean isLoggingOut)
Event-Handler/Callback called after seat left message is sentprotected void
afterSeatTaken(Player player)
Event-Handler/Callback called after seatTaken message is sent.protected Player
afterTurnPlayed(Player player, String action, JsonObject actionData)
Event-Handler/Callback called after player plays turn.protected JsonObject
beforeGamePlayEnded()
Event-Handler/Callback after endGamePlay() is called but before game play is ended.protected void
beforeGamePlayStarted()
Event-Handler/Callback called before game play starts and new game play message is sent.protected void
beforeSeatLeft(Player player, boolean isCurTurnPlayer, boolean isLeavingRoom, boolean isLoggingOut)
Event-Handler/Callback called before player leaves/evicted from the seat.int
botPlayerCount()
The number of bot players in the room.void
cancelAutoStartGamePlay()
Prevents new game play from auto starting after a Game play ends.void
cancelStartGamePlay()
Cancels new Game play before first turn.protected boolean
canSeatBeTaken(Session session, int seatNo, JsonObject data)
Callback called when a session takes seat to check whether session should be allowed to take seat or not.int
compareTo(Room room)
Compares this object with the specified object for order.void
debug(Session session, String txt)
Logs debug messages along with the user name when debug is enabledvoid
debug(String txt)
Logs debug messagesvoid
destroy()
Destroys the room.void
endGamePlay()
Ends the currently running game play in the roomvoid
forceAction(Player player, String action, JsonObject actionData)
Forces an action on the specified player.void
gameAction(String action, JsonObject data)
Creates and sends a gameAction event/message to all the client's (client sessions - both spectators and players) connected to this room.Iterable<Player>
getActivePlayers()
Returns all the players active in the current game playprotected abstract JsonObject
getAdditionalRoomConfig()
Should return the additional configuration data for the room.int
getCurrentGamePlayNo()
Returns the number of the currently active game play in the room.Player
getCurTurnPlayer()
Returns the player whose turn is the current turnint
getCurTurnSeatNo()
Returns the seat number of the player whose turn is the current turnint
getDelayAfterGamePlayEndedInSecs()
Returns the delay between end game play and start game play in seconds.int
getDelayBeforeFirstTurnInSecs()
Returns the delay between game start and first turn in seconds.Player
getFirstActivePlayer()
Returns the first active playerint
getFirstFreeSeatno()
Returns the first free (not occupied) seat number.Player
getFirstPlayer()
Returns the first player in the roomLocation
getLocation()
Returns the room's locationPlayer
getNextActivePlayer()
returns the next active player seated after the current turn player.Player
getNextActivePlayer(int prevSeatNo)
returns the next active player seated after the specified seat number.Player
getNextActivePlayerWhoCanPlayTurn()
Returns the next active player after the current player who can play a turn (player.canPlayTurn() returns true).Player
getNextActivePlayerWhoCanPlayTurn(int prevSeatNo)
Returns the next active player after the specified seat number who can play a turn (player.canPlayTurn() returns true).int
getNextFreeSeatNo(int prevSeatNo)
Returns the first free (not occupied) seat number after the specified seat numberPlayer
getNextPlayer(int prevSeatNo)
Returns the next player seated after the specified seat numberprotected abstract JsonObject
getNextTurnData(Player nextTurnPlayer)
returns the data to be sent to the client along with the nextTurn event/message to clients.String
getOwnerUserId()
Returns user Id of this room's owner if this room is private else nullPlayer
getPlayerBySeatNo(int seatNo)
Returns player seated at the specified seat numberIterable<Player>
getPlayers()
Returns all the players in the roomIterable<Player>
getPlayersWhoPlayed()
Returns all the players who took part in the current game play.protected JsonObject
getRoomInfo()
Returns RoomInfo as json.Iterable<Session>
getSpectators()
returns all the client session who are spectatorsint
getTotalNoOfSeats()
Returns the maximum number of players who can play in the room (total number of seats in the room)int
getTurnDurationInSecs()
Returns the turn duration in secondsvoid
invalidateAction(String errorDescription, JsonObject errorData)
Sets the errorDescription and errorData that is sent to client when the action is not valid.boolean
isGamePlayEnding()
Checks whether Game play is ending or not.boolean
isGamePlayInProgress()
Returns whther a game play is in progress or not in the roomboolean
isPrivate()
Returns whether room is private or notboolean
isSeated(Session session)
Returns whether the specified client session is seated or notboolean
isSpectator(Session session)
returns whether specified client session is a spectator or not.void
leave(Session session)
Evicts the specified client session from the room.void
leaveSeat(Player player)
Evicts the specified player from his/her seat.void
leaveSeat(Session session)
Evicts the specified client session from his/her seatprotected abstract Player
newPlayer(Session session, int SeatNo, JsonObject data)
Factory method called to instantiate a new player.int
nonBotPlayerCount()
The number of non bot players in the room.protected void
onPlayerAction(Player player, String action, JsonObject data, boolean isOutOfTurn)
Event-Handler/Callback called when player plays turn - should call actionPlayed() (this will send turnPlayed or outOfTurnPlayed event/message to clients)protected void
onRoomDestroyed()
Event-Handler/Callback called when room is destroyed but before event/message is sent to clients.protected void
onRoomJoined(Session session)
Event-Handler/Callback called after session is added to room but before joinedRoom message is sent to the client.protected void
onRoomLeft(Session session, boolean isLoggingOut)
Event-Handler/Callback called after room Left but before room Left message is sent to playerprotected void
onSeatTaken(Player player)
Event-Handler/Callback called after player is seated but before seatTaken message is sent to clients.protected void
onTurnTimedOut(Player turnPlayer)
Event-Handler/Callback called when player's turn times out.int
playerCount()
the number of players in the room ( the number of session seated in the room)protected abstract JsonObject
prepareJsonForClient()
Returns room Data to be sent to the client as part of the room state.protected abstract void
resetData()
Called after End Game play to reset game play data.void
sendJsonMessageToAll(String command, JsonObject data, Session sessionNotToSend)
Sends a Json message to all sessions in the room except the one specified.void
sendJsonMessageToPlayers(String command, JsonObject data, Session sessionNotToSend)
Sends a Json message to all players in the room except the one specified.void
sendJsonMessageToSpectators(String command, JsonObject data, Session sessionNotToSend)
Sends a Json message to all spectators in the room except the one specified.void
sendRoomDataToAll()
Sends Room Data to all the client sessions who have joined the room (both spectators and players)void
sendRoomDataToSession(Player player)
Sends Room Data to the specified player's client sessionvoid
sendRoomDataToSession(Session session)
Sends Room Data to the specified sessionvoid
sendTxtMessageToAll(String command, String data, Session sessionNotToSend)
Sends a text message to all sessions in the room except the one specified.void
sendTxtMessageToPlayers(String command, String data, Session sessionNotToSend)
Sends a text message to all players in the room except the one specified.void
sendTxtMessageToSpectators(String command, String data, Session sessionNotToSend)
Sends a text message to all spectators in the room except the one specified.protected abstract void
setAdditionalRoomConfig(JsonObject additionalRoomConfig)
Should set the additional configuration data for the room.void
setDelayBeforeFirstTurnInSecs(int delayInSecs)
Sets the delay between game play start and first turn in seconds.void
setErrorDescription(String errorDescription)
Sets the error description to be sent to client.int
spectatorCount()
The number of spectators (sessions not seated)void
startGamePlay()
Starts a new game play in the room if no game play is running.int
totalNoOfSeats()
the total number of seats in the room
-
Field Details
-
roomId
the room ID. -
roomName
the room name. -
roomType
the room type. -
game
The Game to which this room belongs -
minNoOfPlayersForGame
public final int minNoOfPlayersForGamethe min number of players required to start a new game. Once the min number of players take seat a new game automatically starts -
debugEnabled
public final boolean debugEnabledwhether logging of debug messages is enabled for this player or not
-
-
Constructor Details
-
Room
protected Room(Game game, String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, int delayAfterGameEndedInSecs)Creates a room.- Parameters:
game
- - the Game to which the room belongsroomName
- - the room nameroomType
- - the room typetotalNoOfSeats
- - the max number of players (total number of seats in the room)turnDurationInSecs
- - the duration of 1 turn in secondsdelayAfterGameEndedInSecs
- - the delay between end game and start of a new game.
-
Room
protected Room(Game game, String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, int delayAfterGameEndedInSecs, boolean enableDebug)Creates a room- Parameters:
game
- - the Game to which the room belongsroomName
- - the room nameroomType
- - the room typetotalNoOfSeats
- - the max number of players (total number of seats in the room)turnDurationInSecs
- - the duration of 1 turn in secondsdelayAfterGameEndedInSecs
- - the delay between end game and start of a new game.enableDebug
- - whether logging of debug messages should be enabled or not for this room
-
Room
protected Room(Game game, String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, int delayAfterGameEndedInSecs, boolean enableDebug, int minNoOfPlayersForGame)- Parameters:
game
- - the Game to which the room belongsroomName
- - the room nameroomType
- - the room typetotalNoOfSeats
- - the max number of players (total number of seats in the room)turnDurationInSecs
- - the duration of 1 turn in secondsdelayAfterGameEndedInSecs
- - the delay between end game and start of a new game.enableDebug
- - whether logging of debug messages should be enabled or not for this roomminNoOfPlayersForGame
- - the min number of players required to start a new game. Once the min number of players take seat a new game automatically starts
-
-
Method Details
-
compareTo
Compares this object with the specified object for order. Called to sort the rooms in the location. This method should be overridden in the child class- Specified by:
compareTo
in interfaceComparable<Room>
- Parameters:
room
- - the room to compare to- Returns:
- int - a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
newPlayer
Factory method called to instantiate a new player. When a client session takes seat in the room, this method is called to create a player. Note: till the client session is not seated, the session is considered a spectator. After seat is taken the session is considered a player- Parameters:
session
- - the client session of the playerSeatNo
- - the seat number of the playerdata
- - any additional actionData required to initialize the player in json format- Returns:
- - a new player object linked to the specified session
-
getTotalNoOfSeats
public final int getTotalNoOfSeats()Returns the maximum number of players who can play in the room (total number of seats in the room)- Returns:
- int - total number of seats in the room
-
getOwnerUserId
Returns user Id of this room's owner if this room is private else null- Returns:
- String - user Id of this room's owner if this room is private else null
-
isPrivate
public final boolean isPrivate()Returns whether room is private or not- Returns:
- boolean - true if the room is private
-
getDelayBeforeFirstTurnInSecs
public int getDelayBeforeFirstTurnInSecs()Returns the delay between game start and first turn in seconds.- Returns:
- int - the delayBeforeFirstTurn
-
getDelayAfterGamePlayEndedInSecs
public int getDelayAfterGamePlayEndedInSecs()Returns the delay between end game play and start game play in seconds.- Returns:
- int - the delayAfterGameEnded
-
setDelayBeforeFirstTurnInSecs
public void setDelayBeforeFirstTurnInSecs(int delayInSecs)Sets the delay between game play start and first turn in seconds.- Parameters:
delayInSecs
- - the delay between game play start and first turn in seconds
-
getCurrentGamePlayNo
public int getCurrentGamePlayNo()Returns the number of the currently active game play in the room. When a new game play starts, the gamePlay number is incremented by 1. The game number of the first game play is 1. This value is mainly for debugging purposes to identify which game play number the debug message belongs to- Returns:
- int - the game play number of the currently active game play in the room.
-
sendRoomDataToAll
public void sendRoomDataToAll()Sends Room Data to all the client sessions who have joined the room (both spectators and players) -
sendRoomDataToSession
Sends Room Data to the specified session- Parameters:
session
- - the session to which the room actionData should be sent
-
sendRoomDataToSession
Sends Room Data to the specified player's client session- Parameters:
player
- - the player to whose client the room actionData should be sent
-
cancelAutoStartGamePlay
public final void cancelAutoStartGamePlay()Prevents new game play from auto starting after a Game play ends. Should be called in afterGamePlayEnded() event to prevent a new game play from starting -
startGamePlay
public final void startGamePlay()Starts a new game play in the room if no game play is running. If a game play is already running in the room then nothing is done. -
cancelStartGamePlay
public final void cancelStartGamePlay()Cancels new Game play before first turn. Should be called in the beforeGameStarted event to cancel the new Game play. -
gameAction
Creates and sends a gameAction event/message to all the client's (client sessions - both spectators and players) connected to this room. for eg. in poker this method can be called when the flop, turn and river card/s is dealt- Parameters:
action
- - the actiondata
- - the actionData of the action in json format. For example in poker if the action is 'flop', the actionData will be the value of the flop cards
-
actionPlayed
Sends turnPlayed or outOfTurnPlayed event/message to clients. Should be called in onPlayerAction() event after the player's action has been successfully processed- Parameters:
playerAction
- - the player's processed action. for example in poker it could be 'folded' or 'raised'. Cannot be null. Can be empty StringactionData
- - the action data in json. for eg data could be {"amtBet":48,"raisedBy":20}- Throws:
NullPointerException
- - if playerAction is null
-
setErrorDescription
Sets the error description to be sent to client. For example in canSeatBeTaken() if chips are too less to take seat you can set the error description to 'Chips too less to take seat. Min chips required 100'- Parameters:
errorDescription
- - the error description
-
invalidateAction
Sets the errorDescription and errorData that is sent to client when the action is not valid. Call this method in onPlayerAction() event to invalidate the action. For example in poker if the amt bet is too less, you can invalidate the action with an error description of 'Bet value too less.' and errorData as {"minBet":50,"actualBet":20}- Parameters:
errorDescription
- - the error descriptionerrorData
- - the error data
-
forceAction
Forces an action on the specified player. Usually called in turnTimedOut() event to play a default action on a player whose turn has timed out. For example in poker you can call this method in onTurnTimedOut() event to force the default action of 'check' or 'fold' on the player.- Parameters:
player
- - the player on whom to force the actionaction
- - the action to be forcedactionData
- - the action data
-
isGamePlayEnding
public final boolean isGamePlayEnding()Checks whether Game play is ending or not. For example in poker this method can be called in Player.getGameDataToJsonForOthers() method to decide if a player's hole cards should be sent to other clients or not because on GameEnd your cards are visible to all players- Returns:
- boolean - true is Game is ending
-
endGamePlay
public final void endGamePlay()Ends the currently running game play in the room -
resetData
protected abstract void resetData()Called after End Game play to reset game play data. This method should be overridden in the child class -
leaveSeat
Evicts the specified client session from his/her seat- Parameters:
session
- - the client session to be evicted
-
leaveSeat
Evicts the specified player from his/her seat. This method is similar to leaveSeat(Session session)- Parameters:
player
- - the player to be evicted
-
leave
Evicts the specified client session from the room.- Parameters:
session
- - the client session to be evicted
-
isGamePlayInProgress
public final boolean isGamePlayInProgress()Returns whther a game play is in progress or not in the room- Returns:
- boolean - true is a game play is in progress
-
getSpectators
returns all the client session who are spectators- Returns:
- Iterable<Session> - the spectators as an iterable
-
getPlayersWhoPlayed
Returns all the players who took part in the current game play.- Returns:
- Iterable<Player> - the players who took part in the current game play
-
isSeated
Returns whether the specified client session is seated or not- Parameters:
session
- - the client session- Returns:
- boolean - true if the specified client session is seated
-
isSpectator
returns whether specified client session is a spectator or not. A spectator is a client session which is not seated- Parameters:
session
- - the client session- Returns:
- boolean - true if the specified session is a spectator
-
totalNoOfSeats
public final int totalNoOfSeats()the total number of seats in the room- Returns:
- int - total number of seats
-
playerCount
public final int playerCount()the number of players in the room ( the number of session seated in the room)- Returns:
- int - number of players
-
activePlayerCount
public final int activePlayerCount()The number of players active (i.e. playing) in the current game play. (i.e number of players who have not exited the game play)- Returns:
- int - number of players active in the current game play
-
nonBotPlayerCount
public final int nonBotPlayerCount()The number of non bot players in the room. (the number of non bot sessions seated in the room)- Returns:
- int - The number of non bot players in the room
-
activeNonBotPlayerCount
public final int activeNonBotPlayerCount()The number of non bot players active in the current game play. (i.e number of non bot players who have not exited the game play)- Returns:
- int - number of non bot players active in the current game play
-
botPlayerCount
public final int botPlayerCount()The number of bot players in the room. (the number of bot sessions seated in the room)- Returns:
- int - The number of bot players in the room
-
activeBotPlayerCount
public final int activeBotPlayerCount()The number of bot players active in the current game play - (i.e number of bot players who have not exited the game play)- Returns:
- int - number of bot players in the current game
-
spectatorCount
public final int spectatorCount()The number of spectators (sessions not seated)- Returns:
- int - the number of spectators
-
getLocation
Returns the room's location- Returns:
- Location - the room's location
-
getTurnDurationInSecs
public final int getTurnDurationInSecs()Returns the turn duration in seconds- Returns:
- int - the turn duration in seconds
-
destroy
public final void destroy()Destroys the room. -
sendJsonMessageToAll
Sends a Json message to all sessions in the room except the one specified.- Parameters:
command
- - the message commanddata
- - the message data as jsonsessionNotToSend
- - the session to which message should not be sent. Can be null.
-
sendJsonMessageToSpectators
public final void sendJsonMessageToSpectators(String command, JsonObject data, Session sessionNotToSend)Sends a Json message to all spectators in the room except the one specified.- Parameters:
command
- - the message commanddata
- - the message data as jsonsessionNotToSend
- - the session to which message should not be sent. Can be null.
-
sendJsonMessageToPlayers
public final void sendJsonMessageToPlayers(String command, JsonObject data, Session sessionNotToSend)Sends a Json message to all players in the room except the one specified.- Parameters:
command
- - the message commanddata
- - the message data as jsonsessionNotToSend
- - the session to which message should not be sent. Can be null.
-
sendTxtMessageToAll
Sends a text message to all sessions in the room except the one specified.- Parameters:
command
- - the message commanddata
- - the message data/textsessionNotToSend
- - the session to which message should not be sent. Can be null.
-
sendTxtMessageToSpectators
public final void sendTxtMessageToSpectators(String command, String data, Session sessionNotToSend)Sends a text message to all spectators in the room except the one specified.- Parameters:
command
- - the message commanddata
- - the message data/textsessionNotToSend
- - the session to which message should not be sent. Can be null.
-
sendTxtMessageToPlayers
Sends a text message to all players in the room except the one specified.- Parameters:
command
- - the message commanddata
- - the message data/textsessionNotToSend
- - the session to which message should not be sent. Can be null.
-
getPlayers
Returns all the players in the room- Returns:
- Iterable@lt;Player> - all the players in the room
-
getActivePlayers
Returns all the players active in the current game play- Returns:
- Iterable@lt;Player> - all the players active in the current game play
-
getNextActivePlayer
returns the next active player seated after the current turn player.- Returns:
- Player - the first active player after the current turn player
-
getNextActivePlayer
returns the next active player seated after the specified seat number.- Parameters:
prevSeatNo
- - the seat number after which to start searching- Returns:
- Player - the first active player after the specified seat number
-
getFirstActivePlayer
Returns the first active player- Returns:
- Player - the first active player
-
getFirstPlayer
Returns the first player in the room- Returns:
- Player - the first player in the room
-
getNextPlayer
Returns the next player seated after the specified seat number- Parameters:
prevSeatNo
- - the previous seat number- Returns:
- Player - the next player seated after the specified seat number
-
getNextActivePlayerWhoCanPlayTurn
Returns the next active player after the current player who can play a turn (player.canPlayTurn() returns true). For example in poker if a player is allIn then he/she cannot play another turn in the game.- Returns:
- Player - the next active player who can play a turn
-
getNextActivePlayerWhoCanPlayTurn
Returns the next active player after the specified seat number who can play a turn (player.canPlayTurn() returns true). For example in poker if a player is allIn then he/she cannot play another turn in the game.- Parameters:
prevSeatNo
- - the previous seat number- Returns:
- Player - the next turn player after the specified seat number who can play a turn
-
getPlayerBySeatNo
Returns player seated at the specified seat number- Parameters:
seatNo
- - the seat number of the player- Returns:
- Player - player seated at the specified seat number
-
getCurTurnSeatNo
public int getCurTurnSeatNo()Returns the seat number of the player whose turn is the current turn- Returns:
- int - the seat number of the player whose turn is the current turn
-
getCurTurnPlayer
Returns the player whose turn is the current turn- Returns:
- Player - player whose turn is the current turn
-
getFirstFreeSeatno
public int getFirstFreeSeatno()Returns the first free (not occupied) seat number.- Returns:
- int - the first free seat number
-
getNextFreeSeatNo
public int getNextFreeSeatNo(int prevSeatNo)Returns the first free (not occupied) seat number after the specified seat number- Parameters:
prevSeatNo
- - the previous seat number- Returns:
- int - the first free seat number after prevSeatNo
-
debug
Logs debug messages- Parameters:
txt
- - the message to be logged
-
debug
Logs debug messages along with the user name when debug is enabled- Parameters:
session
- - the session whose user name should be prepended to the debug messagetxt
- - the message to be logged
-
prepareJsonForClient
Returns room Data to be sent to the client as part of the room state. Do not include fields defined in the base class Room such as roomId, roomName, etc For example in poker this data would be the table cards (flop,turn and river), the dealer seatNo, the pot values, the smallBlind etc- Returns:
- JsonObject - the room data to be sent to client as json
-
getRoomInfo
Returns RoomInfo as json. RoomInfo is data that is sent to the client as part of the room list when client requests list of rooms in a given location. For example in poker this could be the smallBlind and the minimum chips to take seat- Returns:
- JsonObject - the RoomInfo as json
-
onRoomJoined
Event-Handler/Callback called after session is added to room but before joinedRoom message is sent to the client.- Parameters:
session
- - the session that has joined the room
-
canSeatBeTaken
Callback called when a session takes seat to check whether session should be allowed to take seat or not. For example in poker if the chips the user wants to put on table is less than the minimum chips to take seat then this method should return false- Parameters:
session
- - the session which is taking a seatseatNo
- - the seat numberdata
- - the data sent by the client with the takeSeat message: For example in poker this could be chipsToPutOnTable- Returns:
- boolean - true to allow player to take seat
-
onSeatTaken
Event-Handler/Callback called after player is seated but before seatTaken message is sent to clients. For example in poker here you could deduct the chip on table from the user's chips in Hand- Parameters:
player
- - the player who took seat
-
afterSeatTaken
Event-Handler/Callback called after seatTaken message is sent. In this event you could call cancelAutoStartGame() to prevent a game autostart. A new game starts automatically if the minimum players required to start game are seated- Parameters:
player
- - the player who took seat
-
beforeSeatLeft
protected void beforeSeatLeft(Player player, boolean isCurTurnPlayer, boolean isLeavingRoom, boolean isLoggingOut)Event-Handler/Callback called before player leaves/evicted from the seat. For eg. for a game like poker in this event you can add the player's chips on table to user's chips in hand. If the player leaving is in Game you can also play the default action of fold on the player- Parameters:
player
- - the player who is leaving seatisCurTurnPlayer
- - whether current turn is of the leaving playerisLeavingRoom
- - is the leave seat triggered as a result of leaving the roomisLoggingOut
- - is the leave seat triggered as a result of user loging out
-
afterSeatLeft
protected void afterSeatLeft(Player player, boolean isCurTurnPlayer, int noOfActivePlayers, boolean isLeavingRoom, boolean isLoggingOut)Event-Handler/Callback called after seat left message is sent- Parameters:
player
- - the player who left seatisCurTurnPlayer
- - whether current turn is of player which leftnoOfActivePlayers
- - number of in game playersisLeavingRoom
- - is the leave seat triggered as a result of leaving the roomisLoggingOut
- - is the leave seat triggered as a result of user loging out
-
onRoomLeft
Event-Handler/Callback called after room Left but before room Left message is sent to player- Parameters:
session
- - session which left roomisLoggingOut
- - is the leave room triggered as a result of user loging out
-
beforeGamePlayStarted
protected void beforeGamePlayStarted()Event-Handler/Callback called before game play starts and new game play message is sent. In a game like poker you can deal the first cards and play the small blind and big blind in this event -
afterGamePlayStarted
Event-Handler/Callback called after new game play message is sent - should return the first turn player- Returns:
- Player - the player whose turn is first
-
onTurnTimedOut
Event-Handler/Callback called when player's turn times out. In this event you should play an action such as fold else turn will not move to the next player- Parameters:
turnPlayer
- - the player whose turn timed out
-
onPlayerAction
Event-Handler/Callback called when player plays turn - should call actionPlayed() (this will send turnPlayed or outOfTurnPlayed event/message to clients)- Parameters:
player
- - the player who played the actionaction
- - the action playeddata
- - the action dataisOutOfTurn
- - is the action out of turn
-
afterTurnPlayed
Event-Handler/Callback called after player plays turn. Its is in this event that you should perform actions to be done after turn has completed. For example in poker if the betting round has completed you could deal the turn card. This method should return the player whose turn is next or null if the game has ended.- Parameters:
player
- - the player who played the actionaction
- - the action playedactionData
- - the action data- Returns:
- - the player whose turn is next or null if the game has ended.
-
getNextTurnData
returns the data to be sent to the client along with the nextTurn event/message to clients. for example in poker this method could return the call value- Parameters:
nextTurnPlayer
- - the player whose turn is next.- Returns:
- JsonObject - the data to be sent to clients. for eg. {"callValue":20}
-
beforeGamePlayEnded
Event-Handler/Callback after endGamePlay() is called but before game play is ended. Should return endGame data to be sent to clients. For eg. the data could contain the winner, winning cards, etc- Returns:
- JsonObject - the data to be sent to clients along with the endGame event/message.
-
afterGamePlayEnded
protected void afterGamePlayEnded()Event-Handler/Callback called after game play has ended and endGamePlay message has been sent to clients. Here you can do actions such as adding the amount won to the winner's chips on table -
getAdditionalRoomConfig
Should return the additional configuration data for the room. This method is called when a private room is saved to the database- Returns:
- JsonObject - returns the additional configuration data for the room as json
-
setAdditionalRoomConfig
Should set the additional configuration data for the room. This method is called when a private room's configuration is changed- Parameters:
additionalRoomConfig
- - the additional configuration data for the room
-
onRoomDestroyed
protected void onRoomDestroyed()Event-Handler/Callback called when room is destroyed but before event/message is sent to clients. For eg in poker you could restore player's chips in hand in this event -
afterRoomDestroyed
protected void afterRoomDestroyed()Event-Handler/Callback called after Room is Destroyed and destroyed event/message is sent to clients. Do deinitialization here
-