ClassiCube-Client
ClassiCube-Client copied to clipboard
Fix for characters >= 128.
When trying to render characters with values >= 128, the client crashes with (for example) 'IndexOutOfBoundsException: 65531'. This is (almost certainly) because Java is treating them as signed bytes and casting them to unsigned chars.
By changing NetHandler.readObject() from
return new String(stringBytes, "UTF-8").trim();
to
char[] chars = new char[64];
for (int i = 0; i < chars.length; i++) {
chars[i] = (char) (stringBytes[i] & 0xFF);
}
return new String(chars).trim();
I was able to fix the problem. (no changes were necessary for rendering)
The current protocol does not use characters above 128, but we've got plans to implement it as an extension, with a more useful charset (Win-1252 derivative, rather than CP437).
Fair enough. But this is more of a fix for reading all characters above 127, so it would still be useful for that future extension.
Don't worry, the whole font renderer and chat subsystem is to be rewritten cleanly.
Yes, a rewrite would definitely be nice.
Slightly off topic, but this should fix the issue of an emote at the end of a message being hidden. (it appears Java's string.trim() was the problem, as it trims all characters <= 32)
int length = 64;
for (int i = 63; i >= 0; i--) {
if (chars[i] == 0 || chars[i] == 32) {
length--;
} else {
length = i + 1;
break;
}
}
return new String(chars).substring(0, length);
Now that's definitely worth fixing for everyone. Thanks!