From 69e91c3e4241e8f46fd3a83f7aed50c05d3ec5cd Mon Sep 17 00:00:00 2001 From: mohammed jasem alaajel Date: Tue, 18 Jun 2024 00:55:12 +0400 Subject: [PATCH] check if player is really on the proxy when connecting this prevents logged in error if somehow proxy shutdowns at weird time --- .../redisbungee/api/ProxyDataManager.java | 7 ++++++ .../redisbungee/BungeePlayerDataManager.java | 22 ++++++++++++------- .../VelocityPlayerDataManager.java | 19 +++++++++++----- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/ProxyDataManager.java b/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/ProxyDataManager.java index c52cf9e2..d58aadf0 100644 --- a/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/ProxyDataManager.java +++ b/api/src/main/java/com/imaginarycode/minecraft/redisbungee/api/ProxyDataManager.java @@ -82,6 +82,13 @@ public Set getPlayersOn(String proxyId) { return getProxyMembers(proxyId); } + // this skip checking if proxy is and its package private + // due proxy shutdown shenanigans + public boolean isPlayerTrulyOnProxy(String proxyId, UUID uuid) { + return unifiedJedis.sismember("redisbungee::" + this.networkId + "::proxies::" + proxyId + "::online-players", uuid.toString()); + } + + public List proxiesIds() { return Collections.list(this.heartbeats.keys()); } diff --git a/proxies/bungeecord/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java b/proxies/bungeecord/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java index 0a5dfbf7..3c2f5e50 100644 --- a/proxies/bungeecord/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java +++ b/proxies/bungeecord/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java @@ -15,7 +15,6 @@ import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent; -import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.LoginEvent; @@ -66,14 +65,21 @@ public void onLoginEvent(LoginEvent event) { event.registerIntent((Plugin) plugin); // check if online if (getLastOnline(event.getConnection().getUniqueId()) == 0) { - if (plugin.configuration().kickWhenOnline()) { - kickPlayer(event.getConnection().getUniqueId(), plugin.langConfiguration().messages().loggedInFromOtherLocation()); - // wait 3 seconds before releasing the event - plugin.executeAsyncAfter(() -> event.completeIntent((Plugin) plugin), TimeUnit.SECONDS, 3); - } else { - event.setCancelled(true); - event.setCancelReason(BungeeComponentSerializer.get().serialize(plugin.langConfiguration().messages().alreadyLoggedIn())); + // because something can go wrong and proxy somehow does not update player data correctly on shutdown + // we have to check proxy if it has the player + String proxyId = getProxyFor(event.getConnection().getUniqueId()); + if (proxyId == null || !plugin.proxyDataManager().isPlayerTrulyOnProxy(proxyId, event.getConnection().getUniqueId())) { event.completeIntent((Plugin) plugin); + } else { + if (plugin.configuration().kickWhenOnline()) { + kickPlayer(event.getConnection().getUniqueId(), plugin.langConfiguration().messages().loggedInFromOtherLocation()); + // wait 3 seconds before releasing the event + plugin.executeAsyncAfter(() -> event.completeIntent((Plugin) plugin), TimeUnit.SECONDS, 3); + } else { + event.setCancelled(true); + event.setCancelReason(BungeeComponentSerializer.get().serialize(plugin.langConfiguration().messages().alreadyLoggedIn())); + event.completeIntent((Plugin) plugin); + } } } else { event.completeIntent((Plugin) plugin); diff --git a/proxies/velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java b/proxies/velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java index b3bcff65..b98bdee7 100644 --- a/proxies/velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java +++ b/proxies/velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java @@ -68,13 +68,20 @@ public void onServerConnectedEvent(ServerConnectedEvent event) { public void onLoginEvent(LoginEvent event, Continuation continuation) { // check if online if (getLastOnline(event.getPlayer().getUniqueId()) == 0) { - if (plugin.configuration().kickWhenOnline()) { - kickPlayer(event.getPlayer().getUniqueId(), plugin.langConfiguration().messages().loggedInFromOtherLocation()); - // wait 3 seconds before releasing the event - plugin.executeAsyncAfter(continuation::resume, TimeUnit.SECONDS, 3); - } else { - event.setResult(ResultedEvent.ComponentResult.denied(plugin.langConfiguration().messages().alreadyLoggedIn())); + // because something can go wrong and proxy somehow does not update player data correctly on shutdown + // we have to check proxy if it has the player + String proxyId = getProxyFor(event.getPlayer().getUniqueId()); + if (proxyId == null || !plugin.proxyDataManager().isPlayerTrulyOnProxy(proxyId, event.getPlayer().getUniqueId())) { continuation.resume(); + } else { + if (plugin.configuration().kickWhenOnline()) { + kickPlayer(event.getPlayer().getUniqueId(), plugin.langConfiguration().messages().loggedInFromOtherLocation()); + // wait 3 seconds before releasing the event + plugin.executeAsyncAfter(continuation::resume, TimeUnit.SECONDS, 3); + } else { + event.setResult(ResultedEvent.ComponentResult.denied(plugin.langConfiguration().messages().alreadyLoggedIn())); + continuation.resume(); + } } } else { continuation.resume();