refactor pingClockTimeout (#4169)

* refactor pingClockTimeout

try to see if it changes #3954

* use lcoks and unlocks again
This commit is contained in:
ebbit1q 2020-11-23 02:21:43 +01:00 committed by GitHub
parent 4aaedf64d2
commit 8441cb7ba9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -169,26 +169,28 @@ void Server_Game::pingClockTimeout()
GameEventStorage ges;
ges.setGameEventContext(Context_PingChanged());
QList<ServerInfo_PlayerPing *> pingList;
QMapIterator<int, Server_Player *> playerIterator(players);
bool allPlayersInactive = true;
int playerCount = 0;
while (playerIterator.hasNext()) {
Server_Player *player = playerIterator.next().value();
for (auto *player : players) {
if (player == nullptr)
continue;
if (!player->getSpectator())
++playerCount;
const int oldPingTime = player->getPingTime();
player->playerMutex.lock();
int oldPingTime = player->getPingTime();
int newPingTime;
if (player->getUserInterface())
player->playerMutex.lock();
if (player->getUserInterface()) {
newPingTime = player->getUserInterface()->getLastCommandTime();
else
} else {
newPingTime = -1;
}
player->playerMutex.unlock();
if ((newPingTime != -1) && !player->getSpectator())
if ((newPingTime != -1) && !player->getSpectator()) {
allPlayersInactive = false;
}
if ((abs(oldPingTime - newPingTime) > 1) || ((newPingTime == -1) && (oldPingTime != -1)) ||
((newPingTime != -1) && (oldPingTime == -1))) {
@ -203,10 +205,12 @@ void Server_Game::pingClockTimeout()
const int maxTime = room->getServer()->getMaxGameInactivityTime();
if (allPlayersInactive) {
if (((++inactivityCounter >= maxTime) && (maxTime > 0)) || (playerCount < maxPlayers))
if (((maxTime > 0) && (++inactivityCounter >= maxTime)) || (playerCount < maxPlayers)) {
deleteLater();
} else
}
} else {
inactivityCounter = 0;
}
}
int Server_Game::getPlayerCount() const