On login, load Player from DB in shard thread, not in login thread

This avoids some needless data shuffling and fixes a rare desync.
This commit is contained in:
2022-12-06 01:07:21 +01:00
parent d92b407349
commit 3f44f53f97
5 changed files with 38 additions and 14 deletions

View File

@@ -224,18 +224,22 @@ static void enterPlayer(CNSocket* sock, CNPacketData* data) {
return;
}
// for convenience
Player& plr = lm->plr;
plr.groupCnt = 1;
plr.iIDGroup = plr.groupIDs[0] = plr.iID;
Player plr = {};
Database::getPlayer(&plr, lm->playerId);
// check if account is already in use
if (isAccountInUse(plr.accountId)) {
// kick the other player
exitDuplicate(plr.accountId);
// re-read the player from disk, in case it was just flushed
plr = {};
Database::getPlayer(&plr, lm->playerId);
}
plr.groupCnt = 1;
plr.iIDGroup = plr.groupIDs[0] = plr.iID;
response.iID = plr.iID;
response.uiSvrTime = getTime();
response.PCLoadData2CL.iUserLevel = plr.accountLevel;
@@ -345,7 +349,7 @@ static void enterPlayer(CNSocket* sock, CNPacketData* data) {
if (pair.second->notify)
Chat::sendServerMessage(pair.first, "[ADMIN]" + getPlayerName(&plr) + " has joined.");
// deallocate lm (and therefore the plr object)
// deallocate lm
delete lm;
}