mirror of https://github.com/LOOHP/Limbo.git
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>Limbo</groupId>
|
<groupId>Limbo</groupId>
|
||||||
<artifactId>Limbo</artifactId>
|
<artifactId>Limbo</artifactId>
|
||||||
<version>0.3.1-ALPHA</version>
|
<version>0.3.2-ALPHA</version>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.loohp.limbo.Server.Packets;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import com.loohp.limbo.Utils.DataTypeIO;
|
import com.loohp.limbo.Utils.DataTypeIO;
|
||||||
|
|
||||||
|
|
@ -46,7 +47,7 @@ public class PacketHandshakingIn extends PacketIn {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketHandshakingIn(DataInputStream in) throws IOException {
|
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() {
|
public int getProtocolVersion() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.loohp.limbo.Server.Packets;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import com.loohp.limbo.Utils.DataTypeIO;
|
import com.loohp.limbo.Utils.DataTypeIO;
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@ public class PacketLoginInLoginStart extends PacketIn {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketLoginInLoginStart(DataInputStream in) throws IOException {
|
public PacketLoginInLoginStart(DataInputStream in) throws IOException {
|
||||||
this(DataTypeIO.readString(in));
|
this(DataTypeIO.readString(in, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ public class PacketLoginInPluginMessaging extends PacketIn {
|
||||||
|
|
||||||
public PacketLoginInPluginMessaging(DataInputStream in, int packetLength, int packetId) throws IOException {
|
public PacketLoginInPluginMessaging(DataInputStream in, int packetLength, int packetId) throws IOException {
|
||||||
messageId = DataTypeIO.readVarInt(in);
|
messageId = DataTypeIO.readVarInt(in);
|
||||||
String rawChannel = DataTypeIO.readString(in);
|
String rawChannel = DataTypeIO.readString(in, StandardCharsets.UTF_8);
|
||||||
channel = new NamespacedKey(rawChannel);
|
channel = new NamespacedKey(rawChannel);
|
||||||
int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getVarIntLength(messageId) - DataTypeIO.getStringLength(rawChannel, StandardCharsets.UTF_8);
|
int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getVarIntLength(messageId) - DataTypeIO.getStringLength(rawChannel, StandardCharsets.UTF_8);
|
||||||
data = new byte[dataLength];
|
data = new byte[dataLength];
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.loohp.limbo.Server.Packets;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import com.loohp.limbo.Utils.DataTypeIO;
|
import com.loohp.limbo.Utils.DataTypeIO;
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@ public class PacketPlayInChat extends PacketIn {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketPlayInChat(DataInputStream in) throws IOException {
|
public PacketPlayInChat(DataInputStream in) throws IOException {
|
||||||
this(DataTypeIO.readString(in));
|
this(DataTypeIO.readString(in, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ public class PacketPlayInPluginMessaging extends PacketIn {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketPlayInPluginMessaging(DataInputStream in, int packetLength, int packetId) throws IOException {
|
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);
|
channel = new NamespacedKey(rawChannel);
|
||||||
int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getStringLength(rawChannel, StandardCharsets.UTF_8);
|
int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getStringLength(rawChannel, StandardCharsets.UTF_8);
|
||||||
data = new byte[dataLength];
|
data = new byte[dataLength];
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.loohp.limbo.Server.Packets;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import com.loohp.limbo.Utils.DataTypeIO;
|
import com.loohp.limbo.Utils.DataTypeIO;
|
||||||
|
|
||||||
|
|
@ -16,7 +17,7 @@ public class PacketPlayInTabComplete extends PacketIn {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketPlayInTabComplete(DataInputStream in) throws IOException {
|
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() {
|
public int getId() {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ public class DataTypeIO {
|
||||||
out.write(b);
|
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);
|
int length = readVarInt(in);
|
||||||
|
|
||||||
if (length == -1) {
|
if (length == -1) {
|
||||||
|
|
@ -43,7 +43,7 @@ public class DataTypeIO {
|
||||||
|
|
||||||
byte[] b = new byte[length];
|
byte[] b = new byte[length];
|
||||||
in.readFully(b);
|
in.readFully(b);
|
||||||
return new String(b);
|
return new String(b, charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStringLength(String string, Charset charset) throws IOException {
|
public static int getStringLength(String string, Charset charset) throws IOException {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue