Package io.sockit.gameclient
Interface ClientEventListener
- All Known Implementing Classes:
ClientEventAdapter
public interface ClientEventListener
Interface for Client events/callbacks. An instance of this interface should be registered with the client object to handle async events received from the server
public class TicTacToeClientListener implements ClientEventListener {
{@literal @}Override
public void onLoggedIn(Client client, boolean isGameSelected) {
if(isGameSelected)
client.getRooms( "Mumbai", RoomType.normal); //fetches room list from Mumbai location
}
{@literal @}Override
public void onGetRooms(Client client, String gameName, String location, RoomType roomtype, List<RoomInfo> rooms) {
client.joinRoom(rooms.get(0).roomId); //joins the first room in the list
}
//....
}
-
Method Summary
Modifier and Type Method Description void
afterServerMessageProcessed(Client client, ServerMessageType serverMessageType, String customMessageCommand, boolean isBinary, Object data)
Event-Handler/Callback called when a message is received from the Server but after it is processedvoid
beforeServerMessageProcessed(Client client, ServerMessageType serverMessageType, String customMessageCommand, boolean isBinary, Object data)
Event-Handler/Callback called when a message is received from the Server but before it is processedvoid
onAvtarChangedOfOtherPlayer(Client client, Player player, int newAvtarId, Room room)
Event-Handler/Callback called when the avtar of another player is changedvoid
onAvtarChangedOfSelf(Client client, int newAvtarId)
Event-Handler/Callback called when the avtar of the user loggedIn via this client changesvoid
onConnecting(Client client)
Event-Handler/Callback called when Client is attempting to connect to the servervoid
onConnectionClosed(Client client)
Event-Handler/Callback called when the connection to the server is closed i.e.void
onConnectionDisconnected(Client client)
Event-Handler/Callback called when Client is disconnected from the server i.e.void
onConnectionFailure(Client client)
Event-Handler/Callback called when Client is fails to connect to the servervoid
onConnectionSuccess(Client client)
Event-Handler/Callback called when Client is successfully connected to the servervoid
onEnterGame(Client client, String gameName)
Event-Handler/Callback called when Client enters/selects a game.void
onError(Client client, int errorCode, String errorDesc)
Event-Handler/Callback called when an error is triggered on the server.void
onExitGame(Client client, String gameName)
Event-Handler/Callback called when Client exits/deselects a game.void
onGameAction(Client client, String gameAction, JsonObject actionData, Room room)
Event-Handler/Callback called when a game action occurs in the game.void
onGamePlayEnded(Client client, Room room, JsonObject endGameData)
Event-Handler/Callback called when game play ends in the roomvoid
onGamePlayStarted(Client client, Room room)
Event-Handler/Callback called when game play starts in the roomvoid
onGetLocations(Client client, String gameName, List<String> locations)
Event-Handler/Callback called when the Client receives the location list from the Servervoid
onGetRooms(Client client, String gameName, String location, RoomType roomtype, List<RoomInfo> rooms)
Event-Handler/Callback called when the Client receives the room list from the Servervoid
onInvalidAction(Client client, String action, String description, JsonObject errorData, Room room, boolean isOutOfTurn)
Event-Handler/Callback called when an action played by the Client is not validvoid
onLoggedIn(Client client, boolean isGameSelected)
Event-Handler/Callback called when the Client successfully logins a user into the servervoid
onLoggedOut(Client client)
Event-Handler/Callback called when the Client successfully logouts a user from the servervoid
onMessageReceivedBytes(Client client, String command, byte[] data)
Event-Handler/Callback called when the Client receives a custom binary message from the servervoid
onMessageReceivedJson(Client client, String command, JsonObject data)
Event-Handler/Callback called when the Client receives a custom Json message from the servervoid
onMessageReceivedString(Client client, String command, String data)
Event-Handler/Callback called when the Client receives a custom text message from the servervoid
onNextTurn(Client client, Player turnPlayer, JsonObject turnData, Room room, boolean isSelfTurn)
Event-Handler/Callback called when a new turn beginsvoid
onNotEligibleToPlay(Client client, Player player, Room room, String reason)
Event-Handler/Callback called when the Client is not eligible to play the new game play that is startingvoid
onOutOfTurnPlayed(Client client, Player outOfTurnPlayer, String playerAction, JsonObject actionData, Room room, boolean isSelf)
Event-Handler/Callback called when an action is played out of turn by a playervoid
onRoomDestroyed(Client client, Room room)
Event-Handler/Callback called when the room joined by this client is destroyedvoid
onRoomJoined(Client client, Room room)
Event-Handler/Callback called when the Client joins a roomvoid
onRoomLeft(Client client)
Event-Handler/Callback called when the Client leaves the roomvoid
onRoomRefreshedFromServer(Client client, Room room)
Event-Handler/Callback called when the room state is refreshed from the server.void
onSeatLeft(Client client, Player playerLeft, Room room, boolean isSelf)
Event-Handler/Callback called when any user leaves a seat in the room.void
onSeatTaken(Client client, Player playerSeated, Room room, boolean isSelf)
Event-Handler/Callback called when any user takes a seat in the room.void
onServerShutdown(Client client)
Event-Handler/Callback called when the server shutsdownvoid
onSessionRejoined(Client client)
Event-Handler/Callback called when session is rejoined by this client.void
onSessionTimedOut(Client client)
Event-Handler/Callback called when the Client session times out on the servervoid
onTurnPlayed(Client client, Player turnPlayer, String playerAction, JsonObject actionData, Room room, boolean isSelf)
Event-Handler/Callback called when a player plays his/her turn
-
Method Details
-
beforeServerMessageProcessed
void beforeServerMessageProcessed(Client client, ServerMessageType serverMessageType, String customMessageCommand, boolean isBinary, Object data)Event-Handler/Callback called when a message is received from the Server but before it is processed- Parameters:
client
- - the Client which received the messageserverMessageType
- - the messageType received from Server e.g. ServerMessageType.roomJoined or ServerMessageType.gamePlayStarted or ...customMessageCommand
- - the custom message command if the serverMessageType is a custom messageisBinary
- - whether message data is binary or notdata
- - the message data
-
afterServerMessageProcessed
void afterServerMessageProcessed(Client client, ServerMessageType serverMessageType, String customMessageCommand, boolean isBinary, Object data)Event-Handler/Callback called when a message is received from the Server but after it is processed- Parameters:
client
- - the Client which received the messageserverMessageType
- - the messageType received from Server e.g. ServerMessageType.roomJoined or ServerMessageType.gamePlayStarted or ...customMessageCommand
- - the custom message command if the serverMessageType is a custom messageisBinary
- - whether message data is binary or notdata
- - the message data
-
onError
Event-Handler/Callback called when an error is triggered on the server.- Parameters:
client
- - the Client which triggered the errorerrorCode
- - the errorCode e.g. ErrorCodes.emailIdAndPasswordDoesNotMatch or ErrorCodes.seatNotFree or ...errorDesc
- - the error description
-
onLoggedIn
Event-Handler/Callback called when the Client successfully logins a user into the server- Parameters:
client
- - the Client which loggedInisGameSelected
- - whether a Game is linked with this user session or not
-
onLoggedOut
Event-Handler/Callback called when the Client successfully logouts a user from the server- Parameters:
client
- - the client which loggedOut
-
onSessionTimedOut
Event-Handler/Callback called when the Client session times out on the server- Parameters:
client
- - the client whose session timed out
-
onServerShutdown
Event-Handler/Callback called when the server shutsdown- Parameters:
client
- - the Client which triggered this event
-
onGetLocations
Event-Handler/Callback called when the Client receives the location list from the Server- Parameters:
client
- - the Client which triggered this eventgameName
- - the name of the game whose locations were requested by the Clientlocations
- - the list of locations
-
onGetRooms
void onGetRooms(Client client, String gameName, String location, RoomType roomtype, List<RoomInfo> rooms)Event-Handler/Callback called when the Client receives the room list from the Server- Parameters:
client
- - the Client which triggered this eventgameName
- - the name of the game whose room list was requested by the Clientlocation
- - the location whose room list was requestedroomtype
- - the type of room list e.g. RoomType.normal or RoomType.fastrooms
- - the room list as a collection of RoomInfo objects
-
onRoomJoined
Event-Handler/Callback called when the Client joins a room- Parameters:
client
- - the Client which triggered this eventroom
- - the room joined by this Client
-
onRoomRefreshedFromServer
Event-Handler/Callback called when the room state is refreshed from the server. Gets triggered when Client receives a ServerMessageType.roomData message from the Server- Parameters:
client
- - the Client which triggered this eventroom
- - the room joined by the client
-
onSeatTaken
Event-Handler/Callback called when any user takes a seat in the room.- Parameters:
client
- - the Client which receives this eventplayerSeated
- - the player which took seatroom
- - the room joined by this clientisSelf
- - if the user seated is the same as this Client
-
onSeatLeft
Event-Handler/Callback called when any user leaves a seat in the room.- Parameters:
client
- - the Client which receives this eventplayerLeft
- - the player which left the seatroom
- - the room joined by this clientisSelf
- - if the user which left is the same as this Client
-
onRoomLeft
Event-Handler/Callback called when the Client leaves the room- Parameters:
client
- - the Client which triggered this event
-
onMessageReceivedJson
Event-Handler/Callback called when the Client receives a custom Json message from the server- Parameters:
client
- - the Client which receives the messagecommand
- - the message commanddata
- - the message data as json
-
onMessageReceivedString
Event-Handler/Callback called when the Client receives a custom text message from the server- Parameters:
client
- - the Client which receives the messagecommand
- - the message commanddata
- - the message data as String
-
onMessageReceivedBytes
Event-Handler/Callback called when the Client receives a custom binary message from the server- Parameters:
client
- - the Client which receives the messagecommand
- - the message commanddata
- - the message data as a byte array
-
onGamePlayStarted
Event-Handler/Callback called when game play starts in the room- Parameters:
client
- - the Client which receives this eventroom
- - the room joined by this client
-
onNextTurn
void onNextTurn(Client client, Player turnPlayer, JsonObject turnData, Room room, boolean isSelfTurn)Event-Handler/Callback called when a new turn begins- Parameters:
client
- - the Client which receives this eventturnPlayer
- - the player whose turn it isturnData
- - the additional data received with the event. For e.g. in a game like Poker it could be {"callValue":20}room
- - the room joined by this clientisSelfTurn
- - whether its the turn of the client which received this event
-
onTurnPlayed
void onTurnPlayed(Client client, Player turnPlayer, String playerAction, JsonObject actionData, Room room, boolean isSelf)Event-Handler/Callback called when a player plays his/her turn- Parameters:
client
- - the Client which receives this eventturnPlayer
- - the player who played the actionplayerAction
- - the action played by the playeractionData
- - the action data if any. For e.g. in a game like Poker it could be {"amtBet":20}room
- - the room joined by this clientisSelf
- - whether the action was played by the client which received this event
-
onOutOfTurnPlayed
void onOutOfTurnPlayed(Client client, Player outOfTurnPlayer, String playerAction, JsonObject actionData, Room room, boolean isSelf)Event-Handler/Callback called when an action is played out of turn by a player- Parameters:
client
- - the Client which receives this eventoutOfTurnPlayer
- - the player who played the actionplayerAction
- - the action played by the playeractionData
- - the action data if any.room
- - the room joined by this clientisSelf
- - whether the action was played by the client which received this event
-
onGameAction
Event-Handler/Callback called when a game action occurs in the game. For e.f. in a game like poker this could be flop cards dealt- Parameters:
client
- - the Client which receives this eventgameAction
- - the game actionactionData
- - the action data. For e.g. in a game like poker this could be the value of the flop cardsroom
- - the room joined by this client
-
onGamePlayEnded
Event-Handler/Callback called when game play ends in the room- Parameters:
client
- - the Client which receives this eventroom
- - the room joined by this clientendGameData
- - the data received with the endGame event. For e.g this could be the winning seat no and the amount won
-
onRoomDestroyed
Event-Handler/Callback called when the room joined by this client is destroyed- Parameters:
client
- - the Client which receives this eventroom
- - the room which was destroyed
-
onAvtarChangedOfSelf
Event-Handler/Callback called when the avtar of the user loggedIn via this client changes- Parameters:
client
- - the Client which receives this eventnewAvtarId
- - the new avtarId of the user
-
onAvtarChangedOfOtherPlayer
Event-Handler/Callback called when the avtar of another player is changed- Parameters:
client
- - the Client which receives this eventplayer
- - the player whose avtar is changednewAvtarId
- - the new avtarIDroom
- - the room joined by this client
-
onNotEligibleToPlay
Event-Handler/Callback called when the Client is not eligible to play the new game play that is starting- Parameters:
client
- - the Client which receives this eventplayer
- - the player linked to this clientroom
- - the room joined by this clientreason
- - the reason why player is not eligible
-
onSessionRejoined
Event-Handler/Callback called when session is rejoined by this client. This event is triggered by the method Client.rejoinSession()- Parameters:
client
- - the Client which receives this event
-
onConnecting
Event-Handler/Callback called when Client is attempting to connect to the server- Parameters:
client
- - the Client which triggers this event
-
onConnectionSuccess
Event-Handler/Callback called when Client is successfully connected to the server- Parameters:
client
- - the Client which triggers this event
-
onConnectionFailure
Event-Handler/Callback called when Client is fails to connect to the server- Parameters:
client
- - the Client which triggers this event
-
onConnectionDisconnected
Event-Handler/Callback called when Client is disconnected from the server i.e. When the Server initiates the connection close.- Parameters:
client
- - the Client which triggers this event
-
onConnectionClosed
Event-Handler/Callback called when the connection to the server is closed i.e. When the Client initiates the connection close.- Parameters:
client
- - the Client which triggers this event
-
onInvalidAction
void onInvalidAction(Client client, String action, String description, JsonObject errorData, Room room, boolean isOutOfTurn)Event-Handler/Callback called when an action played by the Client is not valid- Parameters:
client
- - the Client which triggers this eventaction
- - the action playeddescription
- - the error descriptionerrorData
- - the error data containing more info about the errorroom
- - the room joined by the clientisOutOfTurn
- - true if the action was played out of turn
-
onEnterGame
Event-Handler/Callback called when Client enters/selects a game.- Parameters:
client
- - the Client which triggers this eventgameName
- - the name of the game entered/selected
-
onExitGame
Event-Handler/Callback called when Client exits/deselects a game.- Parameters:
client
- - the Client which triggers this eventgameName
- - the name of the game exited/deselected
-