Latency update and threading fixes.
This commit is contained in:
@ -7,7 +7,7 @@ using System.Diagnostics;
|
|||||||
|
|
||||||
namespace RageCoop.Core.Logging
|
namespace RageCoop.Core.Logging
|
||||||
{
|
{
|
||||||
public class Logger
|
public class Logger :IDisposable
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -20,13 +20,14 @@ namespace RageCoop.Core.Logging
|
|||||||
|
|
||||||
private string Buffer="";
|
private string Buffer="";
|
||||||
private Thread LoggerThread;
|
private Thread LoggerThread;
|
||||||
|
private bool Stopping=false;
|
||||||
|
|
||||||
public Logger(bool overwrite=true)
|
public Logger(bool overwrite=true)
|
||||||
{
|
{
|
||||||
if (File.Exists(LogPath)&&overwrite) { File.Delete(LogPath); }
|
if (File.Exists(LogPath)&&overwrite) { File.Delete(LogPath); }
|
||||||
LoggerThread=new Thread(() =>
|
LoggerThread=new Thread(() =>
|
||||||
{
|
{
|
||||||
while (true)
|
while (!Stopping)
|
||||||
{
|
{
|
||||||
Flush();
|
Flush();
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
@ -132,5 +133,10 @@ namespace RageCoop.Core.Logging
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Stopping=true;
|
||||||
|
LoggerThread?.Join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration>Release</Configuration>
|
<Configuration>Release</Configuration>
|
||||||
<Platform>Any CPU</Platform>
|
<Platform>Any CPU</Platform>
|
||||||
<PublishDir>bin\Release\net6.0\publish\linux-arm\</PublishDir>
|
<PublishDir>bin\Release\net6.0\publish\linux-x64\</PublishDir>
|
||||||
<PublishProtocol>FileSystem</PublishProtocol>
|
<PublishProtocol>FileSystem</PublishProtocol>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<RuntimeIdentifier>linux-arm</RuntimeIdentifier>
|
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||||
<SelfContained>true</SelfContained>
|
<SelfContained>true</SelfContained>
|
||||||
<PublishSingleFile>True</PublishSingleFile>
|
<PublishSingleFile>True</PublishSingleFile>
|
||||||
<PublishTrimmed>True</PublishTrimmed>
|
<PublishTrimmed>True</PublishTrimmed>
|
||||||
|
@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
|||||||
-->
|
-->
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<History>True|2022-05-27T07:20:25.7264350Z;True|2022-05-27T15:20:04.2362276+08:00;True|2022-05-27T15:19:21.4852644+08:00;True|2022-05-27T15:18:36.0857345+08:00;True|2022-05-25T10:30:00.0927959+08:00;True|2022-05-25T10:26:50.6739643+08:00;True|2022-05-25T10:20:36.6658425+08:00;True|2022-05-25T10:19:47.8333108+08:00;True|2022-05-24T11:00:13.3617113+08:00;True|2022-05-22T16:56:31.0481188+08:00;True|2022-05-18T13:35:57.1402751+08:00;True|2022-05-18T13:10:28.4995253+08:00;True|2022-05-01T18:35:01.9624101+08:00;True|2022-05-01T12:32:20.8671319+08:00;False|2022-05-01T12:30:25.4596227+08:00;</History>
|
<History>True|2022-06-01T10:47:39.6707493Z;True|2022-06-01T18:04:32.2932367+08:00;True|2022-06-01T18:03:17.8871227+08:00;True|2022-05-27T15:20:25.7264350+08:00;True|2022-05-27T15:20:04.2362276+08:00;True|2022-05-27T15:19:21.4852644+08:00;True|2022-05-27T15:18:36.0857345+08:00;True|2022-05-25T10:30:00.0927959+08:00;True|2022-05-25T10:26:50.6739643+08:00;True|2022-05-25T10:20:36.6658425+08:00;True|2022-05-25T10:19:47.8333108+08:00;True|2022-05-24T11:00:13.3617113+08:00;True|2022-05-22T16:56:31.0481188+08:00;True|2022-05-18T13:35:57.1402751+08:00;True|2022-05-18T13:10:28.4995253+08:00;True|2022-05-01T18:35:01.9624101+08:00;True|2022-05-01T12:32:20.8671319+08:00;False|2022-05-01T12:30:25.4596227+08:00;</History>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
@ -11,6 +11,7 @@ using RageCoop.Core;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
|
using System.Timers;
|
||||||
|
|
||||||
namespace RageCoop.Server
|
namespace RageCoop.Server
|
||||||
{
|
{
|
||||||
@ -32,10 +33,9 @@ namespace RageCoop.Server
|
|||||||
public static Resource RunningResource = null;
|
public static Resource RunningResource = null;
|
||||||
public static readonly Dictionary<Command, Action<CommandContext>> Commands = new();
|
public static readonly Dictionary<Command, Action<CommandContext>> Commands = new();
|
||||||
public static readonly Dictionary<TriggerEvent, Action<EventContext>> TriggerEvents = new();
|
public static readonly Dictionary<TriggerEvent, Action<EventContext>> TriggerEvents = new();
|
||||||
private static Thread BackgroundThread;
|
|
||||||
|
|
||||||
public static readonly Dictionary<long,Client> Clients = new();
|
public static readonly Dictionary<long,Client> Clients = new();
|
||||||
|
private static System.Timers.Timer SendLatencyTimer = new System.Timers.Timer(5000);
|
||||||
public Server()
|
public Server()
|
||||||
{
|
{
|
||||||
Program.Logger.Info("================");
|
Program.Logger.Info("================");
|
||||||
@ -57,7 +57,9 @@ namespace RageCoop.Server
|
|||||||
|
|
||||||
MainNetServer = new NetServer(config);
|
MainNetServer = new NetServer(config);
|
||||||
MainNetServer.Start();
|
MainNetServer.Start();
|
||||||
|
SendLatencyTimer.Elapsed+=((s,e) => { SendLatency(); });
|
||||||
|
SendLatencyTimer.AutoReset=true;
|
||||||
|
SendLatencyTimer.Enabled=true;
|
||||||
Program.Logger.Info(string.Format("Server listening on {0}:{1}", config.LocalAddress.ToString(), config.Port));
|
Program.Logger.Info(string.Format("Server listening on {0}:{1}", config.LocalAddress.ToString(), config.Port));
|
||||||
|
|
||||||
if (MainSettings.UPnP)
|
if (MainSettings.UPnP)
|
||||||
@ -205,10 +207,8 @@ namespace RageCoop.Server
|
|||||||
Program.Logger.Info("Searching for client-side files...");
|
Program.Logger.Info("Searching for client-side files...");
|
||||||
DownloadManager.CheckForDirectoryAndFiles();
|
DownloadManager.CheckForDirectoryAndFiles();
|
||||||
|
|
||||||
Listen();
|
|
||||||
|
|
||||||
BackgroundThread=new Thread(() => Background());
|
Listen();
|
||||||
BackgroundThread.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Listen()
|
private void Listen()
|
||||||
@ -587,10 +587,9 @@ namespace RageCoop.Server
|
|||||||
// Sleep for 1 second
|
// Sleep for 1 second
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
|
Program.Logger.Dispose();
|
||||||
}
|
}
|
||||||
private void Background()
|
private void SendLatency()
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
foreach (Client c in Clients.Values)
|
foreach (Client c in Clients.Values)
|
||||||
{
|
{
|
||||||
@ -607,9 +606,6 @@ namespace RageCoop.Server
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Latency every 20 seconds.
|
|
||||||
Thread.Sleep(1000*20);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisconnectAndLog(NetConnection senderConnection,PacketTypes type, Exception e)
|
private void DisconnectAndLog(NetConnection senderConnection,PacketTypes type, Exception e)
|
||||||
@ -677,7 +673,7 @@ namespace RageCoop.Server
|
|||||||
}
|
}
|
||||||
);;
|
);;
|
||||||
}
|
}
|
||||||
Program.Logger.Info($"HandShake sucess, Player:{packet.Username} PedID:{packet.PedID}");
|
Program.Logger.Info($"Handshake sucess, Player:{packet.Username} PedID:{packet.PedID}");
|
||||||
NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
|
NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
|
||||||
|
|
||||||
// Create a new handshake packet
|
// Create a new handshake packet
|
||||||
|
Reference in New Issue
Block a user