protected virtual void HandleSetPropertiesOperation( PlayerPeer peer, SetPropertiesRequest setPropertiesRequest, SendParameters sendParameters) { // check if peer has joined this room instance var sender = GetActorByPeer(peer); if (sender == null) { var response = new OperationResponse { OperationCode = setPropertiesRequest.OperationRequest.OperationCode, ReturnCode = -1, DebugMessage = "Room not joined" }; peer.SendOperationResponse(response, sendParameters); return; } if (setPropertiesRequest.ActorNumber > 0) { var actor = Actors.GetActorByNumber(setPropertiesRequest.ActorNumber); if (actor == null) { peer.SendOperationResponse( new OperationResponse { OperationCode = setPropertiesRequest.OperationRequest.OperationCode, ReturnCode = -1, DebugMessage = string.Format( "Actor with number {0} not found.", setPropertiesRequest.ActorNumber) }, sendParameters); return; } actor.Properties.SetProperties(setPropertiesRequest.Properties); } else { Properties.SetProperties(setPropertiesRequest.Properties); } peer.SendOperationResponse( new OperationResponse { OperationCode = setPropertiesRequest.OperationRequest.OperationCode }, sendParameters); // if the optional paramter Broadcast is set a EvPropertiesChanged // event will be send to room actors if (setPropertiesRequest.Broadcast) { var actor = Actors.GetActorByPeer(peer); var recipients = Actors.GetExcludedList(actor); var propertiesChangedEvent = new PropertiesChangedEvent(actor.ActorNr) { TargetActorNumber = setPropertiesRequest.ActorNumber, Properties = setPropertiesRequest.Properties }; PublishEvent(propertiesChangedEvent, recipients, sendParameters); } }
protected virtual void HandleRaiseEventOperation( PlayerPeer peer, RaiseEventRequest raiseEventRequest, SendParameters sendParameters) { // get the actor who send the operation request var actor = GetActorByPeer(peer); if (actor == null) { return; } sendParameters.Flush = raiseEventRequest.Flush; if (raiseEventRequest.Cache == (byte)CacheOperation.RemoveFromRoomCache) { EventCache.RemoveEvents(raiseEventRequest); var response = new OperationResponse(raiseEventRequest.OperationRequest.OperationCode) { ReturnCode = 0 }; peer.SendOperationResponse(response, sendParameters); return; } if (raiseEventRequest.Cache == (byte)CacheOperation.RemoveFromCacheForActorsLeft) { var currentActorNumbers = Actors.GetActorNumbers(); EventCache.RemoveEventsForActorsNotInList(currentActorNumbers); var response = new OperationResponse(raiseEventRequest.OperationRequest.OperationCode) { ReturnCode = 0 }; peer.SendOperationResponse(response, sendParameters); return; } // publish the custom event var customEvent = new CustomEvent(actor.ActorNr, raiseEventRequest.EvCode, raiseEventRequest.Data); var updateEventCache = false; IEnumerable <Actor> recipients; if (raiseEventRequest.Actors != null && raiseEventRequest.Actors.Length > 0) { recipients = Actors.GetActorsByNumbers(raiseEventRequest.Actors); } else if (raiseEventRequest.Group != 0) { ActorGroup group; if (ActorGroups.TryGetValue(raiseEventRequest.Group, out group)) { recipients = group.GetExcludedList(actor); } else { return; } } else { switch ((ReceiverGroup)raiseEventRequest.ReceiverGroup) { case ReceiverGroup.All: recipients = Actors; updateEventCache = true; break; case ReceiverGroup.Others: recipients = Actors.GetExcludedList(actor); updateEventCache = true; break; case ReceiverGroup.MasterClient: recipients = new[] { Actors[0] }; break; default: peer.SendOperationResponse( new OperationResponse { OperationCode = raiseEventRequest.OperationRequest.OperationCode, ReturnCode = -1, DebugMessage = "Invalid ReceiverGroup " + raiseEventRequest.ReceiverGroup }, sendParameters); return; } } if (updateEventCache && raiseEventRequest.Cache != (byte)CacheOperation.DoNotCache) { string msg; if (!UpdateEventCache(actor, raiseEventRequest, out msg)) { peer.SendOperationResponse( new OperationResponse { OperationCode = raiseEventRequest.OperationRequest.OperationCode, ReturnCode = -1, DebugMessage = msg }, sendParameters); return; } } PublishEvent(customEvent, recipients, sendParameters); }