public void RconGetChallenge() { this.RconSend("challenge rcon"); SteamPacket steamPacket = this.GetReply(); RCONGoldSrcResponsePacket responsePacket = steamPacket as RCONGoldSrcResponsePacket; if (responsePacket == null) { throw new PacketFormatException(); } string response = responsePacket.Response; if (response.Equals("You have been banned from this server.")) { throw new RCONNoAuthException(response); } else if (response.Equals("You have been banned from this server")) { throw new RCONBanException(response); } int startIndex = 14; int i = startIndex; while (i < response.Length && response[i] >= '0' && response[i] <= '9') { i++; } this.rconChallenge = Convert.ToInt64(response.Substring(startIndex, i - startIndex)); }
protected SteamPacket CreatePacket() { byte[] packetData = this.bufferReader.ReadBytes(buffer.Length - (int)bufferReader.BaseStream.Position); //byte[] packetData = this.bufferReader.ReadBytes(SteamPacket.PACKET_SIZE); return(SteamPacket.CreatePacket(packetData)); }
private void handleResponseForRequest(int requestType, bool repeatOnFailure) { bool success = false; SteamPacketTypes expectedResponse; SteamPacket requestPacket = null; switch (requestType) { case GameServer.REQUEST_CHALLENGE: expectedResponse = SteamPacketTypes.S2C_CHALLENGE; requestPacket = new SteamPacket(SteamPacketTypes.A2S_SERVERQUERY_GETCHALLENGE); break; case GameServer.REQUEST_INFO: expectedResponse = SteamPacketTypes.S2A_INFO; requestPacket = new SteamPacket(SteamPacketTypes.A2S_INFO); break; case GameServer.REQUEST_PLAYER: expectedResponse = SteamPacketTypes.S2A_PLAYER; requestPacket = new SteamPacket(SteamPacketTypes.A2S_PLAYER, challengeNumber.ReverseBytes().GetBytes()); break; case GameServer.REQUEST_RULES: expectedResponse = SteamPacketTypes.S2A_RULES; requestPacket = new SteamPacket(SteamPacketTypes.A2S_RULES, challengeNumber.ReverseBytes().GetBytes()); break; default: throw new SteamCondenserException("Called with wrong request type."); } this.SendRequest(requestPacket); do { SteamPacket responsePacket = this.GetReply(); success = (responsePacket.PacketType == expectedResponse); if (responsePacket is SourceServerInfoResponsePacket) { success = true; this.serverInfo = (responsePacket as SourceServerInfoResponsePacket).ServerInfo; } else if (responsePacket is PlayersResponsePacket) { playerList = (responsePacket as PlayersResponsePacket).PlayerList; } else if (responsePacket is ChallengeResponsePacket) { this.challengeNumber = (uint)(responsePacket as ChallengeResponsePacket).ChallengeID; } else if (responsePacket is ServerRulesResponsePacket) { this.serverRules = (responsePacket as ServerRulesResponsePacket).ServerRules; } } while (repeatOnFailure && !success); }
public override SteamPacket GetReply() { int bytesRead; SteamPacket packet; bytesRead = this.ReceivePacket(SteamPacket.PACKET_SIZE); if (this.PacketIsSplit()) { byte[] splitData; int packetCount, packetNumber; int requestId; byte packetNumberAndCount; List <byte[]> splitPackets = new List <byte[]>(); do { requestId = this.bufferReader.ReadInt32().ReverseBytes(); packetNumberAndCount = this.bufferReader.ReadByte(); packetCount = packetNumberAndCount & 0xF; packetNumber = (packetNumberAndCount & 0xF0) >> 4; // read preamble only in the first packet, otherwise we cut off stuff if (packetNumber == 0) { this.bufferReader.ReadInt32(); } splitData = this.bufferReader.ReadBytes((int)(this.bufferReader.BaseStream.Length - this.bufferReader.BaseStream.Position)); splitPackets.Add(splitData); if (splitPackets.Count < packetCount) { try { bytesRead = this.ReceivePacket(); } catch { bytesRead = 0; } } else { bytesRead = 0; } // TODO: use packetNumber nad packetCount } while (bytesRead > 0 && this.PacketIsSplit()); packet = SteamPacket.ReassemblePacket(splitPackets); } else { packet = this.CreatePacket(); } return(packet); }
public string RconExec(string password, string command) { if (this.rconChallenge == -1 || IsHLTV) { this.RconGetChallenge(); } RconSend("rcon " + rconChallenge + " " + password + " " + command); string response; if (IsHLTV) { try { SteamPacket packet = this.GetReply(); if (packet == null) { throw new PacketFormatException(); } response = (packet as RCONGoldSrcResponsePacket).Response; } catch { response = ""; } } else { response = ((RCONGoldSrcResponsePacket)this.GetReply()).Response; } if (response.StartsWith("Bad rcon_password.") || response.StartsWith("You have been banned from this server")) { throw new RCONNoAuthException(response); } try { do { RCONGoldSrcResponsePacket packet = this.GetReply() as RCONGoldSrcResponsePacket; if (packet == null) { throw new PacketFormatException(); } response += packet.Response; } while (true); } catch { } return(response); }
public override SteamPacket GetReply() { int bytesRead; SteamPacket packet; bytesRead = ReceivePacket(SteamPacket.PACKET_SIZE); if (PacketIsSplit()) { bool isCompressed = false; byte[] splitData; int packetCount, packetNumber, requestId; int packetsReceived = 1; int packetChecksum = 0; int packetSplit = 0; short splitSize; short uncompressedSize = 0; List <byte[]> splitPackets = new List <byte[]>(); do { // Parsing of split packet headers requestId = ReverseBytes(this.bufferReader.ReadInt32()); isCompressed = this.PacketIsCompressed(requestId); packetCount = (int)this.bufferReader.ReadByte(); packetNumber = (int)this.bufferReader.ReadByte() + 1; splitSize = (this.bufferReader.ReadInt16()); splitSize -= 4; // FIXME: do we get incorrect split sizes???? if (packetsReceived == 1) { for (int i = 0; i < packetCount; i++) { splitPackets.Add(new byte[] { }); } } if (isCompressed) { uncompressedSize = ReverseBytes(this.bufferReader.ReadInt16()); // int32 ?? packetChecksum = ReverseBytes(this.bufferReader.ReadInt32()); } // Omit additional header on the first packet if (packetNumber == 1) { this.bufferReader.ReadInt32(); } // Caching of split packet Data splitData = new byte[splitSize]; this.bufferReader.Read(splitData, 0, splitSize); //splitPackets.Capacity = packetCount; //splitPackets.Add(splitData); splitPackets[packetNumber - 1] = splitData; // Receiving the next packet if (packetsReceived < packetCount) { bytesRead = this.ReceivePacket(); packetSplit = this.bufferReader.ReadInt32(); packetsReceived++; } else { bytesRead = 0; } } while (packetsReceived <= packetCount && bytesRead > 0 && packetSplit == SteamPacket.PACKET_SPLIT_MARKER); if (isCompressed) { packet = SteamPacket.ReassemblePacket(splitPackets, true, uncompressedSize, packetChecksum); } else { packet = SteamPacket.ReassemblePacket(splitPackets); } } else { packet = this.CreatePacket(); } return(packet); }
private void SendRequest(SteamPacket requestData) { this.querySocket.Send(requestData); }
public void Send(SteamPacket dataPacket) { byte[] byteData = dataPacket.GetBytes(true); this.client.Send(byteData, byteData.Length); }