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
}
}