Example #1
0
        public override void ReadPacket()
        {
            ReadHeaders(Packet);

            // Read the byte flag representing which packets
            // are included in this update
            var dataPacketIdFlag = Packet.ReadUShort();
            // Keep track of value of current bit
            var currentTypeValue = 1;

            for (var i = 0; i < Enum.GetNames(typeof(ClientPacketId)).Length; i++)
            {
                // If this bit was set in our flag, we add the type to the list
                if ((dataPacketIdFlag & currentTypeValue) != 0)
                {
                    DataPacketIds.Add((ClientPacketId)i);
                }

                // Increase the value of current bit
                currentTypeValue *= 2;
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerConnect))
            {
                PlayerConnect.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerDisconnect))
            {
                PlayerDisconnect.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerEnterScene))
            {
                PlayerEnterScene.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerAlreadyInScene))
            {
                PlayerAlreadyInScene.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerLeaveScene))
            {
                PlayerLeaveScene.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerUpdate))
            {
                PlayerUpdates.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.EntityUpdate))
            {
                EntityUpdates.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerDeath))
            {
                PlayerDeath.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerTeamUpdate))
            {
                PlayerTeamUpdate.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerSkinUpdate))
            {
                PlayerSkinUpdate.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.PlayerEmoteUpdate))
            {
                PlayerEmoteUpdate.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ClientPacketId.GameSettingsUpdated))
            {
                GameSettingsUpdate.ReadData(Packet);
            }
        }
Example #2
0
        public override void ReadPacket()
        {
            ReadHeaders(Packet);

            // Read the byte flag representing which packets
            // are included in this update
            var dataPacketIdFlag = Packet.ReadUShort();
            // Keep track of value of current bit
            var currentTypeValue = 1;

            for (var i = 0; i < Enum.GetNames(typeof(ServerPacketId)).Length; i++)
            {
                // If this bit was set in our flag, we add the type to the list
                if ((dataPacketIdFlag & currentTypeValue) != 0)
                {
                    DataPacketIds.Add((ServerPacketId)i);
                }

                // Increase the value of current bit
                currentTypeValue *= 2;
            }

            /*
             * foreach (var item in DataPacketIds)
             * {
             *  Logger.Info(this,$"reading packet with {Enum.GetName(typeof(ServerPacketId), item)}");
             * }
             */


            if (DataPacketIds.Contains(ServerPacketId.HelloServer))
            {
                HelloServer.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ServerPacketId.PlayerUpdate))
            {
                PlayerUpdate.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ServerPacketId.EntityUpdate))
            {
                EntityUpdates.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ServerPacketId.PlayerEnterScene))
            {
                PlayerEnterScene.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ServerPacketId.PlayerTeamUpdate))
            {
                PlayerTeamUpdate.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ServerPacketId.PlayerSkinUpdate))
            {
                PlayerSkinUpdate.ReadData(Packet);
            }

            if (DataPacketIds.Contains(ServerPacketId.PlayerEmoteUpdate))
            {
                PlayerEmoteUpdate.ReadData(Packet);
            }
        }