From 619dfccb20c3d6c97c4bf0c17776bbd5372945ed Mon Sep 17 00:00:00 2001 From: Kono Tyran Date: Mon, 29 Jul 2024 15:14:23 -0700 Subject: [PATCH] fix "archipelago" game not showing up in SlotData Add APPrintJsonType enum to printjson packets, instead of just passing a string. defaults to Unknown for invalid/missing field. --- pom.xml | 2 +- .../koifysh/archipelago/Print/APPrint.java | 2 +- .../archipelago/Print/APPrintJsonType.java | 102 ++++++++++++++++++ .../dev/koifysh/archipelago/WebSocket.java | 15 ++- .../archipelago/events/PrintJSONEvent.java | 5 +- .../archipelago/parts/NetworkSlot.java | 6 ++ 6 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 src/main/java/dev/koifysh/archipelago/Print/APPrintJsonType.java diff --git a/pom.xml b/pom.xml index 89832f4..e2c5be2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.koifysh archipelago-client - 0.1.17 + 0.1.18 Archipelago Java Library Library to connect to an Archipelago Server diff --git a/src/main/java/dev/koifysh/archipelago/Print/APPrint.java b/src/main/java/dev/koifysh/archipelago/Print/APPrint.java index 822a508..9462b11 100644 --- a/src/main/java/dev/koifysh/archipelago/Print/APPrint.java +++ b/src/main/java/dev/koifysh/archipelago/Print/APPrint.java @@ -9,7 +9,7 @@ public class APPrint { public APPrintPart[] parts; @SerializedName("type") - public String type; + public APPrintJsonType type; @SerializedName("receiving") public int receiving; diff --git a/src/main/java/dev/koifysh/archipelago/Print/APPrintJsonType.java b/src/main/java/dev/koifysh/archipelago/Print/APPrintJsonType.java new file mode 100644 index 0000000..ce1458c --- /dev/null +++ b/src/main/java/dev/koifysh/archipelago/Print/APPrintJsonType.java @@ -0,0 +1,102 @@ +package dev.koifysh.archipelago.Print; + +import com.google.gson.annotations.SerializedName; + +public enum APPrintJsonType { + + /** + * A player received an item. + */ + @SerializedName("ItemSend") + ItemSend, + + /** + * A player used the `!getitem` command. + */ + @SerializedName("ItemCheat") + ItemCheat, + + /** + * A player hinted. + */ + @SerializedName("Hint") + Hint, + + /** + * A player connected. + */ + @SerializedName("Join") + Join, + + /** + * A player disconnected. + */ + @SerializedName("Part") + Part, + + /** + * A player sent a chat message. + */ + @SerializedName("Chat") + Chat, + + /** + * The server broadcast a message. + */ + @SerializedName("ServerChat") + ServerChat, + + /** + * The client has triggered a tutorial message, such as when first connecting. + */ + @SerializedName("entrance_name") + Tutorial, + + /** + * A player changed their tags. + */ + @SerializedName("TagsChanged") + TagsChanged, + + /** + * Someone (usually the client) entered an ! command. + */ + @SerializedName("CommandResult") + CommandResult, + + /** + * The client entered an !admin command. + */ + @SerializedName("AdminCommandResult") + AdminCommandResult, + + /** + * A player reached their goal. + */ + @SerializedName("Goal") + Goal, + + /** + * A player released the remaining items in their world. + */ + @SerializedName("Release") + Release, + + /** + * A player collected the remaining items for their world. + */ + @SerializedName("Collect") + Collect, + + /** + * The current server countdown has progressed. + */ + @SerializedName("Countdown") + Countdown, + + /** + * The Message type was not set, or is invalid. + */ + Unknown + +} diff --git a/src/main/java/dev/koifysh/archipelago/WebSocket.java b/src/main/java/dev/koifysh/archipelago/WebSocket.java index 5b4d45f..a66c191 100644 --- a/src/main/java/dev/koifysh/archipelago/WebSocket.java +++ b/src/main/java/dev/koifysh/archipelago/WebSocket.java @@ -5,6 +5,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParser; import dev.koifysh.archipelago.Print.APPrint; +import dev.koifysh.archipelago.Print.APPrintJsonType; import dev.koifysh.archipelago.Print.APPrintPart; import dev.koifysh.archipelago.Print.APPrintType; import dev.koifysh.archipelago.helper.DeathLink; @@ -20,6 +21,7 @@ import dev.koifysh.archipelago.events.*; import dev.koifysh.archipelago.network.server.*; +import dev.koifysh.archipelago.parts.NetworkSlot; import org.apache.hc.core5.net.URIBuilder; import org.java_websocket.client.WebSocketClient; import org.java_websocket.handshake.ServerHandshake; @@ -103,10 +105,19 @@ public void onMessage(String message) { client.setTeam(connectedPacket.team); client.setSlot(connectedPacket.slot); + connectedPacket.slotInfo.put(0, new NetworkSlot("Archipelago", "Archipelago", NetworkSlot.flags.SPECTATOR)); client.setSlotInfo(connectedPacket.slotInfo); client.getRoomInfo().networkPlayers.addAll(connectedPacket.players); - client.getRoomInfo().networkPlayers.add(new NetworkPlayer(connectedPacket.team, 0, "Archipelago")); + int teams = 1; + OptionalInt teamsOptional = client.getRoomInfo().networkPlayers.stream().mapToInt(player -> player.team).max(); + if (teamsOptional.isPresent()) { + teams = teamsOptional.getAsInt() + 1; + } + for (int i = 0; i < teams; i++) { + client.getRoomInfo().networkPlayers.add( new NetworkPlayer(i, 0, "Archipelago")); + } + client.setAlias(client.getRoomInfo().getPlayer(connectedPacket.team, connectedPacket.slot).alias); JsonElement slotData = packet.getAsJsonObject().get("slot_data"); @@ -143,6 +154,7 @@ public void onMessage(String message) { case PrintJSON: LOGGER.finest("PrintJSON packet"); APPrint print = gson.fromJson(packet, APPrint.class); + if (print.type == null) print.type = APPrintJsonType.Unknown; //filter though all player IDs and replace id with alias. for (int partNumber = 0; print.parts.length > partNumber; ++partNumber) { APPrintPart part = print.parts[partNumber]; @@ -214,7 +226,6 @@ else if (part.type == APPrintType.locationID) { private void updateRoom(RoomUpdatePacket updateRoomPacket) { if (!updateRoomPacket.networkPlayers.isEmpty()) { client.getRoomInfo().networkPlayers = updateRoomPacket.networkPlayers; - client.getRoomInfo().networkPlayers.add(new NetworkPlayer(client.getTeam(), 0, "Archipelago")); } client.setHintPoints(updateRoomPacket.hintPoints); diff --git a/src/main/java/dev/koifysh/archipelago/events/PrintJSONEvent.java b/src/main/java/dev/koifysh/archipelago/events/PrintJSONEvent.java index 01f639d..3ecf040 100644 --- a/src/main/java/dev/koifysh/archipelago/events/PrintJSONEvent.java +++ b/src/main/java/dev/koifysh/archipelago/events/PrintJSONEvent.java @@ -1,6 +1,7 @@ package dev.koifysh.archipelago.events; import dev.koifysh.archipelago.Print.APPrint; +import dev.koifysh.archipelago.Print.APPrintJsonType; import dev.koifysh.archipelago.parts.NetworkItem; /** @@ -9,7 +10,7 @@ public class PrintJSONEvent implements Event { public APPrint apPrint; - public String type; + public APPrintJsonType type; public int player; public NetworkItem item; @@ -19,7 +20,7 @@ public class PrintJSONEvent implements Event { * @param player int id of the sending player. * @param item the network item that is involved with the message. */ - public PrintJSONEvent(APPrint apPrint, String type, int player, NetworkItem item) { + public PrintJSONEvent(APPrint apPrint, APPrintJsonType type, int player, NetworkItem item) { this.apPrint = apPrint; this.type = type; this.player = player; diff --git a/src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java b/src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java index bd494f4..813d210 100644 --- a/src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java +++ b/src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java @@ -38,4 +38,10 @@ public static class flags { public final static int GROUP = 0b100; } + + public NetworkSlot(String name, String game, int type) { + this.name = name; + this.game = game; + this.type = type; + } }