Пример #1
0
        private bool IsLocked(Locked locked, Touch touch)
        {
            if (locked == null)
                return false;

            Lock holderLock = locked.Holder.Configuration.Lock;

            // Checking whether lock is still active
            if ((DateTime.UtcNow - locked.Time) > TimeSpan.FromMilliseconds(locked.Delay)
                && (!holderLock.DuringTouchSession || locked.Touch.TouchSessionIndex != locked.Touch.Session.TouchSessionIndex))
            {
                if (holderLock.Personal)
                    PersonalLocked.TryRemove(touch.Session.PlayerIndex, out _);
                else
                    Locked = null;
                return false;
            }

            // Immidiately blocking if user who set locked is different from current user
            // or if it is already new TouchSessionIndex since locked set
            bool userInitializedLock = locked.Touch.Session.PlayerIndex == touch.Session.PlayerIndex;
            bool lockingTouchSession = touch.TouchSessionIndex == locked.Touch.TouchSessionIndex;
            if (!userInitializedLock || !lockingTouchSession)
            {
                touch.Session.Enabled = false;
                return true;
            }

            // Here lock exists, active for current user and TouchSessionIndex is the same as when lock was activated.
            if (holderLock.AllowThisTouchSession)
                return false;
            else
            {
                touch.Session.Enabled = false;
                return true;
            }
        }
Пример #2
0
        /// <summary>
        /// Tries to lock this node with specified touch object according to node locking configuration.
        /// </summary>
        /// <param name="touch"></param>
        internal void TrySetLock(Touch touch)
        {
            VisualObject @this = this as VisualObject;
            // You can't lock the same object twice per touch session
            if (Configuration.Lock != null && !touch.Session.LockedObjects.Contains(@this))
            {
                Lock lockConfig = Configuration.Lock;
                int userIndex = touch.Session.PlayerIndex;
                VisualObject target = lockConfig.Level == LockLevel.Self ? @this : Root;

                // We are going to set lock only if target doesn't have an existing one
                lock (target.PersonalLocked)
                    if ((lockConfig.Personal && !target.PersonalLocked.ContainsKey(userIndex))
                        || (!lockConfig.Personal && target.Locked == null))
                        {
                            Locked locked = new Locked(@this, DateTime.UtcNow, lockConfig.Delay, touch);
                            touch.Session.LockedObjects.Add(@this);
                            if (lockConfig.Personal)
                                target.PersonalLocked[userIndex] = locked;
                            else
                                target.Locked = locked;
                        }
            }
        }