From eb94e5f3334d5bce01c0a8bf15aa4768a5cd8983 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 3 Aug 2017 23:06:48 +1000 Subject: [PATCH] Instead of '>'/'<' for partial messages, use ' >'/' <'. Also support fCraft's ' /'/' \' partial messages. Fixes #399. --- MCGalaxy/Network/Socket/Interfaces.cs | 2 +- MCGalaxy/Player/Player.Handlers.cs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/MCGalaxy/Network/Socket/Interfaces.cs b/MCGalaxy/Network/Socket/Interfaces.cs index 9ef183eaa..0f42c7244 100644 --- a/MCGalaxy/Network/Socket/Interfaces.cs +++ b/MCGalaxy/Network/Socket/Interfaces.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Network { void ReceiveNextAsync(); /// Sends a block of data, either synchronously or asynchronously. - void Send(byte[] buffer, bool sync = false); + void Send(byte[] buffer, bool sync); /// Sends a block of low-priority data, either synchronously or asynchronously. void SendLowPriority(byte[] buffer); diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index e2f685d30..b50bcfc96 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -189,7 +189,7 @@ namespace MCGalaxy { int processedLen = 0; try { while (processedLen < bufferLen) { - int packetLen = PacketSize(buffer[processedLen]); + int packetLen = PacketSize(buffer[processedLen]); if (packetLen == -1) return -1; // Partial packet data received @@ -499,17 +499,17 @@ namespace MCGalaxy { text = text.Replace("^detail.user=", ""); } - if (partialMessage.Length > 0 && !text.EndsWith(">") && !text.EndsWith("<")) { + if (partialMessage.Length > 0 && !(IsPartialSpaced(text) || IsPartialJoined(text))) { text = partialMessage + text; partialMessage = ""; } - if (text.EndsWith(">")) { - partialMessage += text.Substring(0, text.Length - 1) + " "; + if (IsPartialSpaced(text)) { + partialMessage += text.Substring(0, text.Length - 2) + " "; SendMessage(Colors.teal + "Partial message: &f" + partialMessage); return true; - } else if (text.EndsWith("<")) { - partialMessage += text.Substring(0, text.Length - 1); + } else if (IsPartialJoined(text)) { + partialMessage += text.Substring(0, text.Length - 2); SendMessage(Colors.teal + "Partial message: &f" + partialMessage); return true; } @@ -522,6 +522,14 @@ namespace MCGalaxy { return text.Length == 0; } + static bool IsPartialSpaced(string text) { + return text.EndsWith(" >") || text.EndsWith(" /"); + } + + static bool IsPartialJoined(string text) { + return text.EndsWith(" <") || text.EndsWith(" \\"); + } + bool DoCommand(string text) { // Typing / repeats last command executed if (text == "/") {