Beispiel #1
0
 /// <summary>
 /// Register an RPC
 /// </summary>
 public void RegisterRPC <CallbackType>(string key, Action <CallbackType> callback) where CallbackType : IRpc
 {
     RegisteredRPCs[key] = new RegisteredRpc((parameters) =>
     {
         callback((CallbackType)parameters);
     }, typeof(CallbackType));
     MtaShared.AddEvent(key, true);
     Element.Root.ListenForEvent(key);
 }
Beispiel #2
0
 /// <summary>
 /// Register an RPC
 /// </summary>
 public void RegisterRPC <CallbackType>(string key, Action <Player, CallbackType> callback)
 {
     RegisteredRPCs[key] = new RegisteredRpc((player, parameters) =>
     {
         callback.Invoke(player, (CallbackType)parameters);
     }, typeof(CallbackType));
     MtaShared.AddEvent(key, true);
     Element.Root.ListenForEvent(key);
 }
Beispiel #3
0
 /// <summary>
 /// Register an RPC
 /// </summary>
 public void RegisterRPC <CallbackType>(string key, Action <CallbackType> callback)
 {
     RegisteredRPCs[key] = (parameters) =>
     {
         /*
          * [[
          *  callback(CallbackType(parameters))
          * ]]
          */
     };
     MtaShared.AddEvent(key, true);
     Element.Root.ListenForEvent(key);
 }
Beispiel #4
0
 /// <summary>
 /// Register an RPC
 /// </summary>
 public void RegisterRPC <CallbackType>(string key, Action <CallbackType> callback) where CallbackType : IRpc
 {
     if (!registeredRPCs.ContainsKey(key))
     {
         registeredRPCs[key] = new List <RegisteredRpc>();
         MtaShared.AddEvent(key, true);
         Element.Root.ListenForEvent(key);
     }
     registeredRPCs[key].Add(new RegisteredRpc((parameters) =>
     {
         callback((CallbackType)parameters);
     }, typeof(CallbackType)));
 }
Beispiel #5
0
        /// <summary>
        /// Register an async RPC
        /// </summary>
        public void RegisterAsyncRPC <ResponseRpc, RequestRpc>(string key, Func <Player, RequestRpc, ResponseRpc> callback)
            where ResponseRpc : IRpc where RequestRpc : IRpc
        {
            if (!registeredAsyncRPCs.ContainsKey(key))
            {
                registeredAsyncRPCs[key] = new List <RegisteredRpc>();
                MtaShared.AddEvent(key, true);
                Element.Root.ListenForEvent(key);
            }

            string responseKey = $"response-{key}";

            registeredAsyncRPCs[key].Add(new RegisteredRpc((player, parameters) =>
            {
                var asyncRpc         = (AsyncRpc)parameters;
                RequestRpc arguments = (RequestRpc)Activator.CreateInstance(typeof(RequestRpc));
                arguments.Parse(asyncRpc.Rpc);

                var result = callback.Invoke(player, arguments);
                this.TriggerRPC(responseKey, new AsyncRpc(asyncRpc.Identifier, result));
            }, typeof(AsyncRpc)));
        }