From 856075394967bc626642c39cf7c5a5ac1ebf20a9 Mon Sep 17 00:00:00 2001 From: ORelio Date: Tue, 29 Sep 2015 14:00:44 +0200 Subject: [PATCH] Extend BrandInfo setting Brand Information tells the server what client is being used to connect to the server, possible values are the following: - none (do not tell anything) - vanilla (tells that you are using MC vanilla) - mcc (tell that you are using MCC + version) This will usually not do anything unless plugins developers use this information for developing some MCC interoperability eg more chat interactions instead of using GUIs. This could also be used to block third party clients, that's why brand information can be disabled or changed to vanilla. --- MinecraftClient/McTcpClient.cs | 3 ++ .../Protocol/Handlers/Protocol16.cs | 5 +++ .../Protocol/Handlers/Protocol18.cs | 43 ++++++++++--------- MinecraftClient/Protocol/IMinecraftCom.cs | 8 ++++ MinecraftClient/Settings.cs | 17 ++++++-- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 0817755c..ccb04f71 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -120,6 +120,9 @@ namespace MinecraftClient { if (handler.Login()) { + if (!String.IsNullOrWhiteSpace(Settings.BrandInfo)) + handler.SendBrandInfo(Settings.BrandInfo.Trim()); + if (singlecommand) { handler.SendChatMessage(command); diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index cf648fc8..1813b9af 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -610,6 +610,11 @@ namespace MinecraftClient.Protocol.Handlers catch (SocketException) { return false; } } + public bool SendBrandInfo(string brandInfo) + { + return false; //Only supported since MC 1.7 + } + public string AutoComplete(string BehindCursor) { if (String.IsNullOrEmpty(BehindCursor)) diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 26054daf..92512110 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -139,12 +139,6 @@ namespace MinecraftClient.Protocol.Handlers case 0x00: //Keep-Alive SendPacket(0x00, packetData); break; - case 0x01: //Join game - if (Settings.SendBrandInfoEnabled.Equals(true)) - { - SendBrandInfo(); - } - break; case 0x02: //Chat message handler.OnTextReceived(ChatParser.ParseText(readNextString(ref packetData))); break; @@ -613,20 +607,6 @@ namespace MinecraftClient.Protocol.Handlers } } - /// - /// Sends information about the client version. - /// - - private void SendBrandInfo() - { - byte[] channel = Encoding.UTF8.GetBytes("MC|Brand"); - byte[] channelLen = getVarInt(channel.Length); - byte[] brand = Encoding.UTF8.GetBytes("Minecraft Console Client v" + Program.Version); - byte[] brandLen = getVarInt(brand.Length); - - SendPacket(0x17, concatBytes(channelLen, channel, brandLen, brand)); - } - /// /// Send a chat message to the server /// @@ -665,6 +645,29 @@ namespace MinecraftClient.Protocol.Handlers catch (SocketException) { return false; } } + /// + /// Tell the server what client is being used to connect to the server + /// + /// Client string describing the client + /// True if brand info was successfully sent + + public bool SendBrandInfo(string brandInfo) + { + if (String.IsNullOrEmpty(brandInfo)) + return false; + try + { + byte[] channel = Encoding.UTF8.GetBytes("MC|Brand"); + byte[] channelLen = getVarInt(channel.Length); + byte[] brand = Encoding.UTF8.GetBytes(brandInfo); + byte[] brandLen = getVarInt(brand.Length); + SendPacket(0x17, concatBytes(channelLen, channel, brandLen, brand)); + return true; + } + catch (SocketException) { return false; } + catch (System.IO.IOException) { return false; } + } + /// /// Disconnect from the server /// diff --git a/MinecraftClient/Protocol/IMinecraftCom.cs b/MinecraftClient/Protocol/IMinecraftCom.cs index 2ae82c14..9c351ebc 100644 --- a/MinecraftClient/Protocol/IMinecraftCom.cs +++ b/MinecraftClient/Protocol/IMinecraftCom.cs @@ -43,5 +43,13 @@ namespace MinecraftClient.Protocol /// True if packet successfully sent bool SendRespawnPacket(); + + /// + /// Tell the server what client is being used to connect to the server + /// + /// Client string describing the client + /// True if brand info was successfully sent + + bool SendBrandInfo(string brandInfo); } } diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 93beb6a8..7a4a4cb5 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -13,6 +13,9 @@ namespace MinecraftClient public static class Settings { + //Minecraft Console Client client information used for BrandInfo setting + private const string MCCBrandInfo = "Minecraft-Console-Client/" + Program.Version; + //Main Settings. //Login: Username or email adress used as login for Minecraft/Mojang account //Username: The actual username of the user, obtained after login to the account @@ -46,7 +49,7 @@ namespace MinecraftClient public static bool playerHeadAsIcon = false; public static string chatbotLogFile = ""; public static bool CacheScripts = true; - public static bool SendBrandInfoEnabled = true; + public static string BrandInfo = MCCBrandInfo; //AntiAFK Settings public static bool AntiAFK_Enabled = false; @@ -168,7 +171,6 @@ namespace MinecraftClient case "mcversion": ServerVersion = argValue; break; case "splitmessagedelay": splitMessageDelay = TimeSpan.FromSeconds(str2int(argValue)); break; case "scriptcache": CacheScripts = str2bool(argValue); break; - case "sendbrandinfo": SendBrandInfoEnabled = str2bool(argValue); break; case "botowners": Bots_Owners.Clear(); @@ -224,6 +226,15 @@ namespace MinecraftClient ServerPort = server_port_temp; } break; + + case "brandinfo": + switch (argValue.Trim().ToLower()) + { + case "mcc": BrandInfo = MCCBrandInfo; break; + case "vanilla": BrandInfo = "vanilla"; break; + default: BrandInfo = null; break; + } + break; } break; @@ -382,6 +393,7 @@ namespace MinecraftClient + "internalcmdchar=slash #use 'none', 'slash' or 'backslash'\r\n" + "splitmessagedelay=2 #seconds between each part of a long message\r\n" + "mcversion=auto #use 'auto' or '1.X.X' values\r\n" + + "brandinfo=mcc #use 'mcc','vanilla', or 'none'\r\n" + "chatbotlogfile= #leave empty for no logfile\r\n" + "accountlist=accounts.txt\r\n" + "serverlist=servers.txt\r\n" @@ -389,7 +401,6 @@ namespace MinecraftClient + "exitonfailure=false\r\n" + "scriptcache=true\r\n" + "timestamps=false\r\n" - + "sendbrandinfo=true\r\n" + "\r\n" + "[AppVars]\r\n" + "#yourvar=yourvalue\r\n"