/// <summary> /// Handles operation RaiseGenericEvent. Sends event ItemGeneric to an Item owner or the subscribers of an Item />. /// </summary> public OperationResponse OperationRaiseGenericEvent(PeerBase peer, OperationRequest request, SendParameters sendParameters) { var operation = new RaiseGenericEvent(peer.Protocol, request); if (!operation.IsValid) { return(new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() }); } operation.OnStart(); Item item; bool actorItem = true; if (this.TryGetItem(operation.ItemId, out item) == false) { if (this.World.ItemCache.TryGetItem(operation.ItemId, out item) == false) { return(operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound")); } actorItem = false; } if (actorItem) { // we are already in the item thread, invoke directly return(ItemOperationRaiseGenericEvent(item, operation, sendParameters)); } // second parameter (peer) allows us to send an error event to the client (in case of an error) item.Fiber.Enqueue(() => this.ExecItemOperation(() => ItemOperationRaiseGenericEvent(item, operation, sendParameters), sendParameters)); // operation continued later return(null); }
public override OperationResponse Handle(MmoActor actor, OperationRequest request, SendParameters sendParameters) { try { var operation = new RaiseGenericEvent(actor.Peer.Protocol, request); if (!operation.IsValid) { return(new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() }); } operation.OnStart(); Item item; bool actorItem = true; if (false == operation.ItemType.HasValue || string.IsNullOrEmpty(operation.ItemId)) { item = actor.Avatar; // set return values operation.ItemType = item.Type; operation.ItemId = item.Id; } else if (actor.TryGetItem(operation.ItemType.Value, operation.ItemId, out item) == false) { if (actor.World.ItemCache.TryGetItem(operation.ItemType.Value, operation.ItemId, out item) == false) { return(operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound")); } actorItem = false; } if (actorItem) { // we are already in the item thread, invoke directly return(ItemOperationRaiseGenericEvent(item, operation, sendParameters)); } // second parameter (peer) allows us to send an error event to the client (in case of an error) item.Fiber.Enqueue(() => actor.ExecItemOperation(() => ItemOperationRaiseGenericEvent(item, operation, sendParameters), sendParameters)); // operation continued later return(null); } catch (Exception ex) { log.Error(ex); } return(null); }