Skip to content

Commit

Permalink
more general fix for GameNetworkException being unexpectedly thrown &…
Browse files Browse the repository at this point in the history
… stopping scripts
  • Loading branch information
Hubcapp committed Apr 24, 2024
1 parent 64a1d2c commit c4249cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
7 changes: 1 addition & 6 deletions server/src/com/openrsc/server/model/entity/npc/Npc.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,7 @@ public void killedBy(Mob mob) {
logNpcKill(owner);
}

try {
ActionSender.sendNpcKills(owner);
} catch (Exception e) {
LOGGER.error("Error sending NPC kills for {}: ", owner.getUsername());
LOGGER.catching(e);
}
ActionSender.sendNpcKills(owner);

/** Item Drops **/
dropItems(owner);
Expand Down
32 changes: 24 additions & 8 deletions server/src/com/openrsc/server/net/rsc/ActionSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ public static void tryFinalizeAndSendPacket(OpcodeOut opcode, AbstractStruct<Opc
if (p != null)
player.write(p);
} catch (GameNetworkException gne) {
throw new GameNetworkException(gne);
// do nothing, the player just doesn't get the packet (possibly logged out) & script this is called from can continue
String username, clientVersion;
if (player != null) {
username = player.getUsername();
clientVersion = String.format("%d", player.getClientVersion());
} else {
username = "<null>";
clientVersion = "<unknown>";
}
LOGGER.warn("GameNetworkException for player " + username + " with client version " + clientVersion + " on opcode " + opcode.name());
}
}

Expand Down Expand Up @@ -1636,6 +1645,9 @@ public static void sendSecondTradeScreen(Player player) {
return;
}

boolean bothPlayersSupportAllItems = true;
int unhandledItemId = 0;

TradeConfirmStruct struct = new TradeConfirmStruct();
struct.targetPlayer = with.getUsername();

Expand All @@ -1644,7 +1656,7 @@ public static void sendSecondTradeScreen(Player player) {
struct.opponentTradeCount = tradedSize;
struct.opponentCatalogIDs = new int[tradedSize];
struct.opponentAmounts = new int[tradedSize];
if (player.getConfig().WANT_BANK_NOTES) {
if (player.getConfig().WANT_BANK_NOTES && player.isUsingCustomClient()) {
struct.opponentNoted = new int[tradedSize];
}
i = 0;
Expand Down Expand Up @@ -1672,19 +1684,23 @@ public static void sendSecondTradeScreen(Player player) {
i = 0;
for (Item item : player.getTrade().getTradeOffer().getItems()) {
struct.myCatalogIDs[i] = item.getCatalogId();
if (item.getCatalogId() > player.getClientLimitations().maxItemId || item.getCatalogId() > with.getClientLimitations().maxItemId) {
bothPlayersSupportAllItems = false;
unhandledItemId = item.getCatalogId();
break;
}
if (struct.myNoted != null) {
struct.myNoted[i] = item.getNoted() ? 1 : 0;
}
struct.myAmounts[i] = item.getAmount();
i++;
}

try {
if (bothPlayersSupportAllItems) {
tryFinalizeAndSendPacket(OpcodeOut.SEND_TRADE_OPEN_CONFIRM, struct, player);
} catch (GameNetworkException gne) {
// an unsupported catalog id was received for authentic client
sendMessage(player, String.format("Cannot handle inauthentic item ID %s", gne.getExposedDetail()));
sendMessage(with, String.format("Other player cannot handle inauthentic item ID %s", gne.getExposedDetail()));
} else {
// an unsupported catalog id was received by an outdated or authentic client
sendMessage(player, String.format("At least one player cannot handle item ID %s", unhandledItemId));
sendMessage(with, String.format("At least one player cannot handle item ID %s", unhandledItemId));
player.getTrade().setTradeActive(false);
with.getTrade().setTradeActive(false);
sendTradeWindowClose(player);
Expand Down

0 comments on commit c4249cb

Please sign in to comment.