diff options
author | rubidium42 <rubidium@openttd.org> | 2021-04-22 08:17:36 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-04-24 08:02:54 +0200 |
commit | e1cebe0ea0719ad408a0a7494efe1d8581b702ce (patch) | |
tree | a9891283253ab252620e621145e5de94c4a29bc0 /src/network/network_server.cpp | |
parent | 2e0f3799a809086054f6d5ac4120283b5bb6fa3b (diff) | |
download | openttd-e1cebe0ea0719ad408a0a7494efe1d8581b702ce.tar.xz |
Add: [Network] Validate the client name server side, so no clients with invalid names can actually join
Diffstat (limited to 'src/network/network_server.cpp')
-rw-r--r-- | src/network/network_server.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 321c8aa09..fbde713eb 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -945,8 +945,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p) break; } - /* We need a valid name.. make it Player */ - if (!NetworkIsValidClientName(name)) strecpy(name, "Player", lastof(name)); + if (!NetworkIsValidClientName(name)) { + /* An invalid client name was given. However, the client ensures the name + * is valid before it is sent over the network, so something went horribly + * wrong. This is probably someone trying to troll us. */ + return this->SendError(NETWORK_ERROR_INVALID_CLIENT_NAME); + } if (!NetworkFindName(name, lastof(name))) { // Change name if duplicate /* We could not create a name for this client */ @@ -1441,6 +1445,13 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST; if (ci != nullptr) { + if (!NetworkIsValidClientName(client_name)) { + /* An invalid client name was given. However, the client ensures the name + * is valid before it is sent over the network, so something went horribly + * wrong. This is probably someone trying to troll us. */ + return this->SendError(NETWORK_ERROR_INVALID_CLIENT_NAME); + } + /* Display change */ if (NetworkFindName(client_name, lastof(client_name))) { NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, client_name); |