Exemplo n.º 1
0
        public ServerUpdatePacket(Packet packet) : base(packet)
        {
            DataPacketIds = new HashSet <ServerPacketId>();

            HelloServer = new HelloServer();

            PlayerUpdate  = new PlayerUpdate();
            EntityUpdates = new PacketDataCollection <EntityUpdate>();

            PlayerEnterScene  = new ServerPlayerEnterScene();
            PlayerTeamUpdate  = new ServerPlayerTeamUpdate();
            PlayerSkinUpdate  = new ServerPlayerSkinUpdate();
            PlayerEmoteUpdate = new ServerPlayerEmoteUpdate();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Find an existing or create a new EntityUpdate instance in the current update packet.
        /// </summary>
        /// <param name="entityType">The type of the entity.</param>
        /// <param name="entityId">The ID of the entity.</param>
        /// <returns>The existing or new EntityUpdate instance.</returns>
        private EntityUpdate FindOrCreateEntityUpdate(EntityType entityType, byte entityId)
        {
            EntityUpdate entityUpdate = null;
            PacketDataCollection <EntityUpdate> entityUpdateCollection;

            // First check whether there actually exists entity data at all
            if (CurrentUpdatePacket.TryGetSendingPacketData(
                    ServerPacketId.EntityUpdate,
                    out var packetData)
                )
            {
                // And if there exists data already, try to find a match for the entity type and id
                entityUpdateCollection = (PacketDataCollection <EntityUpdate>)packetData;
                foreach (var existingPacketData in entityUpdateCollection.DataInstances)
                {
                    var existingEntityUpdate = (EntityUpdate)existingPacketData;
                    if (existingEntityUpdate.EntityType.Equals((byte)entityType) && existingEntityUpdate.Id == entityId)
                    {
                        entityUpdate = existingEntityUpdate;
                        break;
                    }
                }
            }
            else
            {
                // If no data exists yet, we instantiate the data collection class and put it at the respective key
                entityUpdateCollection = new PacketDataCollection <EntityUpdate>();
                CurrentUpdatePacket.SetSendingPacketData(ServerPacketId.EntityUpdate, entityUpdateCollection);
            }

            // If no existing instance was found, create one and add it to the (newly created) collection
            if (entityUpdate == null)
            {
                entityUpdate = new EntityUpdate {
                    EntityType = (byte)entityType,
                    Id         = entityId
                };


                entityUpdateCollection.DataInstances.Add(entityUpdate);
            }

            return(entityUpdate);
        }
Exemplo n.º 3
0
        public ClientUpdatePacket(Packet packet) : base(packet)
        {
            DataPacketIds = new HashSet <ClientPacketId>();

            PlayerConnect        = new PacketDataCollection <PlayerConnect>();
            PlayerDisconnect     = new PacketDataCollection <ClientPlayerDisconnect>();
            PlayerEnterScene     = new PacketDataCollection <ClientPlayerEnterScene>();
            PlayerAlreadyInScene = new ClientPlayerAlreadyInScene();
            PlayerLeaveScene     = new PacketDataCollection <GenericClientData>();

            PlayerUpdates = new PacketDataCollection <PlayerUpdate>();
            EntityUpdates = new PacketDataCollection <EntityUpdate>();

            PlayerDeath       = new PacketDataCollection <GenericClientData>();
            PlayerTeamUpdate  = new PacketDataCollection <ClientPlayerTeamUpdate>();
            PlayerSkinUpdate  = new PacketDataCollection <ClientPlayerSkinUpdate>();
            PlayerEmoteUpdate = new PacketDataCollection <ClientPlayerEmoteUpdate>();

            GameSettingsUpdate = new GameSettingsUpdate();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Find or create a packet data instance in the current packet that matches the given ID of a client.
        /// </summary>
        /// <param name="id">The ID of the client in the generic client data.</param>
        /// <param name="packetId">The ID of the packet data.</param>
        /// <typeparam name="T">The type of the generic client packet data.</typeparam>
        /// <returns>An instance of the packet data in the packet.</returns>
        private T FindOrCreatePacketData <T>(ushort id, ClientPacketId packetId) where T : GenericClientData, new()
        {
            PacketDataCollection <T> packetDataCollection;
            IPacketData packetData = null;

            // First check whether there actually exists a data collection for this packet ID
            if (CurrentUpdatePacket.TryGetSendingPacketData(packetId, out var iPacketDataAsCollection))
            {
                // And if so, try to find the packet data with the requested client ID
                packetDataCollection = (PacketDataCollection <T>)iPacketDataAsCollection;

                foreach (var existingPacketData in packetDataCollection.DataInstances)
                {
                    if (((GenericClientData)existingPacketData).Id == id)
                    {
                        packetData = existingPacketData;
                        break;
                    }
                }
            }
            else
            {
                // If no data collection exists, we create one instead
                packetDataCollection = new PacketDataCollection <T>();
                CurrentUpdatePacket.SetSendingPacketData(packetId, packetDataCollection);
            }

            // If no existing instance was found, create one and add it to the (newly created) collection
            if (packetData == null)
            {
                packetData = new T {
                    Id = id
                };

                packetDataCollection.DataInstances.Add(packetData);
            }

            return((T)packetData);
        }