From a82bb979d79dded832b60105ff72d83088b74c2c Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Mon, 18 Apr 2016 19:52:56 +0000 Subject: [PATCH] reduce code complexity/readability, hopefully make slightly faster --- .../src/shared/ClientConnection.cpp | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp index 76538e6b..b2802982 100755 --- a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp +++ b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp @@ -198,14 +198,11 @@ void ClientConnection::validateClient(const std::string & id, const std::string if (authURL != NULL && strcmp(authURL, "") != 0) { - CURL *curl; - CURLcode res; - std::string readBuffer; - - curl = curl_easy_init(); + CURL *curl = curl_easy_init(); if (curl) { + std::string readBuffer; std::string postData = "user_name=" + id + "&user_password=" + key + "&stationID=" + std::to_string(atoi(id.c_str())) + "&ip=" + getRemoteAddress(); curl_easy_setopt(curl, CURLOPT_URL, authURL); @@ -213,34 +210,29 @@ void ClientConnection::validateClient(const std::string & id, const std::string curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); - res = curl_easy_perform(curl); + CURLcode res = curl_easy_perform(curl); if (res == CURLE_OK && !(readBuffer.empty())) { json j = json::parse(readBuffer); - std::string errMsg = "Message not provided by authentication service."; - if (j.count("status") != 0) + if (j.count("status") != 0 && j["status"].get() == "success") { - std::string status = j["status"].get(); - - if (status == "success") - { - LoginServer::getInstance().onValidateClient(suid, id, this, true, NULL, 0xFFFFFFFF, 0xFFFFFFFF); - } - else - { - if (j.count("message") != 0) - { - errMsg = j["message"].get(); - } - - ErrorMessage err("Login Failed", errMsg); - this->send(err, true); - } + LoginServer::getInstance().onValidateClient(suid, id, this, true, NULL, 0xFFFFFFFF, 0xFFFFFFFF); } else { + std::string errMsg; + + if (j.count("message") != 0) + { + errMsg = j["message"].get(); + } + else + { + errMsg = "Message not provided by authentication service."; + } + ErrorMessage err("Login Failed", errMsg); this->send(err, true); } @@ -250,9 +242,7 @@ void ClientConnection::validateClient(const std::string & id, const std::string ErrorMessage err("Login Failed", "Could not connect to authentication service."); this->send(err, true); } - curl_easy_cleanup(curl); - } } else