public abstract class GameRoomSession extends DefaultSession implements GameRoom
Modifier and Type | Class and Description |
---|---|
static class |
GameRoomSession.GameRoomSessionBuilder |
DefaultSession.SessionBuilder
Session.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 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.
|
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 |
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, setWriteable
private static final org.slf4j.Logger LOG
protected String gameRoomName
protected Game parentGame
SimpleGame
reference of this game room.protected GameStateManagerService stateManager
DefaultPlayer
s connected to this game room.protected Set<PlayerSession> sessions
protected Protocol protocol
protected GameRoomSession(GameRoomSession.GameRoomSessionBuilder gameRoomSessionBuilder)
public PlayerSession createPlayerSession(Player player)
GameRoom
createPlayerSession
in interface GameRoom
public abstract void onLogin(PlayerSession playerSession)
GameRoom
public boolean connectSession(PlayerSession playerSession)
GameRoom
connectSession
in interface GameRoom
playerSession
- The incoming user session. If we are using netty, it would be
a Channel
object wrapped in a PlayerSession
.public void afterSessionConnect(PlayerSession playerSession)
GameRoom
afterSessionConnect
in interface GameRoom
public boolean disconnectSession(PlayerSession playerSession)
GameRoom
disconnectSession
in interface GameRoom
playerSession
- The session to be removed from the set.public void send(Event event)
GameRoom
PlayerSession
s if required.
Implementations are generally expected to be async, so default
implementation would be to just patch incoming event to the
Session.onEvent(org.menacheri.jetserver.event.Event)
of the
GameRoom's session where the actual business logic can be applied.public void sendBroadcast(NetworkEvent networkEvent)
GameRoom
DefaultPlayer
s
to the same state. This method will transmit messages using the delivery
guaranty provided in the NetworkEvent
.sendBroadcast
in interface GameRoom
networkEvent
- The message that is to be broadcast to all user sessions of
this game roompublic void close()
GameRoom
public PlayerSession getSessionInstance(Player player)
public Set<PlayerSession> getSessions()
GameRoom
getSessions
in interface GameRoom
public void setSessions(Set<PlayerSession> sessions)
GameRoom
setSessions
in interface GameRoom
sessions
- The set of sessions to be set.public String getGameRoomName()
getGameRoomName
in interface GameRoom
public void setGameRoomName(String gameRoomName)
GameRoom
setGameRoomName
in interface GameRoom
public Game getParentGame()
GameRoom
getParentGame
in interface GameRoom
public void setParentGame(Game parentGame)
GameRoom
setParentGame
in interface GameRoom
parentGame
- The game to which this game room belongs.public void setStateManager(GameStateManagerService stateManager)
GameRoom
setStateManager
in interface GameRoom
public GameStateManagerService getStateManager()
GameRoom
getStateManager
in interface GameRoom
public Protocol getProtocol()
GameRoom
getProtocol
in interface GameRoom
public void setProtocol(Protocol protocol)
GameRoom
setProtocol
in interface GameRoom
protocol
- The protocol instance to set.public boolean isShuttingDown()
isShuttingDown
in interface Session
isShuttingDown
in class DefaultSession
public void setShuttingDown(boolean isShuttingDown)
protected void createAndAddEventHandlers(PlayerSession playerSession)
playerSession
- The session for which the event handlers are created.Copyright © 2013. All Rights Reserved.