diff --git a/src/game/C4Game.cpp b/src/game/C4Game.cpp index 11ec9c332..2ea048852 100644 --- a/src/game/C4Game.cpp +++ b/src/game/C4Game.cpp @@ -3110,10 +3110,7 @@ void C4Game::ShowGameOverDlg() if (GameOverDlgShown) return; // flag, show GameOverDlgShown = true; -#ifdef USE_CONSOLE - // console engine quits here directly - Application.QuitGame(); -#else +#ifndef USE_CONSOLE if (!Application.isEditor) { C4GameOverDlg *pDlg = new C4GameOverDlg(); diff --git a/src/gui/C4GameLobby.cpp b/src/gui/C4GameLobby.cpp index fb1c202ef..0d4377506 100644 --- a/src/gui/C4GameLobby.cpp +++ b/src/gui/C4GameLobby.cpp @@ -16,6 +16,7 @@ // the ingame-lobby #include "C4Include.h" +#include "C4ForbidLibraryCompilation.h" #include "gui/C4GameLobby.h" #include "game/C4Application.h" @@ -764,14 +765,17 @@ namespace C4GameLobby // countdown done if (!iStartTimer) { +#ifdef USE_CONSOLE // Dedicated server: if there are not enough players for this game, abort and quit the application - if (!::Network.GetLobby() && (Game.PlayerInfos.GetPlayerCount() < Game.C4S.GetMinPlayer()) && !Application.isEditor) + if (Game.PlayerInfos.GetPlayerCount() < Game.C4S.GetMinPlayer() + || ::Network.Clients.Count() <= 2) { Log(LoadResStr("IDS_MSG_NOTENOUGHPLAYERSFORTHISRO")); // it would also be nice to send this message to all clients... Application.Quit(); } // Start the game else +#endif // USE_CONSOLE ::Network.Start(); } } diff --git a/src/network/C4Network2.cpp b/src/network/C4Network2.cpp index 6851f1d95..ccba86977 100644 --- a/src/network/C4Network2.cpp +++ b/src/network/C4Network2.cpp @@ -371,7 +371,7 @@ bool C4Network2::DoLobby() if (Console.Active) { // console lobby - update console - if (Console.Active) Console.UpdateMenus(); + Console.UpdateMenus(); // init lobby countdown if specified if (Game.iLobbyTimeout) StartLobbyCountdown(Game.iLobbyTimeout); // do console lobby @@ -1501,6 +1501,10 @@ void C4Network2::OnClientDisconnect(C4Network2Client *pClient) if (!fStatusReached) if (Status.getState() == GS_Go || Status.getState() == GS_Pause) ChangeGameStatus(Status.getState(), ::Control.ControlTick); +#ifdef USE_CONSOLE + // Dedicated server: stop hosting if there is only one client left we're hosting for. + if (Clients.Count() <= 3) Application.Quit(); // Off-by-1 error +#endif // USE_CONSOLE } // host disconnected? Clear up if (!isHost() && pClient->isHost()) diff --git a/src/network/C4Network2Client.cpp b/src/network/C4Network2Client.cpp index 81f31917a..4de297c75 100644 --- a/src/network/C4Network2Client.cpp +++ b/src/network/C4Network2Client.cpp @@ -347,6 +347,13 @@ C4Network2Client *C4Network2ClientList::GetClient(const C4ClientCore &CCore, int return NULL; } +unsigned int C4Network2ClientList::Count() +{ + unsigned int ret(0); + for (C4Network2Client *pClient = pFirst; pClient; pClient = pClient->pNext) ret++; + return ret; +} + C4Network2Client *C4Network2ClientList::GetHost() { return GetClientByID(C4ClientIDHost); diff --git a/src/network/C4Network2Client.h b/src/network/C4Network2Client.h index 59bca3881..0f47c9729 100644 --- a/src/network/C4Network2Client.h +++ b/src/network/C4Network2Client.h @@ -153,6 +153,7 @@ public: C4Network2Client *GetLocal() const { return pLocal; } C4Network2Client *GetHost(); C4Network2Client *GetNextClient(C4Network2Client *pClient); + unsigned int Count(); void Init(C4ClientList *pClientList, bool fHost); C4Network2Client *RegClient(C4Client *pClient);