/// <summary>
        /// This method reads the current configuration data from the
        /// database.
        /// </summary>
        /// <param name="Database">Supplies the database connection.</param>
        public void ReadConfigurationFromDatabase(IALFADatabase Database)
        {
            Database.ACR_SQLQuery("SELECT `variable`, `value` FROM `config`");

            while (Database.ACR_SQLFetch())
            {
                string VarName = Database.ACR_SQLGetData(0);
                string VarValue = Database.ACR_SQLGetData(1);

                if (VarName == "PlayerPassword")
                    PlayerPassword = VarValue;
                else if (VarName == "RestartWatchdogTimeout")
                    RestartWatchdogTimeout = Convert.ToInt32(VarValue);
                else if (VarName == "AccountAssociationSecret")
                    AccountAssociationSecret = VarValue;
                else if (VarName == "AccountAssociationUrl")
                    AccountAssociationUrl = VarValue;
                else if (VarName == "GetHostnameUrl")
                    GetHostnameUrl = VarValue;
                else if (VarName == "DefaultIrcGatewayId")
                    DefaultIrcGatewayId = Convert.ToInt32(VarValue);
                else if (VarName == "DefaultIrcRecipient")
                    DefaultIrcRecipient = VarValue;
                else if (VarName == "DisableSaveInQuarantine")
                    DisableSaveInQuarantine = Convert.ToInt32(VarValue) != 0;
            }
        }
        /// <summary>
        /// This routine returns the specified column of data from the current
        /// SQL rowset.
        /// </summary>
        /// <param name="ColumnIndex">Supplies the zero-based column index to
        /// retrieve.</param>
        /// <returns>The column data is returned.</returns>
        public string ACR_SQLGetData(int ColumnIndex)
        {
            IALFADatabase DefaultDatabase = ModuleLinkage.DefaultDatabase;

            if (DefaultDatabase != null)
            {
                return(DefaultDatabase.ACR_SQLGetData(ColumnIndex));
            }

            return(Script.NWNXGetString("SQL", "GETDATA", "", ColumnIndex));
        }
        /// <summary>
        /// This routine returns the number of rows affected by a query.
        /// </summary>
        /// <returns>The row count is returned.</returns>
        public int ACR_SQLGetAffectedRows()
        {
            IALFADatabase DefaultDatabase = ModuleLinkage.DefaultDatabase;

            if (DefaultDatabase != null)
            {
                return(DefaultDatabase.ACR_SQLGetAffectedRows());
            }

            return(Script.NWNXGetInt("SQL", "GET AFFECTED ROWS", "", 0));
        }
        /// <summary>
        /// This routine escapes characters for a SQL query.
        /// </summary>
        /// <param name="s">Supplies the string to escape.</param>
        /// <returns>The escaped string is returned.</returns>
        public string ACR_SQLEncodeSpecialChars(string s)
        {
            IALFADatabase DefaultDatabase = ModuleLinkage.DefaultDatabase;

            if (DefaultDatabase != null)
            {
                return(DefaultDatabase.ACR_SQLEncodeSpecialChars(s));
            }

            return(Script.NWNXGetString("SQL", "GET ESCAPE STRING", s, 0));
        }
        /// <summary>
        /// Retrieve the properties of the player from the database.
        /// </summary>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        public void PopulateFromDatabase(IALFADatabase Database)
        {
            Database.ACR_SQLQuery(String.Format(
                                      "SELECT `Name`, `IsDM` FROM `players` WHERE `ID` = {0}",
                                      PlayerId));

            if (!Database.ACR_SQLFetch())
            {
                throw new ApplicationException("Failed to populate data for player " + PlayerId);
            }

            PlayerName = Database.ACR_SQLGetData(0);
            IsDM       = GameWorldManager.ConvertToBoolean(Database.ACR_SQLGetData(1));
        }
        /// <summary>
        /// Retrieve the properties of the player from the database.
        /// </summary>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        public void PopulateFromDatabase(IALFADatabase Database)
        {
            Database.ACR_SQLQuery(String.Format(
                "SELECT `Name`, `IsDM` FROM `players` WHERE `ID` = {0}",
                PlayerId));

            if (!Database.ACR_SQLFetch())
            {
                throw new ApplicationException("Failed to populate data for player " + PlayerId);
            }

            PlayerName = Database.ACR_SQLGetData(0);
            IsDM = GameWorldManager.ConvertToBoolean(Database.ACR_SQLGetData(1));
        }
        /// <summary>
        /// Retrieve the properties of the server from the database.
        /// </summary>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        public void PopulateFromDatabase(IALFADatabase Database)
        {
            Database.ACR_SQLQuery(String.Format(
                "SELECT `Name`, `IPAddress` FROM `servers` WHERE `ID` = {0}",
                ServerId));

            if (!Database.ACR_SQLFetch())
            {
                throw new ApplicationException("Failed to populate data for server " + ServerId);
            }

            ServerName = Database.ACR_SQLGetData(0);
            SetHostnameAndPort(Database.ACR_SQLGetData(1));
        }
Example #8
0
        /// <summary>
        /// Retrieve the properties of the server from the database.
        /// </summary>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        public void PopulateFromDatabase(IALFADatabase Database)
        {
            Database.ACR_SQLQuery(String.Format(
                                      "SELECT `Name`, `IPAddress`, `IsPublic` FROM `servers` WHERE `ID` = {0}",
                                      ServerId));

            if (!Database.ACR_SQLFetch())
            {
                throw new ApplicationException("Failed to populate data for server " + ServerId);
            }

            ServerName = Database.ACR_SQLGetData(0);
            SetHostnameAndPort(Database.ACR_SQLGetData(1));
            Public = GameWorldManager.ConvertToBoolean(Database.ACR_SQLGetData(2));
        }
        /// <summary>
        /// Retrieve the properties of the character from the database.
        /// </summary>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        public void PopulateFromDatabase(IALFADatabase Database)
        {
            Database.ACR_SQLQuery(String.Format(
                "SELECT `Name`, `PlayerID`, `IsOnline`, `Location` FROM `characters` WHERE `ID` = {0}",
                CharacterId));

            if (!Database.ACR_SQLFetch())
            {
                throw new ApplicationException("Failed to populate data for character " + CharacterId);
            }

            CharacterName = Database.ACR_SQLGetData(0);
            PlayerId = Convert.ToInt32(Database.ACR_SQLGetData(1));
            IsOnline = GameWorldManager.ConvertToBoolean(Database.ACR_SQLGetData(2));
            LocationString = Database.ACR_SQLGetData(3);
        }
Example #10
0
        /// <summary>
        /// Retrieve the properties of the character from the database.
        /// </summary>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        public void PopulateFromDatabase(IALFADatabase Database)
        {
            Database.ACR_SQLQuery(String.Format(
                                      "SELECT `Name`, `PlayerID`, `IsOnline`, `Location` FROM `characters` WHERE `ID` = {0}",
                                      CharacterId));

            if (!Database.ACR_SQLFetch())
            {
                throw new ApplicationException("Failed to populate data for character " + CharacterId);
            }

            CharacterName  = Database.ACR_SQLGetData(0);
            PlayerId       = Convert.ToInt32(Database.ACR_SQLGetData(1));
            IsOnline       = GameWorldManager.ConvertToBoolean(Database.ACR_SQLGetData(2));
            LocationString = Database.ACR_SQLGetData(3);
        }
        /// <summary>
        /// Reference the data for a character by the character name.  If the
        /// data was not yet available, it is retrieved from the database.
        /// </summary>
        /// <param name="CharacterName">Supplies the object name.</param>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        /// <returns>The object data is returned, else null if the object did
        /// not exist.</returns>
        public GameCharacter ReferenceCharacterByName(string CharacterName, IALFADatabase Database)
        {
            //
            // Check if the object is already known first.
            //

            GameCharacter Character = (from C in Characters
                                       where C.CharacterName.Equals(CharacterName, StringComparison.InvariantCultureIgnoreCase)
                                       orderby C.Online descending
                                       select C).FirstOrDefault();

            if (Character != null)
                return Character;

            //
            // Need to pull the data from the database.
            //

            if (Database == null)
                return null;

            int ServerId;

            Database.ACR_SQLQuery(String.Format(
                "SELECT `ID`, `PlayerID`, `IsOnline`, `ServerID`, `Name`, `Location` FROM `characters` WHERE `Name` = '{0}' AND `IsDeleted` = 0 AND `IsPlayable` = 1 ORDER BY `ID` ASC ",
                Database.ACR_SQLEncodeSpecialChars(CharacterName)));

            if (!Database.ACR_SQLFetch())
                return null;

            Character = new GameCharacter(this);

            Character.CharacterId = Convert.ToInt32(Database.ACR_SQLGetData(0));
            Character.PlayerId = Convert.ToInt32(Database.ACR_SQLGetData(1));
            Character.Online = ConvertToBoolean(Database.ACR_SQLGetData(2));
            ServerId = Convert.ToInt32(Database.ACR_SQLGetData(3));
            Character.CharacterName = Database.ACR_SQLGetData(4);
            Character.LocationString = Database.ACR_SQLGetData(5);

            InsertNewCharacter(Character, ServerId, Database, null);

            return Character;
        }
        /// <summary>
        /// This routine fetches the next rowset from the database.
        /// </summary>
        /// <returns>Returns true if the query succeeded.</returns>
        public bool ACR_SQLFetch()
        {
            //const int SQL_ERROR = 0;
            const int SQL_SUCCESS = 1;

            IALFADatabase DefaultDatabase = ModuleLinkage.DefaultDatabase;

            if (DefaultDatabase != null)
            {
                return(DefaultDatabase.ACR_SQLFetch());
            }

            if (Script.NWNXGetInt("SQL", "FETCH", " ", 0) != SQL_SUCCESS)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #13
0
        /// <summary>
        /// Re-compute the online status for the server.
        /// </summary>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        public void RefreshOnlineStatus(IALFADatabase Database)
        {
            Database.ACR_SQLQuery(String.Format(
                                      "SELECT " +
                                      "`servers`.`ID` AS server_id " +
                                      "FROM `servers` " +
                                      "INNER JOIN `pwdata` ON `pwdata`.`Name` = `servers`.`Name` " +
                                      "WHERE `servers`.`ID` = {0} " +
                                      "AND pwdata.`Key` = 'ACR_TIME_SERVERTIME' " +
                                      "AND pwdata.`Last` >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 10 MINUTE) ",
                                      ServerId
                                      ));

            if (Database.ACR_SQLFetch())
            {
                Online         = true;
                DatabaseOnline = true;
            }
            else
            {
                Online         = false;
                DatabaseOnline = false;
            }
        }
        /// <summary>
        /// Re-compute the online status for the server.
        /// </summary>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        public void RefreshOnlineStatus(IALFADatabase Database)
        {
            Database.ACR_SQLQuery(String.Format(
                "SELECT " +
                    "`servers`.`ID` AS server_id " +
                "FROM `servers` " +
                "INNER JOIN `pwdata` ON `pwdata`.`Name` = `servers`.`Name` " +
                "WHERE `servers`.`ID` = {0} " +
                "AND pwdata.`Key` = 'ACR_TIME_SERVERTIME' " +
                "AND pwdata.`Last` >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 10 MINUTE) ",
                ServerId
                ));

            if (Database.ACR_SQLFetch())
            {
                Online = true;
                DatabaseOnline = true;
            }
            else
            {
                Online = false;
                DatabaseOnline = false;
            }
        }
 /// <summary>
 /// Reference the data for a character by the character id.  If the
 /// data was not yet available, it is retrieved from the database.
 /// </summary>
 /// <param name="CharacterId">Supplies the object id.</param>
 /// <param name="Database">Supplies the database connection to use for
 /// queries, if required.  The active rowset may be consumed.</param>
 /// <returns>The object data is returned, else null if the object did
 /// not exist.</returns>
 public GameCharacter ReferenceCharacterById(int CharacterId, IALFADatabase Database)
 {
     return ReferenceCharacterById(CharacterId, Database, null);
 }
        /// <summary>
        /// Reference the data for a character by the character id.  If the
        /// data was not yet available, it is retrieved from the database.
        /// </summary>
        /// <param name="CharacterId">Supplies the object id.</param>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        /// <param name="InitialDMState">Supplies the initial DM state of the
        /// backing player object to update, for a synchronization of an
        /// existing player with a new character.</param>
        /// <returns>The object data is returned, else null if the object did
        /// not exist.</returns>
        public GameCharacter ReferenceCharacterById(int CharacterId, IALFADatabase Database, bool? InitialDMState)
        {
            //
            // Check if the object is already known first.
            //

            GameCharacter Character = (from C in Characters
                                       where C.CharacterId == CharacterId
                                       select C).FirstOrDefault();

            if (Character != null)
                return Character;

            //
            // Need to pull the data from the database.
            //

            if (Database == null)
                return null;

            int ServerId;

            Database.ACR_SQLQuery(String.Format(
                "SELECT `Name`, `PlayerID`, `IsOnline`, `ServerID`, `Location` FROM `characters` WHERE `ID` = {0}",
                CharacterId));

            if (!Database.ACR_SQLFetch())
                return null;

            Character = new GameCharacter(this);

            Character.CharacterName = Database.ACR_SQLGetData(0);
            Character.CharacterId = CharacterId;
            Character.PlayerId = Convert.ToInt32(Database.ACR_SQLGetData(1));
            Character.Online = ConvertToBoolean(Database.ACR_SQLGetData(2));
            ServerId = Convert.ToInt32(Database.ACR_SQLGetData(3));
            Character.LocationString = Database.ACR_SQLGetData(4);

            InsertNewCharacter(Character, ServerId, Database, InitialDMState);

            return Character;
        }
        /// <summary>
        /// Reference the data for a server by the server id.  If the data
        /// was not yet available, it is retrieved from the database.
        /// </summary>
        /// <param name="ServerId">Supplies the object id.</param>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        /// <returns>The object data is returned, else null if the object did
        /// not exist.</returns>
        public GameServer ReferenceServerById(int ServerId, IALFADatabase Database)
        {
            //
            // Check if the object is already known first.
            //

            GameServer Server = (from S in Servers
                                 where S.ServerId == ServerId
                                 select S).FirstOrDefault();

            if (Server != null)
                return Server;

            //
            // Need to pull the data from the database.
            //

            if (Database == null)
                return null;

            Database.ACR_SQLQuery(String.Format(
                "SELECT `Name`, `IPAddress` FROM `servers` WHERE `ID` = {0}",
                ServerId));

            if (!Database.ACR_SQLFetch())
                return null;

            Server = new GameServer(this);

            Server.ServerName = Database.ACR_SQLGetData(0);
            Server.ServerId = ServerId;
            Server.SetHostnameAndPort(Database.ACR_SQLGetData(1));

            InsertNewServer(Server, Database);

            return Server;
        }
        /// <summary>
        /// Reference the data for a player by the player name.  If the data
        /// was not yet available, it is retrieved from the database.
        /// </summary>
        /// <param name="PlayerName">Supplies the object name.</param>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        /// <returns>The object data is returned, else null if the object did
        /// not exist.</returns>
        public GamePlayer ReferencePlayerByName(string PlayerName, IALFADatabase Database)
        {
            //
            // Check if the object is already known first.
            //

            GamePlayer Player = (from P in Players
                                 where P.PlayerName.Equals(PlayerName, StringComparison.InvariantCultureIgnoreCase)
                                 select P).FirstOrDefault();

            if (Player != null)
                return Player;

            //
            // Need to pull the data from the database.
            //

            if (Database == null)
                return null;

            Database.ACR_SQLQuery(String.Format(
                "SELECT `ID`, `IsDM`, `Name` FROM `players` WHERE `Name` = '{0}'",
                Database.ACR_SQLEncodeSpecialChars(PlayerName)));

            if (!Database.ACR_SQLFetch())
                return null;

            Player = new GamePlayer(this);

            Player.PlayerId = Convert.ToInt32(Database.ACR_SQLGetData(0));
            Player.IsDM = ConvertToBoolean(Database.ACR_SQLGetData(1));
            Player.PlayerName = Database.ACR_SQLGetData(2);

            InsertNewPlayer(Player, Database);

            return Player;
        }
 /// <summary>
 /// Force synchronization of database configuration.
 /// </summary>
 /// <param name="Database">Supplies the database object to use for
 /// database connectivity.</param>
 public void SynchronizeInitialConfiguration(IALFADatabase Database)
 {
     lock (this)
     {
         ConfigurationStore.ReadConfigurationFromDatabase(Database);
     }
 }
        /// <summary>
        /// This method reads the current configuration data from the
        /// database.
        /// </summary>
        /// <param name="Database">Supplies the database connection.</param>
        public void ReadConfigurationFromDatabase(IALFADatabase Database)
        {
            Database.ACR_SQLQuery("SELECT `variable`, `value` FROM `config`");

            while (Database.ACR_SQLFetch())
            {
                string VarName  = Database.ACR_SQLGetData(0);
                string VarValue = Database.ACR_SQLGetData(1);

                if (VarName == "PlayerPassword")
                {
                    PlayerPassword = VarValue;
                }
                else if (VarName == "RestartWatchdogTimeout")
                {
                    RestartWatchdogTimeout = Convert.ToInt32(VarValue);
                }
                else if (VarName == "AccountAssociationSecret")
                {
                    AccountAssociationSecret = VarValue;
                }
                else if (VarName == "AccountAssociationUrl")
                {
                    AccountAssociationUrl = VarValue;
                }
                else if (VarName == "GetHostnameUrl")
                {
                    GetHostnameUrl = VarValue;
                }
                else if (VarName == "DefaultIrcGatewayId")
                {
                    DefaultIrcGatewayId = Convert.ToInt32(VarValue);
                }
                else if (VarName == "DefaultIrcRecipient")
                {
                    DefaultIrcRecipient = VarValue;
                }
                else if (VarName == "ErrorNotifyIrcRecipient")
                {
                    ErrorNotifyIrcRecipient = VarValue;
                }
                else if (VarName == "DisableSaveInQuarantine")
                {
                    DisableSaveInQuarantine = Convert.ToInt32(VarValue) != 0;
                }
                else if (VarName == "ProtectionLevel")
                {
                    ProtectionLevel = (MemberProtectionLevel)Convert.ToInt32(VarValue);
                }
                else if (VarName == "VaultConnectionString")
                {
                    VaultConnectionString = VarValue;
                }
                else if (VarName == "UpdaterConnectionString")
                {
                    UpdaterConnectionString = VarValue;
                }
                else if (VarName == "VerboseVaultLogging")
                {
                    VerboseVaultLogging = Convert.ToInt32(VarValue) != 0;
                }
            }
        }
        /// <summary>
        /// Reference the data for a server by the server name.  If the data
        /// was not yet available, it is retrieved from the database.
        /// </summary>
        /// <param name="ServerName">Supplies the object name.</param>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        /// <returns>The object data is returned, else null if the object did
        /// not exist.</returns>
        public GameServer ReferenceServerByName(string ServerName, IALFADatabase Database)
        {
            //
            // Check if the object is already known first.
            //

            GameServer Server = (from S in Servers
                                 where S.ServerName.Equals(ServerName, StringComparison.InvariantCultureIgnoreCase)
                                 select S).FirstOrDefault();

            if (Server != null)
                return Server;

            //
            // Need to pull the data from the database.
            //

            if (Database == null)
                return null;

            Database.ACR_SQLQuery(String.Format(
                "SELECT `ID`, `IPAddress`, `Name` FROM `servers` WHERE `Name` = '{0}'",
                Database.ACR_SQLEncodeSpecialChars(ServerName)));

            if (!Database.ACR_SQLFetch())
                return null;

            Server = new GameServer(this);

            Server.ServerId = Convert.ToInt32(Database.ACR_SQLGetData(0));
            Server.SetHostnameAndPort(Database.ACR_SQLGetData(1));
            Server.ServerName = Database.ACR_SQLGetData(2);

            InsertNewServer(Server, Database);

            return Server;
        }
        /// <summary>
        /// This function inserts a character into the various character lists
        /// and issues the character join event.
        /// </summary>
        /// <param name="Character">Supplies the character object to insert.
        /// </param>
        /// <param name="ServerId">Supplies the server id that the player is
        /// logged on to (only meaningful if the character is online).</param>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        /// <param name="InitialDMState">Supplies the initial DM state of the
        /// backing player object to update, for a synchronization of an
        /// existing player with a new character.</param>
        private void InsertNewCharacter(GameCharacter Character, int ServerId, IALFADatabase Database, bool? InitialDMState)
        {
            GameServer Server;

            Character.Player = ReferencePlayerById(Character.PlayerId, Database);

            if (Character.Player == null)
                throw new ApplicationException(String.Format("Character {0} references invalid player id {1}", Character.CharacterId, Character.PlayerId));

            if (InitialDMState != null)
                Character.Player.IsDM = (InitialDMState != false);

            Character.Player.Characters.Add(Character);

            try
            {
                CharacterList.Add(Character);

                try
                {
                    if (Character.Online)
                    {
                        Server = ReferenceServerById(ServerId, Database);

                        if (Server == null)
                            throw new ApplicationException(String.Format("Character {0} is online but references invalid server id {1}", Character.CharacterId, ServerId));

                        Character.Server = Server;

                        //
                        // If the character is coming online, but its associated server is
                        // not actually online, then mark the character as offline.
                        //

                        if (Character.Online && !Character.Server.Online)
                        {
                            Character.Online = false;
                            return;
                        }

                        //
                        // Mark the character as visited so that if we come in
                        // on the main thread during the middle of a character
                        // synchronization cycle, we won't immediate offline
                        // the character.
                        //

                        Character.Visited = true;
                        Character.Server = Server;
                        Character.Server.Characters.Add(Character);

                        try
                        {
                            OnlineCharacterList.Add(Character);

                            try
                            {
                                Character.Player.UpdateOnlineCharacter();
                                OnCharacterJoin(Character);
                            }
                            catch
                            {
                                OnlineCharacterList.Remove(Character);
                                throw;
                            }
                        }
                        catch
                        {
                            Character.Server.Characters.Remove(Character);
                            throw;
                        }
                    }
                }
                catch
                {
                    CharacterList.Remove(Character);
                    throw;
                }
            }
            catch
            {
                Character.Player.Characters.Remove(Character);
                Character.Player.UpdateOnlineCharacter();
                throw;
            }
        }
        /// <summary>
        /// This function inserts a server into the various server lists and
        /// issues the server load event.
        /// </summary>
        /// <param name="Server">Supplies the server object to insert.
        /// </param>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        private void InsertNewServer(GameServer Server, IALFADatabase Database)
        {
            //
            // Mark the server as visited so that if we come in on the main
            // thread during the middle of a server synchronization cycle, we
            // won't immediate offline the server.
            //

            Server.Visited = true;
            Server.RefreshOnlineStatus(Database);

            ServerList.Add(Server);
            OnServerLoaded(Server);
        }
 /// <summary>
 /// This function inserts a player into the various player lists and
 /// issues the player load event.
 /// </summary>
 /// <param name="Player">Supplies the player object to insert.
 /// </param>
 /// <param name="Database">Supplies the database connection to use for
 /// queries, if required.  The active rowset may be consumed.</param>
 private void InsertNewPlayer(GamePlayer Player, IALFADatabase Database)
 {
     PlayerList.Add(Player);
     OnPlayerLoaded(Player);
 }
        /// <summary>
        /// Reference the data for a player by the player id.  If the data
        /// was not yet available, it is retrieved from the database.
        /// </summary>
        /// <param name="PlayerId">Supplies the object id.</param>
        /// <param name="Database">Supplies the database connection to use for
        /// queries, if required.  The active rowset may be consumed.</param>
        /// <returns>The object data is returned, else null if the object did
        /// not exist.</returns>
        public GamePlayer ReferencePlayerById(int PlayerId, IALFADatabase Database)
        {
            //
            // Check if the object is already known first.
            //

            GamePlayer Player = (from P in Players
                                 where P.PlayerId == PlayerId
                                 select P).FirstOrDefault();

            if (Player != null)
                return Player;

            //
            // Need to pull the data from the database.
            //

            if (Database == null)
                return null;

            Database.ACR_SQLQuery(String.Format(
                "SELECT `Name`, `IsDM` FROM `players` WHERE `ID` = {0}",
                PlayerId));

            if (!Database.ACR_SQLFetch())
                return null;

            Player = new GamePlayer(this);

            Player.PlayerName = Database.ACR_SQLGetData(0);
            Player.PlayerId = PlayerId;
            Player.IsDM = ConvertToBoolean(Database.ACR_SQLGetData(1));

            InsertNewPlayer(Player, Database);

            return Player;
        }