public abstract class GameRoomSession extends DefaultSession implements GameRoom
| Modifier and Type | Class and Description |
|---|---|
static class |
GameRoomSession.GameRoomSessionBuilder |
DefaultSession.SessionBuilderSession.Status| Modifier and Type | Field and Description |
|---|---|
protected String |
gameRoomName
The name of the game room, preferably unique across multiple games.
|
private static org.slf4j.Logger |
LOG |
protected Game |
parentGame
The parent
SimpleGame reference of this game room. |
protected Protocol |
protocol
Each game room has its own protocol for communication with client.
|
protected SessionFactory |
sessionFactory |
protected Set<PlayerSession> |
sessions
The set of sessions in this object.
|
protected GameStateManagerService |
stateManager
Each game room has separate state manager instances.
|
creationTime, eventDispatcher, id, isShuttingDown, isUDPEnabled, isWriteable, lastReadWriteTime, sessionAttributes, status, tcpSender, udpSender| Modifier | Constructor and Description |
|---|---|
protected |
GameRoomSession(GameRoomSession.GameRoomSessionBuilder gameRoomSessionBuilder) |
| Modifier and Type | Method and Description |
|---|---|
void |
afterSessionConnect(PlayerSession playerSession)
Method called after the session is created.
|
void |
close()
This method will close down the game room.
|
boolean |
connectSession(PlayerSession playerSession)
When a new user connects to the game, this method will be invoked to add
the incoming session to the game room.
|
protected void |
createAndAddEventHandlers(PlayerSession playerSession)
Method which will create and add event handlers of the player session to
the Game Room's EventDispatcher.
|
PlayerSession |
createPlayerSession(Player player)
Method used to create a player session object.
|
boolean |
disconnectSession(PlayerSession playerSession)
Remove a session from the existing list of user sessions.
|
SessionFactory |
getFactory() |
String |
getGameRoomName() |
Game |
getParentGame()
Each game room belongs to a game.
|
Protocol |
getProtocol()
Each game room has a protocol attached to it.
|
PlayerSession |
getSessionInstance(Player player) |
Set<PlayerSession> |
getSessions()
Returns a list of sessions that is held by the game room.
|
GameStateManagerService |
getStateManager()
Every non trivial game will have some sort of state management service
going on.
|
boolean |
isShuttingDown() |
abstract void |
onLogin(PlayerSession playerSession)
Method called after the session is created.
|
void |
send(Event event)
Used to send an event to the GameRoom.
|
void |
sendBroadcast(NetworkEvent networkEvent)
Method used to send a broadcast message to all sessions in the group.
|
void |
setFactory(SessionFactory factory) |
void |
setGameRoomName(String gameRoomName)
Sets the name of the game room.
|
void |
setParentGame(Game parentGame)
Used to set the parent game object of the game room.
|
void |
setProtocol(Protocol protocol)
Sets the protocol instance on the game room.
|
void |
setSessions(Set<PlayerSession> sessions)
Method used to set the set of user sessions to a particular game room.
|
void |
setShuttingDown(boolean isShuttingDown) |
void |
setStateManager(GameStateManagerService stateManager)
Method used to set the state manager for a game room.
|
addHandler, equals, getAttribute, getCreationTime, getEventDispatcher, getEventHandlers, getId, getLastReadWriteTime, getSessionAttributes, getStatus, getTcpSender, getUdpSender, hashCode, isConnected, isUDPEnabled, isWriteable, onEvent, removeAttribute, removeHandler, setAttribute, setId, setLastReadWriteTime, setStatus, setTcpSender, setUDPEnabled, setUdpSender, setWriteableprivate static final org.slf4j.Logger LOG
protected String gameRoomName
protected Game parentGame
SimpleGame reference of this game room.protected GameStateManagerService stateManager
DefaultPlayers connected to this game room.protected Set<PlayerSession> sessions
protected Protocol protocol
protected SessionFactory sessionFactory
protected GameRoomSession(GameRoomSession.GameRoomSessionBuilder gameRoomSessionBuilder)
public PlayerSession createPlayerSession(Player player)
GameRoomcreatePlayerSession in interface GameRoompublic abstract void onLogin(PlayerSession playerSession)
GameRoompublic boolean connectSession(PlayerSession playerSession)
GameRoomconnectSession in interface GameRoomplayerSession - The incoming user session. If we are using netty, it would be
a Channel object wrapped in a PlayerSession.public void afterSessionConnect(PlayerSession playerSession)
GameRoomafterSessionConnect in interface GameRoompublic boolean disconnectSession(PlayerSession playerSession)
GameRoomdisconnectSession in interface GameRoomplayerSession - The session to be removed from the set.public void send(Event event)
GameRoomPlayerSessions if required.
Implementations are generally expected to be async, so default
implementation would be to just patch incoming event to the
Session.onEvent(io.nadron.event.Event) of the
GameRoom's session where the actual business logic can be applied.public void sendBroadcast(NetworkEvent networkEvent)
GameRoomDefaultPlayer s
to the same state. This method will transmit messages using the delivery
guaranty provided in the NetworkEvent.sendBroadcast in interface GameRoomnetworkEvent - The message that is to be broadcast to all user sessions of
this game roompublic void close()
GameRoompublic PlayerSession getSessionInstance(Player player)
public Set<PlayerSession> getSessions()
GameRoomgetSessions in interface GameRoompublic void setSessions(Set<PlayerSession> sessions)
GameRoomsetSessions in interface GameRoomsessions - The set of sessions to be set.public String getGameRoomName()
getGameRoomName in interface GameRoompublic void setGameRoomName(String gameRoomName)
GameRoomsetGameRoomName in interface GameRoompublic Game getParentGame()
GameRoomgetParentGame in interface GameRoompublic void setParentGame(Game parentGame)
GameRoomsetParentGame in interface GameRoomparentGame - The game to which this game room belongs.public void setStateManager(GameStateManagerService stateManager)
GameRoomsetStateManager in interface GameRoompublic GameStateManagerService getStateManager()
GameRoomgetStateManager in interface GameRoompublic Protocol getProtocol()
GameRoomgetProtocol in interface GameRoompublic void setProtocol(Protocol protocol)
GameRoomsetProtocol in interface GameRoomprotocol - The protocol instance to set.public SessionFactory getFactory()
getFactory in interface GameRoompublic void setFactory(SessionFactory factory)
setFactory in interface GameRoompublic boolean isShuttingDown()
isShuttingDown in interface SessionisShuttingDown in class DefaultSessionpublic void setShuttingDown(boolean isShuttingDown)
protected void createAndAddEventHandlers(PlayerSession playerSession)
playerSession - The session for which the event handlers are created.Copyright © 2013. All Rights Reserved.