Exemplo n.º 1
0
 /// <summary>
 /// Set a chat message in the current packet.
 /// </summary>
 /// <param name="message">The string message.</param>
 public void SetChatMessage(string message)
 {
     lock (Lock) {
         CurrentUpdatePacket.SetSendingPacketData(ServerPacketId.ChatMessage, new ChatMessage {
             Message = message
         });
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Set a skin update in the current packet.
 /// </summary>
 /// <param name="skinId">The ID of the skin of the player.</param>
 public void SetSkinUpdate(byte skinId)
 {
     lock (Lock) {
         CurrentUpdatePacket.SetSendingPacketData(
             ServerPacketId.PlayerSkinUpdate,
             new ServerPlayerSkinUpdate {
             SkinId = skinId
         }
             );
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Set a team update in the current packet.
 /// </summary>
 /// <param name="team">The new team of the player.</param>
 public void SetTeamUpdate(Team team)
 {
     lock (Lock) {
         CurrentUpdatePacket.SetSendingPacketData(
             ServerPacketId.PlayerTeamUpdate,
             new ServerPlayerTeamUpdate {
             Team = team
         }
             );
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Set the login request data in the current packet.
        /// </summary>
        /// <param name="username">The username of the client.</param>
        /// <param name="authKey">The auth key of the client.</param>
        /// <param name="addonData">A list of addon data of the client.</param>
        public void SetLoginRequestData(string username, string authKey, List <AddonData> addonData)
        {
            lock (Lock) {
                var loginRequest = new LoginRequest {
                    Username = username,
                    AuthKey  = authKey
                };
                loginRequest.AddonData.AddRange(addonData);

                CurrentUpdatePacket.SetSendingPacketData(ServerPacketId.LoginRequest, loginRequest);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Find an existing or create a new PlayerUpdate instance in the current update packet.
        /// </summary>
        /// <returns>The existing or new PlayerUpdate instance.</returns>
        private PlayerUpdate FindOrCreatePlayerUpdate()
        {
            if (!CurrentUpdatePacket.TryGetSendingPacketData(
                    ServerPacketId.PlayerUpdate,
                    out var packetData))
            {
                packetData = new PlayerUpdate();
                CurrentUpdatePacket.SetSendingPacketData(ServerPacketId.PlayerUpdate, packetData);
            }

            return((PlayerUpdate)packetData);
        }
Exemplo n.º 6
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.º 7
0
 /// <summary>
 /// Set enter scene data in the current packet.
 /// </summary>
 /// <param name="sceneName">The name of the entered scene.</param>
 /// <param name="position">The position of the player.</param>
 /// <param name="scale">The scale of the player.</param>
 /// <param name="animationClipId">The animation clip ID of the player.</param>
 public void SetEnterSceneData(
     string sceneName,
     Vector2 position,
     bool scale,
     ushort animationClipId
     )
 {
     lock (Lock) {
         CurrentUpdatePacket.SetSendingPacketData(
             ServerPacketId.PlayerEnterScene,
             new ServerPlayerEnterScene {
             NewSceneName    = sceneName,
             Position        = position,
             Scale           = scale,
             AnimationClipId = animationClipId
         }
             );
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Set hello server data in the current packet.
 /// </summary>
 /// <param name="username">The username of the player.</param>
 /// <param name="sceneName">The name of the current scene of the player.</param>
 /// <param name="position">The position of the player.</param>
 /// <param name="scale">The scale of the player.</param>
 /// <param name="animationClipId">The animation clip ID of the player.</param>
 public void SetHelloServerData(
     string username,
     string sceneName,
     Vector2 position,
     bool scale,
     ushort animationClipId
     )
 {
     lock (Lock) {
         CurrentUpdatePacket.SetSendingPacketData(
             ServerPacketId.HelloServer,
             new HelloServer {
             Username        = username,
             SceneName       = sceneName,
             Position        = position,
             Scale           = scale,
             AnimationClipId = animationClipId
         }
             );
     }
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Set that the player has died in the current packet.
 /// </summary>
 public void SetDeath()
 {
     lock (Lock) {
         CurrentUpdatePacket.SetSendingPacketData(ServerPacketId.PlayerDeath, new ReliableEmptyData());
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Set that the player has left the current scene in the current packet.
 /// </summary>
 public void SetLeftScene()
 {
     lock (Lock) {
         CurrentUpdatePacket.SetSendingPacketData(ServerPacketId.PlayerLeaveScene, new ReliableEmptyData());
     }
 }
Exemplo n.º 12
0
 /// <inheritdoc />
 public override void ResendReliableData(ServerUpdatePacket lostPacket)
 {
     lock (Lock) {
         CurrentUpdatePacket.SetLostReliableData(lostPacket);
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// Set that the player has disconnected in the current packet.
 /// </summary>
 public void SetPlayerDisconnect()
 {
     lock (Lock) {
         CurrentUpdatePacket.SetSendingPacketData(ServerPacketId.PlayerDisconnect, new EmptyData());
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Set login response data in the current packet.
 /// </summary>
 /// <param name="loginResponse">The login response data.</param>
 public void SetLoginResponse(LoginResponse loginResponse)
 {
     lock (Lock) {
         CurrentUpdatePacket.SetSendingPacketData(ClientPacketId.LoginResponse, loginResponse);
     }
 }