Esempio n. 1
0
        public async Task <RconClient> GetClient()
        {
            if (this.connection == null)
            {
                return(null);
            }
            // touched
            await this.context.TouchConnection(this.connection);

            // Create an instance of RconClient pointing to an IP and a PORT
            var client = RconClient.Create(this.connection.Server, this.connection.Port.Value);

            await client.ConnectAsync();

            // Send a RCON packet with type AUTH and the RCON password for the target server
            var authenticated = await client.AuthenticateAsync(this.connection.Password);

            if (authenticated)
            {
                // If the response is positive, the connection is authenticated and further commands can be sent
                //var status = await client.ExecuteCommandAsync("status");
                // Some responses will be split into multiple RCON pakcets when body length exceeds the maximum allowed
                // For this reason these commands needs to be issued with isMultiPacketResponse parameter set to true
                // An example is CS:GO cvarlist
                //var cvarlist = await client.ExecuteCommandAsync("cvarlist", true);
                //var userList = await client.ExecuteCommandAsync("users");
                return(client);
            }
            return(null);
        }
Esempio n. 2
0
        protected async Task <string> ExecuteCommandAsync(string command)
        {
            var client = RconClient.Create(_address, _port);
            await client.ConnectAsync();

            if (!await client.AuthenticateAsync(_password))
            {
                throw new AuthenticationException();
            }

            return(await client.ExecuteCommandAsync(command));
        }
Esempio n. 3
0
        public async Task SendMessageShouldReceiveAResponse()
        {
            // Arrange
            var channel    = new FakeChannel();
            var rconClient = RconClient.Create(channel);
            await rconClient.ConnectAsync();

            // Act
            var response = await rconClient.ExecuteCommandAsync("test echo");

            // Assert
            Assert.Equal("Command executed", response);
        }
Esempio n. 4
0
        public async Task MultiPacketResponseShouldBeCorrectlyReceivedFromStrictRCONServers()
        {
            // Arrange
            var channel    = new SourceChannel();
            var rconClient = RconClient.Create(channel);
            await rconClient.ConnectAsync();

            // Act
            var response = await rconClient.ExecuteCommandAsync("print all", true);

            // Assert
            Assert.Equal("This will be a very long message", response);
        }
Esempio n. 5
0
        public async Task AuthenticateShouldWorkOnStrictRCONServers(string password, bool isAuthenticated)
        {
            // Arrange
            var channel    = new SourceChannel();
            var rconClient = RconClient.Create(channel);
            await rconClient.ConnectAsync();

            // Act
            var response = await rconClient.AuthenticateAsync(password);

            // Assert
            Assert.Equal(isAuthenticated, response);
        }
Esempio n. 6
0
        public async Task CanceledResponseShouldDisconnectTheClient()
        {
            // Arrange
            var channel = new FakeChannel();

            channel.CancelNextReponse();
            var rconClient = RconClient.Create(channel);
            await rconClient.ConnectAsync();

            var tcs = new TaskCompletionSource <bool>();

            rconClient.ConnectionClosed += () =>
            {
                tcs.SetResult(true);
            };

            // Act Assert
            await Assert.ThrowsAsync <TaskCanceledException>(() => rconClient.ExecuteCommandAsync("test echo"));

            Assert.True(await tcs.Task);
        }
Esempio n. 7
0
 public RconClient CreateClient(IPEndPoint ipEndPoint)
 {
     return(RconClient.Create(ipEndPoint.Address.ToString(), ipEndPoint.Port));
 }