Example #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;
            }
        }
Example #2
0
 private bool IsLocked(Touch touch)
 {
     // We must check both personal and common lock
     PersonalLocked.TryGetValue(touch.Session.PlayerIndex, out Locked personalLocked);
     return IsLocked(Locked, touch) || IsLocked(personalLocked, touch);
 }