Skip to content

Commit

Permalink
Advanced Packet Logging - Method Tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
FallenDev committed Dec 27, 2024
1 parent d3be8b5 commit 9a109c5
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Zolian.Server.Base/GameScripts/Areas/Generic/Rift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void Update(TimeSpan elapsedTime)
_monstersOnMap = ObjectManager.GetObjects<Monster>(Area, p => p is { Alive: true }).Count;
if (_monstersOnMap != 0) return;

var riftBossKilled = _playersOnMap.Values.FirstOrDefault(p => p.MonsterKillCounters["Rift Boss"].TotalKills >= 1);
var riftBossKilled = _playersOnMap.Values.FirstOrDefault(p => p.MonsterKillCounters.ContainsKey("Rift Boss") && p.MonsterKillCounters["Rift Boss"]?.TotalKills >= 1);
if (riftBossKilled is not null)
{
// ToDo: Create rewards for main player who killed the boss
Expand All @@ -55,7 +55,7 @@ public override void Update(TimeSpan elapsedTime)
return;
}

var topKiller = _playersOnMap.Values.OrderByDescending(p => p.MonsterKillCounters["Rift Mob"].TotalKills).FirstOrDefault();
var topKiller = _playersOnMap.Values.Where(p => p.MonsterKillCounters.ContainsKey("Rift Mob")).OrderByDescending(p => p.MonsterKillCounters["Rift Mob"]?.TotalKills).FirstOrDefault();
if (topKiller is null) return;
if (topKiller.MonsterKillCounters["Rift Mob"].TotalKills >= 20 && !topKiller.Client.SummonRiftBoss)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

using System.Diagnostics;
using Chaos.Networking.Entities.Server;
using Darkages.Network.Server;

namespace Darkages.Network.Client.Abstractions;

public interface IWorldClient : IConnectedClient
{
ServerPacketLogger ServerPacketLogger { get; }
ClientPacketLogger ClientPacketLogger { get; }
bool MapUpdating { get; set; }
Aisling Aisling { get; set; }
DialogSession DlgSession { get; set; }
Expand Down
27 changes: 27 additions & 0 deletions Zolian.Server.Base/Network/Client/ClientPacketLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Darkages.Network.Client;

public class ClientPacketLogger
{
private const int MaxLogSize = 15;
private readonly Queue<string> _packetLog = [];
private readonly Lock _logLock = new();

public void LogPacket(string packetDetails)
{
lock (_logLock)
{
if (_packetLog.Count >= MaxLogSize)
_packetLog.Dequeue(); // Remove the oldest log

_packetLog.Enqueue(packetDetails);
}
}

public IEnumerable<string> GetRecentLogs()
{
lock (_logLock)
{
return _packetLog;
}
}
}
Loading

0 comments on commit 9a109c5

Please sign in to comment.