public override void Parse() { base.Parse(); var ipBytes = RawRequest.Skip(15).Take(4).ToArray(); var portBytes = RawRequest.Skip(19).Take(2).Reverse().ToArray(); // we found that the local port is not correct in gamespy and wireshark ushort port; if (PortType == NatPortType.NN2 || PortType == NatPortType.NN3) { port = (ushort)(BitConverter.ToUInt16(portBytes) + 1); } else { port = BitConverter.ToUInt16(portBytes); } PrivateIPEndPoint = new IPEndPoint(new IPAddress(ipBytes), port); if (RawRequest.Length > 21) { if (RawRequest[RawRequest.Length - 1] == 0) { var gameNameBytes = RawRequest.Skip(21).Take(RawRequest.Length - 22).ToArray(); GameName = UniSpyEncoding.GetString(gameNameBytes); } } }
public override void Parse() { base.Parse(); CommandName = RequestType.ServerListRequest; // if (RequestLength != RawRequest.Length) // { // throw new SBException("Server list request length is not correct."); // } RequestVersion = RawRequest[2]; ProtocolVersion = RawRequest[3]; EncodingVersion = RawRequest[4]; GameVersion = BitConverter.ToInt32(RawRequest.Skip(5).Take(4).ToArray()); //because there are empty string we can not use StringSplitOptions.RemoveEmptyEntries var remainData = RawRequest.Skip(9).ToList(); var devGameNameIndex = remainData.FindIndex(x => x == 0); DevGameName = UniSpyEncoding.GetString(remainData.Take(devGameNameIndex).ToArray()); remainData = remainData.Skip(devGameNameIndex + 1).ToList(); var gameNameIndex = remainData.FindIndex(x => x == 0); GameName = UniSpyEncoding.GetString(remainData.Take(gameNameIndex).ToArray()); remainData = remainData.Skip(gameNameIndex + 1).ToList(); // client challenge length is 8 ClientChallenge = UniSpyEncoding.GetString(remainData.Take(8).ToArray()); remainData = remainData.Skip(8).ToList(); var filterIndex = remainData.FindIndex(x => x == 0); if (filterIndex > 0) { Filter = UniSpyEncoding.GetString(remainData.Take(filterIndex).ToArray()); } remainData = remainData.Skip(filterIndex + 1).ToList(); var keysIndex = remainData.FindIndex(x => x == 0); Keys = UniSpyEncoding.GetString(remainData.Take(keysIndex).ToArray()).Split("\\", StringSplitOptions.RemoveEmptyEntries); remainData = remainData.Skip(keysIndex + 1).ToList(); //gamespy send this in big endian, we need to convert to little endian byte[] byteUpdateOptions = remainData.Take(4).Reverse().ToArray(); UpdateOption = (ServerListUpdateOption)BitConverter.ToInt32(byteUpdateOptions); remainData = remainData.Skip(4).ToList(); if ((UpdateOption & ServerListUpdateOption.AlternateSourceIP) != 0) { SourceIP = new System.Net.IPAddress(remainData.Take(4).ToArray()); remainData = remainData.Skip(7).ToList(); } if ((UpdateOption & ServerListUpdateOption.LimitResultCount) != 0) { if (remainData.Count != 4) { throw new SBException("The max number of server is incorrect."); } MaxServers = BitConverter.ToInt32(remainData.Take(4).Reverse().ToArray()); } }
public override void Parse() { base.Parse(); var _ipBytes = RawRequest.Skip(12).Take(4).ToArray(); var _portBytes = RawRequest.Skip(16).Take(2).ToArray(); GuessedTargetIPEndPoint = new IPEndPoint(new IPAddress(_ipBytes), BitConverter.ToUInt16(_portBytes)); GotYourData = RawRequest[18]; IsFinished = RawRequest[19]; }
public override void Parse() { base.Parse(); SearchOption = Convert.ToInt16(RawRequest.Skip(3).Take(4).ToArray()); MaxResults = Convert.ToInt16(RawRequest.Skip(7).Take(4).ToArray()); int nameLength = BitConverter.ToInt32(RawRequest.Skip(11).Take(4).ToArray()); SearchName = UniSpyEncoding.GetString(RawRequest.Skip(15).Take(nameLength).ToArray()); int messageLength = BitConverter.ToInt32(RawRequest.Skip(15).Take(4).ToArray()); Message = UniSpyEncoding.GetString(RawRequest.Skip(15 + nameLength + 4).Take(messageLength).ToArray()); }
public override void Parse() { base.Parse(); //if(recv.Length<length) //{ // return false; //} CommandName = (RequestType)RawRequest[2]; byte[] ip = RawRequest.Skip(3).Take(4).ToArray(); // raw request is in big endian we need to convert it to little endian byte[] port = RawRequest.Skip(7).Take(2).Reverse().ToArray(); //TODO fix for gbrome!!!!!!!!!!!!!!!!!!! TargetIPEndPoint = new IPEndPoint(new IPAddress(ip), BitConverter.ToUInt16(port)); }
public override void Parse() { base.Parse(); int playerPos, teamPos; int playerLenth, teamLength; DataPartition = UniSpyEncoding.GetString(RawRequest.Skip(5).ToArray()); playerPos = DataPartition.IndexOf("player_\0", StringComparison.Ordinal); teamPos = DataPartition.IndexOf("team_t\0", StringComparison.Ordinal); if (playerPos != -1 && teamPos != -1) { ReportType = HeartBeatReportType.ServerTeamPlayerData; playerLenth = teamPos - playerPos; teamLength = DataPartition.Length - teamPos; var serverDataStr = DataPartition.Substring(0, playerPos - 4); ParseServerData(serverDataStr); var playerDataStr = DataPartition.Substring(playerPos - 1, playerLenth - 2); ParsePlayerData(playerDataStr); var teamDataStr = DataPartition.Substring(teamPos - 1, teamLength); ParseTeamData(teamDataStr); } else if (playerPos != -1) { //normal heart beat ReportType = HeartBeatReportType.ServerPlayerData; playerLenth = DataPartition.Length - playerPos; var serverDataStr = DataPartition.Substring(0, playerPos - 4); ParseServerData(serverDataStr); var playerDataStr = DataPartition.Substring(playerPos - 1, playerLenth); ParsePlayerData(playerDataStr); } else if (playerPos == -1 && teamPos == -1) { ReportType = HeartBeatReportType.ServerData; var serverDataStr = DataPartition; ParseServerData(serverDataStr); } else { throw new QRException("HeartBeat request is invalid."); } }
public override void Parse() { base.Parse(); State = (PreInitState)RawRequest[12]; TargetCookie = BitConverter.ToUInt32(RawRequest.Skip(13).Take(4).ToArray()); }
public override void Parse() { Cookie = BitConverter.ToUInt16(RawRequest.Skip(6).ToArray()); }