diff --git a/RageCoop.Client/Main.cs b/RageCoop.Client/Main.cs index f55b159..dc4bc93 100644 --- a/RageCoop.Client/Main.cs +++ b/RageCoop.Client/Main.cs @@ -89,11 +89,6 @@ namespace RageCoop.Client } #if DEBUG - private ulong _lastDebugData; - private int _debugBytesSent; - private int _debugBytesReceived; - private int _lastBytesSent; - public int _lastBytesReceived; #endif private void OnTick(object sender, EventArgs e) { @@ -136,21 +131,10 @@ namespace RageCoop.Client #if DEBUG if (Networking.ShowNetworkInfo) { - ulong time = Util.GetTickCount64(); - if (time - _lastDebugData > 1000) - { - _lastDebugData = time; - - _debugBytesReceived = Networking.Client.Statistics.ReceivedBytes-_lastBytesReceived; - _lastBytesReceived=Networking.Client.Statistics.ReceivedBytes; - - _debugBytesSent = Networking.Client.Statistics.SentBytes-_lastBytesSent; - _lastBytesSent=Networking.Client.Statistics.SentBytes; - } - + new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 0), $"L: {Networking.Latency * 1000:N0}ms", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw(); - new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 30), $"R: {Lidgren.Network.NetUtility.ToHumanReadable(_debugBytesReceived)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw(); - new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 60), $"S: {Lidgren.Network.NetUtility.ToHumanReadable(_debugBytesSent)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw(); + new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 30), $"R: {Lidgren.Network.NetUtility.ToHumanReadable(Statistics.BytesDownPerSecond)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw(); + new LemonUI.Elements.ScaledText(new PointF(Screen.PrimaryScreen.Bounds.Width / 2, 60), $"S: {Lidgren.Network.NetUtility.ToHumanReadable(Statistics.BytesUpPerSecond)}/s", 0.5f) { Alignment = GTA.UI.Alignment.Center }.Draw(); } #endif diff --git a/RageCoop.Client/Networking/Statistics.cs b/RageCoop.Client/Networking/Statistics.cs new file mode 100644 index 0000000..3e8c450 --- /dev/null +++ b/RageCoop.Client/Networking/Statistics.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace RageCoop.Client +{ + internal static class Statistics + { + public static int BytesDownPerSecond{ get; private set; } + public static int BytesUpPerSecond { get; private set; } + static Statistics() + { + Task.Run(() => + { + while (true) + { + var bu=Networking.Client.Statistics.SentBytes; + var bd = Networking.Client.Statistics.ReceivedBytes; + Thread.Sleep(1000); + BytesUpPerSecond=Networking.Client.Statistics.SentBytes-bu; + BytesDownPerSecond=Networking.Client.Statistics.ReceivedBytes-bd; + } + }); + } + } +} diff --git a/RageCoop.Server/Scripting/API.cs b/RageCoop.Server/Scripting/API.cs index ba8d230..deff9e5 100644 --- a/RageCoop.Server/Scripting/API.cs +++ b/RageCoop.Server/Scripting/API.cs @@ -261,7 +261,7 @@ namespace RageCoop.Server.Scripting /// - /// Send an event and data to the specified clients. Use if you want to send event to individual client. + /// Send an event and data to the specified clients. Use if you want to send event to individual client. /// /// An unique identifier of the event, you can use to get it from a string /// The objects conataing your data, see for supported types. diff --git a/RageCoop.Server/Scripting/ServerResource.cs b/RageCoop.Server/Scripting/ServerResource.cs index 10b583e..12007d4 100644 --- a/RageCoop.Server/Scripting/ServerResource.cs +++ b/RageCoop.Server/Scripting/ServerResource.cs @@ -29,8 +29,8 @@ namespace RageCoop.Server.Scripting var conf = new PluginConfig(Path.GetFullPath(Path.Combine(resDir, Path.GetFileName(resDir)+".dll"))) { PreferSharedTypes = true, - EnableHotReload=!isTemp, - IsUnloadable=true, + EnableHotReload=false, + IsUnloadable=false, LoadInMemory=true, }; ServerResource r = new(conf);