Add garbage collection for non-existent players

This commit is contained in:
Gent 2020-11-10 18:16:06 -05:00
parent 34f2aef248
commit 4454faffc3

View File

@ -501,8 +501,16 @@ Player Database::DbToPlayer(DbPlayer player) {
Database::DbPlayer Database::getDbPlayerById(int id) { Database::DbPlayer Database::getDbPlayerById(int id) {
auto player = db.get_all<DbPlayer>(where(c(&DbPlayer::PlayerID) == id)); auto player = db.get_all<DbPlayer>(where(c(&DbPlayer::PlayerID) == id));
if (player.size() < 1) if (player.size() < 1) {
// garbage collection
db.remove_all<Inventory>(where(c(&Inventory::playerId) == id));
db.remove_all<Nano>(where(c(&Nano::playerId) == id));
db.remove_all<DbQuest>(where(c(&DbQuest::PlayerId) == id));
db.remove_all<Buddyship>(where(c(&Buddyship::PlayerAId) == id || c(&Buddyship::PlayerBId) == id));
db.remove_all<EmailData>(where(c(&EmailData::PlayerId) == id));
db.remove_all<EmailItem>(where(c(&EmailItem::PlayerId) == id));
return DbPlayer{ -1 }; return DbPlayer{ -1 };
}
return player.front(); return player.front();
} }