public SetHostnameAndPort ( string AddressString ) : void | ||
AddressString | string | Supplies the address string to set the /// server network address information from. |
return | void |
/// <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> /// 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> /// 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. /// </summary> private void PerformInitialSynchronization() { IALFADatabase Database = DatabaseLinkQueryThread; List<InitialSynchronizationRow> Rowset = new List<InitialSynchronizationRow>(); Database.ACR_SQLQuery( "SELECT " + "`characters`.`ID` AS character_id, " + // 0 "`characters`.`PlayerID` AS player_id, " + // 1 "`characters`.`Name` AS character_name, " + // 2 "`characters`.`ServerID` AS server_id, " + // 3 "`characters`.`Location` AS character_location, " + // 4 "`players`.`IsDM` AS player_is_dm, " + // 5 "`players`.`Name` AS player_name, " + // 6 "`servers`.`IPAddress` AS server_address_string, " + // 7 "`servers`.`Name` AS server_name " + // 8 "FROM " + "`characters` " + "INNER JOIN `servers` ON `characters`.`ServerID` = `servers`.`ID` " + "INNER JOIN `players` ON `characters`.`PlayerID` = `players`.`ID` " + "WHERE " + "`characters`.`IsOnline` = 1 " ); while (Database.ACR_SQLFetch()) { InitialSynchronizationRow Row; Row.CharacterId = Convert.ToInt32(Database.ACR_SQLGetData(0)); Row.PlayerId = Convert.ToInt32(Database.ACR_SQLGetData(1)); Row.CharacterName = Database.ACR_SQLGetData(2); Row.ServerId = Convert.ToInt32(Database.ACR_SQLGetData(3)); Row.CharacterLocation = Database.ACR_SQLGetData(4); Row.PlayerIsDM = ConvertToBoolean(Database.ACR_SQLGetData(5)); Row.PlayerName = Database.ACR_SQLGetData(6); Row.ServerAddressString = Database.ACR_SQLGetData(7); Row.ServerName = Database.ACR_SQLGetData(8); Rowset.Add(Row); } lock (this) { // // Update entries. // foreach (InitialSynchronizationRow Row in Rowset) { GameServer Server = (from S in Servers where S.ServerId == Row.ServerId select S).FirstOrDefault(); if (Server == null) { Server = new GameServer(this); Server.ServerName = Row.ServerName; Server.ServerId = Row.ServerId; Server.SetHostnameAndPort(Row.ServerAddressString); InsertNewServer(Server, Database); } GamePlayer Player = (from P in Players where P.PlayerId == Row.PlayerId select P).FirstOrDefault(); if (Player == null) { Player = new GamePlayer(this); Player.PlayerName = Row.PlayerName; Player.PlayerId = Row.PlayerId; Player.IsDM = Row.PlayerIsDM; InsertNewPlayer(Player, Database); } GameCharacter Character = (from C in Characters where C.CharacterId == Row.CharacterId select C).FirstOrDefault(); if (Character == null) { Character = new GameCharacter(this); Character.CharacterId = Row.CharacterId; Character.PlayerId = Row.PlayerId; Character.Online = true; Character.CharacterName = Row.CharacterName; Character.LocationString = Row.CharacterLocation; InsertNewCharacter(Character, Row.ServerId, Database, null); } } #if DEBUG_MODE WriteDiagnosticLog(String.Format("GameWorldManager.PerformInitialSynchronization: Synchronized {0} servers, {1} players, {2} characters.", ServerList.Count, PlayerList.Count, CharacterList.Count)); #endif } }