Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Fix for characters >= 128. #283

Open
UnknownShadow200 opened this issue Aug 30, 2014 · 5 comments
Open

Fix for characters >= 128. #283

UnknownShadow200 opened this issue Aug 30, 2014 · 5 comments

Comments

@UnknownShadow200
Copy link
Contributor

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)

@mstefarov
Copy link
Collaborator

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).

@UnknownShadow200
Copy link
Contributor Author

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.

@mstefarov
Copy link
Collaborator

Don't worry, the whole font renderer and chat subsystem is to be rewritten cleanly.

@UnknownShadow200
Copy link
Contributor Author

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);

@mstefarov
Copy link
Collaborator

Now that's definitely worth fixing for everyone. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants