using System;
using System.Threading;
using Duck.Managers;
using Duck.Net.Game;
namespace Duck
{
///
/// The main entry point for Duck.
///
public static class Quack
{
#region Methods
///
/// The main entry point of the emulator. No arguments are supported.
///
///
public static void Main(string[] args)
{
Console.WindowHeight = Console.LargestWindowHeight - 25;
Console.WindowWidth = Console.LargestWindowWidth - 25;
Console.CursorVisible = false;
Console.Title = "Project Duck";
Console.ForegroundColor = ConsoleColor.DarkCyan;
IO.WritePlain("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
Console.ForegroundColor = ConsoleColor.Gray;
IO.WritePlain("Project DUCK");
IO.WritePlain("HABBO HOTEL V9 EMULATOR");
IO.WritePlain("WRITTEN BY: ");
IO.WritePlain(" PEDOBEAR APPROVED: false");
IO.WritePlain(" LANG: C#.NET 3.5");
Console.ForegroundColor = ConsoleColor.DarkCyan;
IO.WritePlain("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
Console.ForegroundColor = ConsoleColor.Gray;
Boot();
Console.ReadKey();
}
///
/// Starts up the Duck emulator.
///
public static void Boot()
{
IO.WriteBlank();
DateTime _START = DateTime.Now;
IO.WriteLine("Starting up Duck...");
ThreadPool.SetMaxThreads(300, 400);
IO.WriteLine("Expanded threadpool.");
IO.WriteLine(@"Checking for mysql.ini...");
string sqlConfigLocation = IO.workingDirectory + @"\mysql.ini";
if (System.IO.File.Exists(sqlConfigLocation) == false)
{
IO.WriteError("mysql.ini not found at " + sqlConfigLocation);
Shutdown();
return;
}
IO.WriteLine("mysql.ini found at " + sqlConfigLocation);
IO.WriteBlank();
string dbHost = IO.readINI("mysql", "host", sqlConfigLocation);
int dbPort = int.Parse(IO.readINI("mysql", "port", sqlConfigLocation));
string dbUsername = IO.readINI("mysql", "username", sqlConfigLocation);
string dbPassword = IO.readINI("mysql", "password", sqlConfigLocation);
string dbName = IO.readINI("mysql", "database", sqlConfigLocation);
if (DB.openConnection(dbHost, dbPort, dbName, dbUsername, dbPassword) == false)
{
Shutdown();
return;
}
Config.Init();
IO.WriteBlank();
Access.initAccessRanks();
IO.WriteBlank();
stringManager.Init(Config.getStringEntry("strings.language"));
int infoPort = Config.getNumericEntry("sockets.info.port");
int infoMaxConnections = Config.getNumericEntry("sockets.info.maxconnections");
int infoBackLog = Config.getNumericEntry("sockets.info.backlog");
if (infoSocketServer.Init(infoPort, infoMaxConnections, infoBackLog) == false)
{
Shutdown();
return;
}
userManager.Init();
IO.WriteBlank();
resetDynamics();
IO.WriteBlank();
printDatabaseStats();
IO.WriteBlank();
DateTime _STOP = DateTime.Now;
TimeSpan _TST = _STOP - _START;
IO.WriteLine("Startup time in fixed milliseconds: " + ((int)(_TST.TotalMilliseconds)).ToString() + ".");
GC.Collect();
IO.WriteLine("Project Duck is ready for connections.");
IO.minimumImportance = IO.logFlags.mehAction; // All logs
}
///
/// Safely shuts Duck down, closing database connections etc.
///
public static void Shutdown()
{
IO.WriteBlank();
DB.closeConnection();
IO.WriteLine("Quack. Shutdown completed. Press a key to exit.");
Console.ReadKey(true);
Environment.Exit(2);
}
#region Fancy methods
///
/// Prints the amount of registered users, the amount of created guestrooms and the amount of active furniture to the console.
///
private static void printDatabaseStats()
{
int userCount = DB.runRead("SELECT COUNT(*) FROM users", null);
int roomCount = DB.runRead("SELECT COUNT(*) FROM rooms", null);
int itemCount = DB.runRead("SELECT COUNT(*) FROM furniture", null);
IO.WriteLine("Result: " + userCount + " users, " + roomCount + " rooms and " + itemCount + " furnitures.");
}
private static void resetDynamics()
{
DB.runQuery("UPDATE duck_stats SET onlinecount = '0',onlinecount_peak = '0',connections_accepted = '0',activerooms = '0'");
DB.runQuery("UPDATE rooms SET visitors_now = '0'");
IO.WriteLine("Client connection statistics reset.");
IO.WriteLine("Room inside counts reset.");
}
#endregion
#endregion
}
}