public static void Destroy() { Logging.WriteLine("Destroying PhoenixEmu environment..."); if (GetGame() != null) { GetGame().Destroy(); Game = null; } if (GetConnectionManager() != null) { Logging.WriteLine("Destroying connection manager."); GetConnectionManager().GetListener().Destroy(); GetConnectionManager().DestroyManager(); ConnectionManager = null; } if (GetDatabase() != null) { try { Logging.WriteLine("Destroying database manager."); MySqlConnection.ClearAllPools(); DatabaseManager = null; } catch { } } Logging.WriteLine("Uninitialized successfully. Closing."); }
public void Initialize() { ServerStarted = DateTime.Now; TextManager.WritePhoenix(); try { Configuration = new ConfigurationData("config.conf"); DateTime now = DateTime.Now; Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Gray; DatabaseServer server = new DatabaseServer(GetConfig().data["db.hostname"], uint.Parse(GetConfig().data["db.port"]), GetConfig().data["db.username"], GetConfig().data["db.password"]); Database database = new Database(GetConfig().data["db.name"], uint.Parse(GetConfig().data["db.pool.minsize"]), uint.Parse(GetConfig().data["db.pool.maxsize"])); DatabaseManager = new DatabaseManager(server, database); Game = new Game(int.Parse(GetConfig().data["game.tcp.conlimit"])); Messages = new MessageHandler(); Messages.RegisterHandshake(); Messages.RegisterMessenger(); Messages.RegisterNavigator(); Messages.RegisterRoomsAction(); Messages.RegisterRoomsAvatar(); Messages.RegisterRoomsChat(); Messages.RegisterRoomsEngine(); Messages.RegisterRoomsFurniture(); Messages.RegisterRoomsPets(); Messages.RegisterRoomsSession(); Messages.RegisterRoomsSettings(); Messages.RegisterCatalog(); Messages.RegisterMarketplace(); Messages.RegisterRecycler(); Messages.RegisterQuest(); Messages.RegisterInventoryAchievements(); Messages.RegisterInventoryAvatarFX(); Messages.RegisterInventoryBadges(); Messages.RegisterInventoryFurni(); Messages.RegisterInventoryPurse(); Messages.RegisterInventoryTrading(); Messages.RegisterAvatar(); Messages.RegisterUsers(); Messages.RegisterRegister(); Messages.RegisterHelp(); Messages.RegisterSound(); Messages.RegisterWired(); Messages.RegisterFriendStream(); //NEW! MusListener = new MusSocket(GetConfig().data["mus.tcp.bindip"], int.Parse(GetConfig().data["mus.tcp.port"]), GetConfig().data["mus.tcp.allowedaddr"].Split(new char[] { ';' }), 20); ConnectionManager = new TcpConnectionManager(GetConfig().data["game.tcp.bindip"], int.Parse(GetConfig().data["game.tcp.port"]), int.Parse(GetConfig().data["game.tcp.conlimit"])); ConnectionManager.GetListener().Start(); TimeSpan span = DateTime.Now - now; Logging.WriteLine(string.Concat(new object[] { "Server -> READY! (", span.Seconds, " s, ", span.Milliseconds, " ms)" })); Console.Beep(); } catch (KeyNotFoundException) { Logging.WriteLine("Failed to boot, key not found."); Logging.WriteLine("Press any key to shut down ..."); Console.ReadKey(true); Destroy(); } catch (InvalidOperationException ex) { Logging.WriteLine("Failed to initialize PhoenixEmulator: " + ex.Message); Logging.WriteLine("Press any key to shut down ..."); Console.ReadKey(true); Destroy(); } }