Exemplo n.º 1
0
        public void SetLostReliableData(ServerUpdatePacket lostPacket)
        {
            if (lostPacket.DataPacketIds.Contains(ServerPacketId.HelloServer))
            {
                Logger.Info(this, "  Resending HelloServer data");

                DataPacketIds.Add(ServerPacketId.HelloServer);
                HelloServer = lostPacket.HelloServer;
            }

            if (lostPacket.DataPacketIds.Contains(ServerPacketId.PlayerEnterScene))
            {
                Logger.Info(this, "  Resending PlayerEnterScene data");

                DataPacketIds.Add(ServerPacketId.PlayerEnterScene);
                PlayerEnterScene = lostPacket.PlayerEnterScene;
            }

            if (lostPacket.DataPacketIds.Contains(ServerPacketId.PlayerLeaveScene))
            {
                Logger.Info(this, "  Resending PlayerLeaveScene data");

                DataPacketIds.Add(ServerPacketId.PlayerLeaveScene);
            }

            if (lostPacket.DataPacketIds.Contains(ServerPacketId.PlayerTeamUpdate))
            {
                // Only update if the current packet does not already contain another team update
                // since we want the latest update to arrive
                if (!DataPacketIds.Contains(ServerPacketId.PlayerTeamUpdate))
                {
                    Logger.Info(this, "  Resending PlayerTeamUpdate data");

                    DataPacketIds.Add(ServerPacketId.PlayerTeamUpdate);
                    PlayerTeamUpdate = lostPacket.PlayerTeamUpdate;
                }
            }

            if (lostPacket.DataPacketIds.Contains(ServerPacketId.PlayerSkinUpdate))
            {
                // Only update if the current packet does not already contain another skin update
                // since we want the latest update to arrive
                if (!DataPacketIds.Contains(ServerPacketId.PlayerSkinUpdate))
                {
                    Logger.Info(this, "  Resending PlayerSkinUpdate data");

                    DataPacketIds.Add(ServerPacketId.PlayerSkinUpdate);
                    PlayerSkinUpdate = lostPacket.PlayerSkinUpdate;
                }
            }
        }
Exemplo n.º 2
0
        /**
         * Handle data received by the server
         */
        public void HandleServerPacket(ushort id, ServerUpdatePacket packet)
        {
            /*foreach (var item in packet.DataPacketIds)
             * {
             *  Logger.Info(this,$"server to handle {Enum.GetName(typeof(ServerPacketId), item)}");
             * }
             */
            // Execute corresponding packet handlers
            if (packet.DataPacketIds.Contains(ServerPacketId.HelloServer))
            {
                ExecuteServerPacketHandler(id, ServerPacketId.HelloServer, packet.HelloServer);
            }

            if (packet.DataPacketIds.Contains(ServerPacketId.PlayerDisconnect))
            {
                ExecuteServerPacketHandler(id, ServerPacketId.PlayerDisconnect, null);
            }

            if (packet.DataPacketIds.Contains(ServerPacketId.PlayerUpdate))
            {
                ExecuteServerPacketHandler(id, ServerPacketId.PlayerUpdate, packet.PlayerUpdate);
            }

            if (packet.DataPacketIds.Contains(ServerPacketId.EntityUpdate))
            {
                foreach (var entityUpdate in packet.EntityUpdates.DataInstances)
                {
                    ExecuteServerPacketHandler(id, ServerPacketId.EntityUpdate, entityUpdate);
                }
            }

            if (packet.DataPacketIds.Contains(ServerPacketId.PlayerEnterScene))
            {
                ExecuteServerPacketHandler(id, ServerPacketId.PlayerEnterScene, packet.PlayerEnterScene);
            }

            if (packet.DataPacketIds.Contains(ServerPacketId.PlayerLeaveScene))
            {
                ExecuteServerPacketHandler(id, ServerPacketId.PlayerLeaveScene, null);
            }

            if (packet.DataPacketIds.Contains(ServerPacketId.PlayerDeath))
            {
                ExecuteServerPacketHandler(id, ServerPacketId.PlayerDeath, null);
            }

            if (packet.DataPacketIds.Contains(ServerPacketId.PlayerTeamUpdate))
            {
                ExecuteServerPacketHandler(id, ServerPacketId.PlayerTeamUpdate, packet.PlayerTeamUpdate);
            }

            if (packet.DataPacketIds.Contains(ServerPacketId.PlayerSkinUpdate))
            {
                ExecuteServerPacketHandler(id, ServerPacketId.PlayerSkinUpdate, packet.PlayerSkinUpdate);
            }

            if (packet.DataPacketIds.Contains(ServerPacketId.PlayerEmoteUpdate))
            {
                ExecuteServerPacketHandler(id, ServerPacketId.PlayerEmoteUpdate, packet.PlayerEmoteUpdate);
            }
        }