diff --git a/ts3-client/core/src/main/java/com/ts3client/myts/MyTeamSpeak.java b/ts3-client/core/src/main/java/com/ts3client/myts/MyTeamSpeak.java index e4ef9af..d435aae 100644 --- a/ts3-client/core/src/main/java/com/ts3client/myts/MyTeamSpeak.java +++ b/ts3-client/core/src/main/java/com/ts3client/myts/MyTeamSpeak.java @@ -184,25 +184,41 @@ public final class MyTeamSpeak { return items; } - /** The encrypted items of one {@code Sync_ItemClasses_Data}; tombstones carry none. */ + /** + * The encrypted items of one {@code Sync_ItemClasses_Data}; tombstones carry none. + * The server answers with every class the account holds, whatever was asked for, + * and not all of them are encrypted (add-on flags come in the clear), so only the + * wanted classes are kept. + */ private static void collectFrames(ProtobufReader itemClass, List frames) throws IOException { + int classId = 0; + List blobs = new ArrayList<>(); while (itemClass.next()) { - if (itemClass.fieldNumber() != 3) { - itemClass.skip(); - continue; - } - ProtobufReader detail = itemClass.readMessage(); - byte[] blob = null; - boolean deleted = false; - while (detail.next()) { - switch (detail.fieldNumber()) { - case 3 -> blob = detail.readBytes(); - case 4 -> deleted = detail.readBool(); - default -> detail.skip(); + switch (itemClass.fieldNumber()) { + case 1 -> classId = (int) itemClass.readVarint(); + case 3 -> { + byte[] blob = itemBlob(itemClass.readMessage()); + if (blob != null) blobs.add(blob); } + default -> itemClass.skip(); } - if (!deleted && blob != null && blob.length > 0) frames.add(blob); } + for (int wanted : ITEM_CLASSES) { + if (wanted == classId) frames.addAll(blobs); + } + } + + private static byte[] itemBlob(ProtobufReader detail) throws IOException { + byte[] blob = null; + boolean deleted = false; + while (detail.next()) { + switch (detail.fieldNumber()) { + case 3 -> blob = detail.readBytes(); + case 4 -> deleted = detail.readBool(); + default -> detail.skip(); + } + } + return !deleted && blob != null && blob.length > 0 ? blob : null; } /** Ends the session rather than leave it for the server to expire; nothing to do if that fails. */ diff --git a/ts3-client/core/src/test/java/com/ts3client/myts/MyTeamSpeakTest.java b/ts3-client/core/src/test/java/com/ts3client/myts/MyTeamSpeakTest.java index 901c29e..93ba3a1 100644 --- a/ts3-client/core/src/test/java/com/ts3client/myts/MyTeamSpeakTest.java +++ b/ts3-client/core/src/test/java/com/ts3client/myts/MyTeamSpeakTest.java @@ -68,10 +68,16 @@ class MyTeamSpeakTest { .string(2, "5d831e3c-d5aa-0e66-7af2-a0feb13af048") .bytes(3, MyTsCryptoTest.itemFrame()); ProtobufWriter tombstone = new ProtobufWriter().string(1, "gone").varint(4, 1); + // Sent though not asked for, and in the clear. + ProtobufWriter addOn = new ProtobufWriter() + .string(1, "38aa56e2-55ae-b37a-a7db-7a11832a9812") + .bytes(3, new ProtobufWriter().string(2, "38aa56e2-55ae-b37a-a7db-7a11832a9812") + .varint(6, 4).toByteArray()); return new ProtobufWriter() .varint(1, 301) .message(2, new ProtobufWriter().varint(1, 0).string(2, "v").message(3, bookmark).message(3, tombstone)) .message(2, new ProtobufWriter().varint(1, 1).varint(4, 1)) + .message(2, new ProtobufWriter().varint(1, 4).string(2, "v").message(3, addOn)) .string(3, "g") .toByteArray(); } catch (java.security.GeneralSecurityException e) {