コード例 #1
0
        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));
        }
コード例 #2
0
        public static SteamPacket CreatePacket(byte[] rawData, bool prefix)
        {
            int start = (prefix ? 4 : 0);

            SteamPacket      packet;
            SteamPacketTypes packetType = (SteamPacketTypes)rawData[start];

            MemoryStream byteStream = new MemoryStream(rawData.Length - 1);

            byteStream.Write(rawData, start + 1, rawData.Length - 1 - start);

            switch (packetType)
            {
            case SteamPacketTypes.S2C_CHALLENGE:
                packet = new ChallengeResponsePacket(byteStream.ToArray());
                break;

            case SteamPacketTypes.S2A_INFO:
                packet = new S2A_INFO_Packet(byteStream.ToArray());
                break;

            case SteamPacketTypes.S2A_INFO2:
                packet = new SourceServerInfoResponsePacket(byteStream.ToArray());
                //packet = new S2A_INFO2_Packet(byteStream.ToArray());
                break;

            case SteamPacketTypes.S2A_INFO_DETAILED:
                packet = new S2A_INFO_DETAILED_Packet(byteStream.ToArray());
                break;

            case SteamPacketTypes.S2A_RULES:
                packet = new ServerRulesResponsePacket(byteStream.ToArray());
                break;

            case SteamPacketTypes.S2A_PLAYER:
                packet = new PlayersResponsePacket(byteStream.ToArray());
                break;

            case SteamPacketTypes.RCON_GOLDSRC_CHALLENGE_HEADER:
            case SteamPacketTypes.RCON_GOLDSRC_NO_CHALLENGE_HEADER:
            case SteamPacketTypes.RCON_GOLDSRC_RESPONSE_HEADER:
                packet = new RCONGoldSrcResponsePacket(byteStream.ToArray());
                break;

            case SteamPacketTypes.M2A_SERVER_BATCH:
                packet = new MasterServerResponseBatchPacket(byteStream.ToArray());
                break;

            default:
                packet = new SteamPacket(packetType, byteStream.ToArray());
                break;
            }

            return(packet);
        }
コード例 #3
0
        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);
        }