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);

View File

@ -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;

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)
{
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<object> callback, ulong hash, Type returnType, params object[] args)
/// <summary>
/// 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
{
@ -172,7 +183,7 @@ namespace RageCoop.Server
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
new Packets.NativeResponse()
{
Hash = hash,
Hash = (ulong)hash,
Args = new List<object>(args) ?? new List<object>(),
ResultType = returnTypeValue,
ID = id