Exemple #1
0
        public Game(int conns)
        {
            this.ClientManager = new GameClientManager(conns);

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

            DateTime now = DateTime.Now;

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

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

                    Essential.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.PixelManager         = new PixelManager();
                    this.AchievementManager   = new AchievementManager();
                    this.ModerationTool       = new ModerationTool();
                    this.BotManager           = new BotManager();
                    this.Marketplace          = new Marketplace();
                    this.QuestManager         = new QuestManager();
                    this.EssentialEnvironment = new EssentialEnvironment();
                    this.GamesManager         = new GamesManager();
                    this.Groups    = new Groups();
                    this.StormWars = new WarsData();
                    EssentialEnvironment.LoadExternalTexts(dbClient);

                    this.BanManager.Initialise(dbClient);

                    this.RoleManager.Initialize(dbClient);

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

                    this.ModerationTool.method_1(dbClient);
                    this.ModerationTool.method_2(dbClient);
                    this.ItemManager.Initialize(dbClient);
                    this.Catalog.Initialize(dbClient);
                    this.Catalog.InitializeCache();
                    PetRace.Init(dbClient);
                    this.Navigator.Initialize(dbClient);
                    this.RoomManager.method_8(dbClient);
                    this.RoomManager.method_0();
                    this.NavigatorCache = new NavigatorCache();
                    this.RoomManager.LoadMagicTiles(dbClient);
                    this.RoomManager.LoadBillboards(dbClient);
                    this.BotManager.Initialize(dbClient);
                    AchievementManager.Load(dbClient);
                    this.PixelManager.Initialize();
                    ChatCommandHandler.Initialize(dbClient);
                    this.QuestManager.Initialize();
                    // this.GamesManager.LoadGameLocales(dbClient);
                    // this.GamesManager.LoadPowerupPackages(dbClient);
                    Groups.Initialize(dbClient);
                    guideManager = new GuideManager(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);
                Essential.Destroy("", true, true);

                return;
            }

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

            StartGameLoop();
        }
Exemple #2
0
        public void HandleRequest(string Request, SocketConnection socket)
        {
            //Yes, i know, that's shitty coded, but it works. At least for me.. Do it better & don't hate me :)
            bool f = false;

            if (Request.StartsWith("GET"))
            {
                string[] Splits = Request.Split(' ');
                if (Request.Split(' ')[1].Equals("/"))
                {
                    socket.SendFile("web/index.html");
                }

                else if (Request.Split(' ')[1].StartsWith("/emu/console"))
                {
                    List <string> alreadySent = new List <string>();
                    if (Splits[1].Split('?')[1].StartsWith("key") && Splits[1].Split('?')[1].Split('=')[1] == Essential.GetConfig().data["web.key"])
                    {
                        try
                        {
                            string[] asdf = Essential.GetConsoleWriter().GetLines();
                            foreach (string line in asdf.ToList <string>())
                            {
                                socket.SendMessage(line + "\n");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                else if (Request.Split(' ')[1].StartsWith("/emu/exceptions"))
                {
                    if (Splits[1].Split('?')[1].StartsWith("key") && Splits[1].Split('?')[1].Split('=')[1] == Essential.GetConfig().data["web.key"])
                    {
                        socket.SendFile("exceptions.err");
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                else if (Request.Split(' ')[1].StartsWith("/emu/restart"))
                {
                    if (Splits[1].Split('?')[1].StartsWith("key") && Splits[1].Split('?')[1].Split('=')[1] == Essential.GetConfig().data["web.key"])
                    {
                        socket.SendMessage("Bye!");
                        this.Close(socket);
                        Console.Clear();
                        Core.Logging.Disable();
                        Essential.Destroy("Disposing.......", false);
                        Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
                        Environment.Exit(0);
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                else if (Request.Split(' ')[1].StartsWith("/emu/console/clear"))
                {
                    if (Splits[1].Split('?')[1].StartsWith("key") && Splits[1].Split('?')[1].Split('=')[1] == Essential.GetConfig().data["web.key"])
                    {
                        Console.Clear();
                        Essential.GetConsoleWriter().ClearIt();
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                else if (Request.Split(' ')[1].StartsWith("/api/furni"))
                {
                    if (Splits[1].Split('?')[1].StartsWith("name"))
                    {
                        FurniImage.HandleRequest(Splits[1].Split('?')[1].Split('=')[1], socket);
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                {
                    socket.SendFile("web" + Request.Split(' ')[1]);
                }
            }
            else if (Request.StartsWith("POST"))
            {
                if (Request.Split(' ')[1].Equals("/"))
                {
                    socket.SendFile("web/index.html");
                }
                else
                {
                    socket.SendFile("web" + Request.Split(' ')[1]);
                }
            }
            if (!f)
            {
                this.Close(socket);
            }
        }