예제 #1
0
 public void AllRoomsBroadcast(LitePeer peer,
                               OperationRequest operationRequest,
                               SendParameters sendParameters,
                               byte EventCode)
 {
     foreach (string roomName in roomList)
     {
         RoomReference  rr             = DiscussionGameCache.Instance.GetRoomReference(roomName);
         DiscussionRoom discussionRoom = rr.Room as DiscussionRoom;
         if (discussionRoom != null)
         {
             discussionRoom.Broadcast(peer,
                                      operationRequest,
                                      sendParameters,
                                      EventCode,
                                      BroadcastTo.RoomAll);
         }
     }
     BroadcastLobby(operationRequest, sendParameters, EventCode);
 }
예제 #2
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
            }
        }