An attempt to fix #12, along with some cleanup and refactor

This commit is contained in:
Sardelka
2022-06-22 10:29:41 +08:00
parent fe6b42e509
commit 42c038d8ab
3 changed files with 17 additions and 6 deletions

View File

@ -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); object result = DecodeNativeCall(packet.Hash, packet.Args, true, packet.ResultType);

View File

@ -192,7 +192,7 @@ namespace RageCoop.Client
Packets.NativeCall packet = new Packets.NativeCall(); Packets.NativeCall packet = new Packets.NativeCall();
packet.Unpack(data); packet.Unpack(data);
DecodeNativeCall(packet.Hash, packet.Args, false); Main.QueueAction(() => { DecodeNativeCall(packet.Hash, packet.Args, false); });
} }
break; break;
@ -202,7 +202,7 @@ namespace RageCoop.Client
Packets.NativeResponse packet = new Packets.NativeResponse(); Packets.NativeResponse packet = new Packets.NativeResponse();
packet.Unpack(data); packet.Unpack(data);
DecodeNativeResponse(packet); DecodeNativeCallWithResponse(packet);
} }
break; break;

View File

@ -89,6 +89,11 @@ namespace RageCoop.Server
} }
} }
/// <summary>
/// Send a native call to client and ignore its return value.
/// </summary>
/// <param name="hash">The function's hash</param>
/// <param name="args">Arguments</param>
public void SendNativeCall(ulong hash, params object[] args) public void SendNativeCall(ulong hash, params object[] args)
{ {
try try
@ -121,8 +126,14 @@ namespace RageCoop.Server
Program.Logger.Error($">> {e.Message} <<>> {e.Source ?? string.Empty} <<>> {e.StackTrace ?? string.Empty} <<"); Program.Logger.Error($">> {e.Message} <<>> {e.Source ?? string.Empty} <<>> {e.StackTrace ?? string.Empty} <<");
} }
} }
/// <summary>
public void SendNativeResponse(Action<object> callback, ulong hash, Type returnType, params object[] args) /// Send a native call to client and do a callback when the response is received.
/// </summary>
/// <param name="callback">The callback to be invoked when the response is received.</param>
/// <param name="hash">The function's hash</param>
/// <param name="returnType">The return type of the response</param>
/// <param name="args">Arguments</param>
public void SendNativeCallWithResponse(Action<object> callback, GTA.Native.Hash hash, Type returnType, params object[] args)
{ {
try try
{ {
@ -172,7 +183,7 @@ namespace RageCoop.Server
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage(); NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
new Packets.NativeResponse() new Packets.NativeResponse()
{ {
Hash = hash, Hash = (ulong)hash,
Args = new List<object>(args) ?? new List<object>(), Args = new List<object>(args) ?? new List<object>(),
ResultType = returnTypeValue, ResultType = returnTypeValue,
ID = id ID = id