Example #1
0
        public void TriggerEvent(string eventName, byte[] argsSerialized, string sourceString)
        {
            try
            {
                var obj = MsgPackDeserializer.Deserialize(argsSerialized, netSource: (sourceString.StartsWith("net") ? sourceString : null)) as List <object> ?? (IEnumerable <object>) new object[0];

                var scripts = ms_definedScripts.ToArray();

                var objArray = obj.ToArray();

                NetworkFunctionManager.HandleEventTrigger(eventName, objArray, sourceString);

                foreach (var script in scripts)
                {
                    Task.Factory.StartNew(() => script.EventHandlers.Invoke(eventName, sourceString, objArray)).Unwrap().ContinueWith(a =>
                    {
                        if (a.IsFaulted)
                        {
                            Debug.WriteLine($"Error invoking event handlers for {eventName}: {a.Exception?.InnerExceptions.Aggregate("", (b, s) => s + b.ToString() + "\n")}");
                        }
                    });
                }

                ExportDictionary.Invoke(eventName, objArray);

                // invoke a single task tick
                CitizenTaskScheduler.Instance.Tick();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
Example #2
0
 protected BaseScript()
 {
     EventHandlers   = new EventHandlerDictionary();
     Exports         = new ExportDictionary();
     CurrentTaskList = new Dictionary <Delegate, Task>();
     Players         = new PlayerList();
 }
Example #3
0
        public void TriggerEvent(string eventName, byte[] argsSerialized, string sourceString)
        {
            try
            {
                var obj = MsgPackDeserializer.Deserialize(argsSerialized) as List <object> ?? (IEnumerable <object>) new object[0];

                var scripts = ms_definedScripts.ToArray();

                // TODO: store source someplace
                var objArray = obj.ToArray();

                foreach (var script in scripts)
                {
                    Task.Factory.StartNew(() => script.EventHandlers.Invoke(eventName, sourceString, objArray)).Unwrap().ContinueWith(a =>
                    {
                        if (a.IsFaulted)
                        {
                            Debug.WriteLine($"Error invoking event handlers for {eventName}: {a.Exception?.InnerExceptions.Aggregate("", (b, s) => s + b.ToString() + "\n")}");
                        }
                    });
                }

                ExportDictionary.Invoke(eventName, objArray);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
Example #4
0
        public void TriggerEvent(string eventName, byte[] argsSerialized, string sourceString)
        {
            if (GameInterface.SnapshotStackBoundary(out var bo))
            {
                ScriptHost.SubmitBoundaryStart(bo, bo.Length);
            }

            try
            {
#if IS_FXSERVER
                var netSource = (sourceString.StartsWith("net") || sourceString.StartsWith("internal-net")) ? sourceString : null;
#else
                var netSource = sourceString.StartsWith("net") ? sourceString : null;
#endif

                var obj = MsgPackDeserializer.Deserialize(argsSerialized, netSource) as List <object> ?? (IEnumerable <object>) new object[0];

                var scripts = ms_definedScripts.ToArray();

                var objArray = obj.ToArray();

                NetworkFunctionManager.HandleEventTrigger(eventName, objArray, sourceString);

                foreach (var script in scripts)
                {
                    Task.Factory.StartNew(() =>
                    {
                        BaseScript.CurrentName = $"eventHandler {script.GetType().Name} -> {eventName}";
                        var t = script.EventHandlers.Invoke(eventName, sourceString, objArray);
                        BaseScript.CurrentName = null;

                        return(t);
                    }, CancellationToken.None, TaskCreationOptions.None, CitizenTaskScheduler.Instance).Unwrap().ContinueWith(a =>
                    {
                        if (a.IsFaulted)
                        {
                            Debug.WriteLine($"Error invoking event handlers for {eventName}: {a.Exception?.InnerExceptions.Aggregate("", (b, s) => s + b.ToString() + "\n")}");
                        }
                    });
                }

                ExportDictionary.Invoke(eventName, objArray);

                // invoke a single task tick
                CitizenTaskScheduler.Instance.Tick();
            }
            catch (Exception e)
            {
                PrintError($"event ({eventName})", e);
            }
            finally
            {
                ScriptHost.SubmitBoundaryStart(null, 0);
            }
        }
Example #5
0
        public void TriggerEvent(string eventName, byte[] argsSerialized, string sourceString)
        {
            try
            {
                var obj = MsgPackDeserializer.Deserialize(argsSerialized) as List <object> ?? (IEnumerable <object>) new object[0];

                var scripts = ms_definedScripts.ToArray();

                // TODO: store source someplace
                var objArray = obj.ToArray();

                foreach (var script in scripts)
                {
                    script.EventHandlers.Invoke(eventName, objArray);
                }

                ExportDictionary.Invoke(eventName, objArray);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }