Skip to content

Commit

Permalink
Merge pull request #215 from terryherbert/Fix-SubClientLoginSerialize…
Browse files Browse the repository at this point in the history
…r_v291

Update SubClientLoginSerializer_v291.java
  • Loading branch information
Alemiz112 authored Jan 29, 2024
2 parents 14da2b0 + 3207db4 commit d14e484
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.cloudburstmc.protocol.bedrock.packet.SubClientLoginPacket;
import org.cloudburstmc.protocol.common.util.VarInts;
import org.jose4j.json.internal.json_simple.JSONArray;
import org.jose4j.json.internal.json_simple.JSONObject;
import org.jose4j.json.internal.json_simple.JSONValue;
import org.jose4j.json.internal.json_simple.parser.ParseException;

Expand All @@ -25,7 +26,11 @@ public class SubClientLoginSerializer_v291 implements BedrockPacketSerializer<Su
public void serialize(ByteBuf buffer, BedrockCodecHelper helper, SubClientLoginPacket packet) {
JSONArray array = new JSONArray();
array.addAll(packet.getChain());
String chainData = array.toJSONString();

JSONObject json = new JSONObject();
json.put("chain", array);

String chainData = json.toJSONString();
int chainLength = ByteBufUtil.utf8Bytes(chainData);
String extraData = packet.getExtra();
int extraLength = ByteBufUtil.utf8Bytes(extraData);
Expand All @@ -43,9 +48,12 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SubClientLogi

try {
Object json = JSONValue.parseWithException(readString(jwt).toString());
checkArgument(json instanceof JSONArray, "Expected JSON array for login chain");
checkArgument(json instanceof JSONObject && ((JSONObject) json).containsKey("chain"), "Invalid login chain");

Object chain = ((JSONObject) json).get("chain");
checkArgument(chain instanceof JSONArray, "Expected JSON array for login chain");

for (Object node : (JSONArray) json) {
for (Object node : (JSONArray) chain) {
checkArgument(node instanceof String, "Expected String in login chain");
packet.getChain().add((String) node);
}
Expand Down

0 comments on commit d14e484

Please sign in to comment.