Feature: [Network] Ensure players fill in a name instead of defaulting to "Player"
This commit is contained in:
@@ -1264,6 +1264,42 @@ bool NetworkIsValidClientName(const char *client_name)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim the given client name in place, i.e. remove leading and trailing spaces.
|
||||
* After the trim check whether the client name is valid. A client name is valid
|
||||
* whenever the name is not empty and does not start with spaces. This check is
|
||||
* done via \c NetworkIsValidClientName.
|
||||
* When the client name is valid, this function returns true.
|
||||
* When the client name is not valid a GUI error message is shown telling the
|
||||
* user to set the client name and this function returns false.
|
||||
*
|
||||
* This function is not suitable for ensuring a valid client name at the server
|
||||
* as the error message will then be shown to the host instead of the client.
|
||||
* @param client_name The client name to validate. It will be trimmed of leading
|
||||
* and trailing spaces.
|
||||
* @return True iff the client name is valid.
|
||||
*/
|
||||
bool NetworkValidateClientName(char *client_name)
|
||||
{
|
||||
StrTrimInPlace(client_name);
|
||||
if (NetworkIsValidClientName(client_name)) return true;
|
||||
|
||||
ShowErrorMessage(STR_NETWORK_ERROR_BAD_PLAYER_NAME, INVALID_STRING_ID, WL_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for NetworkValidateClientName on _settings_client.network.client_name.
|
||||
* It trims the client name and checks whether it is empty. When it is empty
|
||||
* an error message is shown to the GUI user.
|
||||
* See \c NetworkValidateClientName(char*) for details about the functionality.
|
||||
* @return True iff the client name is valid.
|
||||
*/
|
||||
bool NetworkValidateClientName()
|
||||
{
|
||||
return NetworkValidateClientName(_settings_client.network.client_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the server our name.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user