From 1cecf2d7882bc2b8c8a94c930e27db863408b5a5 Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 23 May 2018 19:07:31 +0200 Subject: [PATCH] Improve debug output for HTTPS requests For diagnosing session errors in #450 and #451 --- MinecraftClient/ChatBots/ScriptScheduler.cs | 2 +- MinecraftClient/Protocol/ProtocolHandler.cs | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/MinecraftClient/ChatBots/ScriptScheduler.cs b/MinecraftClient/ChatBots/ScriptScheduler.cs index 7fc5d41f..30d52ca5 100644 --- a/MinecraftClient/ChatBots/ScriptScheduler.cs +++ b/MinecraftClient/ChatBots/ScriptScheduler.cs @@ -189,7 +189,7 @@ namespace MinecraftClient.ChatBots private static string Task2String(TaskDesc task) { return String.Format( - "triggeronfirstlogin = {0}\n triggeronlogin = {1}\n triggerontime = {2}\n " + " triggeronfirstlogin = {0}\n triggeronlogin = {1}\n triggerontime = {2}\n " + "triggeroninterval = {3}\n timevalue = {4}\n timeinterval = {5}\n script = {6}", task.triggerOnFirstLogin, task.triggerOnLogin, diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs index 6e3ea218..dae126e3 100644 --- a/MinecraftClient/Protocol/ProtocolHandler.cs +++ b/MinecraftClient/Protocol/ProtocolHandler.cs @@ -223,13 +223,8 @@ namespace MinecraftClient.Protocol try { string result = ""; - string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + JsonEncode(user) + "\", \"password\": \"" + JsonEncode(pass) + "\", \"clientToken\": \"" + JsonEncode(session.ClientID) + "\" }"; - if (Settings.DebugMessages) - ConsoleIO.WriteLineFormatted("§8Debug: Login Request: " + json_request); int code = DoHTTPSPost("authserver.mojang.com", "/authenticate", json_request, ref result); - if (Settings.DebugMessages) - ConsoleIO.WriteLineFormatted("§8Debug: Login Response: " + result); if (code == 200) { if (result.Contains("availableProfiles\":[]}")) @@ -456,12 +451,28 @@ namespace MinecraftClient.Protocol { try { + if (Settings.DebugMessages) + ConsoleIO.WriteLineFormatted("§8Performing request to " + host); + TcpClient client = ProxyHandler.newTcpClient(host, 443, true); SslStream stream = new SslStream(client.GetStream()); stream.AuthenticateAsClient(host); + + if (Settings.DebugMessages) + foreach (string line in headers) + ConsoleIO.WriteLineFormatted("§8> " + line); + stream.Write(Encoding.ASCII.GetBytes(String.Join("\r\n", headers.ToArray()))); System.IO.StreamReader sr = new System.IO.StreamReader(stream); string raw_result = sr.ReadToEnd(); + + if (Settings.DebugMessages) + { + ConsoleIO.WriteLine(""); + foreach (string line in raw_result.Split('\n')) + ConsoleIO.WriteLineFormatted("§8< " + line); + } + if (raw_result.StartsWith("HTTP/1.1")) { postResult = raw_result.Substring(raw_result.IndexOf("\r\n\r\n") + 4);