From 3bcda302fecdd001d24cbeefc70f01f2091e2adb Mon Sep 17 00:00:00 2001 From: EntenKoeniq <81123713+EntenKoeniq@users.noreply.github.com> Date: Fri, 10 Dec 2021 16:25:59 +0100 Subject: [PATCH] Small changes and bug fixes --- Client/Networking.cs | 2 +- Server/Client.cs | 7 ++++- Server/CoopServer.csproj | 2 +- Server/Server.cs | 1 + Server/ServerScript.cs | 5 ++-- Server/Util.cs | 56 +++++++++++++++++++++------------------- 6 files changed, 42 insertions(+), 31 deletions(-) diff --git a/Client/Networking.cs b/Client/Networking.cs index d8063e6..7c8ffae 100644 --- a/Client/Networking.cs +++ b/Client/Networking.cs @@ -539,7 +539,7 @@ namespace CoopClient } else { - GTA.UI.Notification.Show("[DecodeNativeCall][" + packet.Hash + "]: Type of argument not found!"); + GTA.UI.Notification.Show("[DecodeNativeResponse][" + packet.Hash + "]: Type of argument not found!"); return; } diff --git a/Server/Client.cs b/Server/Client.cs index ebdeb8e..3adabc3 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -84,12 +84,14 @@ namespace CoopServer NetConnection userConnection = Server.MainNetServer.Connections.Find(x => x.RemoteUniqueIdentifier == ID); if (userConnection == null) { + Logging.Error($"[Client->SendNativeCall(ulong hash, params object[] args)]: Connection \"{ID}\" not found!"); return; } List arguments = Util.ParseNativeArguments(args); - if (arguments == null) + if (arguments == null || args.Length == 0) { + Logging.Error($"[Client->SendNativeCall(ulong hash, params object[] args)]: Missing arguments!"); return; } @@ -116,6 +118,7 @@ namespace CoopServer NetConnection userConnection = Server.MainNetServer.Connections.Find(x => x.RemoteUniqueIdentifier == ID); if (userConnection == null) { + Logging.Error($"[Client->SendNativeResponse(Action callback, ulong hash, Type type, params object[] args)]: Connection \"{ID}\" not found!"); return; } @@ -143,12 +146,14 @@ namespace CoopServer } else { + Logging.Error($"[Client->SendNativeResponse(Action callback, ulong hash, Type type, params object[] args)]: Argument does not exist!"); return; } List arguments = Util.ParseNativeArguments(args); if (arguments == null) { + Logging.Error($"[Client->SendNativeResponse(Action callback, ulong hash, Type type, params object[] args)]: One or more arguments do not exist!"); return; } diff --git a/Server/CoopServer.csproj b/Server/CoopServer.csproj index 7dc3099..4ce44d6 100644 --- a/Server/CoopServer.csproj +++ b/Server/CoopServer.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.4.6.0001 + 1.4.7.0001 1.0.0.0 https://github.com/GTACOOP-R/GTACoop-R diff --git a/Server/Server.cs b/Server/Server.cs index 0f9c8ec..bd9ddb8 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -193,6 +193,7 @@ namespace CoopServer private void Listen() { Logging.Info("Listening for clients"); + Logging.Info("Please use CTRL + C if you want to stop the server!"); while (!Program.ReadyToStop) { diff --git a/Server/ServerScript.cs b/Server/ServerScript.cs index 1578e0e..b21a63d 100644 --- a/Server/ServerScript.cs +++ b/Server/ServerScript.cs @@ -238,9 +238,10 @@ namespace CoopServer return; } - List arguments; - if ((arguments = Util.ParseNativeArguments(args)) == null) + List arguments = Util.ParseNativeArguments(args); + if (arguments == null) { + Logging.Error($"[ServerScript->SendNativeCallToAll(ulong hash, params object[] args)]: One or more arguments do not exist!"); return; } diff --git a/Server/Util.cs b/Server/Util.cs index b233067..3e98aa9 100644 --- a/Server/Util.cs +++ b/Server/Util.cs @@ -12,36 +12,40 @@ namespace CoopServer { public static List ParseNativeArguments(params object[] args) { - List result = new(); + List result = null; - foreach (object arg in args) + if (args != null && args.Length > 0) { - Type typeOf = arg.GetType(); + result = new(); - if (typeOf == typeof(int)) + foreach (object arg in args) { - result.Add(new IntArgument() { Data = (int)arg }); - } - else if (typeOf == typeof(bool)) - { - result.Add(new BoolArgument() { Data = (bool)arg }); - } - else if (typeOf == typeof(float)) - { - result.Add(new FloatArgument() { Data = (float)arg }); - } - else if (typeOf == typeof(string)) - { - result.Add(new StringArgument() { Data = (string)arg }); - } - else if (typeOf == typeof(LVector3)) - { - result.Add(new LVector3Argument() { Data = (LVector3)arg }); - } - else - { - Logging.Error("[Util->ParseNativeArguments(params object[] args)]: Type of argument not found!"); - return null; + Type typeOf = arg.GetType(); + + if (typeOf == typeof(int)) + { + result.Add(new IntArgument() { Data = (int)arg }); + } + else if (typeOf == typeof(bool)) + { + result.Add(new BoolArgument() { Data = (bool)arg }); + } + else if (typeOf == typeof(float)) + { + result.Add(new FloatArgument() { Data = (float)arg }); + } + else if (typeOf == typeof(string)) + { + result.Add(new StringArgument() { Data = (string)arg }); + } + else if (typeOf == typeof(LVector3)) + { + result.Add(new LVector3Argument() { Data = (LVector3)arg }); + } + else + { + return null; + } } }