mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fixed issues with passwords containing unicode special characters.
The main fix is the change to ProtocolHandler's jsonEncode method. Previously, it used 'char.IsLetterOrDigit' to see if it needed to be escaped, but some chars, such as "Ð", count as a letter but still need to be escaped. The fix is to check if it's in the right range, rather than using that method. There's also some changes to those methods for performance and clarity reasons. Most of this is using a StringBuilder rather than appending to the string. Not too important, but it makes things clearer.
This commit is contained in:
parent
de4322458a
commit
295dfe717e
2 changed files with 14 additions and 14 deletions
|
|
@ -45,22 +45,18 @@ namespace MinecraftClient
|
||||||
|
|
||||||
public static string ReadPassword()
|
public static string ReadPassword()
|
||||||
{
|
{
|
||||||
string password = "";
|
StringBuilder password = new StringBuilder();
|
||||||
ConsoleKeyInfo k = new ConsoleKeyInfo();
|
|
||||||
while (k.Key != ConsoleKey.Enter)
|
ConsoleKeyInfo k;
|
||||||
|
while ((k = Console.ReadKey(true)).Key != ConsoleKey.Enter)
|
||||||
{
|
{
|
||||||
k = Console.ReadKey(true);
|
|
||||||
switch (k.Key)
|
switch (k.Key)
|
||||||
{
|
{
|
||||||
case ConsoleKey.Enter:
|
|
||||||
Console.Write('\n');
|
|
||||||
return password;
|
|
||||||
|
|
||||||
case ConsoleKey.Backspace:
|
case ConsoleKey.Backspace:
|
||||||
if (password.Length > 0)
|
if (password.Length > 0)
|
||||||
{
|
{
|
||||||
Console.Write("\b \b");
|
Console.Write("\b \b");
|
||||||
password = password.Substring(0, password.Length - 1);
|
password.Remove(password.Length - 1, 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -79,12 +75,14 @@ namespace MinecraftClient
|
||||||
if (k.KeyChar != 0)
|
if (k.KeyChar != 0)
|
||||||
{
|
{
|
||||||
Console.Write('*');
|
Console.Write('*');
|
||||||
password += k.KeyChar;
|
password.Append(k.KeyChar);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return password;
|
|
||||||
|
Console.WriteLine();
|
||||||
|
return password.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -285,16 +285,18 @@ namespace MinecraftClient.Protocol
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
foreach (char c in text)
|
foreach (char c in text)
|
||||||
{
|
{
|
||||||
if (char.IsLetterOrDigit(c))
|
if ((c >= '0' && c <= '9') ||
|
||||||
|
(c >= 'a' && c <= 'z') ||
|
||||||
|
(c >= 'A' && c <= 'Z'))
|
||||||
{
|
{
|
||||||
result.Append(c);
|
result.Append(c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.Append("\\u");
|
result.AppendFormat(@"\u{0:x4}", (int)c);
|
||||||
result.Append(((int)c).ToString("x4"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.ToString();
|
return result.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue