summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordP <dp@dpointer.org>2021-08-16 12:09:54 +0300
committerGitHub <noreply@github.com>2021-08-16 11:09:54 +0200
commit2e6a77a78a465797a5e78c55c6b16f45fc104e5c (patch)
tree81614efc794a819fa82c6bb78e05a97770bbfe8f /src
parentd212505dcf40b14c03195ae020680165bc21c447 (diff)
downloadopenttd-2e6a77a78a465797a5e78c55c6b16f45fc104e5c.tar.xz
Fix: connecting with the same name thrice hangs the server (#9485)
Diffstat (limited to 'src')
-rw-r--r--src/network/network_server.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index fecaa2e00..c506f60a4 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1541,13 +1541,12 @@ static void NetworkAutoCleanCompanies()
bool NetworkMakeClientNameUnique(std::string &name)
{
bool is_name_unique = false;
- uint number = 0;
std::string original_name = name;
- while (!is_name_unique) {
+ for (uint number = 1; !is_name_unique && number <= MAX_CLIENTS; number++) { // Something's really wrong when there're more names than clients
is_name_unique = true;
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
- if (ci->client_name.compare(name) == 0) {
+ if (ci->client_name == name) {
/* Name already in use */
is_name_unique = false;
break;
@@ -1556,7 +1555,7 @@ bool NetworkMakeClientNameUnique(std::string &name)
/* Check if it is the same as the server-name */
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
if (ci != nullptr) {
- if (ci->client_name.compare(name) == 0) is_name_unique = false; // name already in use
+ if (ci->client_name == name) is_name_unique = false; // name already in use
}
if (!is_name_unique) {