private OperationResponse ItemOperationDestroy(Item item, DestroyItem operation) { MethodReturnValue result = this.CheckAccess(item); if (result.IsOk) { item.Destroy(); item.Dispose(); this.RemoveItem(item); item.World.ItemCache.RemoveItem(item.Id); var eventInstance = new ItemDestroyed { ItemId = item.Id }; var eventData = new EventData((byte)EventCode.ItemDestroyed, eventInstance); this.Peer.SendEvent(eventData, new SendParameters { ChannelId = Settings.ItemEventChannel }); // no response, event is sufficient operation.OnComplete(); return null; } return operation.GetOperationResponse(result); }
/// <summary> /// Handles operation DestroyItem: Destroys an existing Item. /// </summary> public OperationResponse OperationDestroyItem(PeerBase peer, OperationRequest request, SendParameters sendParameters) { var operation = new DestroyItem(peer.Protocol, request); if (!operation.IsValid) { return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() }; } operation.OnStart(); Item item; bool actorItem = this.TryGetItem(operation.ItemId, out item); if (actorItem) { // we are already in the item thread, invoke directly return this.ItemOperationDestroy(item, operation); } else { // search world cache just to see if item exists at all if (this.World.ItemCache.TryGetItem(operation.ItemId, out item) == false) { return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"); } else { // second parameter (peer) allows us to send an error event to the client (in case of an error) // error ItemAccessDenied or ItemNotFound will be returned item.Fiber.Enqueue(() => this.ExecItemOperation(() => this.ItemOperationDestroy(item, operation), sendParameters)); // operation is continued later return null; } } }