コード例 #1
0
        private async Task GetFlagFromChat(CheckerTaskMessage task, CancellationToken token)
        {
            var shorterToken = new CancellationTokenSource((int)(task.Timeout * 0.9)).Token;
            var users        = await this.checkerDb.GetUsersAsync(task.Flag !, token);

            if (users.Count <= 0)
            {
                throw new MumbleException("Putflag failed");
            }

            var user1 = users[0];

            this.logger.LogInformation($"GetFlagFromChat -  Name:\"{user1.Username}\", Password:\"{user1.Password}\", SessionId:\"{user1.SessionId}\"");
            using var client1 = this.serviceProvider.GetRequiredService <GamemasterClient>();
            await client1.LoginAsync(task.Address, user1, token);

            var tcs = new TaskCompletionSource <bool>();

            await using GamemasterSignalRClient signalrclient1 = client1.CreateSignalRConnection(task.Address, tcs, task.Flag, this.serviceProvider, shorterToken);
            await signalrclient1.Connect();

            var   tj1 = signalrclient1.Join(user1.SessionId, token);
            await tj1;
            await tcs.Task;
        }
コード例 #2
0
        private async Task PutFlagToChat(CheckerTaskMessage task, CancellationToken token)
        {
            var user1 = Util.GenerateFakeUser(null);
            var user2 = Util.GenerateFakeUser(task.Flag);
            var user3 = Util.GenerateFakeUser(null);

            using var client1 = this.serviceProvider.GetRequiredService <GamemasterClient>();
            using var client2 = this.serviceProvider.GetRequiredService <GamemasterClient>();
            using var client3 = this.serviceProvider.GetRequiredService <GamemasterClient>();
            var   tl1 = client1.RegisterAsync(task.Address, user1, token);
            var   tl2 = client2.RegisterAsync(task.Address, user2, token);
            var   tl3 = client3.RegisterAsync(task.Address, user3, token);
            await tl1;
            await tl2;
            await tl3;
            var   s = await client3.CreateSessionAsync(Util.GenerateFakeSessionName(), "n", "password", token);

            var   ta1 = client3.AddUserToSessionAsync(s !.Id, user2.Username, token);
            var   ta2 = client3.AddUserToSessionAsync(s !.Id, user1.Username, token);
            await ta1;
            await ta2;

            await using GamemasterSignalRClient signalrclient1 = client1.CreateSignalRConnection(task.Address, null, null, this.serviceProvider, token);
            await using GamemasterSignalRClient signalrclient2 = client1.CreateSignalRConnection(task.Address, null, null, this.serviceProvider, token);
            var   tc1 = signalrclient1.Connect();
            var   tc2 = signalrclient2.Connect();
            await tc1;
            await tc2;
            var   tj1 = signalrclient1.Join(s.Id, token);
            var   tj2 = signalrclient2.Join(s.Id, token);
            await tj1;
            await tj2;
            await signalrclient1.SendMessage(task.Flag !, token); // TODO we should check of the other client actually receives this

            user2.SessionId = s.Id;
            await this.checkerDb.AddUserAsync(user2, token);
        }