|
楼主 |
发表于 2020-3-11 01:11:05
|
显示全部楼层
来自 中国–重庆–重庆
- public PlayerResponse GetPlayers()
- {
- try
- {
- var req = Constants.A2S_PLAYER_CHALLENGE_REQUEST;
- request(req);
- var response = fetchResponse();
- var byteReader = response.GetByteReader();
- // byte[] response = fetchResponse();
- //IByteReader byteReader = response.GetByteReader();
- if (!byteReader.GetByte().Equals(0x41))
- {
- response = fetchResponse();
- byteReader = response.GetByteReader();
- //header = byteReader.GetByte();
- if (!byteReader.GetByte().Equals(0x41))
- throw new ArgumentException("Response was no challenge response.");
- }
- req[5] = byteReader.GetByte();
- req[6] = byteReader.GetByte();
- req[7] = byteReader.GetByte();
- req[8] = byteReader.GetByte();
- request(req);
- response = fetchResponse();
- byteReader = response.GetByteReader();
- byte header = byteReader.GetByte();
- if (!header.Equals(0x44))
- throw new ArgumentException("Response was no player response.");
- PlayerResponse playerResponse = new PlayerResponse() { Header = header, Players = new List<Player>() };
- int playercount = byteReader.GetByte();
- for (int i = 1; i <= playercount; i++)
- {
- playerResponse.Players.Add(new Player()
- {
- Index = byteReader.GetByte(),
- Name = byteReader.GetString(),
- Score = byteReader.GetLong(),
- Duration = TimeSpan.FromSeconds(byteReader.GetFloat())
- });
- }
- //IF more bytes == THE SHIP
- if (byteReader.Remaining > 0)
- {
- playerResponse.IsTheShip = true;
- for (int i = 0; i < playercount; i++)
- {
- playerResponse.Players[i].Deaths = byteReader.GetLong();
- playerResponse.Players[i].Money = byteReader.GetLong();
- }
- }
- return playerResponse;
- }
- catch (Exception ex)
- {
- throw new SourceQueryException("Could not gather Players", ex);
- }
- }
复制代码 |
|