mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-04-20 07:50:11 +00:00
new auth system + major optimization
This commit is contained in:
@@ -34,7 +34,7 @@ std::string GenerateCall() {
|
||||
return Ret.str();
|
||||
}
|
||||
std::string RunPromise(const std::string& IP, const std::string& R) {
|
||||
std::packaged_task<std::string()> task([&] { return PostHTTP(IP, R); });
|
||||
std::packaged_task<std::string()> task([&] { return PostHTTP(IP, R, false); });
|
||||
std::future<std::string> f1 = task.get_future();
|
||||
std::thread t(std::move(task));
|
||||
t.detach();
|
||||
@@ -46,7 +46,7 @@ std::string RunPromise(const std::string& IP, const std::string& R) {
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
void Heartbeat() {
|
||||
[[noreturn]] void Heartbeat() {
|
||||
DebugPrintTID();
|
||||
std::string R, T;
|
||||
bool isAuth = false;
|
||||
@@ -54,17 +54,16 @@ void Heartbeat() {
|
||||
R = GenerateCall();
|
||||
if (!CustomIP.empty())
|
||||
R += "&ip=" + CustomIP;
|
||||
std::string link = Sec("https://beammp.com/heartbeatv2");
|
||||
std::string link ="https://beammp.com/heartbeatv2";
|
||||
T = RunPromise(link, R);
|
||||
if (T.find_first_not_of(Sec("20")) != std::string::npos) {
|
||||
|
||||
if (T.substr(0,2) != "20") {
|
||||
//Backend system refused server startup!
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
std::string Backup = Sec("https://backup1.beammp.com/heartbeatv2");
|
||||
std::string Backup = "https://backup1.beammp.com/heartbeatv2";
|
||||
T = RunPromise(Backup, R);
|
||||
if (T.find_first_not_of(Sec("20")) != std::string::npos) {
|
||||
error(Sec("Backend system refused server! Check your AuthKey"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
_Exit(-1);
|
||||
if (T.substr(0,2) != "20") {
|
||||
warn("Backend system refused server! Server might not show in the public list");
|
||||
}
|
||||
}
|
||||
//Server Authenticated
|
||||
@@ -76,7 +75,7 @@ void Heartbeat() {
|
||||
WebsocketInit();
|
||||
isAuth = true;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
}
|
||||
void HBInit() {
|
||||
|
||||
@@ -9,22 +9,21 @@
|
||||
|
||||
std::string CustomIP;
|
||||
std::string GetSVer() {
|
||||
return std::string(Sec("1.13"));
|
||||
return std::string(Sec("1.20"));
|
||||
}
|
||||
std::string GetCVer() {
|
||||
return std::string(Sec("1.70"));
|
||||
return std::string(Sec("1.71"));
|
||||
}
|
||||
void Args(int argc, char* argv[]) {
|
||||
info(Sec("BeamMP Server Running version ") + GetSVer());
|
||||
info("BeamMP Server Running version " + GetSVer());
|
||||
if (argc > 1) {
|
||||
CustomIP = argv[1];
|
||||
size_t n = std::count(CustomIP.begin(), CustomIP.end(), '.');
|
||||
auto p = CustomIP.find_first_not_of(Sec(".0123456789"));
|
||||
if (p != std::string::npos || n != 3 || CustomIP.substr(0, 3) == Sec("127")) {
|
||||
CustomIP.clear();
|
||||
warn(Sec("IP Specified is invalid! Ignoring"));
|
||||
} else
|
||||
info(Sec("Server started with custom IP"));
|
||||
warn("IP Specified is invalid! Ignoring");
|
||||
} else info("Server started with custom IP");
|
||||
}
|
||||
}
|
||||
void InitServer(int argc, char* argv[]) {
|
||||
|
||||
Reference in New Issue
Block a user