示例#1
0
        //user U can take cursor on shape S <=> (U doesn't have other cursors && S is free)
        public void HandleCursorRequest(LitePeer peer,
                                        OperationRequest operationRequest,
                                        SendParameters sendParameters)
        {
            var req = CursorRequest.Read(operationRequest.Parameters);

            var changes = false;

            if (req.doSet)
            {
                if (_doc.UserHasCursor(req.ownerId))
                {
                    return; //already holds another cursor
                }
                var sh = _doc.TryGetShape(req.shapeId);
                if (sh == null)
                {
                    return; //no such shape
                }
                if (sh.GetCursor() != null)
                {
                    return; // shape is busy
                }
                //ok, lock shape
                _doc.LockShape(sh, req.ownerId);
                changes = true;
            }
            else
            {
                //cursor remove operation is always ok
                var sh = _doc.TryGetShape(req.shapeId);
                if (sh == null)
                {
                    return; //no such shape
                }
                _doc.UnlockShape(sh, req.ownerId);
                changes = true;
            }

            if (changes)
            {
                _room.Broadcast(peer,
                                CursorEvent.Write(req.doSet, req.ownerId, req.shapeId, _topicId),
                                sendParameters,
                                (byte)DiscussionEventCode.CursorEvent,
                                BroadcastTo.RoomAll); //include self
            }
        }