Don't count spectator as players in game for testing reset
This commit is contained in:
parent
9747f59e00
commit
37e5ea6806
@ -910,39 +910,48 @@ void ServerLobby::finishedLoadingLiveJoinClient(Event* event)
|
|||||||
void ServerLobby::update(int ticks)
|
void ServerLobby::update(int ticks)
|
||||||
{
|
{
|
||||||
World* w = World::getWorld();
|
World* w = World::getWorld();
|
||||||
|
bool world_started = m_state.load() >= WAIT_FOR_WORLD_LOADED &&
|
||||||
|
m_state.load() <= RACING && m_server_has_loaded_world.load();
|
||||||
|
bool all_players_in_world_disconnected = (w != NULL && world_started);
|
||||||
int sec = ServerConfig::m_kick_idle_player_seconds;
|
int sec = ServerConfig::m_kick_idle_player_seconds;
|
||||||
if (sec > 0 && m_state.load() >= WAIT_FOR_WORLD_LOADED &&
|
if (world_started)
|
||||||
m_state.load() <= RACING && m_server_has_loaded_world.load() == true)
|
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < race_manager->getNumPlayers(); i++)
|
for (unsigned i = 0; i < race_manager->getNumPlayers(); i++)
|
||||||
{
|
{
|
||||||
const RemoteKartInfo& rki = race_manager->getKartInfo(i);
|
const RemoteKartInfo& rki = race_manager->getKartInfo(i);
|
||||||
std::shared_ptr<NetworkPlayerProfile> player =
|
std::shared_ptr<NetworkPlayerProfile> player =
|
||||||
rki.getNetworkPlayerProfile().lock();
|
rki.getNetworkPlayerProfile().lock();
|
||||||
if (!player)
|
if (player)
|
||||||
|
{
|
||||||
|
if (w)
|
||||||
|
all_players_in_world_disconnected = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
continue;
|
continue;
|
||||||
auto peer = player->getPeer();
|
auto peer = player->getPeer();
|
||||||
if (peer && peer->idleForSeconds() > sec)
|
if (!peer)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (peer->idleForSeconds() > 60 && w &&
|
||||||
|
w->getKart(i)->isEliminated())
|
||||||
{
|
{
|
||||||
if (w && w->getKart(i)->isEliminated())
|
// Remove loading world too long (60 seconds) live join peer
|
||||||
{
|
Log::info("ServerLobby", "%s hasn't live-joined within"
|
||||||
// Remove loading world too long live join peer
|
" 60 seconds, remove it.",
|
||||||
Log::info("ServerLobby", "%s hasn't live-joined within"
|
peer->getAddress().toString().c_str());
|
||||||
" %d seconds, remove it.",
|
RemoteKartInfo& rki = race_manager->getKartInfo(i);
|
||||||
peer->getAddress().toString().c_str(), sec);
|
rki.makeReserved();
|
||||||
RemoteKartInfo& rki = race_manager->getKartInfo(i);
|
continue;
|
||||||
rki.makeReserved();
|
}
|
||||||
|
if (sec > 0 && peer->idleForSeconds() > sec &&
|
||||||
|
!peer->isDisconnected() && NetworkConfig::get()->isWAN())
|
||||||
|
{
|
||||||
|
if (w && w->getKart(i)->hasFinishedRace())
|
||||||
continue;
|
continue;
|
||||||
}
|
Log::info("ServerLobby", "%s has been idle for more than"
|
||||||
if (!peer->isDisconnected() && NetworkConfig::get()->isWAN())
|
" %d seconds, kick.",
|
||||||
{
|
peer->getAddress().toString().c_str(), sec);
|
||||||
if (w && w->getKart(i)->hasFinishedRace())
|
peer->kick();
|
||||||
continue;
|
|
||||||
Log::info("ServerLobby", "%s has been idle for more than"
|
|
||||||
" %d seconds, kick.",
|
|
||||||
peer->getAddress().toString().c_str(), sec);
|
|
||||||
peer->kick();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -977,12 +986,21 @@ void ServerLobby::update(int ticks)
|
|||||||
STKHost::get()->updatePlayers();
|
STKHost::get()->updatePlayers();
|
||||||
if ((m_state.load() > WAITING_FOR_START_GAME ||
|
if ((m_state.load() > WAITING_FOR_START_GAME ||
|
||||||
m_game_setup->isGrandPrixStarted()) &&
|
m_game_setup->isGrandPrixStarted()) &&
|
||||||
STKHost::get()->getPlayersInGame() == 0 &&
|
(STKHost::get()->getPlayersInGame() == 0 ||
|
||||||
|
all_players_in_world_disconnected) &&
|
||||||
NetworkConfig::get()->getServerIdFile().empty())
|
NetworkConfig::get()->getServerIdFile().empty())
|
||||||
{
|
{
|
||||||
if (RaceEventManager::getInstance() &&
|
if (RaceEventManager::getInstance() &&
|
||||||
RaceEventManager::getInstance()->isRunning())
|
RaceEventManager::getInstance()->isRunning())
|
||||||
{
|
{
|
||||||
|
// Send a notification to all players who may have start live join
|
||||||
|
// or spectate to go back to lobby
|
||||||
|
NetworkString* back_to_lobby = getNetworkString(2);
|
||||||
|
back_to_lobby->setSynchronous(true);
|
||||||
|
back_to_lobby->addUInt8(LE_BACK_LOBBY).addUInt8(BLR_NONE);
|
||||||
|
sendMessageToPeersInServer(back_to_lobby, /*reliable*/true);
|
||||||
|
delete back_to_lobby;
|
||||||
|
|
||||||
RaceEventManager::getInstance()->stop();
|
RaceEventManager::getInstance()->stop();
|
||||||
RaceEventManager::getInstance()->getProtocol()->requestTerminate();
|
RaceEventManager::getInstance()->getProtocol()->requestTerminate();
|
||||||
GameProtocol::lock()->requestTerminate();
|
GameProtocol::lock()->requestTerminate();
|
||||||
@ -996,7 +1014,7 @@ void ServerLobby::update(int ticks)
|
|||||||
m_state.load() == SELECTING &&
|
m_state.load() == SELECTING &&
|
||||||
STKHost::get()->getPlayersInGame() == 1)
|
STKHost::get()->getPlayersInGame() == 1)
|
||||||
{
|
{
|
||||||
NetworkString* back_lobby = getNetworkString(1);
|
NetworkString* back_lobby = getNetworkString(2);
|
||||||
back_lobby->setSynchronous(true);
|
back_lobby->setSynchronous(true);
|
||||||
back_lobby->addUInt8(LE_BACK_LOBBY)
|
back_lobby->addUInt8(LE_BACK_LOBBY)
|
||||||
.addUInt8(BLR_ONE_PLAYER_IN_RANKED_MATCH);
|
.addUInt8(BLR_ONE_PLAYER_IN_RANKED_MATCH);
|
||||||
@ -1059,7 +1077,7 @@ void ServerLobby::update(int ticks)
|
|||||||
{
|
{
|
||||||
// Send a notification to all clients to exit
|
// Send a notification to all clients to exit
|
||||||
// the race result screen
|
// the race result screen
|
||||||
NetworkString* back_to_lobby = getNetworkString(1);
|
NetworkString* back_to_lobby = getNetworkString(2);
|
||||||
back_to_lobby->setSynchronous(true);
|
back_to_lobby->setSynchronous(true);
|
||||||
back_to_lobby->addUInt8(LE_BACK_LOBBY).addUInt8(BLR_NONE);
|
back_to_lobby->addUInt8(LE_BACK_LOBBY).addUInt8(BLR_NONE);
|
||||||
sendMessageToPeersInServer(back_to_lobby, /*reliable*/true);
|
sendMessageToPeersInServer(back_to_lobby, /*reliable*/true);
|
||||||
|
Loading…
Reference in New Issue
Block a user