Fix: server's client is shown incorrectly in some cases

master
Rubidium 4 weeks ago committed by rubidium42
parent 4740eeaa43
commit 455e202e03

@ -884,7 +884,7 @@ static void NetworkInitGameInfo()
/* There should be always space for the server. */
assert(NetworkClientInfo::CanAllocateItem());
NetworkClientInfo *ci = new NetworkClientInfo(CLIENT_ID_SERVER);
ci->client_playas = _network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST;
ci->client_playas = COMPANY_SPECTATOR;
ci->client_name = _settings_client.network.client_name;
}
@ -987,6 +987,30 @@ bool NetworkServerStart()
return true;
}
/**
* Perform tasks when the server is started. This consists of things
* like putting the server's client in a valid company and resetting the restart time.
*/
void NetworkOnGameStart()
{
if (!_network_server) return;
/* Update the static game info to set the values from the new game. */
NetworkServerUpdateGameInfo();
ChangeNetworkRestartTime(true);
if (!_network_dedicated) {
Company *c = Company::GetIfValid(GetFirstPlayableCompanyID());
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
if (c != nullptr && ci != nullptr) {
ci->client_playas = c->index;
}
ShowClientList();
}
}
/* The server is rebooting...
* The only difference with NetworkDisconnect, is the packets that is sent */
void NetworkReboot()

@ -64,6 +64,8 @@ void NetworkPrintClients();
std::string_view NetworkGetPublicKeyOfClient(ClientID client_id);
void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode);
void NetworkOnGameStart();
/*** Commands ran by the server ***/
void NetworkServerSendConfigUpdate();
void NetworkServerUpdateGameInfo();

@ -34,7 +34,6 @@
#include "console_func.h"
#include "screenshot.h"
#include "network/network.h"
#include "network/network_server.h"
#include "network/network_func.h"
#include "ai/ai.hpp"
#include "ai/ai_config.hpp"
@ -859,8 +858,8 @@ static void OnStartGame(bool dedicated_server)
* or in the case of a dedicated server, a spectator */
SetLocalCompany(dedicated_server ? COMPANY_SPECTATOR : GetFirstPlayableCompanyID());
/* Update the static game info to set the values from the new game. */
NetworkServerUpdateGameInfo();
NetworkOnGameStart();
/* Execute the game-start script */
IConsoleCmdExec("exec scripts/game_start.scr 0");
}
@ -911,12 +910,6 @@ static void MakeNewGameDone()
CheckEngines();
CheckIndustries();
MarkWholeScreenDirty();
if (_network_server) {
ChangeNetworkRestartTime(true);
if (!_network_dedicated) ShowClientList();
}
}
static void MakeNewGame(bool from_heightmap, bool reset_settings)

Loading…
Cancel
Save