Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Collections.Generic;
- using log4net;
- using Plus.Database.Interfaces;
- namespace Plus.HabboHotel.Global
- {
- public class ServerStatusUpdater : IDisposable
- {
- private static ILog log = LogManager.GetLogger("Mango.Global.ServerUpdater");
- private const int UPDATE_IN_SECS = 30;
- private Timer _timer;
- public ServerStatusUpdater()
- {
- }
- public void Init()
- {
- this._timer = new Timer(new TimerCallback(this.OnTick), null, TimeSpan.FromSeconds(UPDATE_IN_SECS), TimeSpan.FromSeconds(UPDATE_IN_SECS));
- Console.Title = "Baykus Emulator - 0 users online - 0 geladen kamers - 0 dag(en) 0 uur(en) aan";
- log.Info("Server Status Updater has been started.");
- }
- public void OnTick(object Obj)
- {
- this.UpdateOnlineUsers();
- }
- private void UpdateOnlineUsers()
- {
- TimeSpan Uptime = DateTime.Now - PlusEnvironment.ServerStarted;
- int UsersOnline = Convert.ToInt32(PlusEnvironment.GetGame().GetClientManager().Count);
- int RoomCount = PlusEnvironment.GetGame().GetRoomManager().Count;
- Console.Title = "Baykus Emulator - " + UsersOnline + " users online - " + RoomCount + "geladen kamers - " + Uptime.Days + " dag(en) " + Uptime.Hours + " uur(en) aan";
- using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.SetQuery("UPDATE `server_status` SET `users_online` = @users, `loaded_rooms` = @loadedRooms LIMIT 1;");
- dbClient.AddParameter("users", UsersOnline);
- dbClient.AddParameter("loadedRooms", RoomCount);
- dbClient.RunQuery();
- }
- int userPeak;
- using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.SetQuery("SELECT `userpeak` FROM `server_status` LIMIT 1");
- userPeak = dbClient.getInteger();
- }
- if (UsersOnline > userPeak)
- {
- using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.SetQuery("UPDATE `server_status` SET `userpeak` = @userpeak LIMIT 1;");
- dbClient.AddParameter("userpeak", UsersOnline);
- dbClient.RunQuery();
- }
- }
- }
- public void Dispose()
- {
- using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.RunQuery("UPDATE `server_status` SET `users_online` = '0', `loaded_rooms` = '0'");
- }
- this._timer.Dispose();
- GC.SuppressFinalize(this);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment