diff --git a/include/Common.h b/include/Common.h index cd8894d..9ceacd1 100644 --- a/include/Common.h +++ b/include/Common.h @@ -65,7 +65,7 @@ public: std::string Resource { "Resources" }; std::string MapName { "/levels/gridmap_v2/info.json" }; std::string Key {}; - std::string Password{}; + std::string Password {}; std::string SSLKeyPath { "./.ssl/HttpServer/key.pem" }; std::string SSLCertPath { "./.ssl/HttpServer/cert.pem" }; bool HTTPServerEnabled { false }; diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 9b17bce..ec9741d 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -209,7 +209,7 @@ void TNetwork::Identify(TConnection&& RawConnection) { } else { beammp_errorf("Invalid code got in Identify: '{}'", Code); } - } catch(const std::exception& e) { + } catch (const std::exception& e) { beammp_errorf("Error during handling of code {} - client left in invalid state, closing socket", Code); boost::system::error_code ec; RawConnection.Socket.shutdown(socket_base::shutdown_both, ec); @@ -278,7 +278,7 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { return nullptr; } - if (!TCPSend(*Client, StringToVector("A"))) { //changed to A for Accepted version + if (!TCPSend(*Client, StringToVector("A"))) { // changed to A for Accepted version // TODO: handle } @@ -289,16 +289,23 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { return nullptr; } - std::string key(reinterpret_cast(Data.data()), Data.size()); - - nlohmann::json AuthReq{}; - std::string AuthResStr{}; + std::string Key(reinterpret_cast(Data.data()), Data.size()); + std::string AuthKey = Application::Settings.Key; + std::string ClientIp = Client->GetIdentifiers().at("ip"); + + nlohmann::json AuthReq {}; + std::string AuthResStr {}; try { AuthReq = nlohmann::json { - { "key", key } + { "key", Key }, + { "auth_key", AuthKey }, + { "client_ip", ClientIp } }; + beammp_debugf("IF YOU SEE THIS AND IT DISPLAYS PROPER INFO, THE FEATURE WORKS: {}", to_string(AuthReq)); + auto Target = "/pkToUser"; + unsigned int ResponseCode = 0; AuthResStr = Http::POST(Application::GetBackendUrlForAuth(), 443, Target, AuthReq.dump(), "application/json", &ResponseCode); @@ -334,14 +341,14 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { return nullptr; } - if(!Application::Settings.Password.empty()) { // ask password - if(!TCPSend(*Client, StringToVector("S"))) { + if (!Application::Settings.Password.empty()) { // ask password + if (!TCPSend(*Client, StringToVector("S"))) { // TODO: handle } beammp_info("Waiting for password"); Data = TCPRcv(*Client); std::string Pass = std::string(reinterpret_cast(Data.data()), Data.size()); - if(Pass != HashPassword(Application::Settings.Password)) { + if (Pass != HashPassword(Application::Settings.Password)) { beammp_debug(Client->GetName() + " attempted to connect with a wrong password"); ClientKick(*Client, "Wrong password!"); return {};