示例#1
0
        private byte[] GetPlayerChallengeId(Stopwatch sw = null)
        {
            var recvBytes = socket.GetResponse(QueryMsg.PlayerChallengeQuery, Type, sw);

            try
            {
                var parser = new Parser(recvBytes);
                var header = parser.ReadByte();
                switch (header)
                {
                case (byte)ResponseMsgHeader.A2S_SERVERQUERY_GETCHALLENGE:
                    IsPlayerChallengeId = true;
                    return(parser.GetUnParsedData());

                case (byte)ResponseMsgHeader.A2S_PLAYER:
                    IsPlayerChallengeId = false;
                    return(recvBytes);

                default:
                    throw new InvalidHeaderException("A2S_SERVERQUERY_GETCHALLENGE message header is not valid");
                }
            }
            catch (Exception e)
            {
                e.Data.Add("ReceivedData", recvBytes);
                throw;
            }
        }
示例#2
0
        internal static RconSrcPacket ProcessPacket(byte[] data)
        {
            RconSrcPacket packet = new RconSrcPacket();

            try
            {
                Parser parser = new Parser(data);
                packet.Size = parser.ReadInt();
                packet.Id   = parser.ReadInt();
                packet.Type = parser.ReadInt();
                byte[] body = parser.GetUnParsedData();
                if (body.Length == 2)
                {
                    packet.Body = string.Empty;
                }
                else
                {
                    packet.Body = Util.BytesToString(body).TrimEnd('\0', ' ');
                }
            }
            catch (Exception e)
            {
                e.Data.Add("ReceivedData", data);
                throw;
            }
            return(packet);
        }
示例#3
0
        private byte[] SourcePackets(byte[] data)
        {
            byte pktCount = data[8];
            List <KeyValuePair <byte, byte[]> > pktList = new List <KeyValuePair <byte, byte[]> >(pktCount);

            pktList.Add(new KeyValuePair <byte, byte[]>(data[9], data));

            byte[] recvData;
            for (int i = 1; i < pktCount; i++)
            {
                recvData = ReceiveData();
                pktList.Add(new KeyValuePair <byte, byte[]>(recvData[9], recvData));
            }

            pktList.Sort((x, y) => x.Key.CompareTo(y.Key));
            Parser      parser       = null;
            bool        isCompressed = false;
            int         checksum     = 0;
            List <byte> recvList     = new List <byte>();

            parser = new Parser(pktList[0].Value);
            parser.Skip(4);           //header
            if (parser.ReadInt() < 0) //ID
            {
                isCompressed = true;
            }
            parser.ReadByte();             //total
            int pktId = parser.ReadByte(); // packet id

            parser.ReadShort();            //size
            if (isCompressed)
            {
                parser.Skip(2);              //[this is not equal to decompressed length of data]
                checksum = parser.ReadInt(); //Checksum
            }
            recvList.AddRange(parser.GetUnParsedData());

            for (int i = 1; i < pktList.Count; i++)
            {
                parser = new Parser(pktList[i].Value);
                parser.Skip(12);//multipacket header only
                recvList.AddRange(parser.GetUnParsedData());
            }
            recvData = recvList.ToArray <byte>();
            if (isCompressed)
            {
                recvData = Decompress(recvData);
                if (!IsValid(recvData, checksum))
                {
                    throw new InvalidPacketException("packet's checksum value does not match with the calculated checksum");
                }
            }
            return(recvData.Skip(4).ToArray <byte>());
        }
示例#4
0
 internal static RconSrcPacket ProcessPacket(byte[] data)
 {
     RconSrcPacket packet = new RconSrcPacket();
     try
     {
         Parser parser = new Parser(data);
         packet.Size = parser.ReadInt();
         packet.Id = parser.ReadInt();
         packet.Type = parser.ReadInt();
         byte[] body = parser.GetUnParsedData();
         if (body.Length == 2)
             packet.Body = string.Empty;
         else
             packet.Body = Util.BytesToString(body, 0, body.Length - 3);
     }
     catch (Exception e)
     {
         e.Data.Add("ReceivedData", data);
         throw;
     }
     return packet;
 }
示例#5
0
 private byte[] GetPlayerChallengeId()
 {
     var recvBytes = socket.GetResponse(QueryMsg.PlayerChallengeQuery, Type);
       try
       {
     var parser = new Parser(recvBytes);
     var header = parser.ReadByte();
     switch (header)
     {
       case (byte) ResponseMsgHeader.A2S_SERVERQUERY_GETCHALLENGE:
     IsPlayerChallengeId = true;
     return parser.GetUnParsedData();
       case (byte) ResponseMsgHeader.A2S_PLAYER:
     IsPlayerChallengeId = false;
     return recvBytes;
       default:
     throw new InvalidHeaderException("A2S_SERVERQUERY_GETCHALLENGE message header is not valid");
     }
       }
       catch (Exception e)
       {
     e.Data.Add("ReceivedData", recvBytes);
     throw;
       }
 }
示例#6
0
        private byte[] SourcePackets(byte[] data)
        {
            byte pktCount = data[8];
            List<KeyValuePair<byte, byte[]>> pktList = new List<KeyValuePair<byte, byte[]>>(pktCount);
            pktList.Add(new KeyValuePair<byte, byte[]>(data[9], data));

            byte[] recvData;
            for (int i = 1; i < pktCount; i++)
            {
                recvData = ReceiveData();
                pktList.Add(new KeyValuePair<byte, byte[]>(recvData[9], recvData));
            }

            pktList.Sort((x, y) => x.Key.CompareTo(y.Key));
            Parser parser = null;
            bool isCompressed = false;
            int checksum = 0;
            List<byte> recvList = new List<byte>();
            parser = new Parser(pktList[0].Value);
            parser.Skip(4);//header
            if (parser.ReadInt() < 0)//ID
                isCompressed = true;
            parser.ReadByte();//total
            int pktId = parser.ReadByte();// packet id
            parser.ReadShort();//size
            if (isCompressed)
            {
                parser.Skip(2);//[this is not equal to decompressed length of data]
                checksum = parser.ReadInt();//Checksum
            }
            recvList.AddRange(parser.GetUnParsedData());

            for (int i = 1; i < pktList.Count; i++)
            {
                parser = new Parser(pktList[i].Value);
                parser.Skip(12);//multipacket header only
                recvList.AddRange(parser.GetUnParsedData());
            }
            recvData = recvList.ToArray<byte>();
            if (isCompressed)
            {
                recvData = Decompress(recvData);
                if (!IsValid(recvData, checksum))
                    throw new InvalidPacketException("packet's checksum value does not match with the calculated checksum");
            }
            return recvData.Skip(4).ToArray<byte>();
        }