Guest User

PlusEMU RecordOnline/Userpeak by Baykus(ctarikc)

a guest
Nov 7th, 2016
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Threading;
  5. using System.Collections.Generic;
  6.  
  7. using log4net;
  8. using Plus.Database.Interfaces;
  9.  
  10.  
  11. namespace Plus.HabboHotel.Global
  12. {
  13.     public class ServerStatusUpdater : IDisposable
  14.     {
  15.         private static ILog log = LogManager.GetLogger("Mango.Global.ServerUpdater");
  16.  
  17.         private const int UPDATE_IN_SECS = 30;
  18.  
  19.         private Timer _timer;
  20.        
  21.         public ServerStatusUpdater()
  22.         {
  23.         }
  24.  
  25.         public void Init()
  26.         {
  27.             this._timer = new Timer(new TimerCallback(this.OnTick), null, TimeSpan.FromSeconds(UPDATE_IN_SECS), TimeSpan.FromSeconds(UPDATE_IN_SECS));
  28.  
  29.             Console.Title = "Baykus Emulator - 0 users online - 0 geladen kamers - 0 dag(en) 0 uur(en) aan";
  30.  
  31.             log.Info("Server Status Updater has been started.");
  32.         }
  33.  
  34.         public void OnTick(object Obj)
  35.         {
  36.             this.UpdateOnlineUsers();
  37.         }
  38.  
  39.         private void UpdateOnlineUsers()
  40.         {
  41.             TimeSpan Uptime = DateTime.Now - PlusEnvironment.ServerStarted;
  42.  
  43.             int UsersOnline = Convert.ToInt32(PlusEnvironment.GetGame().GetClientManager().Count);
  44.             int RoomCount = PlusEnvironment.GetGame().GetRoomManager().Count;
  45.  
  46.             Console.Title = "Baykus Emulator - " + UsersOnline + " users online - " + RoomCount + "geladen kamers - " + Uptime.Days + " dag(en) " + Uptime.Hours + " uur(en) aan";
  47.  
  48.             using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  49.             {
  50.                 dbClient.SetQuery("UPDATE `server_status` SET `users_online` = @users, `loaded_rooms` = @loadedRooms LIMIT 1;");
  51.                 dbClient.AddParameter("users", UsersOnline);
  52.                 dbClient.AddParameter("loadedRooms", RoomCount);
  53.                 dbClient.RunQuery();
  54.             }
  55.  
  56.             int userPeak;
  57.             using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  58.             {
  59.                 dbClient.SetQuery("SELECT `userpeak` FROM `server_status` LIMIT 1");
  60.                 userPeak = dbClient.getInteger();
  61.             }
  62.             if (UsersOnline > userPeak)
  63.             {
  64.                 using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  65.                 {
  66.                     dbClient.SetQuery("UPDATE `server_status` SET `userpeak` = @userpeak LIMIT 1;");
  67.                     dbClient.AddParameter("userpeak", UsersOnline);
  68.                     dbClient.RunQuery();
  69.                 }
  70.             }
  71.         }
  72.  
  73.  
  74.         public void Dispose()
  75.         {
  76.             using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  77.             {
  78.                 dbClient.RunQuery("UPDATE `server_status` SET `users_online` = '0', `loaded_rooms` = '0'");
  79.             }
  80.  
  81.             this._timer.Dispose();
  82.             GC.SuppressFinalize(this);
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment