Make packet charset configurable
Better support for different language clients such as Thai or Korean
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.packet;
|
||||
|
||||
import constants.string.CharsetConstants;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
|
||||
@@ -49,7 +50,7 @@ public class ByteBufInPacket implements InPacket {
|
||||
short length = readShort();
|
||||
byte[] stringBytes = new byte[length];
|
||||
byteBuf.readBytes(stringBytes);
|
||||
return new String(stringBytes, STRING_CHARSET);
|
||||
return new String(stringBytes, CharsetConstants.PACKET_CHARSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.packet;
|
||||
|
||||
import constants.string.CharsetConstants;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@@ -77,12 +78,12 @@ public class ByteBufOutPacket implements OutPacket {
|
||||
@Override
|
||||
public void writeString(String value) {
|
||||
writeShort((short) value.length());
|
||||
writeBytes(value.getBytes(STRING_CHARSET));
|
||||
writeBytes(value.getBytes(CharsetConstants.PACKET_CHARSET));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeFixedString(String value) {
|
||||
writeBytes(value.getBytes(STRING_CHARSET));
|
||||
writeBytes(value.getBytes(CharsetConstants.PACKET_CHARSET));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package net.packet;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public interface Packet {
|
||||
Charset STRING_CHARSET = StandardCharsets.US_ASCII;
|
||||
|
||||
byte[] getBytes();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user