Rework on SendNativeCall

This commit is contained in:
Sardelka
2022-06-23 09:46:38 +08:00
parent 84171e2949
commit 41385abc7d
14 changed files with 369 additions and 137 deletions

View File

@ -11,6 +11,7 @@ namespace RageCoop.Server.Scripting
{
public override void OnStart()
{
API.RegisterCustomEventHandler(CustomEvents.NativeResponse, NativeResponse);
}
public override void OnStop()
{
@ -19,5 +20,26 @@ namespace RageCoop.Server.Scripting
{
c.SendCustomEvent(CustomEvents.SetAutoRespawn, new() { toggle });
}
void NativeResponse(CustomEventReceivedArgs e)
{
try
{
int id = (int)e.Args[0];
Action<object> callback;
lock (e.Sender.Callbacks)
{
if (e.Sender.Callbacks.TryGetValue(id, out callback))
{
callback(e.Args[1]);
e.Sender.Callbacks.Remove(id);
}
}
}
catch (Exception ex)
{
API.GetLogger().Error("Failed to parse NativeResponse");
API.GetLogger().Error(ex);
}
}
}
}