Example #1
0
        public void InitHandler()   //初试化Handler
        {
            CreateGameHandler createGameHandler = new CreateGameHandler();

            handlerDictionary.Add(createGameHandler.opCode, createGameHandler);
            JoinGameHandler joinGameHandler = new JoinGameHandler();

            handlerDictionary.Add(joinGameHandler.opCode, joinGameHandler);
            TeamChooseHandler teamChooseHandler = new TeamChooseHandler();

            handlerDictionary.Add(teamChooseHandler.opCode, teamChooseHandler);
            SyncTransformHandler syncTransformHandler = new SyncTransformHandler();

            handlerDictionary.Add(syncTransformHandler.opCode, syncTransformHandler);
            DamageHandler damageHandler = new DamageHandler();

            handlerDictionary.Add(damageHandler.opCode, damageHandler);
            SyncDropWeaponHandler syncDropWeaponHandler = new SyncDropWeaponHandler();

            handlerDictionary.Add(syncDropWeaponHandler.opCode, syncDropWeaponHandler);
            DeleteDropWeaponHandler deleteDropWeaponHandler = new DeleteDropWeaponHandler();

            handlerDictionary.Add(deleteDropWeaponHandler.opCode, deleteDropWeaponHandler);
            RestartHandler restartHandler = new RestartHandler();

            handlerDictionary.Add(restartHandler.opCode, restartHandler);
        }
Example #2
0
        public void CommandStop(MiNET.Player player, params string[] args)
        {
            if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Admin))
            {
                player.SendMessage("§c§l(!)§r §cYou do not have permission for this command.");
                return;
            }

            if (args.Length > 0)
            {
                if (args[0].Equals("now"))
                {
                    player.SendMessage("§cRebooting Server...");
                    RestartHandler.TriggerReboot(true);
                    return;
                }
                if (args[0].Equals("queue"))
                {
                    player.SendMessage("§cQueueing reboot...");
                    player.SendMessage("§7* Server should reboot after all games have finished their games.");
                    RestartHandler.TriggerReboot(false);
                    return;
                }
            }

            player.SendMessage("§c/stop now (Immediately stops the server)");
            player.SendMessage("§c/stop queue (Queues a reboot once all games are free to reboot)");
        }
Example #3
0
        public async Task RestartCommand()
        {
            await Context.Message.DeleteAsync();

            await ReplyAsync("Restarting...");

            RestartHandler.Restart();
        }
Example #4
0
        public async Task ShutdownCommand()
        {
            await Context.Message.DeleteAsync();

            await ReplyAsync("Shutting down...");

            RestartHandler.Shutdown();
        }
        public void FsChange_WontMakeRestart_WhenDllOutsideWatchedFolderChanged()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, @"C:\watchedFolder", dummyFsWatcherProxy);

            restartHandler.OnFsChange(@"C:\otherFolder\abc.dll");

            Assert.AreEqual(0, spyRestarter.CalledRestartsCount);
        }
        public void Dispose_WillDisposeFsWatcher_Always()
        {
            var spyFsWatcherProxy = new Fake_FsWatcherProxy();

            using (RestartHandler restartHandler = new RestartHandler())
            {
                restartHandler.Init(null, null, spyFsWatcherProxy);
            }

            Assert.IsTrue(spyFsWatcherProxy.CalledDispose);
        }
        public void FsChange_WillMakeRestart_WhenDllInWatchedFolderChanged()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, @"C:\watchedFolder", dummyFsWatcherProxy);

            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");

            Assert.IsTrue(spyRestarter.CalledRestartsCount > 0);
        }
Example #8
0
        //

        public void OnEnable(PluginContext context)
        {
            context.PluginManager.LoadCommands(new SkyCommands(this));      //Initialize Generic Commands
            context.PluginManager.LoadCommands(Permissions);                //Initialize Permission Commands
            context.PluginManager.LoadCommands(new GameCommands());         //Initialize GameController Commands (/gameedit)
            context.PluginManager.LoadCommands(new Whitelist());            //Initialize Whitelist Commands (/whitelist)

            //Register listeners
            context.Server.PlayerFactory.PlayerCreated += (sender, args) =>
            {
                _shouldSchedule = false;         //Avoid scheduling pending tasks once a player has joined

                MiNET.Player player = args.Player;

                player.PlayerLeave += OnPlayerLeave;

                if (_pendingTasks.Count > 0)
                {
                    foreach (PendingTask pendingTask in _pendingTasks)
                    {
                        RunnableTask.RunTaskLater(() =>
                        {
                            try
                            {
                                pendingTask.Invoke();
                            }
                            catch (Exception e)
                            {
                                BugSnagUtil.ReportBug(e, new AnonMetadatable((metadata) =>
                                {
                                    metadata.AddToTab("PendingTask", "Target", pendingTask.Target);
                                    metadata.AddToTab("PendingTask", "Method", pendingTask.Method);
                                }));
                            }
                        }, 5000);
                    }

                    _pendingTasks.Clear();
                }
            };

            //Trigger any post-launch tasks that cannot be run during startup
            foreach (GameController coreGameController in GameModes.Values)
            {
                coreGameController.PostLaunchTask();
            }

            //Start RestartHandler for Automatic Reboots
            RestartHandler.Start();

            SkyUtil.log("Initialized!");
        }
        public void FsChange_WontMakeMultipleRestarts_WhenMultipleFsChangesDetected()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, @"C:\watchedFolder", dummyFsWatcherProxy);

            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");
            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");
            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");

            Assert.AreEqual(1, spyRestarter.CalledRestartsCount);
        }
        public void FsChange_WontMakeRestart_WhenFsChangeDetectedBothDuringAndAfterLoadingTime()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, @"C:\watchedFolder", dummyFsWatcherProxy);

            restartHandler.OnLoadingBegin();
            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");
            restartHandler.OnLoadingEnd();
            restartHandler.OnFsChange(@"C:\watchedFolder\abc.dll");

            Assert.AreEqual(0, spyRestarter.CalledRestartsCount);
        }
Example #11
0
        /// <summary>
        ///     Asynchronous start of the connection.
        /// </summary>
        public async Task Start()
        {
            while (RestartHandler.KeepAlive)
            {
                try
                {
                    DownloadPrerequisites();
                    var config = _config.Read();
                    if (string.IsNullOrWhiteSpace(config.Token))
                    {
                        return;
                    }
                    _client = new DiscordSocketClient(new DiscordSocketConfig
                    {
                        LogLevel = LogSeverity.Verbose
                    });
                    _client.Log += Log;

                    IServiceCollection serviceCollection = new ServiceCollection();
                    ConfigureServices(serviceCollection);
                    _services = serviceCollection.BuildServiceProvider();

                    await _client.LoginAsync(TokenType.Bot, config.Token);

                    await _client.StartAsync();

                    await _client.SetActivityAsync(new Game("her Yukiteru Diary", ActivityType.Watching));

                    await _commandHandler.Initialize(_client, _services);

                    await _channelHandler.Initialize(_client, _services);

                    await _roleHandler.Initialize(_client, _services);

                    await _dblHandler.Initialize(_client, config);

                    await RestartHandler.AwaitRestart();
                }
                catch (Exception e)
                {
                    LogsHandler.Instance.Log("Main", $"Fatal exception occured. Restarting bot. Traceback: {e}");
                }
            }
        }
        public void Init_WillEnableRaisingEventsOfFsWatcherProxy_WhenFolderPathToWatchNotEmpty()
        {
            var spyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            {
                restartHandler.Init(null, @"D:\someFolder", spyFsWatcherProxy);
            }

            Assert.IsTrue(spyFsWatcherProxy.EnableRaisingEvents);
        }
        public void Init_WontEnableRaisingEventsOfFsWatcherProxy_WhenFolderPathToWatchEmpty()
        {
            var spyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            {
                restartHandler.Init(null, "", spyFsWatcherProxy);
            }

            Assert.IsFalse(spyFsWatcherProxy.EnableRaisingEvents);
        }
        public void IsAutoRestartPossible_ReturnsTrue_ByDefault()
        {
            bool autoRestartPossible = false;
            using (RestartHandler restartHandler = new RestartHandler())
            {
                autoRestartPossible = restartHandler.IsAutoRestartPossible();
            }

            Assert.IsTrue(autoRestartPossible);
        }
        public void IsAutoRestartPossible_ReturnsTrue_WhenFsChangeDetectedOnlyAfterLoadingTime()
        {
            RestartHandler restartHandler = new RestartHandler();
            restartHandler.OnLoadingBegin();
            restartHandler.OnLoadingEnd();

            restartHandler.OnFsChange(@"dummyPath.dll");

            Assert.IsTrue(restartHandler.IsAutoRestartPossible());
            restartHandler.Dispose();
        }
        public void RestartNow_WillMakeRestart_Always()
        {
            var dummyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            var spyRestarter = new Fake_AppRestarter();
            restartHandler.Init(spyRestarter, null, dummyFsWatcherProxy);

            restartHandler.RestartNow();

            Assert.IsTrue(spyRestarter.CalledRestartsCount > 0);
        }
        public void SettingIsAutoRestartPossible_WillFireIsAutoRestartPossibleChangedEvent_Always()
        {
            bool eventFired = false;
            RestartHandler restartHandler = new RestartHandler();
            restartHandler.IsAutoRestartPossibleChanged += (sender, args) => eventFired = true;

            restartHandler.OnLoadingBegin();
            restartHandler.OnFsChange(@"dummyPath.dll"); // shall fire IsAutoRestartPossibleChanged event

            Assert.IsTrue(eventFired);
            restartHandler.Dispose();
        }
        public void Init_WillSetWatchedFolderToFsWatcherProxy_Always()
        {
            var spyFsWatcherProxy = new Fake_FsWatcherProxy();
            RestartHandler restartHandler = new RestartHandler();
            {
                restartHandler.Init(null, @"D:\someFolder", spyFsWatcherProxy);
            }

            Assert.AreEqual(@"D:\someFolder", spyFsWatcherProxy.Path);
        }