diff --git a/FxEvents/FxEvents.Client/EventDispatcher.cs b/FxEvents/FxEvents.Client/EventDispatcher.cs
index f8e0e2b..e4b4595 100644
--- a/FxEvents/FxEvents.Client/EventDispatcher.cs
+++ b/FxEvents/FxEvents.Client/EventDispatcher.cs
@@ -1,5 +1,5 @@
global using CitizenFX.Core;
-using CitizenFX.FiveM.Native;
+using CitizenFX.Shared.Native;
using FxEvents.EventSystem;
using FxEvents.Shared;
using Logger;
@@ -19,7 +19,7 @@ public EventDispatcher()
{
Logger = new Log();
Instance = this;
- string debugMode = Natives.GetResourceMetadata(Natives.GetCurrentResourceName(), "fxevents_debug_mode", 0);
+ string debugMode = Natives.GetResourceMetadata((CString)Natives.GetCurrentResourceName(), "fxevents_debug_mode", 0);
Debug = debugMode == "yes" || debugMode == "true" || Convert.ToInt32(debugMode) > 0;
}
@@ -71,14 +71,14 @@ public static void Initalize(string inboundEvent, string outboundEvent, string s
}
///
- /// registra un evento client (TriggerEvent)
+ /// Register an Event (TriggerEvent)
///
- /// Nome evento
- /// Azione legata all'evento
- internal async void AddEventHandler(string eventName, Delegate action)
+ /// Event Name
+ /// Event-related action
+ internal async void AddEventHandler(string eventName, DynFunc action)
{
while (!Initialized) await BaseScript.Delay(0);
- EventHandlers[eventName].Add(Func.Create(action));
+ EventHandlers[eventName].Add(action, Binding.All);
}
public static void Send(string endpoint, params object[] args)
@@ -99,7 +99,7 @@ public static async Coroutine Get(string endpoint, params object[] args)
}
return await Events.Get(endpoint, args);
}
- public static void Mount(string endpoint, Delegate @delegate)
+ public static void Mount(string endpoint, DynFunc @delegate)
{
if (!Initialized)
{
diff --git a/FxEvents/FxEvents.Client/EventSystem/ClientGateway.cs b/FxEvents/FxEvents.Client/EventSystem/ClientGateway.cs
index b99f85c..cd652d0 100644
--- a/FxEvents/FxEvents.Client/EventSystem/ClientGateway.cs
+++ b/FxEvents/FxEvents.Client/EventSystem/ClientGateway.cs
@@ -25,19 +25,9 @@ public ClientGateway()
internal void AddEvents()
{
- EventDispatcher.Instance.AddEventHandler(InboundPipeline, new Action(async serialized =>
- {
- try
- {
- await ProcessInboundAsync(new ServerId().Handle, serialized);
- }
- catch (Exception ex)
- {
- Logger.Error("InboundPipeline:" + ex.ToString());
- }
- }));
+ EventDispatcher.Instance.AddEventHandler(InboundPipeline, Func.Create(OnInboundPipelineHandler));
- EventDispatcher.Instance.AddEventHandler(OutboundPipeline, new Action(serialized =>
+ EventDispatcher.Instance.AddEventHandler(OutboundPipeline, Func.Create(serialized =>
{
try
{
@@ -49,16 +39,28 @@ internal void AddEvents()
}
}));
- EventDispatcher.Instance.AddEventHandler(SignaturePipeline, new Action(signature => _signature = signature));
+ EventDispatcher.Instance.AddEventHandler(SignaturePipeline, Func.Create(signature => _signature = signature));
Events.TriggerServerEvent(SignaturePipeline);
}
+ private async void OnInboundPipelineHandler([Source] Remote remote, byte[] serialized)
+ {
+ try
+ {
+ await ProcessInboundAsync(remote, serialized);
+ }
+ catch (Exception ex)
+ {
+ Logger.Error("InboundPipeline:" + ex.ToString());
+ }
+ }
+
public async Coroutine PrepareAsync(string pipeline, int source, IMessage message)
{
if (string.IsNullOrWhiteSpace(_signature))
{
StopwatchUtil stopwatch = StopwatchUtil.StartNew();
- while (_signature == null) await BaseScript.Delay(0);
+ while (_signature == null) await BaseScript.Yield();
if (EventDispatcher.Debug)
{
Logger.Debug($"[{message}] Halted {stopwatch.Elapsed.TotalMilliseconds}ms due to signature retrieval.");
diff --git a/FxEvents/FxEvents.Client/FxEvents.Client.csproj b/FxEvents/FxEvents.Client/FxEvents.Client.csproj
index c1c9b3b..408c4e5 100644
--- a/FxEvents/FxEvents.Client/FxEvents.Client.csproj
+++ b/FxEvents/FxEvents.Client/FxEvents.Client.csproj
@@ -17,10 +17,9 @@
Properties
FxEvents.Client
FxEvents.Client
- v4.5.2
512
true
- net452
+ net462;net472;net48
latest
..\CompiledLibs\Client
FxEvents.Client
@@ -35,7 +34,7 @@
False
- 1.0.2
+ 2.0.0-beta3-monov2
true
@@ -54,13 +53,8 @@
- L:\FiveM_gioco\FiveM.app\citizen\clr2\lib\mono\4.5\v2\CitizenFX.Core.dll
-
-
- L:\FiveM_gioco\FiveM.app\citizen\clr2\lib\mono\4.5\v2\CitizenFX.FiveM.dll
-
-
- L:\FiveM_gioco\FiveM.app\citizen\clr2\lib\mono\4.5\v2\Native\CitizenFX.FiveM.Native.dll
+ ..\dependencies\FiveM\Client\CitizenFX.Core.dll
+ False
..\FiveMMsgPack\MsgPack.dll
diff --git a/FxEvents/FxEvents.Server/EventDispatcher.cs b/FxEvents/FxEvents.Server/EventDispatcher.cs
index 79ce2d6..1d81dce 100644
--- a/FxEvents/FxEvents.Server/EventDispatcher.cs
+++ b/FxEvents/FxEvents.Server/EventDispatcher.cs
@@ -1,5 +1,6 @@
global using CitizenFX.Core;
global using CitizenFX.Server.Native;
+using CitizenFX.Server;
using FxEvents.EventSystem;
using FxEvents.Shared;
using FxEvents.Shared.EventSubsystem;
@@ -25,7 +26,7 @@ public EventDispatcher()
GetPlayers = new PlayerList();
Logger = new Log();
Instance = this;
- string debugMode = Natives.GetResourceMetadata(Natives.GetCurrentResourceName(), "fxevents_debug_mode", 0);
+ string debugMode = Natives.GetResourceMetadata((CString)Natives.GetCurrentResourceName(), "fxevents_debug_mode", 0);
Debug = debugMode == "yes" || debugMode == "true" || Convert.ToInt32(debugMode) > 0;
}
@@ -77,14 +78,14 @@ public static void Initalize(string inboundEvent, string outboundEvent, string s
}
///
- /// registra un evento (TriggerEvent)
+ /// Register an Event (TriggerEvent)
///
- /// Nome evento
- /// Azione legata all'evento
- internal async void AddEventHandler(string eventName, Delegate action)
+ /// Event Name
+ /// Event-related action
+ internal async void AddEventHandler(string eventName, DynFunc action)
{
while (!Initialized) await Delay(0);
- EventHandlers[eventName].Add(Func.Create(action));
+ EventHandlers[eventName].Add(action, Binding.All);
}
public static void Send(Player player, string endpoint, params object[] args)
@@ -141,7 +142,7 @@ public static Coroutine Get(ISource client, string endpoint, params object
}
return Events.Get(client.Handle, endpoint, args);
}
- public static void Mount(string endpoint, Delegate @delegate)
+ public static void Mount(string endpoint, DynFunc @delegate)
{
if (!Initialized)
{
diff --git a/FxEvents/FxEvents.Server/EventSystem/ServerGateway.cs b/FxEvents/FxEvents.Server/EventSystem/ServerGateway.cs
index 8b6cbdb..c897d88 100644
--- a/FxEvents/FxEvents.Server/EventSystem/ServerGateway.cs
+++ b/FxEvents/FxEvents.Server/EventSystem/ServerGateway.cs
@@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
+using Player = CitizenFX.Server.Player;
namespace FxEvents.EventSystem
{
@@ -27,9 +28,9 @@ public ServerGateway()
internal void AddEvents()
{
- EventDispatcher.Instance.AddEventHandler(SignaturePipeline, new Action(GetSignature));
- EventDispatcher.Instance.AddEventHandler(InboundPipeline, new Action(Inbound));
- EventDispatcher.Instance.AddEventHandler(OutboundPipeline, new Action(Outbound));
+ EventDispatcher.Instance.AddEventHandler(SignaturePipeline, Func.Create(GetSignature));
+ EventDispatcher.Instance.AddEventHandler(InboundPipeline, Func.Create(Inbound));
+ EventDispatcher.Instance.AddEventHandler(OutboundPipeline, Func.Create(Outbound));
}
public void Push(string pipeline, int source, byte[] buffer)
@@ -40,12 +41,11 @@ public void Push(string pipeline, int source, byte[] buffer)
Events.TriggerAllClientsEvent(pipeline, buffer);
}
-
- private void GetSignature(Remote source)
+ private void GetSignature([Source] Player source)
{
try
{
- int client = int.Parse(source.ToString().Substring(7, source.ToString().Length - 1));
+ int client = source.Handle;
if (_signatures.ContainsKey(client))
{
@@ -63,7 +63,7 @@ private void GetSignature(Remote source)
string signature = BitConverter.ToString(holder).Replace("-", "").ToLower();
_signatures.Add(client, signature);
- Events.TriggerClientEvent(SignaturePipeline, EventDispatcher.Instance.GetPlayers[client], signature);
+ Events.TriggerClientEvent(SignaturePipeline, source, signature);
}
catch (Exception ex)
{
@@ -71,13 +71,17 @@ private void GetSignature(Remote source)
}
}
- private async void Inbound(Remote source, byte[] buffer)
+ private async void Inbound([Source] Remote source, byte[] buffer)
{
try
{
- int client = int.Parse(source.ToString().Substring(7, source.ToString().Length - 1));
+ int client = ((Player)source).Handle;
- if (!_signatures.TryGetValue(client, out string signature)) return;
+ if (!_signatures.TryGetValue(client, out string signature))
+ {
+ Logger.Error($"Client {(string)Natives.GetPlayerName("" + client)}[{client}] tried sending an event without a signature.");
+ return;
+ }
using SerializationContext context = new SerializationContext(InboundPipeline, null, Serialization, buffer);
@@ -88,7 +92,7 @@ private async void Inbound(Remote source, byte[] buffer)
try
{
- await ProcessInboundAsync(message, client);
+ await ProcessInboundAsync(message, source);
}
catch (TimeoutException)
{
@@ -112,11 +116,11 @@ public bool VerifySignature(int source, IMessage message, string signature)
return false;
}
- private void Outbound(Remote source, byte[] buffer)
+ private void Outbound([Source] Player source, byte[] buffer)
{
try
{
- int client = int.Parse(source.ToString().Substring(7, source.ToString().Length - 1));
+ int client = source.Handle;
if (!_signatures.TryGetValue(client, out string signature)) return;
diff --git a/FxEvents/FxEvents.Server/FxEvents.Server.csproj b/FxEvents/FxEvents.Server/FxEvents.Server.csproj
index f076108..a863ae3 100644
--- a/FxEvents/FxEvents.Server/FxEvents.Server.csproj
+++ b/FxEvents/FxEvents.Server/FxEvents.Server.csproj
@@ -2,7 +2,7 @@
FxEvents Server
- FxEvents an advanced event subsystem for FiveM C# Resources.
+ FxEvents an advanced event subsystem for CFX C# Resources.
LICENSE.txt
README.md
FxEvents.Server
@@ -19,7 +19,7 @@
Debug;Release
False
False
- 1.0.2
+ 2.0.0-beta3-monov2
@@ -41,10 +41,12 @@
- L:\FiveM\ManuGamemode\citizen\clr2\lib\mono\4.5\v2\CitizenFX.Core.dll
+ ..\dependencies\FiveM\Server\CitizenFX.Core.dll
+ False
- L:\FiveM\ManuGamemode\citizen\clr2\lib\mono\4.5\v2\CitizenFX.Server.dll
+ ..\dependencies\FiveM\Server\CitizenFX.Server.dll
+ False
..\FiveMMsgPack\MsgPack.dll
diff --git a/FxEvents/Shared/EventSubsystem/BaseGateway.cs b/FxEvents/Shared/EventSubsystem/BaseGateway.cs
index 022a7c8..730a095 100644
--- a/FxEvents/Shared/EventSubsystem/BaseGateway.cs
+++ b/FxEvents/Shared/EventSubsystem/BaseGateway.cs
@@ -13,10 +13,10 @@
using System.Threading;
using System.Threading.Tasks;
#if SERVER
-using CitizenFX.Server.Native;
-using CitizenFX.Server;
+using Player = CitizenFX.Server.Player;
#elif CLIENT
-using CitizenFX.FiveM.Native;
+using CitizenFX.Shared.Native;
+using Player = CitizenFX.Shared.Player;
#endif
namespace FxEvents.Shared.EventSubsystem
@@ -42,7 +42,7 @@ public abstract class BaseGateway
public EventMessagePreparation? PrepareDelegate { get; set; }
public EventMessagePush? PushDelegate { get; set; }
- public async Coroutine ProcessInboundAsync(int source, byte[] serialized)
+ public async Coroutine ProcessInboundAsync(Remote? source, byte[] serialized)
{
using SerializationContext context = new SerializationContext(InboundPipeline, "(Process) In", Serialization, serialized);
EventMessage message = context.Deserialize();
@@ -50,12 +50,12 @@ public async Coroutine ProcessInboundAsync(int source, byte[] serialized)
await ProcessInboundAsync(message, source);
}
- public async Coroutine ProcessInboundAsync(EventMessage message, int source)
+ public async Coroutine ProcessInboundAsync(EventMessage message, Remote? source)
{
object InvokeDelegate(EventHandler subscription)
{
List