From f44262f4276a7be275a202002403fedf35761b61 Mon Sep 17 00:00:00 2001 From: HongchengQ <121159914+HongchengQ@users.noreply.github.com> Date: Sat, 6 Dec 2025 16:43:46 +0800 Subject: [PATCH] Fix abnormal player online status on duplicate login - Prevent incorrect player deletion on duplicate login --- .../java/emu/nebula/game/player/Player.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/emu/nebula/game/player/Player.java b/src/main/java/emu/nebula/game/player/Player.java index b29ae1d..25d6ff2 100644 --- a/src/main/java/emu/nebula/game/player/Player.java +++ b/src/main/java/emu/nebula/game/player/Player.java @@ -1,6 +1,7 @@ package emu.nebula.game.player; import java.util.Stack; +import java.util.concurrent.TimeUnit; import dev.morphia.annotations.AlsoLoad; import dev.morphia.annotations.Entity; @@ -185,16 +186,23 @@ public class Player implements GameDatabaseObject { } public void setSession(GameSession session) { - if (this.session != null) { - // Sanity check - if (this.session == session) { - return; - } - - // Clear player from session - this.session.clearPlayer(); + int time = Nebula.getConfig().getServerOptions().sessionTimeout; + long timeout = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(time); + + if (this.session == null) { + // Set session + this.session = session; + return; } - + + // 1. Sanity check + // 2. Prevent incorrect deletion of players when re-logging into the game + if (this.session == session || this.lastLogin > timeout) { + return; + } + + // Clear player from session + this.session.clearPlayer(); // Set session this.session = session; }