mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
Add more info to return to backend's /pkToUser endpoint (#332)
Features added were tested through a custom client (since @sla-ppy is too cheap to own the game) with @lionkor while pair programming. Fixes: #303
This commit is contained in:
commit
2fcb53530a
@ -66,7 +66,7 @@ public:
|
|||||||
std::string Resource { "Resources" };
|
std::string Resource { "Resources" };
|
||||||
std::string MapName { "/levels/gridmap_v2/info.json" };
|
std::string MapName { "/levels/gridmap_v2/info.json" };
|
||||||
std::string Key {};
|
std::string Key {};
|
||||||
std::string Password{};
|
std::string Password {};
|
||||||
std::string SSLKeyPath { "./.ssl/HttpServer/key.pem" };
|
std::string SSLKeyPath { "./.ssl/HttpServer/key.pem" };
|
||||||
std::string SSLCertPath { "./.ssl/HttpServer/cert.pem" };
|
std::string SSLCertPath { "./.ssl/HttpServer/cert.pem" };
|
||||||
bool HTTPServerEnabled { false };
|
bool HTTPServerEnabled { false };
|
||||||
|
@ -209,7 +209,7 @@ void TNetwork::Identify(TConnection&& RawConnection) {
|
|||||||
} else {
|
} else {
|
||||||
beammp_errorf("Invalid code got in Identify: '{}'", Code);
|
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);
|
beammp_errorf("Error during handling of code {} - client left in invalid state, closing socket", Code);
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
RawConnection.Socket.shutdown(socket_base::shutdown_both, ec);
|
RawConnection.Socket.shutdown(socket_base::shutdown_both, ec);
|
||||||
@ -278,7 +278,7 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
return nullptr;
|
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
|
// TODO: handle
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,16 +289,21 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string key(reinterpret_cast<const char*>(Data.data()), Data.size());
|
std::string Key(reinterpret_cast<const char*>(Data.data()), Data.size());
|
||||||
|
std::string AuthKey = Application::Settings.Key;
|
||||||
nlohmann::json AuthReq{};
|
std::string ClientIp = Client->GetIdentifiers().at("ip");
|
||||||
std::string AuthResStr{};
|
|
||||||
|
nlohmann::json AuthReq {};
|
||||||
|
std::string AuthResStr {};
|
||||||
try {
|
try {
|
||||||
AuthReq = nlohmann::json {
|
AuthReq = nlohmann::json {
|
||||||
{ "key", key }
|
{ "key", Key },
|
||||||
|
{ "auth_key", AuthKey },
|
||||||
|
{ "client_ip", ClientIp }
|
||||||
};
|
};
|
||||||
|
|
||||||
auto Target = "/pkToUser";
|
auto Target = "/pkToUser";
|
||||||
|
|
||||||
unsigned int ResponseCode = 0;
|
unsigned int ResponseCode = 0;
|
||||||
AuthResStr = Http::POST(Application::GetBackendUrlForAuth(), 443, Target, AuthReq.dump(), "application/json", &ResponseCode);
|
AuthResStr = Http::POST(Application::GetBackendUrlForAuth(), 443, Target, AuthReq.dump(), "application/json", &ResponseCode);
|
||||||
|
|
||||||
@ -334,14 +339,14 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Application::Settings.Password.empty()) { // ask password
|
if (!Application::Settings.Password.empty()) { // ask password
|
||||||
if(!TCPSend(*Client, StringToVector("S"))) {
|
if (!TCPSend(*Client, StringToVector("S"))) {
|
||||||
// TODO: handle
|
// TODO: handle
|
||||||
}
|
}
|
||||||
beammp_info("Waiting for password");
|
beammp_info("Waiting for password");
|
||||||
Data = TCPRcv(*Client);
|
Data = TCPRcv(*Client);
|
||||||
std::string Pass = std::string(reinterpret_cast<const char*>(Data.data()), Data.size());
|
std::string Pass = std::string(reinterpret_cast<const char*>(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");
|
beammp_debug(Client->GetName() + " attempted to connect with a wrong password");
|
||||||
ClientKick(*Client, "Wrong password!");
|
ClientKick(*Client, "Wrong password!");
|
||||||
return {};
|
return {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user