Ejemplo n.º 1
0
        public async Task Test_CommandProcessing_IsBroadcastCommand()
        {
            string broadcastPrefix = "@@";
            var    config          = ConfigurationGenerators.CreateApplicationConfiguration();

            config.BroadcastCommandPrefix = broadcastPrefix;
            var server = serviceProvider.GetRequiredService <IW4MServer>();

            var cmd = EventGenerators.GenerateEvent(GameEvent.EventType.Command, $"{broadcastPrefix}{nameof(MockCommand)}", server);

            var result = await CommandProcessing.ValidateCommand(cmd, config);

            Assert.AreEqual(nameof(MockCommand), result.Name);
            Assert.IsTrue(result.IsBroadcast);
        }
Ejemplo n.º 2
0
        public async Task Test_Ban_WithGlobalRule()
        {
            var expectedReason = "testglobalrule";

            appConfig.GlobalRules = new[] { expectedReason };
            var command   = serviceProvider.GetRequiredService <BanCommand>();
            var server    = serviceProvider.GetRequiredService <IW4MServer>();
            var gameEvent = EventGenerators.GenerateEvent(GameEvent.EventType.Command, "rule1", server);

            gameEvent.Origin.CurrentServer = server;
            gameEvent.Target = gameEvent.Origin;

            await command.ExecuteAsync(gameEvent);

            Assert.NotNull(mockEventHandler.Events
                           .FirstOrDefault(e => e.Data == expectedReason &&
                                           e.Type == GameEvent.EventType.Ban));
        }
Ejemplo n.º 3
0
        public async Task Test_LoadMap_FindsMapName_FromPartialAlias()
        {
            var cmd        = serviceProvider.GetRequiredService <LoadMapCommand>();
            var server     = serviceProvider.GetRequiredService <IW4MServer>();
            var rconParser = serviceProvider.GetRequiredService <IRConParser>();

            server.Maps.Add(new Map()
            {
                Name  = "mp_test",
                Alias = "test"
            });
            var gameEvent = EventGenerators.GenerateEvent(GameEvent.EventType.Command, server.Maps.First().Name, server);

            await cmd.ExecuteAsync(gameEvent);

            A.CallTo(() => rconParser.ExecuteCommandAsync(A <IRConConnection> .Ignored, A <string> .That.Contains(server.Maps[0].Name)))
            .MustHaveHappened();
        }
Ejemplo n.º 4
0
        public void Test_LoadMap_WaitsAppropriateTime_BeforeExecutingCommand()
        {
            var cmd        = serviceProvider.GetRequiredService <LoadMapCommand>();
            var server     = serviceProvider.GetRequiredService <IW4MServer>();
            var rconParser = serviceProvider.GetRequiredService <IRConParser>();

            server.Maps.Add(new Map()
            {
                Name  = "mp_test",
                Alias = "test"
            });
            var gameEvent = EventGenerators.GenerateEvent(GameEvent.EventType.Command, server.Maps.First().Name, server);

            Func <Task> act = () => cmd.ExecuteAsync(gameEvent);

            act.ExecutionTime().Should().BeCloseTo(appConfig.MapChangeDelaySeconds.Seconds(), 500.Milliseconds());
            A.CallTo(() => rconParser.ExecuteCommandAsync(A <IRConConnection> .Ignored, A <string> .Ignored))
            .MustHaveHappened();
        }
Ejemplo n.º 5
0
        public async Task Test_PrivateMessageAdmins_GameNotSupported()
        {
            var cmd    = serviceProvider.GetRequiredService <PrivateMessageAdminsCommand>();
            var server = serviceProvider.GetRequiredService <IW4MServer>();
            var origin = ClientGenerators.CreateDatabaseClient();

            origin.Level         = Permission.Administrator;
            origin.CurrentServer = server;
            var gameEvent = EventGenerators.GenerateEvent(GameEvent.EventType.Command, "", server);

            gameEvent.Origin = origin;
            cmdConfig.Commands.Add(nameof(PrivateMessageAdminsCommand), new CommandProperties());

            server.Clients[0] = origin;
            server.Clients[1] = origin;
            await cmd.ExecuteAsync(gameEvent);

            int expectedEvents = 1;

            Assert.AreEqual(expectedEvents, mockEventHandler.Events.Count(_event => _event.Type == GameEvent.EventType.Tell));
        }
Ejemplo n.º 6
0
        public async Task Test_TempBan_WithServerRule()
        {
            var server         = serviceProvider.GetRequiredService <IW4MServer>();
            var expectedReason = "testserverrule";

            appConfig.Servers = new [] { new ServerConfiguration()
                                         {
                                             IPAddress = server.IP,
                                             Port      = server.Port,
                                             Rules     = new [] { expectedReason }
                                         } };
            var command   = serviceProvider.GetRequiredService <TempBanCommand>();
            var gameEvent = EventGenerators.GenerateEvent(GameEvent.EventType.Command, "1h serverrule1", server);

            gameEvent.Origin.CurrentServer = server;
            gameEvent.Target = gameEvent.Origin;

            await command.ExecuteAsync(gameEvent);

            Assert.NotNull(mockEventHandler.Events
                           .FirstOrDefault(e => e.Data == expectedReason &&
                                           e.Type == GameEvent.EventType.TempBan));
        }