Esempio n. 1
0
        private RconResponse SendWithTerminator(RconCommand command)
        {
            var commands = new List <RconCommand> {
                command, new EndCommand()
            };

            foreach (var c in commands)
            {
                var bytes     = c.ToPacket(++_requestId).Bytes;
                var bytesSent = _socket.Send(bytes);

                if (c is EndCommand)
                {
                    continue;
                }

                _openResponses.Add(_requestId);

                Debug.Print("   > command.RequestId: " + c.RequestId);
                Debug.Print("   > command.CommandType: " + c.CommandType);
                Debug.Print("   > command.Command: " + c.Command);
                Debug.Print("   > Bytes sent: " + bytesSent);
                Debug.Print("----------------------------------------------");
            }

            Receive();

            return(_responses.Single(r => r.RequestId == command.RequestId.Value));
        }
Esempio n. 2
0
        private byte[] GetBytes(RconCommand command)
        {
            Debug.Assert(command.RequestId.HasValue);

            var utf = new UTF8Encoding();

            var id            = BitConverter.GetBytes(command.RequestId.Value);
            var commandType   = BitConverter.GetBytes((int)command.CommandType);
            var commandString = utf.GetBytes(command.ToCommandString());

            var totalLength = PacketSizeLength
                              + RequestIdLength
                              + TypeLength
                              + commandString.Length
                              + TerminatorLength;

            var packetSize = BitConverter.GetBytes(totalLength - PacketSizeLength);
            var bytes      = new byte[totalLength];
            var i          = 0;

            packetSize.CopyTo(bytes, i);
            i += PacketSizeLength;

            id.CopyTo(bytes, i);
            i += RequestIdLength;

            commandType.CopyTo(bytes, i);
            i += TypeLength;

            commandString.CopyTo(bytes, i);
            i += commandString.Length;

            bytes[i] = 0;
            i++;

            bytes[i] = 0;

            return(bytes);
        }
Esempio n. 3
0
 public RconCommandPacket(RconCommand command)
 {
     Bytes = GetBytes(command);
 }
Esempio n. 4
0
 public RconResponse Send(RconCommand command)
 {
     return(SendWithTerminator(command));
 }