Photon Server API Documentation v5.0RC1

Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Properties | List of all members
Photon.Hive.Room Class Reference

A room has Actors, can have properties, and provides an ExecutionFiber with a few wrapper methods to solve otherwise complicated threading issues: All actions enqueued to the ExecutionFiber are executed in a serial order. Operations of all Actors in a room are handled via ExecutionFiber. More...

Inheritance diagram for Photon.Hive.Room:
Photon.Hive.HiveGame Photon.Hive.HiveHostGame Photon.LoadBalancing.GameServer.Game

Classes

class  DefaultGameStateFactory
 

Public Member Functions

 Room (string name, RoomCacheBase roomCache=null, IGameStateFactory gameStateFactory=null, int maxEmptyRoomTTL=0, ExtendedPoolFiber executionFiber=null)
 Initializes a new instance of the Room class without a room name. More...
 
override string ToString ()
 
virtual bool BeforeRemoveFromCache ()
 Called by the RoomCacheBase if the room is about to be removed from the cache. More...
 
void EnqueueMessage (IMessage message)
 Enqueues an IMessage to the end of the execution queue. More...
 
void EnqueueOperation (HivePeer peer, Operation operationRequest, SendParameters sendParameters)
 Enqueues an OperationRequest to the end of the execution queue. More...
 
IDisposable ScheduleMessage (IMessage message, int timeMs)
 Schedules a message to be processed after a specified time. More...
 
void Dispose ()
 Releases resources used by this instance. More...
 
void Release ()
 

Protected Types

enum  RemoveState {
  RemoveState.Alive, RemoveState.TryRemoveRoomFromCacheCalled, RemoveState.RoomRemoved, RemoveState.TryRemoveRoomFromCacheCalledRoomNotRemoved,
  RemoveState.ProcessCloseGameCalled, RemoveState.TriggerPluginOnCloseCalled, RemoveState.AliveGotNewPlayer, RemoveState.ScheduleTriggerPluginOnCloseCalled,
  RemoveState.ProcessBeforeCloseGameCalled, RemoveState.ProcessBeforeCloseGameCalledEmptyRoomLiveTimeLECalled, RemoveState.BeforeRemoveFromCacheCalled, RemoveState.BeforeRemoveFromCacheActionCalled,
  RemoveState.GameDisposeCalled
}
 

Protected Member Functions

 Room (string name, ExtendedPoolFiber executionFiber, RoomCacheBase roomCache, IGameStateFactory gameStateFactory=null, int maxEmptyRoomTTL=0)
 Initializes a new instance of the Room class. More...
 
virtual void Dispose (bool dispose)
 Releases unmanaged and - optionally - managed resources More...
 
virtual void ExecuteOperation (HivePeer peer, Operation operation, SendParameters sendParameters)
 This method is invoked sequentially for each operation request enqueued in the ExecutionFiber using the EnqueueOperation method. More...
 
virtual void ProcessMessage (IMessage message)
 This method is invoked sequentially for each message enqueued by the EnqueueMessage or ScheduleMessage method. More...
 
void PublishEvent (HiveEventBase e, Actor actor, SendParameters sendParameters)
 Publishes an event to a single actor on a specified channel. More...
 
void PublishEvent (HiveEventBase e, IEnumerable< Actor > actorList, SendParameters sendParameters)
 Publishes an event to a list of actors on a specified channel. More...
 
void PublishEvent (EventData e, IEnumerable< Actor > actorList, SendParameters sendParameters)
 Publishes an event to a list of actors on a specified channel. More...
 
void PublishErrorInfoEvent (string errorMsg, IEnumerable< Actor > actorList, SendParameters sendParameters)
 
void ScheduleRoomRemoval (int roomLiveTime)
 Schedules the removal of the room instance from the cache. The room will be removed after the specified time if there are no room references left. More...
 
void TryRemoveRoomFromCache ()
 Removes the room instance from the cache if there are no references to the instance left. More...
 
virtual void OnClose ()
 

Protected Attributes

readonly RoomCacheBase roomCache
 
readonly IGameStateFactory gameStateFactory
 
string RemoveRoomPathString
 
DateTime removalStartTimestamp = DateTime.MinValue
 
GameState roomState
 

Properties

RemoveState RemoveRoomPath [get, set]
 
ExtendedPoolFiber ExecutionFiber [get]
 Gets a PoolFiber instance used to synchronize access to this instance. More...
 
bool IsDisposed [get]
 Gets a value indicating whether IsDisposed. More...
 
string Name [get]
 Gets the name (id) of the room. More...
 
int EmptyRoomLiveTime [get, protected set]
 Gets or sets a value indicating how long the room instance will be keeped alive in the room cache after all peers have left the room. More...
 
int MaxEmptyRoomTTL [get]
 
DateTime UtcCreated [get]
 
long RoomCreationTS [get]
 
IDisposable RemoveTimer [get, set]
 Timer for removing room More...
 
PropertyBag< object > Properties [get]
 Gets a PropertyBag instance used to store custom room properties. More...
 

Detailed Description

A room has Actors, can have properties, and provides an ExecutionFiber with a few wrapper methods to solve otherwise complicated threading issues: All actions enqueued to the ExecutionFiber are executed in a serial order. Operations of all Actors in a room are handled via ExecutionFiber.

Member Enumeration Documentation

◆ RemoveState

enum Photon.Hive.Room.RemoveState
strongprotected
Enumerator
Alive 
TryRemoveRoomFromCacheCalled 
RoomRemoved 
TryRemoveRoomFromCacheCalledRoomNotRemoved 
ProcessCloseGameCalled 
TriggerPluginOnCloseCalled 
AliveGotNewPlayer 
ScheduleTriggerPluginOnCloseCalled 
ProcessBeforeCloseGameCalled 
ProcessBeforeCloseGameCalledEmptyRoomLiveTimeLECalled 
BeforeRemoveFromCacheCalled 
BeforeRemoveFromCacheActionCalled 
GameDisposeCalled 

Constructor & Destructor Documentation

◆ Room() [1/2]

Photon.Hive.Room.Room ( string  name,
RoomCacheBase  roomCache = null,
IGameStateFactory  gameStateFactory = null,
int  maxEmptyRoomTTL = 0,
ExtendedPoolFiber  executionFiber = null 
)
inline

Initializes a new instance of the Room class without a room name.

Parameters
nameThe room name.
roomCacheThe RoomCacheBase instance to which the room belongs.
gameStateFactoryFatory for game state
maxEmptyRoomTTLA value indicating how long the room instance will be keeped alive in the room cache after all peers have left the room.
executionFiberFiber which will execute rooms actions

◆ Room() [2/2]

Photon.Hive.Room.Room ( string  name,
ExtendedPoolFiber  executionFiber,
RoomCacheBase  roomCache,
IGameStateFactory  gameStateFactory = null,
int  maxEmptyRoomTTL = 0 
)
inlineprotected

Initializes a new instance of the Room class.

Parameters
nameThe room name.
executionFiberThe execution fiber used to synchronize access to this instance.
roomCacheThe RoomCacheBase instance to which the room belongs.
gameStateFactoryFatory for game state
maxEmptyRoomTTLA value indicating how long the room instance will be keeped alive in the room cache after all peers have left the room.

Member Function Documentation

◆ BeforeRemoveFromCache()

virtual bool Photon.Hive.Room.BeforeRemoveFromCache ( )
inlinevirtual

Called by the RoomCacheBase if the room is about to be removed from the cache.

Returns
True if the room should be automaticly by removed by the RoomCacheBase. False if the room has an custom remove implementation and will remove itself from the cache.

The default implementation checks if the EmptyRoomLiveTime value is set to a value greater zero. If it's set the method will return false to indicate that the cache should not remove this instance automaticly. The removal of the room is then scheduled using the ExecutionFiber.

Reimplemented in Photon.Hive.HiveHostGame.

◆ Dispose() [1/2]

void Photon.Hive.Room.Dispose ( )
inline

Releases resources used by this instance.

◆ Dispose() [2/2]

virtual void Photon.Hive.Room.Dispose ( bool  dispose)
inlineprotectedvirtual

Releases unmanaged and - optionally - managed resources

Parameters
disposetrue to release both managed and unmanaged resources; false to release only unmanaged resources.

Reimplemented in Photon.LoadBalancing.GameServer.Game, and Photon.Hive.HiveHostGame.

◆ EnqueueMessage()

void Photon.Hive.Room.EnqueueMessage ( IMessage  message)
inline

Enqueues an IMessage to the end of the execution queue.

Parameters
messageThe message to enqueue.

ProcessMessage is called sequentially for each operation request stored in the execution queue. Using an execution queue ensures that messages are processed in order and sequentially to prevent object synchronization (multi threading).

◆ EnqueueOperation()

void Photon.Hive.Room.EnqueueOperation ( HivePeer  peer,
Operation  operationRequest,
SendParameters  sendParameters 
)
inline

Enqueues an OperationRequest to the end of the execution queue.

Parameters
peerThe peer.
operationRequestThe operation request to enqueue.
sendParametersThe send Parameters.

ExecuteOperation is called sequentially for each operation request stored in the execution queue. Using an execution queue ensures that operation request are processed in order and sequentially to prevent object synchronization (multi threading).

◆ ExecuteOperation()

virtual void Photon.Hive.Room.ExecuteOperation ( HivePeer  peer,
Operation  operation,
SendParameters  sendParameters 
)
inlineprotectedvirtual

This method is invoked sequentially for each operation request enqueued in the ExecutionFiber using the EnqueueOperation method.

Parameters
peerThe peer.
operationThe operation request.
sendParametersThe send Parameters.

Reimplemented in Photon.Hive.HiveGame.

◆ OnClose()

virtual void Photon.Hive.Room.OnClose ( )
inlineprotectedvirtual

◆ ProcessMessage()

virtual void Photon.Hive.Room.ProcessMessage ( IMessage  message)
inlineprotectedvirtual

This method is invoked sequentially for each message enqueued by the EnqueueMessage or ScheduleMessage method.

Parameters
messageThe message to process.

Reimplemented in Photon.Hive.HiveGame, and Photon.LoadBalancing.GameServer.Game.

◆ PublishErrorInfoEvent()

void Photon.Hive.Room.PublishErrorInfoEvent ( string  errorMsg,
IEnumerable< Actor actorList,
SendParameters  sendParameters 
)
inlineprotected

◆ PublishEvent() [1/3]

void Photon.Hive.Room.PublishEvent ( EventData  e,
IEnumerable< Actor actorList,
SendParameters  sendParameters 
)
inlineprotected

Publishes an event to a list of actors on a specified channel.

Parameters
eThe event to publish.
actorListA list of Actor who should receive the event.
sendParametersThe send Parameters.

◆ PublishEvent() [2/3]

void Photon.Hive.Room.PublishEvent ( HiveEventBase  e,
Actor  actor,
SendParameters  sendParameters 
)
inlineprotected

Publishes an event to a single actor on a specified channel.

Parameters
eThe event to publish.
actorThe Actor who should receive the event.
sendParametersThe send Parameters.

◆ PublishEvent() [3/3]

void Photon.Hive.Room.PublishEvent ( HiveEventBase  e,
IEnumerable< Actor actorList,
SendParameters  sendParameters 
)
inlineprotected

Publishes an event to a list of actors on a specified channel.

Parameters
eThe event to publish.
actorListA list of Actor who should receive the event.
sendParametersThe send Parameters.

◆ Release()

void Photon.Hive.Room.Release ( )
inline

◆ ScheduleMessage()

IDisposable Photon.Hive.Room.ScheduleMessage ( IMessage  message,
int  timeMs 
)
inline

Schedules a message to be processed after a specified time.

Parameters
messageThe message to schedule.
timeMsThe time in milliseconds to wait before the message will be processed.
Returns
an IDisposable

◆ ScheduleRoomRemoval()

void Photon.Hive.Room.ScheduleRoomRemoval ( int  roomLiveTime)
inlineprotected

Schedules the removal of the room instance from the cache. The room will be removed after the specified time if there are no room references left.

Parameters
roomLiveTimeThe time to remove the room in milliseconds.

◆ ToString()

override string Photon.Hive.Room.ToString ( )
inline

◆ TryRemoveRoomFromCache()

void Photon.Hive.Room.TryRemoveRoomFromCache ( )
inlineprotected

Removes the room instance from the cache if there are no references to the instance left.

when we are here it may happens (for instacne because plugin OnCloseGame handler does some sync http request) that new players already acuired new refernces to room. and room can not be removed from cache

we had a bug in WebHooks12 and it caused Continue to be called right after sync http call. that led to big delay for this method execution. because of that confusion CheckGame method logged that empty room still in cache so, now to prevent such situation we set here MaxValue instead of min, so that CheckGame is quiet

Member Data Documentation

◆ gameStateFactory

readonly IGameStateFactory Photon.Hive.Room.gameStateFactory
protected

◆ removalStartTimestamp

DateTime Photon.Hive.Room.removalStartTimestamp = DateTime.MinValue
protected

◆ RemoveRoomPathString

string Photon.Hive.Room.RemoveRoomPathString
protected

◆ roomCache

readonly RoomCacheBase Photon.Hive.Room.roomCache
protected

◆ roomState

GameState Photon.Hive.Room.roomState
protected

Property Documentation

◆ EmptyRoomLiveTime

int Photon.Hive.Room.EmptyRoomLiveTime
getprotected set

Gets or sets a value indicating how long the room instance will be keeped alive in the room cache after all peers have left the room.

◆ ExecutionFiber

ExtendedPoolFiber Photon.Hive.Room.ExecutionFiber
get

Gets a PoolFiber instance used to synchronize access to this instance.

A PoolFiber instance.

◆ IsDisposed

bool Photon.Hive.Room.IsDisposed
get

Gets a value indicating whether IsDisposed.

◆ MaxEmptyRoomTTL

int Photon.Hive.Room.MaxEmptyRoomTTL
get

◆ Name

string Photon.Hive.Room.Name
get

Gets the name (id) of the room.

◆ Properties

PropertyBag<object> Photon.Hive.Room.Properties
get

Gets a PropertyBag instance used to store custom room properties.

◆ RemoveRoomPath

RemoveState Photon.Hive.Room.RemoveRoomPath
getsetprotected

◆ RemoveTimer

IDisposable Photon.Hive.Room.RemoveTimer
getsetprotected

Timer for removing room

◆ RoomCreationTS

long Photon.Hive.Room.RoomCreationTS
get

◆ UtcCreated

DateTime Photon.Hive.Room.UtcCreated
get