Remove broken honor titles when logging in

This commit is contained in:
Melledy
2025-12-22 19:36:54 -08:00
parent c75da823e0
commit 450b0cca30
4 changed files with 70 additions and 2 deletions
@@ -32,6 +32,7 @@ public class GameConstants {
public static final String PROTO_BASE_TYPE_URL = "type.googleapis.com/proto."; public static final String PROTO_BASE_TYPE_URL = "type.googleapis.com/proto.";
public static final int INTRO_GUIDE_ID = 1; public static final int INTRO_GUIDE_ID = 1;
public static final int DEFAULT_HONOR_ID = 111001;
public static final int GOLD_ITEM_ID = 1; public static final int GOLD_ITEM_ID = 1;
public static final int GEM_ITEM_ID = 2; public static final int GEM_ITEM_ID = 2;
@@ -1,6 +1,7 @@
package emu.nebula.data.resources; package emu.nebula.data.resources;
import emu.nebula.data.BaseDef; import emu.nebula.data.BaseDef;
import emu.nebula.data.GameData;
import emu.nebula.data.ResourceType; import emu.nebula.data.ResourceType;
import lombok.Getter; import lombok.Getter;
@@ -9,9 +10,27 @@ import lombok.Getter;
public class HonorDef extends BaseDef { public class HonorDef extends BaseDef {
private int Id; private int Id;
private int Type; private int Type;
private int[] Params;
@Override @Override
public int getId() { public int getId() {
return Id; return Id;
} }
public boolean isValid() {
if (this.Type == 2) {
if (this.Params.length < 1) {
return false;
}
int charId = this.Params[0];
var charData = GameData.getCharacterDataTable().get(charId);
if (charData == null || !charData.isAvailable()) {
return false;
}
}
return true;
}
} }
@@ -259,6 +259,10 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
return true; return true;
} }
public boolean hasHonor(int id) {
return id == GameConstants.DEFAULT_HONOR_ID || this.getHonorList().contains(id);
}
// Resources // Resources
public synchronized int getResourceCount(int id) { public synchronized int getResourceCount(int id) {
@@ -405,8 +405,20 @@ public class Player implements GameDatabaseObject {
// Verify that we have the honor titles // Verify that we have the honor titles
for (int id : honorIds) { for (int id : honorIds) {
if (id != 0 && !getInventory().getHonorList().contains(id)) { // Empty honor title
System.out.println(id); if (id == 0) {
continue;
}
// Make sure we own the honor title
if (!getInventory().hasHonor(id)) {
return false;
}
// Make sure honor exists and won't crash the client
var honor = GameData.getHonorDataTable().get(id);
if (honor == null || !honor.isValid()) {
return false; return false;
} }
} }
@@ -788,6 +800,9 @@ public class Player implements GameDatabaseObject {
// See if we need to reset dailies // See if we need to reset dailies
this.checkResetDailies(); this.checkResetDailies();
// Fix any broken honor ids
this.checkBrokenHonor();
// Update last login time // Update last login time
this.lastLogin = System.currentTimeMillis(); this.lastLogin = System.currentTimeMillis();
Nebula.getGameDatabase().update(this, this.getUid(), "lastLogin", this.getLastLogin()); Nebula.getGameDatabase().update(this, this.getUid(), "lastLogin", this.getLastLogin());
@@ -815,6 +830,35 @@ public class Player implements GameDatabaseObject {
} }
} }
/**
* Checks the player's honor ids to make sure they don't crash the client
*/
private void checkBrokenHonor() {
boolean changed = false;
for (int i = 0; i < this.honor.length; i++) {
int honorId = this.honor[i];
if (honorId == 0) {
continue;
}
// Get honor data
var honor = GameData.getHonorDataTable().get(honorId);
// Check if honor is valid
if (honor == null || !honor.isValid()) {
this.honor[i] = 0;
changed = true;
}
}
// Update in database
if (changed) {
Nebula.getGameDatabase().update(this, this.getUid(), "honor", this.getHonor());
}
}
// Proto // Proto
public PlayerInfo toProto() { public PlayerInfo toProto() {