fix: Adds more NetState dumping for debug (#1795)

This commit is contained in:
Kamron Batman 2024-05-27 12:10:27 -07:00 • committed by GitHub
parent 21c5e46565
commit ccad915464
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 30 deletions

View file

@ -26,13 +26,13 @@ public static class DumpNetStates
public static void DumpNetStatesCommand(CommandEventArgs args) public static void DumpNetStatesCommand(CommandEventArgs args)
{ {
using var file = new StreamWriter("netstatedump.csv"); using var file = new StreamWriter($"netstatedump-{Core.Now:yyyy-M-d-HH-mm-ss}_{Core.TickCount}.csv");
file.WriteLine("NetState, RecvTask, SendTask, ProtocolState, ParserState"); file.WriteLine("NetState, ConnectedOn, NextActivityCheck, SocketConnected, ProtocolState, ParserState");
foreach (var ns in NetState.Instances) foreach (var ns in NetState.Instances)
{ {
file.WriteLine($"{ns}, {ns._protocolState}, {ns._parserState}"); file.WriteLine($"{ns}, {ns.ConnectedOn}, {ns.NextActivityCheck}, {ns.Connection.Connected}, {ns._protocolState}, {ns._parserState}");
} }
} }
} }

View file

@ -67,7 +67,6 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
private readonly string _toString; private readonly string _toString;
private ClientVersion _version; private ClientVersion _version;
private long _nextActivityCheck;
private bool _running = true; private bool _running = true;
private volatile DecodePacket _packetDecoder; private volatile DecodePacket _packetDecoder;
private volatile EncodePacket _packetEncoder; private volatile EncodePacket _packetEncoder;
@ -133,7 +132,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
Trades = []; Trades = [];
RecvPipe = new Pipe(RecvPipeSize); RecvPipe = new Pipe(RecvPipeSize);
SendPipe = new Pipe(SendPipeSize); SendPipe = new Pipe(SendPipeSize);
_nextActivityCheck = Core.TickCount + 30000; NextActivityCheck = Core.TickCount + 30000;
ConnectedOn = Core.Now; ConnectedOn = Core.Now;
try try
@ -166,6 +165,8 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
public NetState Previous { get; set; } public NetState Previous { get; set; }
public bool OnLinkList { get; set; } public bool OnLinkList { get; set; }
public long NextActivityCheck { get; private set; }
// Only use this for debugging. This will make your server very slow! // Only use this for debugging. This will make your server very slow!
public bool PacketLogging public bool PacketLogging
{ {
@ -340,28 +341,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
return null; return null;
} }
public SecureTradeContainer FindTradeContainer(Mobile m) public SecureTradeContainer FindTradeContainer(Mobile m) => FindTrade(m)?.From.Container;
{
for (var i = 0; i < Trades.Count; ++i)
{
var trade = Trades[i];
var from = trade.From;
var to = trade.To;
if (from.Mobile == Mobile && to.Mobile == m)
{
return from.Container;
}
if (from.Mobile == m && to.Mobile == Mobile)
{
return to.Container;
}
}
return null;
}
public SecureTradeContainer AddTrade(NetState state) public SecureTradeContainer AddTrade(NetState state)
{ {
@ -920,7 +900,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
if (bytesWritten > 0) if (bytesWritten > 0)
{ {
_nextActivityCheck = Core.TickCount + 90000; NextActivityCheck = Core.TickCount + 90000;
reader.Advance((uint)bytesWritten); reader.Advance((uint)bytesWritten);
} }
@ -972,7 +952,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
DecodePacket(buffer, ref bytesWritten); DecodePacket(buffer, ref bytesWritten);
writer.Advance((uint)bytesWritten); writer.Advance((uint)bytesWritten);
_nextActivityCheck = Core.TickCount + 90000; NextActivityCheck = Core.TickCount + 90000;
} }
private static void DisconnectUnattachedSockets() private static void DisconnectUnattachedSockets()
@ -1084,7 +1064,7 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
public void CheckAlive(long curTicks) public void CheckAlive(long curTicks)
{ {
if (Connection != null && _nextActivityCheck - curTicks < 0) if (Connection != null && NextActivityCheck - curTicks < 0)
{ {
LogInfo("Disconnecting due to inactivity..."); LogInfo("Disconnecting due to inactivity...");
Disconnect("Disconnecting due to inactivity."); Disconnect("Disconnecting due to inactivity.");