From 25f7e1321aa3a7a715e4119cf4b21ae651577b03 Mon Sep 17 00:00:00 2001 From: games647 Date: Fri, 18 Jun 2021 14:55:21 +0200 Subject: [PATCH] Check inventory authentication status only on cache Fixes #2212 In #2112, we found out that in configurations with disabled cache (like Bungee), this adapter will perform blocking queries on the main thread which impacts the performance. The original code (81cf14fbc16aaecf7ac72dfea9a8acbff21f4f6d) is in place to preserve the inventory for unregistered and configurations without enforcing a registration (#1830, #1752). Alternatives are: 1. Send the inventory on registration like p.updateInventory() * Still hides it before for unregistered 2. Checking for the enforce registration setting would mean it hides also the inventory for unregistered players 3. Get a notification on player status changes * Requires a complex setup to propagate the changes across spigot servers or different solution for web interfaces * Refresh events, when the status is updated within the plugin itself would be possible, however requires previous queries like registration/login requests. Instant reports about registration will still be complicated. Example: Every time we make queries, save the result locally and fire an event for our components to check for potential changes without making the same query again. Nevertheless this again delays changes if there is no need to that. --- .../protocollib/InventoryPacketAdapter.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/InventoryPacketAdapter.java b/src/main/java/fr/xephi/authme/listener/protocollib/InventoryPacketAdapter.java index bceeaca7a..ce9a0e03d 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/InventoryPacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/InventoryPacketAdapter.java @@ -83,7 +83,20 @@ public void register(BukkitService bukkitService) { } private boolean shouldHideInventory(String playerName) { - return !playerCache.isAuthenticated(playerName) && dataSource.isAuthAvailable(playerName); + if (playerCache.isAuthenticated(playerName)) { + // fully logged in - no need to protect it + return false; + } + + if (dataSource.isCached()) { + // load from cache or only request once + return dataSource.isAuthAvailable(playerName); + } + + // data source is not cached - this means queries would run blocking + // Assume the player is registered would mean the inventory will be protected + // and any potential information leak can be prevented + return true; } public void unregister() {