Fix abnormal player online status on duplicate login

- Prevent incorrect player deletion on duplicate login
This commit is contained in:
HongchengQ
2025-12-06 16:43:46 +08:00
committed by Melledy
parent cf63bc0b7e
commit f44262f427

View File

@@ -1,6 +1,7 @@
package emu.nebula.game.player; package emu.nebula.game.player;
import java.util.Stack; import java.util.Stack;
import java.util.concurrent.TimeUnit;
import dev.morphia.annotations.AlsoLoad; import dev.morphia.annotations.AlsoLoad;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
@@ -185,16 +186,23 @@ public class Player implements GameDatabaseObject {
} }
public void setSession(GameSession session) { public void setSession(GameSession session) {
if (this.session != null) { int time = Nebula.getConfig().getServerOptions().sessionTimeout;
// Sanity check long timeout = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(time);
if (this.session == session) {
return; if (this.session == null) {
} // Set session
this.session = session;
// Clear player from session return;
this.session.clearPlayer();
} }
// 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 // Set session
this.session = session; this.session = session;
} }