# HG changeset patch # User Wuzzy # Date 1534942804 -7200 # Node ID 27e5e311c7a38c573bb5df8e5047e49878cb39c7 # Parent a8b2a5e7e9db85f5c76a19bf299c0c08333a22ba Fix critical failure to cleanup teams list after rejoining game after a force-quit. Fixes bug 597 diff -r a8b2a5e7e9db -r 27e5e311c7a3 ChangeLog.txt --- a/ChangeLog.txt Tue Aug 21 23:56:49 2018 +0200 +++ b/ChangeLog.txt Wed Aug 22 15:00:04 2018 +0200 @@ -34,6 +34,7 @@ Frontend: + Add setting to disable audio dampening when losing window focus * Fix rare crash when aborting video encoding in progress + * Fix critical failure to cleanup teams list after rejoining game under certain conditions * Controllers are detected again * Fix failure to shutdown game window properly after player got kicked * No longer allow having schemes with equal names (case-insensitive) diff -r a8b2a5e7e9db -r 27e5e311c7a3 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Tue Aug 21 23:56:49 2018 +0200 +++ b/QTfrontend/hwform.cpp Wed Aug 22 15:00:04 2018 +0200 @@ -1746,7 +1746,15 @@ Music(ui.pageOptions->CBFrontendMusic->isChecked()); if (wBackground) wBackground->startAnimation(); GoToPage(ID_PAGE_GAMESTATS); - if (hwnet && (!game || !game->netSuspend)) hwnet->gameFinished(true); + if (hwnet) + { + if (!game || !game->netSuspend) + hwnet->gameFinished(true); + // After a game, the local player might have pseudo-teams left + // when rejoining a previously left game. This makes sure the + // teams list is in a consistent state. + ui.pageNetGame->cleanupFakeNetTeams(); + } if (game) game->netSuspend = false; break; } diff -r a8b2a5e7e9db -r 27e5e311c7a3 QTfrontend/ui/page/pagenetgame.cpp --- a/QTfrontend/ui/page/pagenetgame.cpp Tue Aug 21 23:56:49 2018 +0200 +++ b/QTfrontend/ui/page/pagenetgame.cpp Wed Aug 22 15:00:04 2018 +0200 @@ -218,6 +218,10 @@ chatWidget->displayWarning(message); } +void PageNetGame::cleanupFakeNetTeams() +{ + pNetTeamsWidget->cleanupFakeNetTeams(); +} void PageNetGame::setReadyStatus(bool isReady) { @@ -280,6 +284,7 @@ void PageNetGame::setUser(const QString & nickname) { + pNetTeamsWidget->setUser(nickname); chatWidget->setUser(nickname); } diff -r a8b2a5e7e9db -r 27e5e311c7a3 QTfrontend/ui/page/pagenetgame.h --- a/QTfrontend/ui/page/pagenetgame.h Tue Aug 21 23:56:49 2018 +0200 +++ b/QTfrontend/ui/page/pagenetgame.h Wed Aug 22 15:00:04 2018 +0200 @@ -40,6 +40,7 @@ void displayError(const QString & message); void displayNotice(const QString & message); void displayWarning(const QString & message); + void cleanupFakeNetTeams(); QPushButton *BtnGo; QPushButton *BtnMaster; diff -r a8b2a5e7e9db -r 27e5e311c7a3 QTfrontend/ui/widget/teamselect.cpp --- a/QTfrontend/ui/widget/teamselect.cpp Tue Aug 21 23:56:49 2018 +0200 +++ b/QTfrontend/ui/widget/teamselect.cpp Wed Aug 22 15:00:04 2018 +0200 @@ -74,6 +74,11 @@ framePlaying->setInteractivity(interactive); } +void TeamSelWidget::setUser(const QString& nickname) +{ + m_curUser = nickname; +} + void TeamSelWidget::hhNumChanged(const HWTeam& team) { QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); @@ -152,6 +157,37 @@ emit setEnabledGameStart(curPlayingTeams.size()>1); } +// Removes teams classified as net teams but which are owned by the local user. +// Those teams don't make sense and might be leftovers from a finished game +// after rejoining. See also: Bugzilla bug 597. +void TeamSelWidget::cleanupFakeNetTeams() +{ + // m_curUser is not set for offline games. No cleanup is needed when offline. + if(m_curUser.isNull()) + return; + + QList::iterator itPlay = curPlayingTeams.begin(); + while(itPlay != curPlayingTeams.end()) + { + if(itPlay->isNetTeam() && itPlay->owner() == m_curUser) + { + qDebug() << QString("cleanupFakeNetTeams: team '%1' removed").arg(itPlay->name()); + QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam))); + framePlaying->removeTeam(*itPlay); + itPlay = curPlayingTeams.erase(itPlay); + } + else + itPlay++; + } + + // Show team notice if less than two teams. + if (curPlayingTeams.size() < 2) + { + numTeamNotice->show(); + } + emit setEnabledGameStart(curPlayingTeams.size()>1); +} + void TeamSelWidget::changeTeamStatus(HWTeam team) { QList::iterator itDontPlay=std::find(m_curNotPlayingTeams.begin(), m_curNotPlayingTeams.end(), team); diff -r a8b2a5e7e9db -r 27e5e311c7a3 QTfrontend/ui/widget/teamselect.h --- a/QTfrontend/ui/widget/teamselect.h Tue Aug 21 23:56:49 2018 +0200 +++ b/QTfrontend/ui/widget/teamselect.h Wed Aug 22 15:00:04 2018 +0200 @@ -49,6 +49,8 @@ QList getNotPlayingTeams() const; unsigned short getNumHedgehogs() const; void setInteractivity(bool interactive); + void setUser(const QString& nickname); + void cleanupFakeNetTeams(); public slots: void addTeam(HWTeam team); @@ -78,6 +80,7 @@ QLabel *numTeamNotice; bool m_acceptOuter; void repaint(); + QString m_curUser; QList curPlayingTeams; QList m_curNotPlayingTeams;