forked from BLOCKFANTASY/LOOHP-Limbo
Fixed string reading not using UTF-8
This commit is contained in:
parent
148a9423c9
commit
10789c3c60
2
pom.xml
2
pom.xml
|
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>Limbo</groupId>
|
||||
<artifactId>Limbo</artifactId>
|
||||
<version>0.3.1-ALPHA</version>
|
||||
<version>0.3.2-ALPHA</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.loohp.limbo.Server.Packets;
|
|||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import com.loohp.limbo.Utils.DataTypeIO;
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ public class PacketHandshakingIn extends PacketIn {
|
|||
}
|
||||
|
||||
public PacketHandshakingIn(DataInputStream in) throws IOException {
|
||||
this(DataTypeIO.readVarInt(in), DataTypeIO.readString(in), in.readShort() & 0xFFFF, HandshakeType.fromNetworkId(DataTypeIO.readVarInt(in)));
|
||||
this(DataTypeIO.readVarInt(in), DataTypeIO.readString(in, StandardCharsets.UTF_8), in.readShort() & 0xFFFF, HandshakeType.fromNetworkId(DataTypeIO.readVarInt(in)));
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.loohp.limbo.Server.Packets;
|
|||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import com.loohp.limbo.Utils.DataTypeIO;
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ public class PacketLoginInLoginStart extends PacketIn {
|
|||
}
|
||||
|
||||
public PacketLoginInLoginStart(DataInputStream in) throws IOException {
|
||||
this(DataTypeIO.readString(in));
|
||||
this(DataTypeIO.readString(in, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class PacketLoginInPluginMessaging extends PacketIn {
|
|||
|
||||
public PacketLoginInPluginMessaging(DataInputStream in, int packetLength, int packetId) throws IOException {
|
||||
messageId = DataTypeIO.readVarInt(in);
|
||||
String rawChannel = DataTypeIO.readString(in);
|
||||
String rawChannel = DataTypeIO.readString(in, StandardCharsets.UTF_8);
|
||||
channel = new NamespacedKey(rawChannel);
|
||||
int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getVarIntLength(messageId) - DataTypeIO.getStringLength(rawChannel, StandardCharsets.UTF_8);
|
||||
data = new byte[dataLength];
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.loohp.limbo.Server.Packets;
|
|||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import com.loohp.limbo.Utils.DataTypeIO;
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ public class PacketPlayInChat extends PacketIn {
|
|||
}
|
||||
|
||||
public PacketPlayInChat(DataInputStream in) throws IOException {
|
||||
this(DataTypeIO.readString(in));
|
||||
this(DataTypeIO.readString(in, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class PacketPlayInPluginMessaging extends PacketIn {
|
|||
}
|
||||
|
||||
public PacketPlayInPluginMessaging(DataInputStream in, int packetLength, int packetId) throws IOException {
|
||||
String rawChannel = DataTypeIO.readString(in);
|
||||
String rawChannel = DataTypeIO.readString(in, StandardCharsets.UTF_8);
|
||||
channel = new NamespacedKey(rawChannel);
|
||||
int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getStringLength(rawChannel, StandardCharsets.UTF_8);
|
||||
data = new byte[dataLength];
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.loohp.limbo.Server.Packets;
|
|||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import com.loohp.limbo.Utils.DataTypeIO;
|
||||
|
||||
|
|
@ -16,7 +17,7 @@ public class PacketPlayInTabComplete extends PacketIn {
|
|||
}
|
||||
|
||||
public PacketPlayInTabComplete(DataInputStream in) throws IOException {
|
||||
this(DataTypeIO.readVarInt(in), DataTypeIO.readString(in));
|
||||
this(DataTypeIO.readVarInt(in), DataTypeIO.readString(in, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class DataTypeIO {
|
|||
out.write(b);
|
||||
}
|
||||
|
||||
public static String readString(DataInputStream in) throws IOException {
|
||||
public static String readString(DataInputStream in, Charset charset) throws IOException {
|
||||
int length = readVarInt(in);
|
||||
|
||||
if (length == -1) {
|
||||
|
|
@ -43,7 +43,7 @@ public class DataTypeIO {
|
|||
|
||||
byte[] b = new byte[length];
|
||||
in.readFully(b);
|
||||
return new String(b);
|
||||
return new String(b, charset);
|
||||
}
|
||||
|
||||
public static int getStringLength(String string, Charset charset) throws IOException {
|
||||
|
|
|
|||
Loading…
Reference in New Issue