示例#1
0
 private void RemoveInTransitAvatar(InTransitAvatar transitAvatar)
 {
     lock (_inTransitAvatars)
     {
         _inTransitAvatars.Remove(transitAvatar.UserId);
     }
 }
示例#2
0
        private async Task DoBeginOutboundTransit(InTransitAvatar transitAvatar)
        {
            Exception transitError = null;

            try
            {
                await BeginOutboundTransit(transitAvatar);
            }
            catch (Exception e)
            {
                var last = _lastError;
                if (last != null && (last.Item1 != transitAvatar.UserId || e.Message != last.Item2))
                {
                    _log.ErrorFormat("[TRANSITCONTROLLER]: Error while sending avatar {0}. {1}", transitAvatar.UserId, e);
                    _lastError = Tuple.Create(transitAvatar.UserId, e.Message);
                }

                try
                {
                    transitAvatar.Rollback();
                }
                catch (Exception er)
                {
                    _log.ErrorFormat("[TRANSITCONTROLLER]: Error while performing rollback of avatar that failed transit. {0}", er);
                }

                transitError = e;
            }

            if (transitError != null)
            {
                try
                {
                    await transitAvatar.TriggerOnTransitStageChanged(TransitStage.SendError, transitAvatar.RideOnPrims);
                }
                catch (Exception e)
                {
                    _log.ErrorFormat("[TRANSITCONTROLLER]: Error while triggering TransitStage.SendError. {0}", e);
                }

                RemoveInTransitAvatar(transitAvatar);

                throw new AvatarTransitException(transitError.Message, transitError);
            }
            else
            {
                try
                {
                    await transitAvatar.TriggerOnTransitStageChanged(TransitStage.SendCompletedSuccess, transitAvatar.RideOnPrims);
                }
                catch (Exception e)
                {
                    _log.ErrorFormat("[TRANSITCONTROLLER]: Error while triggering TransitStage.SendCompletedSuccess. {0}", e);
                }

                RemoveInTransitAvatar(transitAvatar);
            }
        }
示例#3
0
        /// <summary>
        /// Called by an intransit avatar when its transit stage has changed
        /// </summary>
        /// <param name="inTransitAvatar"></param>
        /// <param name="transitStage"></param>
        internal async Task TriggerOnTransitStageChanged(InTransitAvatar inTransitAvatar, TransitStage transitStage,
                                                         IEnumerable <uint> rideOnPrims)
        {
            var tscDelegate = this.OnTransitStateChanged;

            if (tscDelegate != null)
            {
                await tscDelegate(inTransitAvatar.ScenePresence, transitStage, rideOnPrims);
            }
        }
示例#4
0
        /// <summary>
        /// Begins a transit to another region
        /// </summary>
        /// <param name="transit"></param>
        /// <param name="transitAvatar"></param>
        private Task BeginOutboundTransit(InTransitAvatar transitAvatar)
        {
            transitAvatar.ScenePresence = _scene.GetScenePresence(transitAvatar.UserId);
            if (transitAvatar.ScenePresence == null)
            {
                throw new InvalidOperationException(String.Format("Avatar {0} is not in the scene and can not be put in transit", transitAvatar.UserId));
            }

            return(transitAvatar.SetNewState(new SendStates.TransitBeginState(transitAvatar)));
        }
示例#5
0
        /// <summary>
        /// Tries to begin a transit from or to another region
        /// </summary>
        /// <param name="transit"></param>
        /// <returns>Whether or not the transit was started, or one was already in progress</returns>
        public async Task TryBeginTransit(TransitArguments transit)
        {
            InTransitAvatar transitAvatar;

            lock (_inTransitAvatars)
            {
                if (_inTransitAvatars.TryGetValue(transit.UserId, out transitAvatar))
                {
                    throw new AvatarTransitException("Avatar is already in transit");
                }

                transitAvatar = new InTransitAvatar(this, transit);
                _inTransitAvatars.Add(transit.UserId, transitAvatar);
            }

            if (transit.Type == TransitType.OutboundTeleport || transit.Type == TransitType.OutboundCrossing)
            {
                await DoBeginOutboundTransit(transitAvatar);
            }
        }
示例#6
0
 /// <summary>
 /// Called by an intransit avatar when its transit stage has changed
 /// </summary>
 /// <param name="inTransitAvatar"></param>
 /// <param name="transitStage"></param>
 internal async Task TriggerOnTransitStageChanged(InTransitAvatar inTransitAvatar, TransitStage transitStage, 
     IEnumerable<uint> rideOnPrims)
 {
     var tscDelegate = this.OnTransitStateChanged;
     if (tscDelegate != null)
     {
         await tscDelegate(inTransitAvatar.ScenePresence, transitStage, rideOnPrims);
     }
 }
示例#7
0
        /// <summary>
        /// Begins a transit to another region
        /// </summary>
        /// <param name="transit"></param>
        /// <param name="transitAvatar"></param>
        private Task BeginOutboundTransit(InTransitAvatar transitAvatar)
        {
            transitAvatar.ScenePresence = _scene.GetScenePresence(transitAvatar.UserId);
            if (transitAvatar.ScenePresence == null)
            {
                throw new InvalidOperationException(String.Format("Avatar {0} is not in the scene and can not be put in transit", transitAvatar.UserId));
            }

            return transitAvatar.SetNewState(new SendStates.TransitBeginState(transitAvatar));
        }
示例#8
0
 private void RemoveInTransitAvatar(InTransitAvatar transitAvatar)
 {
     lock (_inTransitAvatars)
     {
         _inTransitAvatars.Remove(transitAvatar.UserId);
     }
 }
示例#9
0
        private async Task DoBeginOutboundTransit(InTransitAvatar transitAvatar)
        {
            Exception transitError = null;
            try
            {
                await BeginOutboundTransit(transitAvatar);
            }
            catch (Exception e)
            {
                var last = _lastError;
                if (last != null && (last.Item1 != transitAvatar.UserId || e.Message != last.Item2))
                {
                    _log.ErrorFormat("[TRANSITCONTROLLER]: Error while sending avatar {0}. {1}", transitAvatar.UserId, e);
                    _lastError = Tuple.Create(transitAvatar.UserId, e.Message);
                }

                try
                {
                    transitAvatar.Rollback();
                }
                catch (Exception er)
                {
                    _log.ErrorFormat("[TRANSITCONTROLLER]: Error while performing rollback of avatar that failed transit. {0}", er);
                }

                transitError = e;
            }

            if (transitError != null)
            {
                try
                {
                    await transitAvatar.TriggerOnTransitStageChanged(TransitStage.SendError, transitAvatar.RideOnPrims);
                }
                catch (Exception e)
                {
                    _log.ErrorFormat("[TRANSITCONTROLLER]: Error while triggering TransitStage.SendError. {0}", e);
                }

                RemoveInTransitAvatar(transitAvatar);

                throw new AvatarTransitException(transitError.Message, transitError);
            }
            else
            {
                try
                {
                    await transitAvatar.TriggerOnTransitStageChanged(TransitStage.SendCompletedSuccess, transitAvatar.RideOnPrims);
                }
                catch (Exception e)
                {
                    _log.ErrorFormat("[TRANSITCONTROLLER]: Error while triggering TransitStage.SendCompletedSuccess. {0}", e);
                }

                RemoveInTransitAvatar(transitAvatar);
            }
        }
示例#10
0
        /// <summary>
        /// Tries to begin a transit from or to another region
        /// </summary>
        /// <param name="transit"></param>
        /// <returns>Whether or not the transit was started, or one was already in progress</returns>
        public async Task TryBeginTransit(TransitArguments transit)
        {
            InTransitAvatar transitAvatar;
            lock (_inTransitAvatars)
            {
                if (_inTransitAvatars.TryGetValue(transit.UserId, out transitAvatar))
                {
                    throw new AvatarTransitException("Avatar is already in transit");
                }

                transitAvatar = new InTransitAvatar(this, transit);
                _inTransitAvatars.Add(transit.UserId, transitAvatar);
            }

            if (transit.Type == TransitType.OutboundTeleport || transit.Type == TransitType.OutboundCrossing)
            {
                await DoBeginOutboundTransit(transitAvatar);
            }
        }