public void Load() { Program.MainForm.LogAppend("Reading Config File... ", false); LoadConfig(ServerConfigFile); LoadClientPatchData(ServerConfigFile); LoadDBConfig(Path.Combine(Environment.CurrentDirectory, "..", "DataSvr", "Database.img")); Program.MainForm.LogAppend(" Done!", false); Program.MainForm.LogAppend("Starting to patch... ", false); DataBasePatcher.StartPatching(UsersDatabase, Path.Combine(Application.StartupPath, "evolutions", "login"), "login"); Program.MainForm.LogAppend(" Done!", false); MasterThread.RepeatingAction.Start("Center Reconnect Timer", time => { foreach (var kvp in Worlds) { if (kvp.Value.IsConnected) { continue; } try { kvp.Value.Connect(); } catch { } } }, 0, 5000); using (var reader = UsersDatabase.RunQuery( "SELECT private_ip FROM servers WHERE configname = '" + Name + "' AND world_id = 0" ) as MySqlDataReader) { if (reader != null && reader.Read()) { // Server exists, try to migrate var privateIp = reader.GetString("private_ip"); Program.MainForm.LogAppend("Starting migration... {0}:{1}", privateIp, LTLPort); reader.Close(); try { bool wasConnected = false; LoginToLoginConnection = new LoginToLoginConnection(privateIp, LTLPort); for (var i = 0; i < 10; i++) { System.Threading.Thread.Sleep(100); if (LoginToLoginConnection.Disconnected == false) { wasConnected = true; break; } } if (!wasConnected) { LoginToLoginConnection.PreventConnectFromSucceeding = true; Program.MainForm.LogAppend("Not able to migrate as server is not accessible."); StartLTLAcceptor(); StartListening(); } else { Program.MainForm.LogAppend("Connected to LTL acceptor"); InMigration = false; var pw = new Packet(ISServerMessages.ServerMigrationUpdate); pw.WriteByte((byte)ServerMigrationStatus.StartMigration); LoginToLoginConnection.SendPacket(pw); } } catch (Exception ex) { Program.MainForm.LogAppend("Migration failed! {0}", ex); // It failed. StartLTLAcceptor(); StartListening(); } } else { StartLTLAcceptor(); StartListening(); } } UsersDatabase.SetupPinger(MasterThread.Instance); DiscordReporter.Username = Name; ServerTraceDiscordReporter = new DiscordReporter(DiscordReporter.ServerTraceURL); }
public void Load() { Program.MainForm.LogAppend("Reading Config File... ", false); LoadConfig(Path.Combine(Environment.CurrentDirectory, "..", "DataSvr", ConfigName + ".img")); LoadDBConfig(Path.Combine(Environment.CurrentDirectory, "..", "DataSvr", "Database.img")); ReloadEvents(); Program.MainForm.UpdateServerList(); Program.MainForm.LogAppend(" Done!", false); Program.MainForm.LogAppend("Starting to patch... ", false); DataBasePatcher.StartPatching(CharacterDatabase, Path.Combine(Application.StartupPath, "evolutions", "center"), "center"); Program.MainForm.LogAppend(" Done!", false); using (var reader = CharacterDatabase.RunQuery( "SELECT private_ip FROM servers WHERE configname = 'Center' AND world_id = " + World.ID ) as MySqlDataReader) { if (reader != null && reader.Read()) { // Server exists, try to migrate Program.MainForm.LogAppend("Starting migration..."); var privateIp = reader.GetString("private_ip"); reader.Close(); // Close reader here to prevent next updates to error try { bool wasConnected = false; CenterToCenterConnection = new CenterToCenterConnection(privateIp, CTCPort); for (var i = 0; i < 10; i++) { System.Threading.Thread.Sleep(100); if (CenterToCenterConnection.Disconnected == false) { wasConnected = true; break; } } if (!wasConnected) { // Timeout CenterToCenterConnection.PreventConnectFromSucceeding = true; CenterToCenterConnection = null; Program.MainForm.LogAppend("Not able to migrate as server is not accessible."); StartCTCAcceptor(); StartListening(); } else { Program.MainForm.LogAppend("Connected to CTC acceptor"); InMigration = false; var pw = new Packet(ISServerMessages.ServerMigrationUpdate); pw.WriteByte((byte)ServerMigrationStatus.StartMigration); CenterToCenterConnection.SendPacket(pw); } } catch (Exception ex) { Program.MainForm.LogAppend("Migration failed! {0}", ex); // It failed. StartCTCAcceptor(); StartListening(); } } else { StartCTCAcceptor(); StartListening(); } } CharacterDatabase.SetupPinger(MasterThread.Instance); MasterThread.RepeatingAction.Start("WorldServer event checker", World.CheckForEvents, 0, 2000); }