private OperationResponse ExecAction(PeerBase peer, OperationRequest request, SendParameters sendParameters) { try { var operation = new ExecAction(peer.Protocol, request); if (false == operation.IsValid) { return(GetErrorResponse(ReturnCode.InvalidOperationParameter, operation.GetErrorMessage())); } var method = this.executor.GetType().GetMethod(operation.Action); if (method != null) { object methodResult = method.Invoke(this.executor, operation.Parameters); if (methodResult != null && methodResult is Hashtable) { var hashResult = methodResult as Hashtable; ExecActionResponse response = new ExecActionResponse { Result = hashResult, Action = operation.Action, ItemId = string.Empty }; return(new OperationResponse(OperationCode.ExecAction.toByte(), response) { ReturnCode = (int)ReturnCode.Ok, DebugMessage = "action: {0} completed".f(operation.Action) }); } else { return(GetErrorResponse(ReturnCode.Fatal, "Invalid return value from method")); } } else { return(GetErrorResponse(ReturnCode.Fatal, "Method {0} in executor not founded".f(operation.Action))); } } catch (Exception ex) { CL.Out(LogFilter.PLAYER, ex.Message); CL.Out(LogFilter.PLAYER, ex.StackTrace); } return(null); }
public override OperationResponse Handle(MmoActor actor, OperationRequest request, SendParameters sendParameters) { var operation = new ExecAction(actor.Peer.Protocol, request); if (!operation.IsValid) { return(new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() }); } operation.OnStart(); //CL.Out("exec action called: " + operation.Action); Item item; bool actorItem = actor.TryGetItem((byte)ItemType.Avatar, operation.ItemId, out item); if (actorItem == false) { if (actor.World.ItemCache.TryGetItem((byte)ItemType.Avatar, operation.ItemId, out item) == false) { //return new OperationResponse((byte)OperationCode.ExecAction) { ReturnCode = (short)ReturnCode.ItemNotFound, DebugMessage = "ItemNotFound" }; Hashtable methodResult = null; var method = actor.ActionExecutor.GetType().GetMethod(operation.Action); if (method != null) { object respObject = method.Invoke(actor.ActionExecutor, operation.Parameters); if (respObject != null && respObject is Hashtable) { methodResult = respObject as Hashtable; ExecActionResponse response = new ExecActionResponse { Result = methodResult, Action = operation.Action, ItemId = string.Empty }; return(new OperationResponse(OperationCode.ExecAction.toByte(), response) { ReturnCode = (int)ReturnCode.Ok, DebugMessage = string.Format("Action completed when no avatar") }); } } return(new OperationResponse(OperationCode.ExecAction.toByte(), new ExecActionResponse { Result = new Hashtable(), Action = operation.Action, ItemId = string.Empty }) { ReturnCode = (int)ReturnCode.Fatal, DebugMessage = "Method not found", }); } } if (actorItem) { if (item is MmoItem) { return(this.ItemOperationExecAction(item as MmoItem, operation, actor)); } else { return(new OperationResponse((byte)OperationCode.ExecAction, new ExecActionResponse { Result = new Hashtable(), Action = operation.Action, ItemId = string.Empty }) { ReturnCode = (short)ReturnCode.Fatal, DebugMessage = "Actor item Item not MmoItem" }); } } if (item is MmoItem) { MmoItem mmoItem = item as MmoItem; item.Fiber.Enqueue(() => actor.ExecItemOperation(() => this.ItemOperationExecAction(mmoItem, operation, actor), sendParameters)); return(null); } else { return(new OperationResponse((byte)OperationCode.ExecAction, new ExecActionResponse { Action = operation.Action, ItemId = string.Empty, Result = new Hashtable() }) { ReturnCode = (short)ReturnCode.Fatal, DebugMessage = "Foreign Actor item Item not MmoItem" }); } }