diff --git a/Core/Logging/Logger.cs b/Core/Logging/Logger.cs index 64c89ef..f0d08a3 100644 --- a/Core/Logging/Logger.cs +++ b/Core/Logging/Logger.cs @@ -7,7 +7,7 @@ using System.Diagnostics; namespace RageCoop.Core.Logging { - public class Logger + public class Logger :IDisposable { /// @@ -20,13 +20,14 @@ namespace RageCoop.Core.Logging private string Buffer=""; private Thread LoggerThread; + private bool Stopping=false; public Logger(bool overwrite=true) { if (File.Exists(LogPath)&&overwrite) { File.Delete(LogPath); } LoggerThread=new Thread(() => { - while (true) + while (!Stopping) { Flush(); Thread.Sleep(1000); @@ -132,5 +133,10 @@ namespace RageCoop.Core.Logging } } + public void Dispose() + { + Stopping=true; + LoggerThread?.Join(); + } } } diff --git a/Server/Properties/PublishProfiles/FolderProfile.pubxml b/Server/Properties/PublishProfiles/FolderProfile.pubxml index 2eb4874..f262f64 100644 --- a/Server/Properties/PublishProfiles/FolderProfile.pubxml +++ b/Server/Properties/PublishProfiles/FolderProfile.pubxml @@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net6.0\publish\linux-arm\ + bin\Release\net6.0\publish\linux-x64\ FileSystem net6.0 - linux-arm + linux-x64 true True True diff --git a/Server/Properties/PublishProfiles/FolderProfile.pubxml.user b/Server/Properties/PublishProfiles/FolderProfile.pubxml.user index d301e53..61bab07 100644 --- a/Server/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/Server/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - 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; + 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; \ No newline at end of file diff --git a/Server/Server.cs b/Server/Server.cs index a32391c..cd7cad9 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -11,6 +11,7 @@ using RageCoop.Core; using Newtonsoft.Json; using System.Threading.Tasks; using Lidgren.Network; +using System.Timers; namespace RageCoop.Server { @@ -32,10 +33,9 @@ namespace RageCoop.Server public static Resource RunningResource = null; public static readonly Dictionary> Commands = new(); public static readonly Dictionary> TriggerEvents = new(); - private static Thread BackgroundThread; public static readonly Dictionary Clients = new(); - + private static System.Timers.Timer SendLatencyTimer = new System.Timers.Timer(5000); public Server() { Program.Logger.Info("================"); @@ -57,7 +57,9 @@ namespace RageCoop.Server MainNetServer = new NetServer(config); 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)); if (MainSettings.UPnP) @@ -205,10 +207,8 @@ namespace RageCoop.Server Program.Logger.Info("Searching for client-side files..."); DownloadManager.CheckForDirectoryAndFiles(); - Listen(); - BackgroundThread=new Thread(() => Background()); - BackgroundThread.Start(); + Listen(); } private void Listen() @@ -587,29 +587,25 @@ namespace RageCoop.Server // Sleep for 1 second 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) + MainNetServer.Connections.FindAll(x => x.RemoteUniqueIdentifier != c.NetID).ForEach(x => { - MainNetServer.Connections.FindAll(x => x.RemoteUniqueIdentifier != c.NetID).ForEach(x => + NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage(); + new Packets.PlayerInfoUpdate() { - NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage(); - new Packets.PlayerInfoUpdate() - { - PedID=c.Player.PedID, - Username=c.Player.Username, - Latency=c.Player.Latency=c.Latency, - }.Pack(outgoingMessage); - MainNetServer.SendMessage(outgoingMessage, x, NetDeliveryMethod.ReliableSequenced, (byte)ConnectionChannel.Default); - }); - } - - // Update Latency every 20 seconds. - Thread.Sleep(1000*20); + PedID=c.Player.PedID, + Username=c.Player.Username, + Latency=c.Player.Latency=c.Latency, + }.Pack(outgoingMessage); + MainNetServer.SendMessage(outgoingMessage, x, NetDeliveryMethod.ReliableSequenced, (byte)ConnectionChannel.Default); + }); } + } 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(); // Create a new handshake packet