From 42c038d8ab7d5801ccb4c232ea7f062698d3ee9e Mon Sep 17 00:00:00 2001 From: Sardelka Date: Wed, 22 Jun 2022 10:29:41 +0800 Subject: [PATCH] An attempt to fix #12, along with some cleanup and refactor --- RageCoop.Client/Networking/Networking.cs | 2 +- RageCoop.Client/Networking/Receive.cs | 4 ++-- RageCoop.Server/Client.cs | 17 ++++++++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/RageCoop.Client/Networking/Networking.cs b/RageCoop.Client/Networking/Networking.cs index aa9fdfa..6378ddf 100644 --- a/RageCoop.Client/Networking/Networking.cs +++ b/RageCoop.Client/Networking/Networking.cs @@ -173,7 +173,7 @@ namespace RageCoop.Client } } - private static void DecodeNativeResponse(Packets.NativeResponse packet) + private static void DecodeNativeCallWithResponse(Packets.NativeResponse packet) { object result = DecodeNativeCall(packet.Hash, packet.Args, true, packet.ResultType); diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs index 0c81ade..225e65f 100644 --- a/RageCoop.Client/Networking/Receive.cs +++ b/RageCoop.Client/Networking/Receive.cs @@ -192,7 +192,7 @@ namespace RageCoop.Client Packets.NativeCall packet = new Packets.NativeCall(); packet.Unpack(data); - DecodeNativeCall(packet.Hash, packet.Args, false); + Main.QueueAction(() => { DecodeNativeCall(packet.Hash, packet.Args, false); }); } break; @@ -202,7 +202,7 @@ namespace RageCoop.Client Packets.NativeResponse packet = new Packets.NativeResponse(); packet.Unpack(data); - DecodeNativeResponse(packet); + DecodeNativeCallWithResponse(packet); } break; diff --git a/RageCoop.Server/Client.cs b/RageCoop.Server/Client.cs index 681ad56..b754bc1 100644 --- a/RageCoop.Server/Client.cs +++ b/RageCoop.Server/Client.cs @@ -89,6 +89,11 @@ namespace RageCoop.Server } } + /// + /// Send a native call to client and ignore its return value. + /// + /// The function's hash + /// Arguments public void SendNativeCall(ulong hash, params object[] args) { try @@ -121,8 +126,14 @@ namespace RageCoop.Server Program.Logger.Error($">> {e.Message} <<>> {e.Source ?? string.Empty} <<>> {e.StackTrace ?? string.Empty} <<"); } } - - public void SendNativeResponse(Action callback, ulong hash, Type returnType, params object[] args) + /// + /// Send a native call to client and do a callback when the response is received. + /// + /// The callback to be invoked when the response is received. + /// The function's hash + /// The return type of the response + /// Arguments + public void SendNativeCallWithResponse(Action callback, GTA.Native.Hash hash, Type returnType, params object[] args) { try { @@ -172,7 +183,7 @@ namespace RageCoop.Server NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage(); new Packets.NativeResponse() { - Hash = hash, + Hash = (ulong)hash, Args = new List(args) ?? new List(), ResultType = returnTypeValue, ID = id