diff --git a/Source/Client/Windows/ChatWindow.cs b/Source/Client/Windows/ChatWindow.cs index 66402903..5ef46f7e 100644 --- a/Source/Client/Windows/ChatWindow.cs +++ b/Source/Client/Windows/ChatWindow.cs @@ -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, @@ -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)); @@ -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) @@ -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(); } diff --git a/Source/Client/Windows/DebugTextWindow.cs b/Source/Client/Windows/DebugTextWindow.cs index 4e14c9a2..b77c45dc 100644 --- a/Source/Client/Windows/DebugTextWindow.cs +++ b/Source/Client/Windows/DebugTextWindow.cs @@ -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; diff --git a/Source/Common/LiteNetManager.cs b/Source/Common/LiteNetManager.cs index 778f06a7..9d52129f 100644 --- a/Source/Common/LiteNetManager.cs +++ b/Source/Common/LiteNetManager.cs @@ -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(); } @@ -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 @@ -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(); + } + } }