Ejemplo n.º 1
0
        public Game(int conns)
        {
            this.ClientManager = new GameClientManager(conns);

            if (GoldTree.GetConfig().data["client.ping.enabled"] == "1")
            {
                this.ClientManager.method_10();
            }

            DateTime now = DateTime.Now;

            Logging.Write("Connecting to the database.. ");

            try
            {
                using (DatabaseClient dbClient = GoldTree.GetDatabase().GetClient())
                {
                    Logging.WriteLine("completed!", ConsoleColor.Green);

                    GoldTree.Game = this;
                    this.LoadServerSettings(dbClient);
                    this.BanManager           = new ModerationBanManager();
                    this.RoleManager          = new RoleManager();
                    this.HelpTool             = new HelpTool();
                    this.Catalog              = new Catalog();
                    this.Navigator            = new Navigator();
                    this.ItemManager          = new ItemManager();
                    this.RoomManager          = new RoomManager();
                    this.AdvertisementManager = new AdvertisementManager();
                    this.PixelManager         = new PixelManager();
                    this.AchievementManager   = new AchievementManager();
                    this.ModerationTool       = new ModerationTool();
                    this.BotManager           = new BotManager();
                    this.Marketplace          = new Marketplace();
                    this.QuestManager         = new QuestManager();
                    this.GoldTreeEnvironment  = new GoldTreeEnvironment();

                    this.Groups = new Groups();

                    GoldTreeEnvironment.LoadExternalTexts(dbClient);

                    this.BanManager.Initialise(dbClient);

                    this.RoleManager.method_0(dbClient);

                    this.HelpTool.method_0(dbClient);
                    this.HelpTool.method_3(dbClient);

                    this.ModerationTool.method_1(dbClient);
                    this.ModerationTool.method_2(dbClient);
                    this.ItemManager.method_0(dbClient);
                    this.Catalog.method_0(dbClient);
                    this.Catalog.method_1();
                    this.Navigator.method_0(dbClient);
                    this.RoomManager.method_8(dbClient);
                    this.RoomManager.method_0();
                    this.NavigatorCache = new NavigatorCache();
                    this.AdvertisementManager.method_0(dbClient);
                    this.BotManager.method_0(dbClient);
                    AchievementManager.smethod_0(dbClient);
                    this.PixelManager.method_0();
                    ChatCommandHandler.smethod_0(dbClient);
                    this.QuestManager.method_0();
                    Groups.smethod_0(dbClient);
                    this.RestoreStatistics(dbClient, 1);
                }
            }
            catch (MySql.Data.MySqlClient.MySqlException e)
            {
                Logging.WriteLine("failed!", ConsoleColor.Red);
                Logging.WriteLine(e.Message + " Check the given configuration details in config.conf\r\n", ConsoleColor.Yellow);
                GoldTree.Destroy("", true, true);

                return;
            }

            this.task_0 = new Task(new Action(LowPriorityWorker.Initialise));
            this.task_0.Start();

            StartGameLoop();
        }
Ejemplo n.º 2
0
        public static void Initialise()
        {
            double lastDatabaseUpdate = GoldTree.GetUnixTimestamp();

            while (true)
            {
                try
                {
                    DateTime now      = DateTime.Now;
                    TimeSpan timeSpan = now - GoldTree.ServerStarted;
                    new PerformanceCounter("Processor", "% Processor Time", "_Total");
                    int Status = 1;

                    int UsersOnline = GoldTree.GetGame().GetClientManager().ClientCount;
                    int RoomsLoaded = GoldTree.GetGame().GetRoomManager().LoadedRoomsCount;

                    try
                    {
                        if (GoldTree.GetConfig().data["shutdown-server"] != null)
                        {
                            DateTime shutdown_server_time = Convert.ToDateTime(GoldTree.GetConfig().data["shutdown-server"]);
                            var      time  = shutdown_server_time.TimeOfDay.TotalSeconds;
                            string   s     = DateTime.Now.ToString("HH:mm:ss");
                            DateTime dt2   = DateTime.ParseExact(s, "HH:mm:ss", CultureInfo.InvariantCulture);
                            var      time2 = dt2.TimeOfDay.TotalSeconds;
                            try
                            {
                                if (GoldTree.GetConfig().data["shutdown-warning-alert"] != null)
                                {
                                    if (time - time2 <= 60 && time - time2 >= 50)
                                    {
                                        try
                                        {
                                            if (int.Parse(GoldTree.GetConfig().data["shutdown-server-player-limit"]) < UsersOnline || int.Parse(GoldTree.GetConfig().data["shutdown-server-player-limit"]) <= 0)
                                            {
                                                string        str      = GoldTree.GetConfig().data["shutdown-warning-alert"];
                                                ServerMessage Message2 = new ServerMessage(808u);
                                                Message2.AppendStringWithBreak(GoldTreeEnvironment.GetExternalText("cmd_ha_title"));
                                                Message2.AppendStringWithBreak(str + "\r\n- " + "Hotel");
                                                ServerMessage Message3 = new ServerMessage(161u);
                                                Message3.AppendStringWithBreak(str + "\r\n- " + "Hotel");
                                                GoldTree.GetGame().GetClientManager().method_15(Message2, Message3);
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                            if (time - time2 <= 11 && time - time2 >= 0)
                            {
                                try
                                {
                                    if (int.Parse(GoldTree.GetConfig().data["shutdown-server-player-limit"]) < UsersOnline || int.Parse(GoldTree.GetConfig().data["shutdown-server-player-limit"]) <= 0)
                                    {
                                        GoldTree.Destroy("SERVER SHUTDOWN! YOU HAVE SETUP TO CONFIG.CONF FILE SHUTDOWN TIME!", true);
                                    }
                                }
                                catch
                                {
                                    GoldTree.Destroy("SERVER SHUTDOWN! YOU HAVE SETUP TO CONFIG.CONF FILE SHUTDOWN TIME!", true);
                                }
                            }
                        }
                    }
                    catch
                    {
                    }

                    double timestamp = GoldTree.GetUnixTimestamp() - lastDatabaseUpdate;

                    if (timestamp >= 30)
                    {
                        using (DatabaseClient dbClient = GoldTree.GetDatabase().GetClient())
                        {
                            dbClient.ExecuteQuery(string.Concat(new object[]
                            {
                                "UPDATE server_status SET stamp = UNIX_TIMESTAMP(), status = '", Status, "', users_online = '", UsersOnline, "', rooms_loaded = '", RoomsLoaded, "', server_ver = '", GoldTree.PrettyVersion, "' LIMIT 1"
                            }));
                            uint num3 = (uint)dbClient.ReadInt32("SELECT users FROM system_stats ORDER BY ID DESC LIMIT 1");
                            if ((long)UsersOnline > (long)((ulong)num3))
                            {
                                dbClient.ExecuteQuery(string.Concat(new object[]
                                {
                                    "UPDATE system_stats SET users = '",
                                    UsersOnline,
                                    "', rooms = '",
                                    RoomsLoaded,
                                    "' ORDER BY ID DESC LIMIT 1"
                                }));
                            }
                        }

                        lastDatabaseUpdate = timestamp;
                    }

                    GoldTree.GetGame().GetClientManager().method_23();

                    Console.Title = string.Concat(new object[]
                    {
                        "GTE 3.0 | Online Users: ",
                        UsersOnline,
                        " | Rooms Loaded: ",
                        RoomsLoaded,
                        " | Uptime: ",
                        timeSpan.Days,
                        " days, ",
                        timeSpan.Hours,
                        " hours and ",
                        timeSpan.Minutes,
                        " minutes"
                    });
                }
                catch (Exception ex)
                {
                    Program.DeleteMenu(Program.GetSystemMenu(Program.GetConsoleWindow(), true), Program.SC_CLOSE, Program.MF_BYCOMMAND);
                    Logging.LogThreadException(ex.ToString(), "Server status update task");
                }
                Thread.Sleep(5000);
            }
        }