Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions Source/Client/Windows/ChatWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ private void DrawInfo(Rect inRect)
Widgets.Label(inRect, Multiplayer.session.gameName);
inRect.yMin += Text.CalcHeight(Multiplayer.session.gameName, inRect.width) + 10f;

if (Prefs.DevMode)
{
var rect = new Rect(inRect).Height(25f).Width(80f);
if (Widgets.ButtonText(rect, "Net info"))
Find.WindowStack.Add(new DebugTextWindow(NetInfoText()));

inRect.yMin += rect.height + 10f;
}

DrawList(
"MpChatPlayers".Translate(Multiplayer.session.players.Count),
Multiplayer.session.players,
Expand Down Expand Up @@ -350,9 +359,7 @@ public void SendMsg()

if (currentMsg.NullOrEmpty()) return;

if (MpVersion.IsDebug && currentMsg == "/netinfo")
Find.WindowStack.Add(new DebugTextWindow(NetInfoText()));
else if (Multiplayer.Client == null)
if (Multiplayer.Client == null)
Multiplayer.session.AddMsg(Multiplayer.username + ": " + currentMsg);
else
Multiplayer.Client.Send(ClientChatPacket.Create(currentMsg));
Expand All @@ -366,21 +373,13 @@ private string NetInfoText()

var text = new StringBuilder();

void LogNetData(string name, NetStatistics stats)
if (Multiplayer.Client is ClientLiteNetConnection conn)
{
text.AppendLine(name);
text.AppendLine($"Bytes received: {stats.BytesReceived}");
text.AppendLine($"Bytes sent: {stats.BytesSent}");
text.AppendLine($"Packets received: {stats.PacketsReceived}");
text.AppendLine($"Packets sent: {stats.PacketsSent}");
text.AppendLine($"Packet loss: {stats.PacketLoss}");
text.AppendLine($"Packet loss percent: {stats.PacketLossPercent}");
text.AppendLine("Client");
text.AppendLine(conn.peer.Statistics.ToDebugString());
text.AppendLine();
}

if (Multiplayer.Client is ClientLiteNetConnection conn)
LogNetData("Client", conn.peer.Statistics);

if (Multiplayer.LocalServer != null)
{
foreach (var man in Multiplayer.LocalServer.netManagers)
Expand All @@ -406,16 +405,19 @@ void LogNetData(string name, NetStatistics stats)
text.AppendLine($"Connecting: {state.m_bConnecting}");
text.AppendLine($"Error: {state.m_eP2PSessionError}");
text.AppendLine($"Using relay: {state.m_bUsingRelay}");
text.AppendLine($"Bytes to send: {state.m_nBytesQueuedForSend}");
text.AppendLine($"Packets to send: {state.m_nPacketsQueuedForSend}");
text.AppendLine($"Remote IP: {state.m_nRemoteIP}");
text.AppendLine($"Remote port: {state.m_nRemotePort}");
text.AppendLine($"Send queue: {state.m_nBytesQueuedForSend}B {state.m_nPacketsQueuedForSend} packets");
text.AppendLine($"Remote IP: {state.m_nRemoteIP}:{state.m_nRemotePort}");
}
else
{
text.AppendLine("No connection");
}

foreach (var pending in Multiplayer.session.pendingSteam)
{
text.AppendLine($"Steam pending {pending}:{SteamFriends.GetFriendPersonaName(remote)}");
}

text.AppendLine();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Windows/DebugTextWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override void DoWindowContents(Rect inRect)

Text.Font = GameFont.Tiny;

if (Widgets.ButtonText(new Rect(0, 0, 55f, 20f), "Copy all"))
if (Widgets.ButtonText(new Rect(0, 0, 65f, 20f), "Copy all"))
GUIUtility.systemCopyBuffer = text;

Text.Font = GameFont.Small;
Expand Down
16 changes: 14 additions & 2 deletions Source/Common/LiteNetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public string GetDiagnosticsInfo()
foreach (var (endpoint, man) in netManagers)
{
text.AppendLine($"{endpoint}");
text.AppendLine($"{man.Statistics}");
text.AppendLine(man.Statistics.ToDebugString());
}
return text.ToString();
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public void Tick()
public void Stop() => lanManager.Stop();

public string GetDiagnosticsName() => $"Lan (LiteNet) {lanAddress}:{lanManager.LocalPort}";
public string GetDiagnosticsInfo() => lanManager.Statistics.ToString();
public string GetDiagnosticsInfo() => lanManager.Statistics.ToDebugString();
}

public class LiteNetEndpoint
Expand All @@ -149,4 +149,16 @@ public override string ToString()
$"{ipv4}:{port} / {ipv6}:{port}";
}
}

public static class LiteNetExtensions
{
public static string ToDebugString(this NetStatistics stats)
{
var text = new StringBuilder();
text.AppendLine($"Recv: {stats.BytesReceived}B {stats.PacketsReceived} packets");
text.AppendLine($"Sent: {stats.BytesSent}B {stats.PacketsSent} packets");
text.AppendLine($"Loss: {stats.PacketLoss} packets ({stats.PacketLossPercent}%)");
return text.ToString();
}
}
}
Loading