diff --git a/engine/server/application/ConnectionServer/src/shared/ClientConnection.cpp b/engine/server/application/ConnectionServer/src/shared/ClientConnection.cpp index 5fa67b9f..afb9e7f5 100755 --- a/engine/server/application/ConnectionServer/src/shared/ClientConnection.cpp +++ b/engine/server/application/ConnectionServer/src/shared/ClientConnection.cpp @@ -309,6 +309,7 @@ void ClientConnection::handleClientIdMessage(const ClientIdMsg &msg) { if (ConfigConnectionServer::getValidateStationKey()) { bool cont = false; StationId apiSuid = 0; + const std::string clientIP = getRemoteAddress(); const std::string sess = sessionId; @@ -324,10 +325,18 @@ void ClientConnection::handleClientIdMessage(const ClientIdMsg &msg) { bool status = api.getNullableValue("status"); if (status) { - apiSuid = api.getNullableValue("user_id"); - int expired = api.getNullableValue("expired"); std::string apiUser = api.getString("user_name"); std::string apiIP = api.getString("ip"); + int expired = api.getNullableValue("expired"); + + if (!ConfigConnectionServer::getUseOldSuidGenerator()) { + apiSuid = api.getNullableValue("user_id"); + } else { + if (apiUser.length() > MAX_ACCOUNT_NAME_LENGTH) { + apiUser.resize(MAX_ACCOUNT_NAME_LENGTH); + } + apiSuid = std::hash{}(apiUser.c_str()); + } if (apiIP == clientIP && expired == 0) { m_suid = apiSuid; @@ -337,9 +346,9 @@ void ClientConnection::handleClientIdMessage(const ClientIdMsg &msg) { } if (!cont) { - LOG("ClientDisconnect", - ("SUID %d (%d) passed a bad token to the connections erver. Disconnecting.", m_suid, apiSuid)); + LOG("ClientDisconnect", ("SUID %d (%d) passed a bad token to the connections erver. Disconnecting.", m_suid, apiSuid)); disconnect(); + return; } } @@ -381,12 +390,14 @@ void ClientConnection::handleClientIdMessage(const ClientIdMsg &msg) { return; } + // test mode only if (!m_suid && !ConfigConnectionServer::getValidateStationKey()) { WARNING(true, ("Generating suid from username. This is not safe or secure.")); + m_suid = atoi(m_accountName.c_str()); + if (m_suid == 0) { - std::hash h; - m_suid = h(m_accountName.c_str()); + m_suid = std::hash{}(m_accountName.c_str()); } } diff --git a/engine/server/application/ConnectionServer/src/shared/ConfigConnectionServer.cpp b/engine/server/application/ConnectionServer/src/shared/ConfigConnectionServer.cpp index 52d2ef2f..538e2c01 100755 --- a/engine/server/application/ConnectionServer/src/shared/ConfigConnectionServer.cpp +++ b/engine/server/application/ConnectionServer/src/shared/ConfigConnectionServer.cpp @@ -89,7 +89,6 @@ void ConfigConnectionServer::install(void) KEY_INT (lagReportThreshold, 10000); KEY_INT (defaultGameFeatures, 0xFFFFFFFF); KEY_INT (defaultSubscriptionFeatures, 0xFFFFFFFF); - KEY_INT (maxConnectionsPerIP, 6); KEY_BOOL (validateStationKey, false); KEY_STRING (sessionServers, ""); @@ -116,6 +115,7 @@ void ConfigConnectionServer::install(void) KEY_INT (fakeBuddyPoints, 0); KEY_STRING (altPublicBindAddress, ""); + KEY_BOOL (useOldSuidGenerator, false); int index = 0; char const * result = 0; diff --git a/engine/server/application/ConnectionServer/src/shared/ConfigConnectionServer.h b/engine/server/application/ConnectionServer/src/shared/ConfigConnectionServer.h index 114af1d8..8c817183 100755 --- a/engine/server/application/ConnectionServer/src/shared/ConfigConnectionServer.h +++ b/engine/server/application/ConnectionServer/src/shared/ConfigConnectionServer.h @@ -41,7 +41,6 @@ public: int clientMaxDataHoldTime; int clientHashTableSize; int lagReportThreshold; - int maxConnectionsPerIP; bool validateStationKey; const char *sessionServers; @@ -71,6 +70,7 @@ public: const char *altPublicBindAddress; + const bool useOldSuidGenerator; }; @@ -186,8 +186,7 @@ public: static const char *getPublicBindAddress(); - static int getMaxConnectionsPerIP(); - + static bool getUseOldSuidGenerator(); private: static Data *data; }; @@ -477,8 +476,8 @@ inline int ConfigConnectionServer::getConnectionServerNumber() { } -inline int ConfigConnectionServer::getMaxConnectionsPerIP() { - return data->maxConnectionsPerIP; +inline bool ConfigConnectionServer::getUseOldSuidGenerator() { + return data->useOldSuidGenerator; } #endif // _ConfigConnectionServer_H diff --git a/engine/server/application/ConnectionServer/src/shared/ConnectionServer.cpp b/engine/server/application/ConnectionServer/src/shared/ConnectionServer.cpp index 7e7f5783..55fb16e6 100755 --- a/engine/server/application/ConnectionServer/src/shared/ConnectionServer.cpp +++ b/engine/server/application/ConnectionServer/src/shared/ConnectionServer.cpp @@ -92,7 +92,6 @@ ConnectionServer::ConnectionServer() s_clientServiceSetup->maxDataHoldTime = ConfigConnectionServer::getClientMaxDataHoldTime(); s_clientServiceSetup->hashTableSize = ConfigConnectionServer::getClientHashTableSize(); s_clientServiceSetup->port = ConfigConnectionServer::getClientServicePortPublic(); - s_clientServiceSetup->maxConnectionsPerIP = ConfigConnectionServer::getMaxConnectionsPerIP(); s_clientServiceSetup->compress = ConfigConnectionServer::getCompressClientNetworkTraffic(); s_clientServiceSetup->useTcp = false; @@ -504,12 +503,10 @@ ConnectionServer::receiveMessage(const MessageDispatch::Emitter &source, const M if (ConfigConnectionServer::getStartPublicServer()) { s_clientServiceSetup->port = ConfigConnectionServer::getClientServicePortPublic(); - s_clientServiceSetup->maxConnectionsPerIP = ConfigConnectionServer::getMaxConnectionsPerIP(); clientServicePublic = new Service(ConnectionAllocator(), *s_clientServiceSetup); } s_clientServiceSetup->port = ConfigConnectionServer::getClientServicePortPrivate(); - s_clientServiceSetup->maxConnectionsPerIP = 0; clientServicePrivate = new Service(ConnectionAllocator(), *s_clientServiceSetup); connectToMessage("ClientConnectionOpened");