-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
59 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
namespace Darkages.Network.Client; | ||
using System.Collections.Concurrent; | ||
using System.Net; | ||
|
||
namespace Darkages.Network.Client; | ||
|
||
public class ClientPacketLogger | ||
{ | ||
private const int MaxLogSize = 15; | ||
private readonly Queue<string> _packetLog = []; | ||
private ConcurrentDictionary<IPAddress, Queue<string>> _packetLog = []; | ||
private readonly Lock _logLock = new(); | ||
|
||
public void LogPacket(string packetDetails) | ||
public void LogPacket(IPAddress ip, string packetDetails) | ||
{ | ||
lock (_logLock) | ||
{ | ||
if (_packetLog.Count >= MaxLogSize) | ||
_packetLog.Dequeue(); // Remove the oldest log | ||
_packetLog.TryGetValue(ip, out var packetLog); | ||
if (packetLog is null) return; | ||
if (packetLog.Count >= MaxLogSize) | ||
packetLog.Dequeue(); // Remove the oldest log | ||
|
||
_packetLog.Enqueue(packetDetails); | ||
packetLog.Enqueue(packetDetails); | ||
} | ||
} | ||
|
||
public IEnumerable<string> GetRecentLogs() | ||
public IEnumerable<string> GetRecentLogs(IPAddress ip) | ||
{ | ||
lock (_logLock) | ||
{ | ||
return _packetLog; | ||
_packetLog.TryGetValue(ip, out var packetLog); | ||
return packetLog; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
namespace Darkages.Network.Server; | ||
using System.Collections.Concurrent; | ||
using System.Net; | ||
|
||
namespace Darkages.Network.Server; | ||
|
||
public class ServerPacketLogger | ||
{ | ||
private const int MaxLogSize = 15; | ||
private readonly Queue<string> _packetLog = []; | ||
private ConcurrentDictionary<IPAddress, Queue<string>> _packetLog = []; | ||
private readonly Lock _logLock = new(); | ||
|
||
public void LogPacket(string packetDetails) | ||
public void LogPacket(IPAddress ip, string packetDetails) | ||
{ | ||
lock (_logLock) | ||
{ | ||
if (_packetLog.Count >= MaxLogSize) | ||
_packetLog.Dequeue(); // Remove the oldest log | ||
_packetLog.TryGetValue(ip, out var packetLog); | ||
if (packetLog is null) return; | ||
if (packetLog.Count >= MaxLogSize) | ||
packetLog.Dequeue(); // Remove the oldest log | ||
|
||
_packetLog.Enqueue(packetDetails); | ||
packetLog.Enqueue(packetDetails); | ||
} | ||
} | ||
|
||
public IEnumerable<string> GetRecentLogs() | ||
public IEnumerable<string> GetRecentLogs(IPAddress ip) | ||
{ | ||
lock (_logLock) | ||
{ | ||
return _packetLog; | ||
_packetLog.TryGetValue(ip, out var packetLog); | ||
return packetLog; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters