mirror of https://github.com/OpenTTD/OpenTTD
Change: [Network] Prevent invalid client names being sent to the server when changing it using the console/settings
parent
bfb0ab3e2f
commit
2e0f3799a8
|
@ -716,7 +716,14 @@ DEF_CONSOLE_CMD(ConClientNickChange)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!NetworkServerChangeClientName(client_id, argv[2])) {
|
||||
char *client_name = argv[2];
|
||||
StrTrimInPlace(client_name);
|
||||
if (!NetworkIsValidClientName(client_name)) {
|
||||
IConsoleError("Cannot give a client an empty name");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!NetworkServerChangeClientName(client_id, client_name)) {
|
||||
IConsoleError("Cannot give a client a duplicate name");
|
||||
}
|
||||
|
||||
|
|
|
@ -1308,6 +1308,11 @@ void NetworkUpdateClientName()
|
|||
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 (strcmp(ci->client_name, _settings_client.network.client_name) != 0) {
|
||||
|
|
Loading…
Reference in New Issue