예제 #1
0
        public Task <TResponseRpc> TriggerAsyncRpc <TResponseRpc>(Player target, string key, IRpc argument)
            where TResponseRpc : IRpc
        {
            int    tickCount   = MtaShared.GetTickCount();
            string responseKey = $"response-{key}";

            Task <TResponseRpc>       task     = null;
            Action <Player, AsyncRpc> callback = null;

            this.asyncRpcIndex++;
            string identifier = $"{this.asyncRpcIndex}";

            /*
             * [[
             *  local asyncCallback
             *  callback = function(player, parameters)
             *      if (parameters.Identifier == identifier) then
             *          local asyncRpc = System.cast(SlipeSharedRpc.AsyncRpc, parameters)
             *          local arguments = System.cast(TResponseRpc, System.Activator.CreateInstance(System.typeof(TResponseRpc)))
             *          arguments:Parse(asyncRpc.Rpc)
             *
             *          asyncCallback(player, arguments)
             *      end
             *  end
             *
             *  task, asyncCallback = System.Task.Callback(function(player, responseRpc)
             *      this.registeredRPCs:get(responseKey):Remove(callback)
             *      return responseRpc;
             *  end)
             * ]]
             */

            this.RegisterRPC(responseKey, callback);

            if (target.IsReadyForIncomingRequests)
            {
                MtaServer.TriggerClientEvent(target.MTAElement, key, Element.Root.MTAElement, new AsyncRpc(identifier, argument));
            }
            else if (argument.OnClientRpcFailed == ClientRpcFailedAction.Queue)
            {
                QueueRpc(target, key, new AsyncRpc(identifier, argument));
            }

            return(task);
        }
예제 #2
0
        public Task <TResponseRpc> TriggerAsyncRpc <TResponseRpc>(string key, IRpc argument)
            where TResponseRpc : IRpc
        {
            int    tickCount   = MtaShared.GetTickCount();
            string responseKey = $"response-{key}";

            Task <TResponseRpc> task     = null;
            Action <AsyncRpc>   callback = null;

            this.asyncRpcIndex++;
            string identifier = $"{this.asyncRpcIndex}";

            /*
             * [[
             *  local asyncCallback
             *  callback = function(parameters)
             *      if (parameters.Identifier == identifier) then
             *          local asyncRpc = System.cast(SlipeSharedRpc.AsyncRpc, parameters)
             *          local arguments = System.cast(TResponseRpc, System.Activator.CreateInstance(System.typeof(TResponseRpc)))
             *          arguments:Parse(asyncRpc.Rpc)
             *
             *          asyncCallback(arguments)
             *      end
             *  end
             *
             *  task, asyncCallback = System.Task.Callback(function(responseRpc)
             *      this.registeredRPCs:get(responseKey):Remove(callback)
             *      return responseRpc;
             *  end)
             * ]]
             */

            this.RegisterRPC(responseKey, callback);

            MtaClient.TriggerServerEvent(key, Element.Root.MTAElement, new AsyncRpc(identifier, argument));

            return(task);
        }