allow legacy suid generation in the connection server as well

This commit is contained in:
DarthArgus
2017-01-03 22:52:13 -06:00
parent 11fc9a7564
commit 43047889f7
4 changed files with 22 additions and 15 deletions
@@ -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<bool>("status");
if (status) {
apiSuid = api.getNullableValue<int>("user_id");
int expired = api.getNullableValue<int>("expired");
std::string apiUser = api.getString("user_name");
std::string apiIP = api.getString("ip");
int expired = api.getNullableValue<int>("expired");
if (!ConfigConnectionServer::getUseOldSuidGenerator()) {
apiSuid = api.getNullableValue<int>("user_id");
} else {
if (apiUser.length() > MAX_ACCOUNT_NAME_LENGTH) {
apiUser.resize(MAX_ACCOUNT_NAME_LENGTH);
}
apiSuid = std::hash<std::string>{}(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<std::string> h;
m_suid = h(m_accountName.c_str());
m_suid = std::hash<std::string>{}(m_accountName.c_str());
}
}
@@ -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;
@@ -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
@@ -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<ClientConnection>(), *s_clientServiceSetup);
}
s_clientServiceSetup->port = ConfigConnectionServer::getClientServicePortPrivate();
s_clientServiceSetup->maxConnectionsPerIP = 0;
clientServicePrivate = new Service(ConnectionAllocator<ClientConnection>(), *s_clientServiceSetup);
connectToMessage("ClientConnectionOpened");