public static SteamPacket CreatePacket(byte[] rawData)
        {
            SteamPacket packet;
            SteamPacketTypes packetType = (SteamPacketTypes)rawData[0];

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

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

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

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

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

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

            return packet;
        }
예제 #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);
        }
        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;
        }