public void SendCreateShapeRequest(int ownerId, int shapeId, VdShapeType shapeType, bool takeCursor, double startX, double startY, int tag, int topicId) { if (peer == null || peer.PeerState != PeerStateValue.Connected) { return; } peer.OpCustom((byte)DiscussionOpCode.CreateShapeRequest, CreateShape.Write(ownerId, shapeId, shapeType, startX, startY, takeCursor, tag, topicId), true); }
public void HandleBadgeCreated(int argPointId, LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { var ctx = new DiscCtx(Discussions.ConfigManager.ConnStr); var ap = ctx.ArgPoint.FirstOrDefault(ap0 => ap0.Id == argPointId); if (ap == null) { throw new NotSupportedException("cannot find badge in db!"); } var badgeSh = new ServerBaseVdShape(_doc.BadgeIdGen.NextId(), ap.Person.Id, VdShapeType.Badge, argPointId); _doc.AddShape(badgeSh); _topology.CreateBadge(badgeSh.Id()); //get position double x; double y; GetBadgeSmartLocation(ap.Person.Id, out x, out y); //set initial badge state var st = new ShapeState(VdShapeType.Badge, ap.Person.Id, badgeSh.Id(), null, null, new double[] { x, y }, _topicId); badgeSh.ApplyState(st); var badgeCreateEv = CreateShape.Write(ap.Person.Id, badgeSh.Id(), VdShapeType.Badge, st.doubles[0], st.doubles[1], false, argPointId, _topicId); //include self, badge is created in private board, and if our public board is open, we want to play new badge _room.Broadcast(peer, badgeCreateEv, sendParameters, (byte)DiscussionEventCode.CreateShapeEvent, BroadcastTo.RoomAll); _pendingChanges = true; }
public void HandleInitialSceneLoad(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters) { //// var req = InitialSceneLoadRequest.Read(operationRequest); /// req.topicId _log.Debug("scene load request"); CleanupEmptyClusters(); //1st phase, send creation events for simple shapes (+cluster) in the scene var simpleShapes = _doc.GetShapes().Where(sh => sh.ShapeCode() != VdShapeType.ClusterLink).ToArray(); foreach (var sh in simpleShapes) { _room.PublishEventToSingle(peer, CreateShape.Write(sh.InitialOwner(), sh.Id(), sh.ShapeCode(), 400, 400, false, sh.Tag(), _topicId), sendParameters, (byte)DiscussionEventCode.CreateShapeEvent); } //2nd phase, send state update packets foreach (var sh in simpleShapes) { var st = sh.GetState(); if (st == null) { continue; } _room.PublishEventToSingle(peer, st.ToDict(), sendParameters, (byte)DiscussionEventCode.StateSyncEvent); } //3rd phase, sequence of cluster-add operations (enumerate contents of all existing clusters) var clusterShapes = _doc.GetShapes().Where(sh => sh.ShapeCode() == VdShapeType.Cluster); foreach (var clShape in clusterShapes) { var cluster = _topology.GetCluster(clShape.Id()); _log.Info("scene load, cluster updates, num badges =" + cluster.GetClusterables()); foreach (var badge in cluster.GetClusterables()) { var clustMsg = ClusterBadgeMessage.Write(badge.GetId(), _doc.TryGetShape(badge.GetId()).InitialOwner(), badge == cluster.GetClusterables().Last(), cluster.GetId(), _topicId, -1); _room.PublishEventToSingle(peer, clustMsg, sendParameters, (byte)DiscussionEventCode.ClusterBadgeEvent); } } //4rd phase, create links var linkShapes = _doc.GetShapes().Where(sh => sh.ShapeCode() == VdShapeType.ClusterLink); foreach (var lnk in linkShapes) { var edge = _topology.GetForwardEdge(lnk.Id()); var ev = LinkCreateMessage.Write(edge.curr.GetId(), edge.next.GetId(), lnk.InitialOwner(), lnk.Id(), _topicId, false, (LinkHeadType)lnk.Tag()); _room.PublishEventToSingle(peer, ev, sendParameters, (byte)DiscussionEventCode.LinkCreateEvent); //send link state update var st = lnk.GetState(); if (st != null) { _room.PublishEventToSingle(peer, st.ToDict(), sendParameters, (byte)DiscussionEventCode.StateSyncEvent); } } //5th phase, send cursor events foreach (var sh in _doc.GetShapes()) { if (sh.GetCursor() == null) { continue; //cursors are unset by default for all shapes } _room.PublishEventToSingle(peer, CursorEvent.Write(true, sh.GetCursor().OwnerId, sh.Id(), _topicId), sendParameters, (byte)DiscussionEventCode.CursorEvent); } //6th phase, send ink if (_doc.inkData != null) { _room.PublishEventToSingle(peer, InkMessage.Write(-1, _topicId, _doc.inkData), sendParameters, (byte)DiscussionEventCode.InkEvent); } //7th phase, send laser pointers foreach (var laserPointer in _doc.LaserPointers) { _room.PublishEventToSingle(peer, laserPointer.ToDict(), sendParameters, (byte)DiscussionEventCode.AttachLaserPointerEvent); } //notify client loading sequence complete _room.PublishEventToSingle(peer, null, sendParameters, (byte)DiscussionEventCode.SceneLoadingDone); }