Fix seg fault in buddy data for deleted player

This commit is contained in:
Gent 2020-11-10 18:00:34 -05:00
parent 121c65d7ea
commit 34f2aef248
2 changed files with 6 additions and 1 deletions

View File

@ -65,6 +65,8 @@ void BuddyManager::refreshBuddyList(CNSocket* sock) {
if (buddyID != 0) { if (buddyID != 0) {
sBuddyBaseInfo buddyInfo = {}; sBuddyBaseInfo buddyInfo = {};
Database::DbPlayer buddyPlayerData = Database::getDbPlayerById(buddyID); Database::DbPlayer buddyPlayerData = Database::getDbPlayerById(buddyID);
if (buddyPlayerData.PlayerID == -1)
continue;
buddyInfo.bBlocked = 0; buddyInfo.bBlocked = 0;
buddyInfo.bFreeChat = 1; buddyInfo.bFreeChat = 1;
buddyInfo.iGender = buddyPlayerData.Gender; buddyInfo.iGender = buddyPlayerData.Gender;

View File

@ -500,7 +500,10 @@ Player Database::DbToPlayer(DbPlayer player) {
} }
Database::DbPlayer Database::getDbPlayerById(int id) { Database::DbPlayer Database::getDbPlayerById(int id) {
return db.get_all<DbPlayer>(where(c(&DbPlayer::PlayerID) == id)).front(); auto player = db.get_all<DbPlayer>(where(c(&DbPlayer::PlayerID) == id));
if (player.size() < 1)
return DbPlayer{ -1 };
return player.front();
} }
Player Database::getPlayer(int id) { Player Database::getPlayer(int id) {