private void Work() { try { ConnectEntity(); //we do this here to ensure single threaded on handle! // Program.Entity.Users.Count(); //force connection to be open & test //Log.WriteLine(LogLevel.Info, "Database Initialized at {0}", Settings.Instance.Entity.DataCatalog); } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, "Error initializing database: {0}", ex.ToString()); return; } Action action; while (this.IsRunning) { while (callbacks.TryDequeue(out action)) { try { UserWorkItem Work = new UserWorkItem(action); Work.Queue(); //action(); } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, ex.ToString()); } } Thread.Sleep(sleep); } Log.WriteLine(LogLevel.Info, "Server stopped handling callbacks."); }
private void Work() { while (Program.ServiceInfo == null) { System.Threading.Thread.Sleep(200); // Wait.. } try { // Estrella.Database.DatabaseHelper.Initialize(Settings.Instance.WorldConnString, "WorkerConn"); // Program.Entity.Characters.Count(); //test if database is online Log.WriteLine(LogLevel.Info, "Database Initialized."); } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, "Error initializing database: {0}", ex.ToString()); return; } Action action; ulong last = 0; DateTime lastCheck = DateTime.Now; DateTime lastPing = DateTime.Now; DateTime lastGC = DateTime.Now; DateTime lastClientTime = DateTime.Now; DateTime LastMountCheck = DateTime.Now; for (ulong i = 0; ; i++) { if (!this.IsRunning) { break; } try { DateTime now = Program.CurrentTime; while (callbacks.TryDequeue(out action)) { try { UserWorkItem Work = new UserWorkItem(action); Work.Queue(); // action(); } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, ex.ToString()); } } if (now.Subtract(lastCheck).TotalSeconds >= 1) { TicksPerSecond = i - last; last = i; lastCheck = now; //Log.WriteLine(LogLevel.Debug, "TicksPerSecond: {0}", TicksPerSecond); if (TicksPerSecond <= 100) { Log.WriteLine(LogLevel.Warn, "Server overload! Only {0} ticks per second!", TicksPerSecond); } } if (now.Subtract(lastPing).TotalSeconds >= 300) { ClientManager.Instance.PingCheck(); lastPing = now; } if (now.Subtract(lastGC).TotalSeconds >= 300) { GC.Collect(); lastGC = now; } if (now.Subtract(lastClientTime).TotalSeconds >= 60) { } if (now.Subtract(LastMountCheck).TotalSeconds >= 30) { ClientManager.Instance.UpdateMountTicks(now); LastMountCheck = now; } if (i % 2000 == 0 && MapManager.Instance != null) { foreach (var val in MapManager.Instance.Maps) { foreach (var map in val.Value) { map.Update(now); //test } } } if (i % ticksToSleep == 0) // No max load but most ticks to be parsed. Epic win! { Program.CurrentTime = DateTime.Now; // Laaast update Thread.Sleep(sleep); } } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, "Ohgod. {0}", ex.ToString()); } } Log.WriteLine(LogLevel.Info, "Server stopped handling callbacks."); }
private void Work() { try { //ConnectEntity(); // Program.Entity.Characters.Count(); //test if database is online // Log.WriteLine(LogLevel.Info, "Database Initialized at {0}", Settings.Instance.Entity.DataCatalog); } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, "Error initializing database: {0}", ex.ToString()); return; } Action action; DateTime pingCheckRan = DateTime.Now; DateTime lastClientTime = DateTime.Now; ulong last = 0; DateTime lastCheck = DateTime.Now; for (ulong i = 0; ; i++) { if (!this.IsRunning) break; DateTime now = DateTime.Now; while (callbacks.TryDequeue(out action)) { try { UserWorkItem Work = new UserWorkItem(action); Work.Queue(); //action(); } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, ex.ToString()); } } if (now.Subtract(pingCheckRan).TotalSeconds >= 15) { // Just check every minute ClientManager.Instance.PingCheck(now); pingCheckRan = now; } if (now.Subtract(lastCheck).TotalSeconds >= 1) { TicksPerSecond = i - last; last = i; lastCheck = now; //Log.WriteLine(LogLevel.Debug, "TicksPerSecond: {0}", TicksPerSecond); if (TicksPerSecond <= 100) { Log.WriteLine(LogLevel.Warn, "Server overload! Only {0} ticks per second!", TicksPerSecond); } } if (now.Subtract(lastClientTime).TotalSeconds >= 60) { ClientManager.Instance.UpdateClientTime(now); lastClientTime = now; } if (i % TicksToSleep == 0) { Program.CurrentTime = DateTime.Now; Thread.Sleep(sleep); } } Log.WriteLine(LogLevel.Info, "Server stopped handling callbacks."); }