Dedicated server: stop game when there are less than 2 clients

directional-lights
Julius Michaelis 2016-10-30 21:35:38 +01:00
parent 890669ea0d
commit 55b6713185
5 changed files with 19 additions and 6 deletions

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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())

View File

@ -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);

View File

@ -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);