mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-26 08:33:54 -07:00
refactor pingClockTimeout (#4169)
* refactor pingClockTimeout try to see if it changes #3954 * use lcoks and unlocks again
This commit is contained in:
parent
4aaedf64d2
commit
8441cb7ba9
1 changed files with 15 additions and 11 deletions
|
|
@ -169,26 +169,28 @@ void Server_Game::pingClockTimeout()
|
||||||
GameEventStorage ges;
|
GameEventStorage ges;
|
||||||
ges.setGameEventContext(Context_PingChanged());
|
ges.setGameEventContext(Context_PingChanged());
|
||||||
|
|
||||||
QList<ServerInfo_PlayerPing *> pingList;
|
|
||||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
|
||||||
bool allPlayersInactive = true;
|
bool allPlayersInactive = true;
|
||||||
int playerCount = 0;
|
int playerCount = 0;
|
||||||
while (playerIterator.hasNext()) {
|
for (auto *player : players) {
|
||||||
Server_Player *player = playerIterator.next().value();
|
if (player == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!player->getSpectator())
|
if (!player->getSpectator())
|
||||||
++playerCount;
|
++playerCount;
|
||||||
|
|
||||||
const int oldPingTime = player->getPingTime();
|
int oldPingTime = player->getPingTime();
|
||||||
player->playerMutex.lock();
|
|
||||||
int newPingTime;
|
int newPingTime;
|
||||||
if (player->getUserInterface())
|
player->playerMutex.lock();
|
||||||
|
if (player->getUserInterface()) {
|
||||||
newPingTime = player->getUserInterface()->getLastCommandTime();
|
newPingTime = player->getUserInterface()->getLastCommandTime();
|
||||||
else
|
} else {
|
||||||
newPingTime = -1;
|
newPingTime = -1;
|
||||||
|
}
|
||||||
player->playerMutex.unlock();
|
player->playerMutex.unlock();
|
||||||
|
|
||||||
if ((newPingTime != -1) && !player->getSpectator())
|
if ((newPingTime != -1) && !player->getSpectator()) {
|
||||||
allPlayersInactive = false;
|
allPlayersInactive = false;
|
||||||
|
}
|
||||||
|
|
||||||
if ((abs(oldPingTime - newPingTime) > 1) || ((newPingTime == -1) && (oldPingTime != -1)) ||
|
if ((abs(oldPingTime - newPingTime) > 1) || ((newPingTime == -1) && (oldPingTime != -1)) ||
|
||||||
((newPingTime != -1) && (oldPingTime == -1))) {
|
((newPingTime != -1) && (oldPingTime == -1))) {
|
||||||
|
|
@ -203,10 +205,12 @@ void Server_Game::pingClockTimeout()
|
||||||
|
|
||||||
const int maxTime = room->getServer()->getMaxGameInactivityTime();
|
const int maxTime = room->getServer()->getMaxGameInactivityTime();
|
||||||
if (allPlayersInactive) {
|
if (allPlayersInactive) {
|
||||||
if (((++inactivityCounter >= maxTime) && (maxTime > 0)) || (playerCount < maxPlayers))
|
if (((maxTime > 0) && (++inactivityCounter >= maxTime)) || (playerCount < maxPlayers)) {
|
||||||
deleteLater();
|
deleteLater();
|
||||||
} else
|
}
|
||||||
|
} else {
|
||||||
inactivityCounter = 0;
|
inactivityCounter = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server_Game::getPlayerCount() const
|
int Server_Game::getPlayerCount() const
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue