public virtual bool Parse() { if (RawRequest.Length < 3) { return(false); } PacketType = (QRPacketType)RawRequest[0]; InstantKey = BitConverter.ToInt32(ByteTools.SubBytes(RawRequest, 1, 4)); return(true); }
public virtual bool Parse(byte[] recv) { if (recv.Length < 3) { return(false); } PacketType = (QRPacketType)recv[0]; InstantKey = BitConverter.ToInt32(ByteTools.SubBytes(recv, 1, 4)); return(true); }
/// <summary> /// Parse all value to this class /// </summary> /// <param name="recv"></param> public bool Parse(byte[] recv) { ushort length = ByteTools.ToUInt16(ByteTools.SubBytes(recv, 0, 2), true); if (length != recv.Length) { return(false); } RequestVersion = recv[2]; ProtocolVersion = recv[3]; EncodingVersion = recv[4]; GameVersion = BitConverter.ToInt32(ByteTools.SubBytes(recv, 5, 4)); //because there are empty string we can not use StringSplitOptions.RemoveEmptyEntries string remainData = Encoding.ASCII.GetString(recv.Skip(9).ToArray()); remainData.IndexOf('\0'); DevGameName = remainData.Substring(0, remainData.IndexOf('\0')); remainData = remainData.Substring(remainData.IndexOf('\0') + 1); GameName = remainData.Substring(0, remainData.IndexOf('\0')); remainData = remainData.Substring(remainData.IndexOf('\0') + 1); Challenge = remainData.Substring(0, remainData.IndexOf('\0')).Substring(0, 8); if (remainData.Substring(0, remainData.IndexOf('\0')).Length > 8) { Filter = remainData.Substring(8, remainData.IndexOf('\0') - 8); } remainData = remainData.Substring(remainData.IndexOf('\0') + 1); Keys = remainData.Substring(0, remainData.IndexOf('\0')).Split("\\", StringSplitOptions.RemoveEmptyEntries); remainData = remainData.Substring(remainData.IndexOf('\0') + 1); byte[] byteUpdateOptions = Encoding.ASCII.GetBytes(remainData.Substring(0, 4)); //gamespy send this in big endian, we need to convert to little endian Array.Reverse(byteUpdateOptions); UpdateOption = (SBServerListUpdateOption)BitConverter.ToInt32(byteUpdateOptions); if ((UpdateOption & SBServerListUpdateOption.AlternateSourceIP) != 0) { SourceIP = Encoding.ASCII.GetBytes(remainData.Substring(0, 4)); remainData = remainData.Substring(7); } if ((UpdateOption & SBServerListUpdateOption.LimitResultCount) != 0) { MaxServers = ByteTools.ToInt32(remainData.Substring(0, 4), true); } return(true); }
public override bool Parse(byte[] recv) { if (!base.Parse(recv)) { return(false); } PortType = recv[BasePacket.Size]; // ClientIndex = recv[BasePacket.Size + 1]; //00 UseGamePort = recv[BasePacket.Size + 2]; //00 LocalIP = BitConverter.ToInt32(ByteTools.SubBytes(recv, BasePacket.Size + 3, 4)); LocalPort = BitConverter.ToInt16(ByteTools.SubBytes(recv, BasePacket.Size + 7, 2)); return(true); }
public virtual bool Parse(byte[] recv) { if (recv.Length < Size) { return(false); } Version = recv[MagicData.Length]; PacketType = (NatPacketType)recv[MagicData.Length + 1]; Cookie = BitConverter.ToInt32(ByteTools.SubBytes(recv, MagicData.Length + 2, 4)); return(true); }
public virtual bool Parse() { if (RawRequest.Length < Size) { return(false); } Version = RawRequest[MagicData.Length]; PacketType = (NatPacketType)RawRequest[MagicData.Length + 1]; Cookie = BitConverter.ToUInt32(ByteTools.SubBytes(RawRequest, MagicData.Length + 2, 4)); return(true); }
public PlayerSearchRequest(byte[] recv) { ByteTools.SubBytes(recv, 3, 3 + 4).CopyTo(SearchOption, 0); ByteTools.SubBytes(recv, 7, 7 + 4).CopyTo(MaxResults, 0); int nameLength = BitConverter.ToInt32(ByteTools.SubBytes(recv, 11, 11 + 4)); _searchName = new byte[nameLength]; ByteTools.SubBytes(recv, 15, nameLength).CopyTo(_searchName, 0); int messageLength = BitConverter.ToInt32(ByteTools.SubBytes(recv, 15 + nameLength, 4)); _message = new byte[messageLength]; ByteTools.SubBytes(recv, 15 + nameLength + 4, messageLength).CopyTo(_message, 0); }
public override bool Parse(byte[] recv) { if (!base.Parse(recv)) { return(false); } PortType = recv[13]; ClientIndex = recv[14]; NegResult = recv[15]; NatType = (NatNegotiationType)BitConverter.ToInt32(ByteTools.SubBytes(recv, 17, sizeof(int))); MappingScheme = (NatNegotiationMappingScheme)BitConverter.ToInt32(ByteTools.SubBytes(recv, 19, sizeof(int))); GameName = Encoding.ASCII.GetString(ByteTools.SubBytes(recv, 23, recv.Length - 23)); return(true); }
public bool Parse(byte[] recv) { ushort length = ByteTools.ToUInt16(ByteTools.SubBytes(recv, 0, 2), true); if (length != recv.Length) { return(false); } byte[] ip = ByteTools.SubBytes(recv, 3, 4); byte[] port = ByteTools.SubBytes(recv, 7, 2); IPEndPoint iPEnd = ByteTools.GetIPEndPoint(ip, port); TargetServerIP = iPEnd.Address.ToString(); TargetServerHostPort = iPEnd.Port.ToString(); return(true); }
public override bool Parse() { if (!base.Parse()) { return(false); } PortType = (NatPortType)RawRequest[NNRequestBase.Size]; // ClientIndex = RawRequest[NNRequestBase.Size + 1]; //00 UseGamePort = RawRequest[NNRequestBase.Size + 2]; //00 LocalIP = HtonsExtensions. BytesToIPString( ByteTools.SubBytes(RawRequest, NNRequestBase.Size + 3, 4)); LocalPort = HtonsExtensions. BytesToUshortPort( ByteTools.SubBytes(RawRequest, NNRequestBase.Size + 7, 2)); return(true); }
public override bool Parse(byte[] recv) { if (!base.Parse(recv)) { return(false); } PortType = (NatPortType)recv[BasePacket.Size]; // ClientIndex = recv[BasePacket.Size + 1]; //00 UseGamePort = recv[BasePacket.Size + 2]; //00 LocalIP = HtonsExtensions. BytesToIPString( ByteTools.SubBytes(recv, BasePacket.Size + 3, 4)); LocalPort = HtonsExtensions. BytesToUshortPort( ByteTools.SubBytes(recv, BasePacket.Size + 7, 2)); return(true); }
public bool Parse(byte[] recv) { ushort length = ByteTools.ToUInt16(ByteTools.SubBytes(recv, 0, 2), true); //if(recv.Length<length) //{ // return false; //} byte[] ip = ByteTools.SubBytes(recv, 3, 4); byte[] port = ByteTools.SubBytes(recv, 7, 2); Array.Reverse(port); IPEndPoint iPEnd = ByteTools.GetIPEndPoint(ip, port); TargetServerIP = iPEnd.Address.ToString(); TargetServerHostPort = iPEnd.Port.ToString(); return(true); }
public override bool Parse() { if (!base.Parse()) { return(false); } PortType = RawRequest[13]; ClientIndex = RawRequest[14]; NatResult = (NATNegotiationResult)RawRequest[15]; NatType = (NATNegotiationType)BitConverter.ToInt32( ByteTools.SubBytes(RawRequest, 17, sizeof(int))); MappingScheme = (NATNegotiationMappingScheme)BitConverter.ToInt32( ByteTools.SubBytes(RawRequest, 19, sizeof(int))); GameName = Encoding.ASCII.GetString( ByteTools.SubBytes(RawRequest, 23, RawRequest.Length - 23)); return(true); }
public virtual void Parse(byte[] recv) { PacketType = (QRPacketType)recv[0]; InstantKey = BitConverter.ToInt32(ByteTools.SubBytes(recv, 1, 4)); }