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.
This commit is contained in:
ORelio 2015-09-29 14:00:44 +02:00
parent fe68e881fb
commit 8560753949
5 changed files with 53 additions and 23 deletions

View file

@ -120,6 +120,9 @@ namespace MinecraftClient
{ {
if (handler.Login()) if (handler.Login())
{ {
if (!String.IsNullOrWhiteSpace(Settings.BrandInfo))
handler.SendBrandInfo(Settings.BrandInfo.Trim());
if (singlecommand) if (singlecommand)
{ {
handler.SendChatMessage(command); handler.SendChatMessage(command);

View file

@ -610,6 +610,11 @@ namespace MinecraftClient.Protocol.Handlers
catch (SocketException) { return false; } catch (SocketException) { return false; }
} }
public bool SendBrandInfo(string brandInfo)
{
return false; //Only supported since MC 1.7
}
public string AutoComplete(string BehindCursor) public string AutoComplete(string BehindCursor)
{ {
if (String.IsNullOrEmpty(BehindCursor)) if (String.IsNullOrEmpty(BehindCursor))

View file

@ -139,12 +139,6 @@ namespace MinecraftClient.Protocol.Handlers
case 0x00: //Keep-Alive case 0x00: //Keep-Alive
SendPacket(0x00, packetData); SendPacket(0x00, packetData);
break; break;
case 0x01: //Join game
if (Settings.SendBrandInfoEnabled.Equals(true))
{
SendBrandInfo();
}
break;
case 0x02: //Chat message case 0x02: //Chat message
handler.OnTextReceived(ChatParser.ParseText(readNextString(ref packetData))); handler.OnTextReceived(ChatParser.ParseText(readNextString(ref packetData)));
break; break;
@ -613,20 +607,6 @@ namespace MinecraftClient.Protocol.Handlers
} }
} }
/// <summary>
/// Sends information about the client version.
/// </summary>
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));
}
/// <summary> /// <summary>
/// Send a chat message to the server /// Send a chat message to the server
/// </summary> /// </summary>
@ -665,6 +645,29 @@ namespace MinecraftClient.Protocol.Handlers
catch (SocketException) { return false; } catch (SocketException) { return false; }
} }
/// <summary>
/// Tell the server what client is being used to connect to the server
/// </summary>
/// <param name="brandInfo">Client string describing the client</param>
/// <returns>True if brand info was successfully sent</returns>
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; }
}
/// <summary> /// <summary>
/// Disconnect from the server /// Disconnect from the server
/// </summary> /// </summary>

View file

@ -43,5 +43,13 @@ namespace MinecraftClient.Protocol
/// <returns>True if packet successfully sent</returns> /// <returns>True if packet successfully sent</returns>
bool SendRespawnPacket(); bool SendRespawnPacket();
/// <summary>
/// Tell the server what client is being used to connect to the server
/// </summary>
/// <param name="brandInfo">Client string describing the client</param>
/// <returns>True if brand info was successfully sent</returns>
bool SendBrandInfo(string brandInfo);
} }
} }

View file

@ -13,6 +13,9 @@ namespace MinecraftClient
public static class Settings public static class Settings
{ {
//Minecraft Console Client client information used for BrandInfo setting
private const string MCCBrandInfo = "Minecraft-Console-Client/" + Program.Version;
//Main Settings. //Main Settings.
//Login: Username or email adress used as login for Minecraft/Mojang account //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 //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 bool playerHeadAsIcon = false;
public static string chatbotLogFile = ""; public static string chatbotLogFile = "";
public static bool CacheScripts = true; public static bool CacheScripts = true;
public static bool SendBrandInfoEnabled = true; public static string BrandInfo = MCCBrandInfo;
//AntiAFK Settings //AntiAFK Settings
public static bool AntiAFK_Enabled = false; public static bool AntiAFK_Enabled = false;
@ -168,7 +171,6 @@ namespace MinecraftClient
case "mcversion": ServerVersion = argValue; break; case "mcversion": ServerVersion = argValue; break;
case "splitmessagedelay": splitMessageDelay = TimeSpan.FromSeconds(str2int(argValue)); break; case "splitmessagedelay": splitMessageDelay = TimeSpan.FromSeconds(str2int(argValue)); break;
case "scriptcache": CacheScripts = str2bool(argValue); break; case "scriptcache": CacheScripts = str2bool(argValue); break;
case "sendbrandinfo": SendBrandInfoEnabled = str2bool(argValue); break;
case "botowners": case "botowners":
Bots_Owners.Clear(); Bots_Owners.Clear();
@ -224,6 +226,15 @@ namespace MinecraftClient
ServerPort = server_port_temp; ServerPort = server_port_temp;
} }
break; break;
case "brandinfo":
switch (argValue.Trim().ToLower())
{
case "mcc": BrandInfo = MCCBrandInfo; break;
case "vanilla": BrandInfo = "vanilla"; break;
default: BrandInfo = null; break;
}
break;
} }
break; break;
@ -382,6 +393,7 @@ namespace MinecraftClient
+ "internalcmdchar=slash #use 'none', 'slash' or 'backslash'\r\n" + "internalcmdchar=slash #use 'none', 'slash' or 'backslash'\r\n"
+ "splitmessagedelay=2 #seconds between each part of a long message\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" + "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" + "chatbotlogfile= #leave empty for no logfile\r\n"
+ "accountlist=accounts.txt\r\n" + "accountlist=accounts.txt\r\n"
+ "serverlist=servers.txt\r\n" + "serverlist=servers.txt\r\n"
@ -389,7 +401,6 @@ namespace MinecraftClient
+ "exitonfailure=false\r\n" + "exitonfailure=false\r\n"
+ "scriptcache=true\r\n" + "scriptcache=true\r\n"
+ "timestamps=false\r\n" + "timestamps=false\r\n"
+ "sendbrandinfo=true\r\n"
+ "\r\n" + "\r\n"
+ "[AppVars]\r\n" + "[AppVars]\r\n"
+ "#yourvar=yourvalue\r\n" + "#yourvar=yourvalue\r\n"