mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 21:04:36 +01:00
Fix abnormal player online status on duplicate login
- Prevent incorrect player deletion on duplicate login
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear player from session
|
if (this.session == null) {
|
||||||
this.session.clearPlayer();
|
// 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
|
// Set session
|
||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user