using System; using System.Threading; using Holo.Managers; using Holo.Socketservers; using Microsoft.VisualBasic; using Holo.Source.Managers; using Ion.Storage; using Holo.GameConnectionSystem; using Holo.Source.GameConnectionSystem; using Holo.Source.Managers.User; namespace Holo { /// /// The core of Holograph Emulator codename "Eucalypt", contains Main() void for booting server, plus monitoring thread and shutdown void. /// public class Eucalypt { private static Thread serverMonitor = new Thread(new ThreadStart(monitorServer)); public delegate void commonDelegate(); public static string dbHost; public static uint dbPort; public static string dbUsername; public static string dbPassword; public static string dbName; public static uint dbMaxConnections; public static int dbPool; public static DatabaseManager dbManager; public static Ion.Storage.Database database; private static void Main() { //Console.WindowHeight = Console.LargestWindowHeight - 25; //Console.WindowWidth = Console.LargestWindowWidth - 25; Console.CursorVisible = false; Out.WriteLine("Connect to DB.../Conectando a la BD"); ThreadPool.SetMaxThreads(300,400); DateTime _START = DateTime.Now; string sqlConfigLocation = IO.workingDirectory + @"\Config\Config.ini"; dbHost = IO.readINI("mysql", "host", sqlConfigLocation); dbPort = uint.Parse(IO.readINI("mysql", "port", sqlConfigLocation)); dbUsername = IO.readINI("mysql", "username", sqlConfigLocation); dbPassword = IO.readINI("mysql", "password", sqlConfigLocation); dbName = IO.readINI("mysql", "database", sqlConfigLocation); dbMaxConnections = uint.Parse(IO.readINI("mysql", "clientamount", sqlConfigLocation)); dbManager = new DatabaseManager(dbHost, dbPort, dbUsername, dbPassword, dbName, 1, 100); dbManager.SetClientAmount(dbMaxConnections); dbManager.StartMonitor(); int gamePort; int gameMaxConnections; int musPort; int musMaxConnections; string musHost; string langExt = Config.getTableEntry("lang"); if (langExt == "en") { Out.WriteLine("HabboX Created by Caselles!"); Out.WriteLine("Starting Emulator of the habbo!"); Out.WriteLine("Dowloand fuseright of the habbo"); Out.WriteLine("Loading rooms"); Out.WriteLine("Credits to: Hebbo,Klounter,kolesias123,Nillus,meth0d,dj_d2,KekoMundo,joselitoelgallo,Mikado and rikku"); Out.WriteLine("Loading sockets on the windows"); Out.WriteLine("HabboX Was started! :)"); } string espa = Config.getTableEntry("lang"); if (langExt == "es") { Out.WriteLine("HabboX a sido creado por Caselles"); Out.WriteLine("Iniciando emulador de habbo!"); Out.WriteLine("Descargando fuseright de habbo!"); Out.WriteLine("Cargando salas"); Out.WriteLine("Creditos a: Hebbo,Klounter,kolesias123,Nillus,meth0d,dj_d2,KekoMundo,joselitoelgallo,Mikado and rikku"); Out.WriteLine("Iniciando sockets de windows"); Out.WriteLine("HabboX se a iniciado :)"); } try { gamePort = int.Parse(Config.getTableEntry("server_game_port")); gameMaxConnections = int.Parse(Config.getTableEntry("server_game_maxconnections")); musPort = int.Parse(Config.getTableEntry("server_mus_port")); musMaxConnections = int.Parse(Config.getTableEntry("server_mus_maxconnections")); musHost = Config.getTableEntry("server_mus_host"); } catch { Out.WriteError("No se pudo conectar a la Base de datos"); Shutdown(); return; } #region Secciones stringManager.Init(langExt, false); stringManager.initFilter(false); eventManager.Init(); catalogueManager.Init(false); modeldataManager.Init(false); FuserightManager.Init(false); navigatorManager.Init(); recyclerManager.Init(false); rankManager.Init(false); roomManager.Init(); Config.Init(false); userManager.Init(); gameSocketServer.SetupSocket(); resetDynamics(); DateTime _STOP = DateTime.Now; TimeSpan _TST = _STOP - _START; Out.WriteLine("HabboX iniciado correctamente! :)"); GC.Collect(); serverMonitor.Priority = ThreadPriority.Lowest; serverMonitor.Start(); #endregion } public static void Shutdown()//Ya no se apaga ^^ { Out.WriteLine("HabboX Encontro un error interno,se pudo salvar!"); } private static void resetDynamics() { using (DatabaseClient dbClient = dbManager.GetClient()) { dbClient.runQuery("UPDATE system SET onlinecount = '0',onlinecount_peak = '0',connections_accepted = '0',activerooms = '0'"); dbClient.runQuery("UPDATE users SET ticket_sso = NULL"); dbClient.runQuery("UPDATE rooms SET visitors_now = '0'"); } } private static void monitorServer() { while(true) { int onlineCount = userManager.userCount; int peakOnlineCount = userManager.peakUserCount; int roomCount = roomManager.roomCount; int peakRoomCount = roomManager.peakRoomCount; int starvationNumber = dbManager.getStarvationNumber(); int acceptedConnections = gameSocketServer.acceptedConnections; long memUsage = GC.GetTotalMemory(false) / 2042; Console.Title = "HabboX V4 | Ususarios: " + onlineCount + " | Salas: " + roomCount + " | RAM: " + memUsage + "KB | Maximos on: " + peakOnlineCount + ""; using (DatabaseClient dbClient = dbManager.GetClient()) { dbClient.runQuery("UPDATE system SET onlinecount = '" + onlineCount + "',onlinecount_peak = '" + peakOnlineCount + "',activerooms = '" + roomCount + "',activerooms_peak = '" + peakRoomCount + "',connections_accepted = '" + acceptedConnections + "'"); } Thread.Sleep(10000); } } } }