예제 #1
0
파일: Factory.cs 프로젝트: trjate/Infantry
        public PacketBase createPacket(NetworkClient client, ushort typeID, byte[] buffer, int index, int count)
        {
            PacketBase packet = null;

            switch (typeID)
            {
            case CS_Initiate.TypeID:
                packet = new CS_Initiate(typeID, buffer, index, count);
                break;

            case CS_Version.TypeID:
                packet = new CS_Version(typeID, buffer, index, count);
                break;

            case CS_ZoneList.TypeID:
                packet = new CS_ZoneList(typeID, buffer, index, count);
                break;

            case CS_AckZoneList.TypeID:
                packet = new CS_AckZoneList(typeID, buffer, index, count);
                break;

            default:
                //Undefined packet type
                //TODO: Type 7
                packet = new PacketDummy(typeID, buffer, index, count);
                break;
            }

            return(packet);
        }
예제 #2
0
        /// <summary>
        /// Triggered when an unknown packet is received
        /// </summary>
        static public void Handle_PacketDummy(PacketDummy pkt, Client client)
        {               //Are we logging unknown packets?
            if (!Client.bLogUnknowns)
            {
                return;
            }

            //Write a dump of it to disk
            Log.write("Unknown Packet #{0}", pkt._type);
            Log.write(pkt.DataDump);
        }
예제 #3
0
        /// <summary>
        /// Creates a new packet based on the typeID and the received content
        /// inside the buffer. The user has to create an own implementation
        /// of this interface.
        /// </summary>
        public PacketBase createPacket(NetworkClient client, ushort typeID, byte[] buffer, int offset, int size)
        {       //Ready our packet base
            PacketBase packet = null;

            size--;

            //Was it a system packet?
            if (buffer[offset++] == 0)
            {
                //Yes, find the appropriate type
                return(createSystemPacket(typeID, buffer, offset, size));
            }

            //So what was the typeid?
            switch (typeID)
            {
            case SC_Login.TypeID:
                packet = new SC_Login(typeID, buffer, offset, size);
                break;

            case SC_PatchInfo.TypeID:
                packet = new SC_PatchInfo(typeID, buffer, offset, size);
                break;

            case SC_AssetInfo.TypeID:
                packet = new SC_AssetInfo(typeID, buffer, offset, size);
                break;

            case SC_SetIngame.TypeID:
                packet = new SC_SetIngame(typeID, buffer, offset, size);
                break;

            case SC_Chat.TypeID:
                packet = new SC_Chat(typeID, buffer, offset, size);
                break;


            default:
                //An undefined packet.
                packet = new PacketDummy(typeID, buffer, offset, size);
                break;
            }

            return(packet);
        }
예제 #4
0
        /// <summary>
        /// Deserializes the data present in the packet contents into data fields in the class.
        /// </summary>
        public override void Deserialize()
        {               //Initialize our packet list
            packets = new List <PacketBase>();

            //While there's more packets in the buffer..
            byte[] packetData = Data;
            int    idx        = 0;

            while (_size - idx > 0)
            {                   //Get the size of the following packet
                byte nextSize = packetData[idx];

                //Form the new packet
                ushort typeID = NetworkClient.getTypeID(packetData, idx + 1);

                try
                {                       //Transplant the data into a packet class
                    PacketBase packet = _handler.getFactory().createPacket(_client, typeID, packetData, idx + 1, nextSize);

                    packet._client  = _client;
                    packet._handler = _handler;
                    packet.Deserialize();

                    //Add it to our list!
                    packets.Add(packet);
                }
                catch (Exception ex)
                {                       //There was an error while deserializing the packet, create a dummy packet
                    PacketBase packet = new PacketDummy(typeID, packetData, idx + 1, nextSize);

                    packet._client  = _client;
                    packet._handler = _handler;
                    packets.Add(packet);

                    Log.write(TLog.Exception, "Exception while deserializing box packet:\r\n{0}\r\n{1}", ex, packet.DataDump);
                }

                idx += nextSize + 1;
            }
        }
예제 #5
0
    {           /// <summary>
                /// Creates a new system protocol packet.
                /// </summary>
        public PacketBase createSystemPacket(ushort typeID, byte[] buffer, int offset, int size)
        {       //Ready our packet base
            PacketBase packet = null;

            offset++;
            size--;

            //What are we dealing with?
            switch (typeID)
            {
            case CS_Initial.TypeID:
                packet = new CS_Initial(typeID, buffer, offset, size);
                break;

            case BoxPacket.TypeID:
                packet = new BoxPacket(typeID, buffer, offset, size);
                break;

            case Disconnect.TypeID:
                packet = new Disconnect(typeID, buffer, offset, size);
                break;

            case PingPacket.TypeID:
                packet = new PingPacket(typeID, buffer, offset, size);
                break;

            case CS_State.TypeID:
                packet = new CS_State(typeID, buffer, offset, size);
                break;

            case Reliable.TypeID:
                packet = new Reliable(typeID, buffer, offset, size, 0);
                break;

            case Reliable.TypeID + 1:
                packet = new Reliable(typeID, buffer, offset, size, 1);
                break;

            case Reliable.TypeID + 2:
                packet = new Reliable(typeID, buffer, offset, size, 2);
                break;

            case Reliable.TypeID + 3:
                packet = new Reliable(typeID, buffer, offset, size, 3);
                break;

            case OutOfSync.TypeID:
                packet = new OutOfSync(typeID, buffer, offset, size, 0);
                break;

            case OutOfSync.TypeID + 1:
                packet = new OutOfSync(typeID, buffer, offset, size, 1);
                break;

            case OutOfSync.TypeID + 2:
                packet = new OutOfSync(typeID, buffer, offset, size, 2);
                break;

            case OutOfSync.TypeID + 3:
                packet = new OutOfSync(typeID, buffer, offset, size, 3);
                break;

            case ReliableEcho.TypeID:
                packet = new ReliableEcho(typeID, buffer, offset, size, 0);
                break;

            case ReliableEcho.TypeID + 1:
                packet = new ReliableEcho(typeID, buffer, offset, size, 1);
                break;

            case ReliableEcho.TypeID + 2:
                packet = new ReliableEcho(typeID, buffer, offset, size, 2);
                break;

            case ReliableEcho.TypeID + 3:
                packet = new ReliableEcho(typeID, buffer, offset, size, 3);
                break;

            case ReliableBox.TypeID:
                packet = new ReliableBox(typeID, buffer, offset, size, 0);
                break;

            case ReliableBox.TypeID + 1:
                packet = new ReliableBox(typeID, buffer, offset, size, 1);
                break;

            case ReliableBox.TypeID + 2:
                packet = new ReliableBox(typeID, buffer, offset, size, 2);
                break;

            case ReliableBox.TypeID + 3:
                packet = new ReliableBox(typeID, buffer, offset, size, 3);
                break;

            case DataPacketRcv.TypeID:
                packet = new DataPacketRcv(typeID, buffer, offset, size, 0);
                break;

            case DataPacketRcv.TypeID + 1:
                packet = new DataPacketRcv(typeID, buffer, offset, size, 1);
                break;

            case DataPacketRcv.TypeID + 2:
                packet = new DataPacketRcv(typeID, buffer, offset, size, 2);
                break;

            case DataPacketRcv.TypeID + 3:
                packet = new DataPacketRcv(typeID, buffer, offset, size, 3);
                break;

            default:
                //An undefined packet.
                packet = new PacketDummy(typeID, buffer, offset, size);
                break;
            }

            return(packet);
        }
예제 #6
0
        /// <summary>
        /// Creates a new packet based on the typeID and the received content
        /// inside the buffer. The user has to create an own implementation
        /// of this interface.
        /// </summary>
        public PacketBase createPacket(NetworkClient client, ushort typeID, byte[] buffer, int offset, int size)
        {               //Ready our packet base
            PacketBase packet = null;

            size--;

            //Was it a system packet?
            if (buffer[offset++] == 0)
            {
                //Yes, find the appropriate type
                return(createSystemPacket(typeID, buffer, offset, size));
            }

            //So what was the typeid?
            switch (typeID)
            {
            case CS_Auth <T> .TypeID:
                packet = new CS_Auth <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerLogin <T> .TypeID:
                packet = new CS_PlayerLogin <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerUpdate <T> .TypeID:
                packet = new CS_PlayerUpdate <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerLeave <T> .TypeID:
                packet = new CS_PlayerLeave <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerBanner <T> .TypeID:
                packet = new CS_PlayerBanner <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerStatsRequest <T> .TypeID:
                packet = new CS_PlayerStatsRequest <T>(typeID, buffer, offset, size);
                break;

            case CS_Whisper <T> .TypeID:
                packet = new CS_Whisper <T>(typeID, buffer, offset, size);
                break;

            case CS_JoinChat <T> .TypeID:
                packet = new CS_JoinChat <T>(typeID, buffer, offset, size);
                break;

            case CS_LeaveChat <T> .TypeID:
                packet = new CS_LeaveChat <T>(typeID, buffer, offset, size);
                break;

            case CS_PrivateChat <T> .TypeID:
                packet = new CS_PrivateChat <T>(typeID, buffer, offset, size);
                break;

            case CS_ModCommand <T> .TypeID:
                packet = new CS_ModCommand <T>(typeID, buffer, offset, size);
                break;

            case CS_Squads <T> .TypeID:
                packet = new CS_Squads <T>(typeID, buffer, offset, size);
                break;

            case CS_ChatQuery <T> .TypeID:
                packet = new CS_ChatQuery <T>(typeID, buffer, offset, size);
                break;

            case Disconnect <T> .TypeID:
                packet = new Disconnect <T>(typeID, buffer, offset, size);
                break;

            case CS_Ban <T> .TypeID:
                packet = new CS_Ban <T>(typeID, buffer, offset, size);
                break;

            case CS_SquadMatch <T> .TypeID:
                packet = new CS_SquadMatch <T>(typeID, buffer, offset, size);
                break;

            case CS_ModQuery <T> .TypeID:
                packet = new CS_ModQuery <T>(typeID, buffer, offset, size);
                break;

            case CS_ChatCommand <T> .TypeID:
                packet = new CS_ChatCommand <T>(typeID, buffer, offset, size);
                break;

            case CS_StatsUpdate <T> .TypeID:
                packet = new CS_StatsUpdate <T>(typeID, buffer, offset, size);
                break;

            case CS_ArenaUpdate <T> .TypeID:
                packet = new CS_ArenaUpdate <T>(typeID, buffer, offset, size);
                break;

            default:
                //An undefined packet.
                packet = new PacketDummy(typeID, buffer, offset, size);
                break;
            }

            return(packet);
        }
예제 #7
0
파일: Factory.cs 프로젝트: trjate/Infantry
        /// <summary>
        /// Creates a new packet based on the typeID and the received content
        /// inside the buffer. The user has to create an own implementation
        /// of this interface.
        /// </summary>
        public PacketBase createPacket(NetworkClient client, ushort typeID, byte[] buffer, int offset, int size)
        {               //Ready our packet base
            PacketBase packet = null;

            size--;

            //Was it a system packet?
            if (buffer[offset++] == 0)
            {
                //Yes, find the appropriate type
                return(createSystemPacket(typeID, buffer, offset, size));
            }

            //So what was the typeid?
            switch (typeID)
            {
            case CS_Login.TypeID:
                packet = new CS_Login(typeID, buffer, offset, size);
                break;

            case CS_ArenaJoin.TypeID:
                packet = new CS_ArenaJoin(typeID, buffer, offset, size);
                break;

            case CS_PlayerJoin.TypeID:
                packet = new CS_PlayerJoin(typeID, buffer, offset, size);
                break;

            case CS_Ready.TypeID:
                packet = new CS_Ready(typeID, buffer, offset, size);
                break;

            case CS_PlayerPickup.TypeID:
                packet = new CS_PlayerPickup(typeID, buffer, offset, size);
                break;

            case CS_PlayerDrop.TypeID:
                packet = new CS_PlayerDrop(typeID, buffer, offset, size);
                break;

            case CS_Chat.TypeID:
                packet = new CS_Chat(typeID, buffer, offset, size);
                break;

            case CS_PlayerUseItem.TypeID:
                packet = new CS_PlayerUseItem(typeID, buffer, offset, size);
                break;

            case CS_Explosion.TypeID:
                packet = new CS_Explosion(typeID, buffer, offset, size);
                break;

            case CS_PlayerUpdate.TypeID:
                packet = new CS_PlayerUpdate(typeID, buffer, offset, size);
                break;

            case CS_Shop.TypeID:
                packet = new CS_Shop(typeID, buffer, offset, size);
                break;

            case CS_ShopSkill.TypeID:
                packet = new CS_ShopSkill(typeID, buffer, offset, size);
                break;

            case CS_PlayerSwitch.TypeID:
                packet = new CS_PlayerSwitch(typeID, buffer, offset, size);
                break;

            case CS_PlayerFlag.TypeID:
                packet = new CS_PlayerFlag(typeID, buffer, offset, size);
                break;

            case CS_RequestUpdate.TypeID:
                packet = new CS_RequestUpdate(typeID, buffer, offset, size);
                break;

            case CS_StartUpdate.TypeID:
                packet = new CS_StartUpdate(typeID, buffer, offset, size);
                break;

            case CS_VehicleDeath.TypeID:
                packet = new CS_VehicleDeath(typeID, buffer, offset, size);
                break;

            case CS_PlayerPortal.TypeID:
                packet = new CS_PlayerPortal(typeID, buffer, offset, size);
                break;

            case CS_AllowSpectator.TypeID:
                packet = new CS_AllowSpectator(typeID, buffer, offset, size);
                break;

            case CS_RequestSpectator.TypeID:
                packet = new CS_RequestSpectator(typeID, buffer, offset, size);
                break;

            case CS_ItemExpired.TypeID:
                packet = new CS_ItemExpired(typeID, buffer, offset, size);
                break;

            case CS_PlayerProduce.TypeID:
                packet = new CS_PlayerProduce(typeID, buffer, offset, size);
                break;

            case CS_SetBanner.TypeID:
                packet = new CS_SetBanner(typeID, buffer, offset, size);
                break;

            case CS_FileSend.TypeID:
                packet = new CS_FileSend(typeID, buffer, offset, size);
                break;

            case CS_Environment.TypeID:
                packet = new CS_Environment(typeID, buffer, offset, size);
                break;

            case CS_Frames.TypeID:
                packet = new CS_Frames(typeID, buffer, offset, size);
                break;

            case CS_ChartRequest.TypeID:
                packet = new CS_ChartRequest(typeID, buffer, offset, size);
                break;

            case CS_SecurityCheck.TypeID:
                packet = new CS_SecurityCheck(typeID, buffer, offset, size);
                break;

            case CS_BallPickup.TypeID:
                packet = new CS_BallPickup(typeID, buffer, offset, size);
                break;

            case CS_BallDrop.TypeID:
                packet = new CS_BallDrop(typeID, buffer, offset, size);
                break;

            case CS_GoalScored.TypeID:
                packet = new CS_GoalScored(typeID, buffer, offset, size);
                break;

            case CS_VehiclePickup.TypeID:
                packet = new CS_VehiclePickup(typeID, buffer, offset, size);
                break;

            case CS_SendBanner.TypeID:
                packet = new CS_SendBanner(typeID, buffer, offset, size);
                break;

            case CS_DamageEvent.TypeID:
                packet = new CS_DamageEvent(typeID, buffer, offset, size);
                break;

            case CS_PlayerZoneDisconnected.TypeID:
                packet = new CS_PlayerZoneDisconnected(typeID, buffer, offset, size);
                break;

            case CS_RegResponse.TypeID:
                packet = new CS_RegResponse(typeID, buffer, offset, size);
                break;

            case CS_Unknown.TypeID:
                packet = new CS_Unknown(typeID, buffer, offset, size);
                break;

            default:
                //An undefined packet.
                packet = new PacketDummy(typeID, buffer, offset, size);
                break;
            }

            return(packet);
        }
예제 #8
0
        /// <summary>
        /// Creates a new packet based on the typeID and the received content
        /// inside the buffer. The user has to create an own implementation
        /// of this interface.
        /// </summary>
        public PacketBase createPacket(NetworkClient client, ushort typeID, byte[] buffer, int offset, int size)
        {               //Ready our packet base
            PacketBase packet = null;

            size--;

            //Was it a system packet?
            if (buffer[offset++] == 0)
            {
                //Yes, find the appropriate type
                return(createSystemPacket(typeID, buffer, offset, size));
            }

            //So what was the typeid?
            switch (typeID)
            {
            case SC_Auth <T> .TypeID:
                packet = new SC_Auth <T>(typeID, buffer, offset, size);
                break;

            case SC_PlayerLogin <T> .TypeID:
                packet = new SC_PlayerLogin <T>(typeID, buffer, offset, size);
                break;

            case SC_PlayerStatsResponse <T> .TypeID:
                packet = new SC_PlayerStatsResponse <T>(typeID, buffer, offset, size);
                break;

            case SC_Whisper <T> .TypeID:
                packet = new SC_Whisper <T>(typeID, buffer, offset, size);
                break;

            case SC_JoinChat <T> .TypeID:
                packet = new SC_JoinChat <T>(typeID, buffer, offset, size);
                break;

            case SC_LeaveChat <T> .TypeID:
                packet = new SC_LeaveChat <T>(typeID, buffer, offset, size);
                break;

            case SC_PrivateChat <T> .TypeID:
                packet = new SC_PrivateChat <T>(typeID, buffer, offset, size);
                break;

            case SC_Chat <T> .TypeID:
                packet = new SC_Chat <T>(typeID, buffer, offset, size);
                break;

            case SC_Zones <T> .TypeID:
                packet = new SC_Zones <T>(typeID, buffer, offset, size);
                break;

            case Disconnect <T> .TypeID:
                packet = new Disconnect <T>(typeID, buffer, offset, size);
                break;

            default:
                //An undefined packet.
                packet = new PacketDummy(typeID, buffer, offset, size);
                break;
            }

            return(packet);
        }