mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
Remove interfering legacy code (http,password,etc)
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
This commit is contained in:
parent
ff812429ed
commit
13e641b3a3
@ -172,7 +172,6 @@ Http::Server::THttpServerInstance::THttpServerInstance() {
|
||||
}
|
||||
|
||||
void Http::Server::THttpServerInstance::operator()() try {
|
||||
beammp_info("HTTP(S) Server started on port " + std::to_string(Application::Settings.HTTPServerPort));
|
||||
std::unique_ptr<httplib::Server> HttpLibServerInstance;
|
||||
HttpLibServerInstance = std::make_unique<httplib::Server>();
|
||||
// todo: make this IP agnostic so people can set their own IP
|
||||
@ -214,10 +213,6 @@ void Http::Server::THttpServerInstance::operator()() try {
|
||||
beammp_debug("Http Server: " + Req.method + " " + Req.target + " -> " + std::to_string(Res.status));
|
||||
});
|
||||
Application::SetSubsystemStatus("HTTPServer", Application::Status::Good);
|
||||
auto ret = HttpLibServerInstance->listen(Application::Settings.HTTPServerIP.c_str(), Application::Settings.HTTPServerPort);
|
||||
if (!ret) {
|
||||
beammp_error("Failed to start http server (failed to listen). Please ensure the http server is configured properly in the ServerConfig.toml, or turn it off if you don't need it.");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
beammp_error("Failed to start http server. Please ensure the http server is configured properly in the ServerConfig.toml, or turn it off if you don't need it. Error: " + std::string(e.what()));
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ void TConfig::CreateConfigFile() {
|
||||
try {
|
||||
if (fs::exists("Server.cfg")) {
|
||||
// parse it (this is weird and bad and should be removed in some future version)
|
||||
ParseOldFormat();
|
||||
// ParseOldFormat();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
beammp_error("an error occurred and was ignored during config transfer: " + std::string(e.what()));
|
||||
@ -179,55 +179,6 @@ void TConfig::CreateConfigFile() {
|
||||
FlushToFile();
|
||||
}
|
||||
|
||||
void TConfig::TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, std::string& OutValue) {
|
||||
if (!Env.empty()) {
|
||||
// If this environment variable exists, return a C-String and check if it's empty or not
|
||||
if (const char* envp = std::getenv(Env.data()); envp != nullptr && std::strcmp(envp, "") != 0) {
|
||||
OutValue = std::string(envp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mDisableConfig) {
|
||||
return;
|
||||
}
|
||||
if (Table[Category.c_str()][Key.data()].is_string()) {
|
||||
OutValue = Table[Category.c_str()][Key.data()].as_string();
|
||||
}
|
||||
}
|
||||
|
||||
void TConfig::TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, bool& OutValue) {
|
||||
if (!Env.empty()) {
|
||||
// If this environment variable exists, return a C-String and check if it's empty or not
|
||||
if (const char* envp = std::getenv(Env.data()); envp != nullptr && std::strcmp(envp, "") != 0) {
|
||||
auto Str = std::string(envp);
|
||||
OutValue = Str == "1" || Str == "true";
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mDisableConfig) {
|
||||
return;
|
||||
}
|
||||
if (Table[Category.c_str()][Key.data()].is_boolean()) {
|
||||
OutValue = Table[Category.c_str()][Key.data()].as_boolean();
|
||||
}
|
||||
}
|
||||
|
||||
void TConfig::TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, int& OutValue) {
|
||||
if (!Env.empty()) {
|
||||
// If this environment variable exists, return a C-String and check if it's empty or not
|
||||
if (const char* envp = std::getenv(Env.data()); envp != nullptr && std::strcmp(envp, "") != 0) {
|
||||
OutValue = int(std::strtol(envp, nullptr, 10));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mDisableConfig) {
|
||||
return;
|
||||
}
|
||||
if (Table[Category.c_str()][Key.data()].is_integer()) {
|
||||
OutValue = int(Table[Category.c_str()][Key.data()].as_integer());
|
||||
}
|
||||
}
|
||||
|
||||
// This arcane template magic is needed for using lambdas as overloaded visitors
|
||||
// See https://en.cppreference.com/w/cpp/utility/variant/visit for reference
|
||||
template <class... Ts>
|
||||
|
@ -54,9 +54,6 @@ void THeartbeatThread::operator()() {
|
||||
|
||||
Last = Body;
|
||||
LastNormalUpdateTime = Now;
|
||||
if (!Application::Settings.CustomIP.empty()) {
|
||||
Body += "&ip=" + Application::Settings.CustomIP;
|
||||
}
|
||||
|
||||
auto Target = "/heartbeat";
|
||||
unsigned int ResponseCode = 0;
|
||||
|
@ -334,22 +334,6 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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<const char*>(Data.data()), Data.size());
|
||||
if(Pass != HashPassword(Application::Settings.Password)) {
|
||||
beammp_debug(Client->GetName() + " attempted to connect with a wrong password");
|
||||
ClientKick(*Client, "Wrong password!");
|
||||
return {};
|
||||
} else {
|
||||
beammp_debug(Client->GetName() + " used the correct password");
|
||||
}
|
||||
}
|
||||
|
||||
beammp_debug("Name -> " + Client->GetName() + ", Guest -> " + std::to_string(Client->IsGuest()) + ", Roles -> " + Client->GetRoles());
|
||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||
std::shared_ptr<TClient> Cl;
|
||||
|
@ -123,17 +123,6 @@ TEST_CASE("GetPidVid") {
|
||||
TServer::TServer(const std::vector<std::string_view>& Arguments) {
|
||||
beammp_info("BeamMP Server v" + Application::ServerVersionString());
|
||||
Application::SetSubsystemStatus("Server", Application::Status::Starting);
|
||||
if (Arguments.size() > 1) {
|
||||
Application::Settings.CustomIP = Arguments[0];
|
||||
size_t n = std::count(Application::Settings.CustomIP.begin(), Application::Settings.CustomIP.end(), '.');
|
||||
auto p = Application::Settings.CustomIP.find_first_not_of(".0123456789");
|
||||
if (p != std::string::npos || n != 3 || Application::Settings.CustomIP.substr(0, 3) == "127") {
|
||||
Application::Settings.CustomIP.clear();
|
||||
beammp_warn("IP Specified is invalid! Ignoring");
|
||||
} else {
|
||||
beammp_info("server started with custom IP");
|
||||
}
|
||||
}
|
||||
Application::SetSubsystemStatus("Server", Application::Status::Good);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user