public void HandleDeleteSingleShape(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var req = DeleteSingleShapeRequest.Read(operationRequest.Parameters); var sh = _doc.TryGetShape(req.shapeId); if (sh == null) { return; } switch (sh.ShapeCode()) { case VdShapeType.ClusterLink: var edge = _topology.GetForwardEdge(req.shapeId); _topology.Unlink(edge.curr.GetId(), edge.next.GetId(), req.ownerId); //see __linkRemove break; case VdShapeType.Cluster: //not sent manually, but by system (client) _topology.DeleteCluster(_topology.GetCluster(req.shapeId), -1); break; default: UnlockDeleteBroadcast(sh.Id(), req.ownerId); break; } _pendingChanges = true; }
public void HandleDeleteShapes(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var req = DeleteShapesRequest.Read(operationRequest.Parameters); var owner = req.initialOwnerId; var shapesBeingRemoved = _doc.GetShapes().Where(sh => sh.InitialOwner() == owner && sh.ShapeCode() != VdShapeType.Badge && sh.ShapeCode() != VdShapeType.Cluster && sh.ShapeCode() != VdShapeType.ClusterLink ); //check permissions foreach (var sr in shapesBeingRemoved) { if (!_doc.editingPermission(sr, owner)) { return; } } //ok, remove foreach (var sr in shapesBeingRemoved.ToArray()) { UnlockDeleteBroadcast(sr.Id(), req.ownerId); } _pendingChanges = true; }
private void HandleSourceView(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { Broadcast(peer, operationRequest, sendParameters, (byte)DiscussionEventCode.SourceViewEvent, BroadcastTo.RoomExceptSelf); }
public void Broadcast(LitePeer peer, Dictionary <byte, object> data, SendParameters sendParameters, byte EventCode, BroadcastTo addresses = BroadcastTo.RoomExceptSelf) { IEnumerable <Actor> recipients; // get the actor who send the operation request if (addresses == BroadcastTo.RoomExceptSelf) { Actor actor = this.GetActorByPeer(peer); if (actor == null) { return; } recipients = this.Actors.GetExcludedList(actor); } else { //peer==null ok recipients = this.Actors; } PublishDiscussionEvent(EventCode, data, recipients, sendParameters); }
private void HandleNameChanged(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { Broadcast(peer, operationRequest, sendParameters, (byte)DiscussionEventCode.UserAccPlusMinus, BroadcastTo.RoomAll); }
private void HandleNotifyArgPointChanged(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { PointChangedType pointChangeType; int personId; int topicId; var pointId = Serializers.ReadChangedArgPoint(operationRequest.Parameters, out pointChangeType, out topicId, out personId); switch (pointChangeType) { case PointChangedType.Created: VectEditor(topicId).HandleBadgeCreated(pointId, peer, operationRequest, sendParameters); break; case PointChangedType.Deleted: VectEditor(topicId).HandleBadgeDeleted(pointId, peer, operationRequest, sendParameters); break; case PointChangedType.Modified: VectEditor(topicId).HandleBadgeModified(pointId, peer, operationRequest, sendParameters); break; default: throw new NotSupportedException(); } //broadcast initial event anyway Broadcast(peer, operationRequest, sendParameters, (byte)DiscussionEventCode.ArgPointChanged, BroadcastTo.RoomAll); }
private void SetupGameProperties(LitePeer peer, JoinGameRequest createRequest, Hashtable gameProperties, ref SendParameters sendParameters, out byte?newMaxPlayer, out bool?newIsOpen, out bool?newIsVisible, out object[] newLobbyProperties) { newMaxPlayer = null; newIsOpen = null; newIsVisible = null; newLobbyProperties = null; // special treatment for game and actor properties sent by AS3/Flash or JSON clients var protocol = peer.Protocol.ProtocolType; if (protocol == ProtocolType.Amf3V152 || protocol == ProtocolType.Json) { Utilities.ConvertAs3WellKnownPropertyKeys(createRequest.GameProperties, createRequest.ActorProperties); } // try to parse build in properties for the first actor (creator of the game) if (this.Actors.Count == 0) { if (gameProperties != null && gameProperties.Count > 0) { if (!TryParseDefaultProperties(peer, createRequest, gameProperties, sendParameters, out newMaxPlayer, out newIsOpen, out newIsVisible, out newLobbyProperties)) { return; } } } return; }
/// <summary> /// Updates the lobby when an <see cref = "Actor" /> leaves (disconnect, <see cref = "LeaveRequest" />, <see cref = "JoinRequest" /> for another game). /// </summary> /// <param name = "peer"> /// The <see cref = "LitePeer" /> to remove. /// </param> /// <param name="leaveRequest"> /// The <see cref="LeaveRequest"/> sent by the peer or null if the peer have been disconnected without sending a leave request. /// </param> /// <returns> /// The actore number of the removed actor. /// If the specified peer does not exists -1 will be returned. /// </returns> protected override int RemovePeerFromGame(LitePeer peer, LeaveRequest leaveRequest) { int actorNr = base.RemovePeerFromGame(peer, leaveRequest); this.UpdateLobby(); return(actorNr); }
private bool ValidateGame(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var gamePeer = (GameClientPeer)peer; // check if the game is open if (this.isOpen == false) { var errorResponse = new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (int)ErrorCode.GameClosed, DebugMessage = "Game closed" }; peer.SendOperationResponse(errorResponse, sendParameters); gamePeer.OnJoinFailed(ErrorCode.GameClosed); return(false); } // check if the maximum number of players has already been reached if (this.maxPlayers > 0 && this.Actors.Count >= this.maxPlayers) { var errorResponse = new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = (int)ErrorCode.GameFull, DebugMessage = "Game full" }; peer.SendOperationResponse(errorResponse, sendParameters); gamePeer.OnJoinFailed(ErrorCode.GameFull); return(false); } return(true); }
protected virtual Actor HandleJoinGameOperation(LitePeer peer, JoinRequest joinRequest, SendParameters sendParameters) { if (!this.ValidateGame(peer, joinRequest.OperationRequest, sendParameters)) { return(null); } // special treatment for game and actor properties sent by AS3/Flash var protocol = peer.Protocol.ProtocolType; if (protocol == ProtocolType.Amf3V151 || protocol == ProtocolType.Amf3V152 || protocol == ProtocolType.Json) { Utilities.ConvertAs3WellKnownPropertyKeys(joinRequest.GameProperties, joinRequest.ActorProperties); } var gamePeer = (GameClientPeer)peer; Actor actor = this.HandleJoinOperation(peer, joinRequest, sendParameters); if (actor == null) { return(null); } // update game state at master server var peerId = gamePeer.PeerId ?? string.Empty; this.UpdateGameStateOnMaster(null, null, null, null, joinRequest.GameProperties, peerId); return(actor); }
private void HandleStatsEvent(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { Broadcast(peer, operationRequest, sendParameters, (byte)DiscussionEventCode.StatsEvent, BroadcastTo.RoomAll); }
public void HandleClusterBadgeRequest(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var req = ClusterBadgeMessage.Read(operationRequest.Parameters); if (_topology.ClusterBadge(req.badgeId, req.clusterId)) { _room.Broadcast(peer, operationRequest, sendParameters, (byte)DiscussionEventCode.ClusterBadgeEvent, BroadcastTo.RoomAll); //might fail, we need message too EventLogger.LogAndBroadcast(new DiscCtx(Discussions.ConfigManager.ConnStr), _room, StEvent.ClusterIn, req.ownerId, req.topicId); } else { _log.Info("cluster badge request failed badgeId=" + req.badgeId + "clusterId=" + req.clusterId); } _pendingChanges = true; }
private void HandleNotifyStructureChanged(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { Broadcast(peer, operationRequest, sendParameters, (byte)DiscussionEventCode.StructureChanged, BroadcastTo.RoomAll); }
/// cluster engine public void HandleLinkCreateRequest(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var req = LinkCreateMessage.Read(operationRequest.Parameters); //shape var link = new ServerBaseVdShape(req.shapeId, req.ownerId, VdShapeType.ClusterLink, (int)req.HeadType); _doc.AddShape(link); //topology _topology.Link(req.end1Id, req.end2Id, req.shapeId); _room.BroadcastReliableToRoom((byte)DiscussionEventCode.LinkCreateEvent, LinkCreateMessage.Write(req.end1Id, req.end2Id, req.ownerId, req.shapeId, _topicId, false, req.HeadType)); EventLogger.LogAndBroadcast(new DiscCtx(Discussions.ConfigManager.ConnStr), _room, StEvent.LinkCreated, req.ownerId, req.topicId); //transient state until link state update, don't save //pendingChanges = true; }
public void Broadcast(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters, byte EventCode, BroadcastTo addresses = BroadcastTo.RoomExceptSelf) { Broadcast(peer, operationRequest.Parameters, sendParameters, EventCode, addresses); }
public void HandleUnclusterBadgeRequest(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var req = UnclusterBadgeMessage.Read(operationRequest.Parameters); _topology.UnclusterBadge(req.badgeId, req.usrId); }
protected override void HandleGetPropertiesOperation(LitePeer peer, GetPropertiesRequest getPropertiesRequest, SendParameters sendParameters) { // special handling for game properties send by AS3/Flash (Amf3 protocol) clients if (peer.Protocol.ProtocolType == ProtocolType.Amf3V151 || peer.Protocol.ProtocolType == ProtocolType.Amf3V152) { Utilities.ConvertAs3WellKnownPropertyKeys(getPropertiesRequest.GamePropertyKeys, getPropertiesRequest.ActorPropertyKeys); } base.HandleGetPropertiesOperation(peer, getPropertiesRequest, sendParameters); }
private void DebugLog(LitePeer peer, OperationRequest operationRequest) { if (this.LogQueue.Log.IsDebugEnabled) { this.LogQueue.Add( new LogEntry( "ExecuteOperation: " + (Lite.Operations.OperationCode)operationRequest.OperationCode, "Peer=" + peer.ConnectionId)); } }
public void HandleUnselectAll(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var ev = UnselectAllEvent.Write(); _room.Broadcast(peer, ev, sendParameters, (byte)DiscussionEventCode.UnselectAllEvent, BroadcastTo.RoomExceptSelf); }
protected virtual Actor HandleCreateGameOperation(LitePeer peer, JoinGameRequest createRequest, SendParameters sendParameters) { if (!this.ValidateGame(peer, createRequest.OperationRequest, sendParameters)) { return(null); } HandleCreateGameOperationBody(peer, createRequest, sendParameters, false); return(null); }
public void HandlePdfScrollSubmitted(LitePeer peer, PdfScrollPosition req, OperationRequest operationRequest, SendParameters sendParameters) { _doc.PdfScrollPosition = req; _room.Broadcast(peer, req.ToDict(), sendParameters, (byte)DiscussionEventCode.PdfScrollChangedEvent); }
/// <summary> /// Updates the lobby when an <see cref = "Actor" /> joins. /// </summary> /// <param name = "peer"> /// The peer. /// </param> /// <param name = "joinRequest"> /// The join operation. /// </param> /// <param name = "sendParamters"> /// The send Paramters. /// </param> /// <returns> /// The newly created (joined) <see cref = "Actor" />. /// </returns> protected override Actor HandleJoinOperation(LitePeer peer, JoinRequest joinRequest, SendParameters sendParamters) { Actor actor = base.HandleJoinOperation(peer, joinRequest, sendParamters); if (actor != null) { this.UpdateLobby(); } return(actor); }
/// <summary> /// Executes the base <see cref="LiteGame.HandleJoinOperation">HandleJoinOperation</see> and then sends an updated game list to all <see cref="Actor"/>s in the lobby. /// </summary> /// <param name="peer"> /// The peer. /// </param> /// <param name="joinRequest"> /// The join request. /// </param> /// <param name="sendParameters"> /// The send Parameters. /// </param> /// <returns> /// The new actor /// </returns> protected virtual Actor HandleJoinOperation(LitePeer peer, JoinRequest joinRequest, SendParameters sendParameters) { Actor actor = base.HandleJoinOperation(peer, joinRequest, sendParameters); if (actor != null) { this.PublishGameList(actor); } return(actor); }
public void HandlePdfScrollRequested(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { if (_doc.PdfScrollPosition != null) { _room.PublishEventToSingle(peer, _doc.PdfScrollPosition.ToDict(), sendParameters, (byte)DiscussionEventCode.PdfScrollChangedEvent); } }
public void PublishEventToSingle(LitePeer peer, Dictionary <byte, object> data, SendParameters sendParameters, byte EventCode) { Actor actor = this.GetActorByPeer(peer); PublishDiscussionEvent(EventCode, data, new Actor[] { actor }, sendParameters); }
void DetachLaserPointerFormAnyTopic(LitePeer peer, int ptrId) { foreach (var kv in _vectEditors) { var topicId = kv.Key; var lp = new LaserPointer { TopicId = topicId, UserId = ptrId }; kv.Value.HandleDetachLaserPointer(peer, lp, new OperationRequest((byte)DiscussionOpCode.DetachLaserPointerRequest, lp.ToDict()), new SendParameters()); } }
public void HandleManipulateImageViewer(LitePeer peer, ImageViewerMatrix imgMatrix, OperationRequest operationRequest, SendParameters sendParameters) { _doc.SetImageViewer(imgMatrix); _room.Broadcast(peer, operationRequest, sendParameters, (byte)DiscussionEventCode.ImageViewerManipulatedEvent, BroadcastTo.RoomExceptSelf); }
/// <summary> /// Called for each operation in the execution queue. /// </summary> /// <param name="peer">The peer.</param> /// <param name="operationRequest">The operation request to execute.</param> /// <param name="sendParameters"></param> /// <remarks> /// ExecuteOperation is overriden to handle our custom operations. /// </remarks> protected override void ExecuteOperation(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { switch ((MyOperationCodes)operationRequest.OperationCode) { case MyOperationCodes.GameOperation: this.HandleMyGameOperation(peer, operationRequest, sendParameters); break; default: // all other operations will be handled by the LiteGame implementation base.ExecuteOperation(peer, operationRequest, sendParameters); break; } }
private void HandleLiteOperations(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { string message = string.Format("Unknown operation code {0}", (Lite.Operations.OperationCode)operationRequest.OperationCode); peer.SendOperationResponse( new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = -1, DebugMessage = message }, sendParameters); if (Log.IsWarnEnabled) { Log.Warn(message); } }
public void HandleLaserPointerMoved(LitePeer peer, LaserPointer ptr, OperationRequest operationRequest, SendParameters sendParameters) { if (_doc.MoveLaserPointer(ptr)) { _room.Broadcast(peer, operationRequest, sendParameters, (byte)DiscussionEventCode.LaserPointerMovedEvent, BroadcastTo.RoomExceptSelf); } }