Merge branch 'master' into jgrpp-beta
# Conflicts: # src/economy.cpp # src/lang/traditional_chinese.txt # src/order_gui.cpp # src/settings.cpp # src/settings_internal.h # src/table/company_settings.ini # src/table/currency_settings.ini # src/table/gameopt_settings.ini # src/table/misc_settings.ini # src/table/settings.h.preamble # src/table/settings.ini # src/table/win32_settings.ini # src/table/window_settings.ini
This commit is contained in:
@@ -865,10 +865,6 @@ void NetworkClientJoinGame()
|
||||
|
||||
static void NetworkInitGameInfo()
|
||||
{
|
||||
if (_settings_client.network.server_name.empty()) {
|
||||
_settings_client.network.server_name = "Unnamed Server";
|
||||
}
|
||||
|
||||
FillStaticNetworkServerGameInfo();
|
||||
/* The server is a client too */
|
||||
_network_game_info.clients_on = _network_dedicated ? 0 : 1;
|
||||
@@ -881,6 +877,25 @@ static void NetworkInitGameInfo()
|
||||
ci->client_name = _settings_client.network.client_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim the given server name in place, i.e. remove leading and trailing spaces.
|
||||
* After the trim check whether the server name is not empty.
|
||||
* When the server name is empty a GUI error message is shown telling the
|
||||
* user to set the servername and this function returns false.
|
||||
*
|
||||
* @param server_name The server name to validate. It will be trimmed of leading
|
||||
* and trailing spaces.
|
||||
* @return True iff the server name is valid.
|
||||
*/
|
||||
bool NetworkValidateServerName(std::string &server_name)
|
||||
{
|
||||
StrTrimInPlace(server_name);
|
||||
if (!server_name.empty()) return true;
|
||||
|
||||
ShowErrorMessage(STR_NETWORK_ERROR_BAD_SERVER_NAME, INVALID_STRING_ID, WL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the client and server name are set, for a dedicated server and if not set them to some default
|
||||
* value and tell the user to change this as soon as possible.
|
||||
@@ -890,12 +905,14 @@ static void NetworkInitGameInfo()
|
||||
static void CheckClientAndServerName()
|
||||
{
|
||||
static const std::string fallback_client_name = "Unnamed Client";
|
||||
StrTrimInPlace(_settings_client.network.client_name);
|
||||
if (_settings_client.network.client_name.empty() || _settings_client.network.client_name.compare(fallback_client_name) == 0) {
|
||||
DEBUG(net, 1, "No \"client_name\" has been set, using \"%s\" instead. Please set this now using the \"name <new name>\" command", fallback_client_name.c_str());
|
||||
_settings_client.network.client_name = fallback_client_name;
|
||||
}
|
||||
|
||||
static const std::string fallback_server_name = "Unnamed Server";
|
||||
StrTrimInPlace(_settings_client.network.server_name);
|
||||
if (_settings_client.network.server_name.empty() || _settings_client.network.server_name.compare(fallback_server_name) == 0) {
|
||||
DEBUG(net, 1, "No \"server_name\" has been set, using \"%s\" instead. Please set this now using the \"server_name <new name>\" command", fallback_server_name.c_str());
|
||||
_settings_client.network.server_name = fallback_server_name;
|
||||
|
||||
@@ -1563,27 +1563,22 @@ bool NetworkValidateClientName()
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the server our name.
|
||||
* Send the server our name as callback from the setting.
|
||||
* @param newname The new client name.
|
||||
*/
|
||||
void NetworkUpdateClientName()
|
||||
void NetworkUpdateClientName(const std::string &client_name)
|
||||
{
|
||||
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
|
||||
|
||||
if (ci == nullptr) return;
|
||||
/* There is no validation on string settings, it is actually a post change callback.
|
||||
* This method is called from that post change callback. So, when the client name is
|
||||
* changed via the console there is no easy way to prevent an invalid name. Though,
|
||||
* we can prevent it getting sent here. */
|
||||
if (!NetworkValidateClientName()) return;
|
||||
|
||||
/* Don't change the name if it is the same as the old name */
|
||||
if (_settings_client.network.client_name.compare(ci->client_name) != 0) {
|
||||
if (client_name.compare(ci->client_name) != 0) {
|
||||
if (!_network_server) {
|
||||
MyClient::SendSetName(_settings_client.network.client_name.c_str());
|
||||
MyClient::SendSetName(client_name.c_str());
|
||||
} else {
|
||||
/* Copy to a temporary buffer so no #n gets added after our name in the settings when there are duplicate names. */
|
||||
char temporary_name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
strecpy(temporary_name, _settings_client.network.client_name.c_str(), lastof(temporary_name));
|
||||
strecpy(temporary_name, client_name.c_str(), lastof(temporary_name));
|
||||
if (NetworkFindName(temporary_name, lastof(temporary_name))) {
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, temporary_name);
|
||||
ci->client_name = temporary_name;
|
||||
|
||||
@@ -38,7 +38,8 @@ byte NetworkSpectatorCount();
|
||||
bool NetworkIsValidClientName(const std::string_view client_name);
|
||||
bool NetworkValidateClientName();
|
||||
bool NetworkValidateClientName(std::string &client_name);
|
||||
void NetworkUpdateClientName();
|
||||
bool NetworkValidateServerName(std::string &server_name);
|
||||
void NetworkUpdateClientName(const std::string &client_name);
|
||||
bool NetworkCompanyHasClients(CompanyID company);
|
||||
std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password);
|
||||
void NetworkReboot();
|
||||
|
||||
@@ -1110,6 +1110,7 @@ struct NetworkStartServerWindow : public Window {
|
||||
break;
|
||||
|
||||
case WID_NSS_GENERATE_GAME: // Start game
|
||||
if (!CheckServerName()) return;
|
||||
_is_network_server = true;
|
||||
if (_ctrl_pressed) {
|
||||
StartNewGameWithoutGUI(GENERATE_NEW_SEED);
|
||||
@@ -1119,16 +1120,19 @@ struct NetworkStartServerWindow : public Window {
|
||||
break;
|
||||
|
||||
case WID_NSS_LOAD_GAME:
|
||||
if (!CheckServerName()) return;
|
||||
_is_network_server = true;
|
||||
ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD);
|
||||
break;
|
||||
|
||||
case WID_NSS_PLAY_SCENARIO:
|
||||
if (!CheckServerName()) return;
|
||||
_is_network_server = true;
|
||||
ShowSaveLoadDialog(FT_SCENARIO, SLO_LOAD);
|
||||
break;
|
||||
|
||||
case WID_NSS_PLAY_HEIGHTMAP:
|
||||
if (!CheckServerName()) return;
|
||||
_is_network_server = true;
|
||||
ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_LOAD);
|
||||
break;
|
||||
@@ -1148,11 +1152,13 @@ struct NetworkStartServerWindow : public Window {
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
void OnEditboxChanged(int wid) override
|
||||
bool CheckServerName()
|
||||
{
|
||||
if (wid == WID_NSS_GAMENAME) {
|
||||
_settings_client.network.server_name = this->name_editbox.text.buf;
|
||||
}
|
||||
std::string str = this->name_editbox.text.buf;
|
||||
if (!NetworkValidateServerName(str)) return false;
|
||||
|
||||
SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), str);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnTimeout() override
|
||||
@@ -2214,16 +2220,13 @@ public:
|
||||
case WID_CL_SERVER_NAME_EDIT: {
|
||||
if (!_network_server) break;
|
||||
|
||||
SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), StrEmpty(str) ? "Unnamed Server" : str);
|
||||
SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), str);
|
||||
this->InvalidateData();
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_CL_CLIENT_NAME_EDIT: {
|
||||
std::string client_name(str);
|
||||
if (!NetworkValidateClientName(client_name)) break;
|
||||
|
||||
SetSettingValue(GetSettingFromName("network.client_name")->AsStringSetting(), client_name.c_str());
|
||||
SetSettingValue(GetSettingFromName("network.client_name")->AsStringSetting(), str);
|
||||
this->InvalidateData();
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user