Networking statistics, disable resource unload

This commit is contained in:
Sardelka 2022-07-06 01:03:18 +08:00
parent 05304f9461
commit 5a5d78ac27
4 changed files with 35 additions and 22 deletions

View File

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

View File

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

View File

@ -261,7 +261,7 @@ namespace RageCoop.Server.Scripting
/// <summary>
/// Send an event and data to the specified clients. Use <see cref="Client.SendCustomEvent(int, List{object})"/> if you want to send event to individual client.
/// Send an event and data to the specified clients. Use <see cref="Client.SendCustomEvent(int,object[])"/> if you want to send event to individual client.
/// </summary>
/// <param name="eventHash">An unique identifier of the event, you can use <see cref="CustomEvents.Hash(string)"/> to get it from a string</param>
/// <param name="args">The objects conataing your data, see <see cref="Scripting.CustomEventReceivedArgs.Args"/> for supported types.</param>

View File

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