/// Made by: Hebbo + Maarten, released by MoBaT [Under Permission].
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 Build = "PRE-RTM";
public static string Rev = "4.8.0.0";
public static string serverVersion = "R35";
public static string DcrVersion = "35_20090630_0501_18816";
public static string DcrHash = "a9e9d9ea454515efb391924f2c1fa9b9";
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 string Encryption;
public static string EncryptionVersion;
public static DatabaseManager dbManager;
public static Ion.Storage.Database database;
///
/// Starts up Holograph Emulator codename "Eucalypt".
///
private static void Main()
{
Console.WindowHeight = Console.LargestWindowHeight - 25;
Console.WindowWidth = Console.LargestWindowWidth - 25;
Console.CursorVisible = false;
Console.Title = "Life Emulator V35 ~HoloGraph Edit";
Out.WritePlain(serverVersion);
Out.WritePlain("RolePlaying Emulator,Edited By Him");
Out.WriteBlank();
Out.WritePlain("Revision 35");
Out.WritePlain("Holograph Emulator Created By Nillus, Edited by AresCJ");
Out.WritePlain("CORE: Eucalypt, C#.NET");
Out.WritePlain("CLIENT:" + DcrVersion);
Out.WritePlain("HASH CLIENT:" + DcrHash);
Out.WriteBlank();
Out.WriteBlank();
Boot();
}
///
/// Boots the emulator.
///
private static void Boot()
{
ThreadPool.SetMaxThreads(300,400);
DateTime _START = DateTime.Now;
Out.WriteLine("Starting up Holograph Emulator for " + Environment.UserName + "...");
string sqlConfigLocation = IO.workingDirectory + @"\Config\Config.ini";
string Encryption = IO.workingDirectory + @"\Config\Encryption.ini";
if (System.IO.File.Exists(sqlConfigLocation) == false)
{
Out.WriteError("Config.ini not found at " + sqlConfigLocation);
return;
}
Out.WriteLine("Config.ini found at " + sqlConfigLocation);
Out.WriteLine("Encryption.ini found at " + Encryption);
Out.WriteBlank();
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));
EncryptionVersion = IO.readINI("Encryption", "Ver", Encryption);
Encryption = IO.readINI("Encryption", "Hash", Encryption);
Out.WriteLine("Encryption Version : " + EncryptionVersion);
Out.WriteLine("Encryption Hash : " + Encryption);
Out.WriteBlank();
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;
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("system_config table contains invalid values for socket server configuration!");
Shutdown();
return;
}
string langExt = Config.getTableEntry("lang");
if (langExt == "")
{
Out.WriteError("No valid language extension [field: lang] was set in the system_config table!");
Shutdown();
return;
}
stringManager.Init(langExt, false);
Out.WriteBlank();
stringManager.initFilter(false);
Out.WriteBlank();
catalogueManager.Init(false);
Out.WriteBlank();
modeldataManager.Init(false);
Out.WriteBlank();
FuserightManager.Init(false);
Out.WriteBlank();
navigatorManager.Init();
Out.WriteBlank();
recyclerManager.Init(false);
Out.WriteBlank();
rankManager.Init(false);
Out.WriteBlank();
Config.Init(false);
userManager.Init();
Out.WriteBlank();
eventManager.Init();
Out.WriteBlank();
if (musSocketServer.Init(musPort, musHost) == false)
{
Shutdown();
return;
}
Out.WriteBlank();
gameSocketServer.SetupSocket();
Out.WriteBlank();
resetDynamics();
Out.WriteBlank();
DateTime _STOP = DateTime.Now;
TimeSpan _TST = _STOP - _START;
Out.WriteLine("Startup Time: " + _TST.TotalMilliseconds.ToString() + ".");
GC.Collect();
Out.WriteLine("Emulator Started. Ready for Connections!");
Out.WriteBlank();
Out.minimumImportance = Out.logFlags.MehAction; // All logs
serverMonitor.Priority = ThreadPriority.Lowest;
serverMonitor.Start();
}
///
/// Safely shutdowns Holograph Emulator, closing database and socket connections. Requires key press from user for final abort.
///
public static void Shutdown()
{
try
{
gameSocketServer.Destroy();
}
catch { }
Out.WriteBlank();
if(serverMonitor.IsAlive)
serverMonitor.Abort();
Out.WriteLine("Press any key to close the emulator.");
Console.ReadKey(true);
Environment.Exit(2);
}
///
/// Prints the usercount, guestroomcount and furniturecount in datebase to console.
///
private static void printDatabaseStats()
{
int userCount;
int roomCount;
int itemCount;
using (DatabaseClient dbClient = dbManager.GetClient())
{
userCount = dbClient.getInt("SELECT COUNT(*) FROM users");
roomCount = dbClient.getInt("SELECT COUNT(*) FROM rooms");
itemCount = dbClient.getInt("SELECT COUNT(*) FROM furniture");
}
Out.WriteLine("Result: " + userCount + " users, " + roomCount + " rooms and " + itemCount + " furnitures.");
}
private static void resetDynamics()
{
int maxOnline = 0;
using (DatabaseClient dbClient = dbManager.GetClient())
{
maxOnline = dbClient.getInt("SELECT onlinecount_peak FROM system");
dbClient.runQuery("UPDATE system SET onlinecount = '0',onlinecount_peak = '" + maxOnline + "',connections_accepted = '0',activerooms = '0'");
dbClient.runQuery("UPDATE users SET ticket_sso = NULL");
dbClient.runQuery("UPDATE rooms SET visitors_now = '0'");
Out.WriteLine("Client connection statistics reset.");
Out.WriteLine("Room inside counts reset.");
Out.WriteLine("Login tickets nulled.");
}
}
///
/// Threaded void. Ran on background thread at lowest priority, interval = 3500 ms. Updates console title and online users count, active rooms count, peak connections count and peak online users count in database.
///
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) / 1024;
GC.Collect();
Console.Title = "Life Emulator V35 ~HoloGraph Edit: | Connected Users: " + onlineCount + " | Loaded Rooms: " + roomCount + " | RAM usage: " + memUsage + "KB | Max Connections: " + peakOnlineCount + " | SQL Starvation: " + starvationNumber + " | SQL Connections: " + dbManager.databaseClients;
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);
}
}
}
}