Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Commit

Permalink
Version 0.1.9, protocol 8
Browse files Browse the repository at this point in the history
/steaminfo chat cmd
  • Loading branch information
Zetrith committed Dec 22, 2018
1 parent 2a39b14 commit bf9dbe9
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 81 deletions.
4 changes: 2 additions & 2 deletions About/Manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Manifest>
<identifier>Multiplayer</identifier>
<version>0.1.8</version>
<version>0.1.9</version>
<manifestUri>https://github.com/Zetrith/Multiplayer/master/About/Manifest.xml</manifestUri>
<downloadUri>https://github.com/Zetrith/Multiplayer/releases/latest</downloadUri>
</Manifest>
</Manifest>
38 changes: 37 additions & 1 deletion Source/Client/ChatWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,50 @@ public void SendMsg()

if (currentMsg.NullOrEmpty()) return;

if (Multiplayer.Client == null)
if (currentMsg == "/steaminfo")
OpenSteamDebug();
else if (Multiplayer.Client == null)
Multiplayer.session.AddMsg(Multiplayer.username + ": " + currentMsg);
else
Multiplayer.Client.Send(Packets.Client_Chat, currentMsg);

currentMsg = "";
}

private void OpenSteamDebug()
{
var text = new StringBuilder();

if (Multiplayer.session != null)
{
foreach (var remote in Multiplayer.session.knownUsers)
{
text.AppendLine(SteamFriends.GetFriendPersonaName(remote));
text.AppendLine(remote.ToString());

if (SteamNetworking.GetP2PSessionState(remote, out P2PSessionState_t state))
{
text.AppendLine($"Active: {state.m_bConnectionActive}");
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}");
}
else
{
text.AppendLine("No connection");
}

text.Append("\n");
}
}

Find.WindowStack.Add(new DebugTextWindow(text.ToString()));
}

public void OnChatReceived()
{
chatScroll.y = messagesHeight;
Expand Down
74 changes: 0 additions & 74 deletions Source/Client/DesyncCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,78 +287,4 @@ public SyncMapInfo(int mapId)
}
}

public class DesyncInfoWindow : Window
{
public override Vector2 InitialSize => new Vector2(600, 300);

private Vector2 scroll;
private string text;

public DesyncInfoWindow(Replay replay)
{
absorbInputAroundWindow = true;
doCloseX = true;

var text = new StringBuilder();

using (var zip = replay.ZipFile)
{
try
{
text.AppendLine("[info]");
text.AppendLine(zip["info"].GetString());
text.AppendLine();
}
catch { }

try
{
PrintSyncInfo(text, zip, "sync_local");
}
catch { }

try
{
PrintSyncInfo(text, zip, "sync_remote");
}
catch { }

try
{
text.AppendLine("[desync_info]");
var desyncInfo = new ByteReader(zip["desync_info"].GetBytes());
text.AppendLine($"Arbiter online: {desyncInfo.ReadBool()}");
text.AppendLine($"Last valid tick: {desyncInfo.ReadInt32()}");
text.AppendLine($"Last valid arbiter online: {desyncInfo.ReadBool()}");
text.AppendLine($"Mod version: {desyncInfo.ReadString()}");
text.AppendLine($"Mod is debug: {desyncInfo.ReadBool()}");
text.AppendLine($"Dev mode: {desyncInfo.ReadBool()}");
}
catch { }
}

this.text = text.ToString();
}

private void PrintSyncInfo(StringBuilder text, ZipFile zip, string file)
{
text.AppendLine($"[{file}]");

var sync = SyncInfo.Deserialize(new ByteReader(zip[file].GetBytes()));
text.AppendLine($"Start: {sync.startTick}");
text.AppendLine($"Map count: {sync.maps.Count}");
text.AppendLine($"Last map state: {sync.maps.Select(m => $"{m.mapId}/{m.map.LastOrDefault()}/{m.map.Count}").ToStringSafeEnumerable()}");
text.AppendLine($"Last world state: {sync.world.LastOrDefault()}/{sync.world.Count}");
text.AppendLine($"Last cmd state: {sync.cmds.LastOrDefault()}/{sync.cmds.Count}");
text.AppendLine($"Trace hashes: {sync.traceHashes.Count}");

text.AppendLine();
}

public override void DoWindowContents(Rect inRect)
{
Widgets.TextAreaScrollable(inRect, text, ref scroll);
}
}

}
1 change: 1 addition & 0 deletions Source/Client/Multiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private static void InitSteam()
if (session?.localSettings != null && session.localSettings.steam && !session.pendingSteam.Contains(req.m_steamIDRemote))
{
session.pendingSteam.Add(req.m_steamIDRemote);
session.knownUsers.Add(req.m_steamIDRemote);
session.hasUnread = true;
SteamFriends.RequestUserInformation(req.m_steamIDRemote, true);
}
Expand Down
1 change: 1 addition & 0 deletions Source/Client/MultiplayerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class MultiplayerSession

public bool allowSteam;
public List<CSteamID> pendingSteam = new List<CSteamID>();
public List<CSteamID> knownUsers = new List<CSteamID>();

public const int MaxMessages = 200;
public List<ChatMsg> messages = new List<ChatMsg>();
Expand Down
65 changes: 63 additions & 2 deletions Source/Client/ServerBrowser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using LiteNetLib;
extern alias zip;

using LiteNetLib;
using Multiplayer.Common;
using RimWorld;
using Steamworks;
Expand All @@ -13,6 +15,7 @@
using UnityEngine;
using Verse;
using Verse.Steam;
using zip::Ionic.Zip;

namespace Multiplayer.Client
{
Expand Down Expand Up @@ -315,7 +318,7 @@ private void DrawSaveList(List<SaveFile> saves, float width, ref float y)
if (Widgets.ButtonInvisible(entryRect))
{
if (saveFile.replay && Event.current.button == 1 && MpVersion.IsDebug)
Find.WindowStack.Add(new DesyncInfoWindow(Replay.ForLoading(saveFile.file)));
Find.WindowStack.Add(new DebugTextWindow(GetDebugString(Replay.ForLoading(saveFile.file))));
else
selectedFile = saveFile;
}
Expand All @@ -324,6 +327,64 @@ private void DrawSaveList(List<SaveFile> saves, float width, ref float y)
}
}

private static string GetDebugString(Replay replay)
{
var text = new StringBuilder();

using (var zip = replay.ZipFile)
{
try
{
text.AppendLine("[info]");
text.AppendLine(zip["info"].GetString());
text.AppendLine();
}
catch { }

try
{
PrintSyncInfo(text, zip, "sync_local");
}
catch { }

try
{
PrintSyncInfo(text, zip, "sync_remote");
}
catch { }

try
{
text.AppendLine("[desync_info]");
var desyncInfo = new ByteReader(zip["desync_info"].GetBytes());
text.AppendLine($"Arbiter online: {desyncInfo.ReadBool()}");
text.AppendLine($"Last valid tick: {desyncInfo.ReadInt32()}");
text.AppendLine($"Last valid arbiter online: {desyncInfo.ReadBool()}");
text.AppendLine($"Mod version: {desyncInfo.ReadString()}");
text.AppendLine($"Mod is debug: {desyncInfo.ReadBool()}");
text.AppendLine($"Dev mode: {desyncInfo.ReadBool()}");
}
catch { }
}

return text.ToString();

void PrintSyncInfo(StringBuilder builder, ZipFile zip, string file)
{
builder.AppendLine($"[{file}]");

var sync = SyncInfo.Deserialize(new ByteReader(zip[file].GetBytes()));
builder.AppendLine($"Start: {sync.startTick}");
builder.AppendLine($"Map count: {sync.maps.Count}");
builder.AppendLine($"Last map state: {sync.maps.Select(m => $"{m.mapId}/{m.map.LastOrDefault()}/{m.map.Count}").ToStringSafeEnumerable()}");
builder.AppendLine($"Last world state: {sync.world.LastOrDefault()}/{sync.world.Count}");
builder.AppendLine($"Last cmd state: {sync.cmds.LastOrDefault()}/{sync.cmds.Count}");
builder.AppendLine($"Trace hashes: {sync.traceHashes.Count}");

builder.AppendLine();
}
}

private bool ButtonImage(Rect rect, Texture2D image, Color imageColor, Vector2? imageSize)
{
bool result = Widgets.ButtonText(rect, string.Empty, true, false, true);
Expand Down
21 changes: 21 additions & 0 deletions Source/Client/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,25 @@ private bool TrySave()
}
}

public class DebugTextWindow : Window
{
public override Vector2 InitialSize => new Vector2(600, 300);

private Vector2 scroll;
private string text;

public DebugTextWindow(string text)
{
absorbInputAroundWindow = true;
doCloseX = true;

this.text = text;
}

public override void DoWindowContents(Rect inRect)
{
Widgets.TextAreaScrollable(inRect, text, ref scroll);
}
}

}
4 changes: 2 additions & 2 deletions Source/Common/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
public static class MpVersion
{
public const string Version = "0.1.8";
public const int Protocol = 7;
public const string Version = "0.1.9";
public const int Protocol = 8;

#if DEBUG
public const bool IsDebug = true;
Expand Down

0 comments on commit bf9dbe9

Please sign in to comment.