コード例 #1
0
        public void Configure(MiNetServer server)
        {
            Server = server;

            SkyUtil.log("Hooking into MiNET.");

            Instance = this;
            SkyUtil.log("SkyCore Initializing...");

            //Initialize Bugsnag Exception Reporting
            BugSnagUtil.Init();

            SkyUtil.log($"Dev Mode: ({Config.GetProperty("dev-server", "false")})");
            try
            {
                if (Config.GetProperty("dev-server", "false").Equals("true"))
                {
                    IsDevelopmentServer = true;
                    SkyUtil.log("Initializing Server In Development Mode");

                    //Forcefully Enable Whitelist
                    Whitelist.LoadWhitelist();

                    if (!Whitelist.WhitelistContent.Enabled)
                    {
                        SkyUtil.log("Enforcing Whitelist");
                        Whitelist.WhitelistContent.Enabled = true;
                        Whitelist.SaveWhitelist();
                    }
                }
            }
            catch (Exception e)
            {
                BugSnagUtil.ReportBug(e);
            }

            ServerPath = Environment.CurrentDirectory;
            SkyUtil.log($"Registered Server Path at '{ServerPath}'");

            CurrentIp = new WebClient().DownloadString("http://icanhazip.com").Replace("\n", "") + ":" + Config.GetProperty("port", "19132");
            SkyUtil.log($"Registered current IP as {CurrentIp}");

            ExternalGameHandler.CurrentHostAddress = CurrentIp;

            BlockFactory.CustomBlockFactory = new SkyBlockFactory();
            server.LevelManager             = new SkyLevelManager(this);

            //Create Games once the LevelManager has been initialized to avoid launching without any levels

            ExternalGameHandler.Init(server);             //Start listening for game servers

            string serverGame = Config.GetProperty("game-type", "none");

            SkyUtil.log($"Setting up Custom Game {serverGame}...");
            GameType = serverGame;
            try
            {
                Type   gameControllerType = null;
                string gameName           = null;

                switch (serverGame)
                {
                case "murder":
                {
                    gameName           = "Murder Mystery";
                    gameControllerType = typeof(MurderGameController);
                    break;
                }

                case "build-battle":
                {
                    gameName           = "Build Battle";
                    gameControllerType = typeof(BuildBattleGameController);
                    break;
                }

                case "none":
                {
                    gameName = "Pure Hub";

                    //none -> hub
                    GameType = "hub";

                    gameControllerType = typeof(HubController);

                    break;
                }
                }

                if (gameControllerType == null)
                {
                    SkyUtil.log("No Game Loaded.");
                    return;
                }

                SkyUtil.log($"Initializing Game {gameName}...");
                _initializeCustomGame(Activator.CreateInstance(gameControllerType, this) as GameController);
                Thread.Sleep(1000);                 //Pause the main thread for a second to ensure the levels are setup and avoid any CME
                SkyUtil.log($"Finished Initializing {gameName}");

                //Register all remaining games
                bool spawnNPC = gameName.Equals("Pure Hub");

                ExternalGameHandler.RegisterGameIntent("murder", spawnNPC);
                ExternalGameHandler.RegisterGameIntent("build-battle", spawnNPC);
                ExternalGameHandler.RegisterGameIntent("block-hunt", spawnNPC);
                ExternalGameHandler.RegisterGameIntent("bed-wars", spawnNPC);
            }
            catch (Exception e)
            {
                BugSnagUtil.ReportBug(e);
                //TODO: Prevent players joining
            }

            //

            Permissions          = new SkyPermissions(this);
            server.PlayerFactory = new SkyPlayerFactory {
                SkyCoreApi = this
            };

            SkyUtil.log("Finished Hooks.");
        }