Esempio n. 1
0
 public FakeChannel()
 {
     responsesMap = new Dictionary <PacketType, byte[]>
     {
         { PacketType.ExecCommand, RconPacket.Create(PacketType.Response, "Command executed").ToBytes() },
         { PacketType.Auth, RconPacket.Create(PacketType.AuthResponse, "").ToBytes() }
     };
 }
Esempio n. 2
0
        public void ConvertRconPacketToBytesShouldReturnValidRCONBuffer()
        {
            // Arrange
            ProgressiveId.Seed(1);
            var content      = "test";
            var packetType   = PacketType.Auth;
            var bufferLength = 18;
            var packetLength = 14;
            var packet       = RconPacket.Create(packetType, content);

            // Act
            var buffer = packet.ToBytes();

            // Asert
            Assert.NotNull(buffer);
            Assert.Equal(bufferLength, buffer.Length);              // 12 headers bytes + 8 bytes for "password" string encoding + 1 ending
            Assert.Equal(packetLength, BitConverter.ToInt32(buffer[0..4]));
Esempio n. 3
0
        public Task SendAsync(ReadOnlyMemory <byte> payload)
        {
            var request = RconPacket.FromBytes(payload.ToArray());

            switch (request.Type)
            {
            case PacketType.Auth:
                pendingResponses.Add(RconPacket.Create(PacketType.Response, "").ToBytes());
                pendingResponses.Add(RconPacket.Create(request.Body.Equals("valid") ? request.Id : -1, PacketType.AuthResponse, "").ToBytes());
                break;

            case PacketType.ExecCommand:
                pendingResponses.Add(RconPacket.Create(PacketType.Response, "This will be a ve").ToBytes());
                pendingResponses.Add(RconPacket.Create(PacketType.Response, "ry long message").ToBytes());
                break;

            case PacketType.Response:
                pendingResponses.Add(RconPacket.Create(0, PacketType.Response, "").ToBytes());
                pendingResponses.Add(RconPacket.Create(0, PacketType.Response, "\u0001").ToBytes());
                break;
            }
            return(Task.CompletedTask);
        }