C# Class ACR_ServerCommunicator.GameWorldManager

This object (which is a singleton) manages the local server's view of the game world wide state (data for all servers and players is locally stored here). State elements are, generally, lazily added to the game world manager's state cache. Only when a character, player, or server has actually been observed will it be added to the local cache. This helps prevent the local cache from growing too large up front, as it does not need to have the entire database contents pre-downloaded. As identifiers for unknown servers, players, or characters are seen, the local state cache is updated from the database. The local state cache is also updated based on polling the online player list periodically. In effect, the state cache serves as the current server's view of player presence across the entire game world, spanning every online server. All internal operations on the GameWorldManager assume that the caller has provided appropriate synchronization. Many operations may block on the first reference to a previously unresolved object identifier or object name.
Show file Open project: ALandFarAway/ALFA-Base-Resources Class Usage Examples

Public Methods

Method Description
ConvertToBoolean ( string Str ) : bool

Convert a database string to a Boolean value.

EnqueueAccountAssociationToPlayer ( uint PlayerObject, string AccountAssociationSecret, string AccountAssociationURL ) : void

Enqueue an account association event to a player for processing in the main thread. N.B. The world manager is assumed to be locked.

EnqueueMessageToPlayer ( uint PlayerObject, string Message ) : void

Enqueue a message to a player for outbound transmission on the main server thread. N.B. The world manager is assumed to be locked.

GameWorldManager ( int LocalServerId, string LocalServerName ) : System

Create a new GameWorldManager.

IsEventPending ( ) : bool

Check whether an event might be pending, without taking the lock. Note that this is purely an advisory mechanism; the caller must repeatedly check as they may lose the race for when the event pending flag is set. The purpose of this function is to allow the main thread to avoid needlessly blocking on the query thread.

IsEventQueueEmpty ( ) : bool

Check whether the event queue is empty.

ReferenceCharacterById ( int CharacterId, IALFADatabase Database ) : ACR_ServerCommunicator.GameCharacter

Reference the data for a character by the character id. If the data was not yet available, it is retrieved from the database.

ReferenceCharacterById ( int CharacterId, IALFADatabase Database, bool InitialDMState ) : ACR_ServerCommunicator.GameCharacter

Reference the data for a character by the character id. If the data was not yet available, it is retrieved from the database.

ReferenceCharacterByName ( string CharacterName, IALFADatabase Database ) : ACR_ServerCommunicator.GameCharacter

Reference the data for a character by the character name. If the data was not yet available, it is retrieved from the database.

ReferencePlayerById ( int PlayerId, IALFADatabase Database ) : ACR_ServerCommunicator.GamePlayer

Reference the data for a player by the player id. If the data was not yet available, it is retrieved from the database.

ReferencePlayerByName ( string PlayerName, IALFADatabase Database ) : ACR_ServerCommunicator.GamePlayer

Reference the data for a player by the player name. If the data was not yet available, it is retrieved from the database.

ReferenceServerById ( int ServerId, IALFADatabase Database ) : GameServer

Reference the data for a server by the server id. If the data was not yet available, it is retrieved from the database.

ReferenceServerByName ( string ServerName, IALFADatabase Database ) : GameServer

Reference the data for a server by the server name. If the data was not yet available, it is retrieved from the database.

RunQueue ( ACR_ServerCommunicator Script, ALFA Database ) : void

Run the event queue down. All events in the queue are given a chance to run.

SignalIPCEvent ( IPC_EVENT Event ) : void

Signal an IPC event on a remote server by adding the event to the outbound event queue.

SignalIPCEventWakeup ( ) : void

Signal that the query thread should wake up to process IPC events soon. This may reduce the time until the next outbound event is sent. Note that, unlike most members, this method does not require any particular synchronization.

SignalQueryThreadAction ( QueryThreadAction Action ) : void

Signal a request to invoke an action in the context of the query thread. N.B. The routine should NOT be invoked with the world manager locked. Internal synchronization is provided.

SynchronizeInitialConfiguration ( IALFADatabase Database ) : void

Force synchronization of database configuration.

WriteDiagnosticLog ( string Message ) : void

This method is called to write a diagnostic log message to the main server log. The method is called with synchronization held on the WorldManager object.

Private Methods

Method Description
ConsistencyCheck ( ) : void

This debug routine verifies the consistency of the game world data model.

DispatchQueryThreadActions ( ) : void

This method dispatches query thread actions that have been queued to the database query/synchronizer thread.

DistributeDatabaseOnlineNotification ( bool Online ) : void

Send a direct, database online/offline status update to all online servers. Note that the update is sent as an unreliable datagram so it is possible that it may never arrive, or may arrive in the wrong order, etc. The notification is purely advisory.

EnqueueEvent ( IGameEventQueueEvent Event ) : void

This routine wrappers the process of enqueuing an event, and also sets the events queued flag if necessary.

InsertNewCharacter ( ACR_ServerCommunicator.GameCharacter Character, int ServerId, IALFADatabase Database, bool InitialDMState ) : void

This function inserts a character into the various character lists and issues the character join event.

InsertNewPlayer ( ACR_ServerCommunicator.GamePlayer Player, IALFADatabase Database ) : void

This function inserts a player into the various player lists and issues the player load event.

InsertNewServer ( GameServer Server, IALFADatabase Database ) : void

This function inserts a server into the various server lists and issues the server load event.

IsConnectivityFailureException ( Exception e, string Description ) : bool

Check whether an exception might be a database connectivity related exception (versus any other reason).

OnBroadcastNotification ( string Message ) : void

This method is called when a broadcast notification is received.

OnCharacterJoin ( ACR_ServerCommunicator.GameCharacter Character ) : void

This method is called when a character is discovered to have come online. The character is inserted already.

OnCharacterPart ( ACR_ServerCommunicator.GameCharacter Character ) : void

This method is called when a character is discovered to have gone offline.

OnChatTell ( ACR_ServerCommunicator.GameCharacter Sender, ACR_ServerCommunicator.GamePlayer Recipient, string Message ) : void

This method is called when a chat tell IPC event is received.

OnConfigurationSyncTimer ( object StateInfo ) : void

This timer callback is invoked when the configuration sync timer has elapsed, in the context of a thread pool thread. Its purpose is to record an activation event for the query thread.

OnDisconnectPlayer ( ACR_ServerCommunicator.GamePlayer Player ) : void

This method is called when a disconnect player request is received.

OnPage ( ACR_ServerCommunicator.GamePlayer Sender, ACR_ServerCommunicator.GamePlayer Recipient, string Message ) : void

This method is called when a page IPC event is received.

OnPlayerLoaded ( ACR_ServerCommunicator.GamePlayer Player ) : void

This method is called when a player has had all of its data loaded from the database. The player is inserted already.

OnPurgeCachedCharacter ( ACR_ServerCommunicator.GamePlayer Player, string CharacterFileName ) : void

This method is called when a purge cached character request is received.

OnRunScript ( GameServer SourceServer, string ScriptName, string ScriptArgument ) : void

This method is called when a run script IPC event is received.

OnServerJoin ( GameServer Server ) : void

This method is called when a server is discovered to have come online. The server is inserted already.

OnServerLoaded ( GameServer Server ) : void

This method is called when a server has had all of its data loaded from the database. The server is inserted already.

OnServerPart ( GameServer Server ) : void

This method is called when a server is discovered to have gone offline.

OnShutdownServer ( string Message ) : void

This method is called when a server shutdown request is received.

OnUnsupportedIPCEventType ( int RecordId, int P0, int P1, int P2, int EventType, string P3 ) : void

This method is called when an unsupported IPC event code is received.

OnUpdateDatabaseOnlineTimer ( object StateInfo ) : void

This timer callback is invoked when it is time to rebroadcast the local server's view of whether the database is online or offline.

OnUpdateServerCheckinTimer ( object StateInfo ) : void

This timer callback is invoked when the update server checkin timer has elapsed, in the context of a thread pool thread. Its purpose is to record an activation event for the query thread.

PerformInitialSynchronization ( ) : void

This method performs the initial synchronization step at first run that downloads the initial character list. A bulk query is issued here to reduce the number of database round-trips at startup time. Note that no attempt is made to mark offline characters here. That step is done in the normal synchronization round, as this is the initial round anyway.

QueryDispatchThreadRoutine ( ) : void

This thread routine periodically queries the database for new events and updates the local state cache as appropriate. It also enqueues game events to the game event queue as required.

RunQueryCycle ( ) : void

This method polls the database for changes and updates the game world state as appropriate.

StartShutdownWatchdog ( int WatchdogTimeout ) : void

Start the shutdown server watchdog. A timer is begun and if the server has not shut down cleanly before the timer elapses, then the process is hard aborted.

SynchronizeConfiguration ( ) : void

This method synchronizes the configuration settings block with the database.

SynchronizeIPCEventQueue ( ) : void

This method synchronizes the IPC event queue for the server.

SynchronizeOnlineCharacters ( ) : void

This method synchronizes the online character list with the central database. Character join or part events are generated, as is appropriate.

SynchronizeOnlineServers ( ) : void

This method synchronizes the online status of the server list.

TransmitOutboundIPCEvents ( ) : void

This method transmits locally buffered, outboud IPC events to the routing entity (e.g. the database).

UpdateServerCheckinTimestamp ( ) : void

This method updates the checkin timestamp for ACR_TIME_SERVERTIME, for the local server. This must be periodically done from the query thread, as the main thread's DelayCommand (ACR_StoreTime()) may not run for an extended duration if the server is paused by a DM.

Method Details

ConvertToBoolean() public static method

Convert a database string to a Boolean value.
public static ConvertToBoolean ( string Str ) : bool
Str string Supplies the database string.
return bool

EnqueueAccountAssociationToPlayer() public method

Enqueue an account association event to a player for processing in the main thread. N.B. The world manager is assumed to be locked.
public EnqueueAccountAssociationToPlayer ( uint PlayerObject, string AccountAssociationSecret, string AccountAssociationURL ) : void
PlayerObject uint Supplies the local object id of the /// player to send to.
AccountAssociationSecret string Supplies the account /// association secret.
AccountAssociationURL string Supplies the base URL of the /// account association service.
return void

EnqueueMessageToPlayer() public method

Enqueue a message to a player for outbound transmission on the main server thread. N.B. The world manager is assumed to be locked.
public EnqueueMessageToPlayer ( uint PlayerObject, string Message ) : void
PlayerObject uint Supplies the local object id of the /// player to send to.
Message string Supplies the message text.
return void

GameWorldManager() public method

Create a new GameWorldManager.
public GameWorldManager ( int LocalServerId, string LocalServerName ) : System
LocalServerId int Supplies the server id of the local /// server.
LocalServerName string Supplies the server name of the local /// server, as referenced in the pwdata table in the database.
return System

IsEventPending() public method

Check whether an event might be pending, without taking the lock. Note that this is purely an advisory mechanism; the caller must repeatedly check as they may lose the race for when the event pending flag is set. The purpose of this function is to allow the main thread to avoid needlessly blocking on the query thread.
public IsEventPending ( ) : bool
return bool

IsEventQueueEmpty() public method

Check whether the event queue is empty.
public IsEventQueueEmpty ( ) : bool
return bool

ReferenceCharacterById() public method

Reference the data for a character by the character id. If the data was not yet available, it is retrieved from the database.
public ReferenceCharacterById ( int CharacterId, IALFADatabase Database ) : ACR_ServerCommunicator.GameCharacter
CharacterId int Supplies the object id.
Database IALFADatabase Supplies the database connection to use for /// queries, if required. The active rowset may be consumed.
return ACR_ServerCommunicator.GameCharacter

ReferenceCharacterById() public method

Reference the data for a character by the character id. If the data was not yet available, it is retrieved from the database.
public ReferenceCharacterById ( int CharacterId, IALFADatabase Database, bool InitialDMState ) : ACR_ServerCommunicator.GameCharacter
CharacterId int Supplies the object id.
Database IALFADatabase Supplies the database connection to use for /// queries, if required. The active rowset may be consumed.
InitialDMState bool Supplies the initial DM state of the /// backing player object to update, for a synchronization of an /// existing player with a new character.
return ACR_ServerCommunicator.GameCharacter

ReferenceCharacterByName() public method

Reference the data for a character by the character name. If the data was not yet available, it is retrieved from the database.
public ReferenceCharacterByName ( string CharacterName, IALFADatabase Database ) : ACR_ServerCommunicator.GameCharacter
CharacterName string Supplies the object name.
Database IALFADatabase Supplies the database connection to use for /// queries, if required. The active rowset may be consumed.
return ACR_ServerCommunicator.GameCharacter

ReferencePlayerById() public method

Reference the data for a player by the player id. If the data was not yet available, it is retrieved from the database.
public ReferencePlayerById ( int PlayerId, IALFADatabase Database ) : ACR_ServerCommunicator.GamePlayer
PlayerId int Supplies the object id.
Database IALFADatabase Supplies the database connection to use for /// queries, if required. The active rowset may be consumed.
return ACR_ServerCommunicator.GamePlayer

ReferencePlayerByName() public method

Reference the data for a player by the player name. If the data was not yet available, it is retrieved from the database.
public ReferencePlayerByName ( string PlayerName, IALFADatabase Database ) : ACR_ServerCommunicator.GamePlayer
PlayerName string Supplies the object name.
Database IALFADatabase Supplies the database connection to use for /// queries, if required. The active rowset may be consumed.
return ACR_ServerCommunicator.GamePlayer

ReferenceServerById() public method

Reference the data for a server by the server id. If the data was not yet available, it is retrieved from the database.
public ReferenceServerById ( int ServerId, IALFADatabase Database ) : GameServer
ServerId int Supplies the object id.
Database IALFADatabase Supplies the database connection to use for /// queries, if required. The active rowset may be consumed.
return GameServer

ReferenceServerByName() public method

Reference the data for a server by the server name. If the data was not yet available, it is retrieved from the database.
public ReferenceServerByName ( string ServerName, IALFADatabase Database ) : GameServer
ServerName string Supplies the object name.
Database IALFADatabase Supplies the database connection to use for /// queries, if required. The active rowset may be consumed.
return GameServer

RunQueue() public method

Run the event queue down. All events in the queue are given a chance to run.
public RunQueue ( ACR_ServerCommunicator Script, ALFA Database ) : void
Script ACR_ServerCommunicator Supplies the script object.
Database ALFA Supplies the database connection.
return void

SignalIPCEvent() public method

Signal an IPC event on a remote server by adding the event to the outbound event queue.
public SignalIPCEvent ( IPC_EVENT Event ) : void
Event IPC_EVENT Supplies the event to signal.
return void

SignalIPCEventWakeup() public method

Signal that the query thread should wake up to process IPC events soon. This may reduce the time until the next outbound event is sent. Note that, unlike most members, this method does not require any particular synchronization.
public SignalIPCEventWakeup ( ) : void
return void

SignalQueryThreadAction() public method

Signal a request to invoke an action in the context of the query thread. N.B. The routine should NOT be invoked with the world manager locked. Internal synchronization is provided.
public SignalQueryThreadAction ( QueryThreadAction Action ) : void
Action QueryThreadAction Supplies the action to enqueue to the query /// thread.
return void

SynchronizeInitialConfiguration() public method

Force synchronization of database configuration.
public SynchronizeInitialConfiguration ( IALFADatabase Database ) : void
Database IALFADatabase Supplies the database object to use for /// database connectivity.
return void

WriteDiagnosticLog() public method

This method is called to write a diagnostic log message to the main server log. The method is called with synchronization held on the WorldManager object.
public WriteDiagnosticLog ( string Message ) : void
Message string Supplies the message text to log.
return void