Skip to content

Commit

Permalink
fix "archipelago" game not showing up in SlotData
Browse files Browse the repository at this point in the history
Add APPrintJsonType enum to printjson packets, instead of just passing a string.
defaults to Unknown for invalid/missing field.
  • Loading branch information
KonoTyran committed Jul 29, 2024
1 parent dc88ab0 commit 619dfcc
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.koifysh</groupId>
<artifactId>archipelago-client</artifactId>
<version>0.1.17</version>
<version>0.1.18</version>

<name>Archipelago Java Library</name>
<description>Library to connect to an Archipelago Server</description>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/koifysh/archipelago/Print/APPrint.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class APPrint {
public APPrintPart[] parts;

@SerializedName("type")
public String type;
public APPrintJsonType type;

@SerializedName("receiving")
public int receiving;
Expand Down
102 changes: 102 additions & 0 deletions src/main/java/dev/koifysh/archipelago/Print/APPrintJsonType.java
Original file line number Diff line number Diff line change
@@ -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

}
15 changes: 13 additions & 2 deletions src/main/java/dev/koifysh/archipelago/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -9,7 +10,7 @@
public class PrintJSONEvent implements Event {

public APPrint apPrint;
public String type;
public APPrintJsonType type;
public int player;
public NetworkItem item;

Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 619dfcc

Please sign in to comment.