fix more stuff

This commit is contained in:
Lion Kortlepel 2021-02-17 01:06:02 +01:00 committed by Anonymous275
parent d360403c56
commit aec6ad9c14
8 changed files with 22 additions and 17 deletions

View File

@ -14,7 +14,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
if (UNIX) if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -s -fno-builtin") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -s -fno-builtin")
if (SANITIZE) if (SANITIZE)
message(STATUS "sanitize is ON") message(STATUS "sanitize is ON")
@ -43,7 +43,7 @@ add_executable(BeamMP-Server
include/TResourceManager.h src/TResourceManager.cpp include/TResourceManager.h src/TResourceManager.cpp
include/THeartbeatThread.h src/THeartbeatThread.cpp include/THeartbeatThread.h src/THeartbeatThread.cpp
include/Http.h src/Http.cpp include/Http.h src/Http.cpp
include/SocketIO.h src/SocketIO.cpp # include/SocketIO.h src/SocketIO.cpp
include/TPPSMonitor.h src/TPPSMonitor.cpp include/TPPSMonitor.h src/TPPSMonitor.cpp
include/TUDPServer.h src/TUDPServer.cpp include/TUDPServer.h src/TUDPServer.cpp
include/TTCPServer.h src/TTCPServer.cpp) include/TTCPServer.h src/TTCPServer.cpp)

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#include <deque>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <deque>
#include "TConsole.h" #include "TConsole.h"
@ -31,9 +31,6 @@ public:
int Port {}; int Port {};
std::string CustomIP; std::string CustomIP;
[[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); } [[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); }
// new settings
std::string ResourceFolder;
}; };
using TShutdownHandler = std::function<void()>; using TShutdownHandler = std::function<void()>;
@ -80,4 +77,3 @@ static inline void luaprint(const std::string& str) {
#define Biggest 30000 #define Biggest 30000
std::string Comp(std::string Data); std::string Comp(std::string Data);
std::string DeComp(std::string Compressed); std::string DeComp(std::string Compressed);

View File

@ -7,8 +7,11 @@ class IThreaded {
public: public:
IThreaded() IThreaded()
// invokes operator() on this object // invokes operator() on this object
: mThread(std::thread([this] { (*this)(); })) { } : mThread() { }
virtual void Start() final {
mThread = std::thread([this] { (*this)(); });
}
virtual void operator()() = 0; virtual void operator()() = 0;
protected: protected:

View File

@ -2,7 +2,7 @@
#include "Client.h" #include "Client.h"
#include "Http.h" #include "Http.h"
#include "SocketIO.h" //#include "SocketIO.h"
#include <sstream> #include <sstream>
void THeartbeatThread::operator()() { void THeartbeatThread::operator()() {
@ -27,12 +27,12 @@ void THeartbeatThread::operator()() {
if (!Application::Settings.CustomIP.empty()) if (!Application::Settings.CustomIP.empty())
Body += "&ip=" + Application::Settings.CustomIP; Body += "&ip=" + Application::Settings.CustomIP;
T = Http::POST("backend.beammp.com", "/heartbeat", {}, Body, false); T = Http::POST("beammp.com", "/heartbeatv2", {}, Body, false);
if (T.substr(0, 2) != "20") { if (T.substr(0, 2) != "20") {
//Backend system refused server startup! //Backend system refused server startup!
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
T = Http::POST("backend.beammp.com", "/heartbeat", {}, Body, false); T = Http::POST("beammp.com", "/heartbeatv2", {}, Body, false);
// TODO backup2 + HTTP flag (no TSL) // TODO backup2 + HTTP flag (no TSL)
if (T.substr(0, 2) != "20") { if (T.substr(0, 2) != "20") {
warn("Backend system refused server! Server might not show in the public list"); warn("Backend system refused server! Server might not show in the public list");
@ -51,7 +51,7 @@ void THeartbeatThread::operator()() {
} }
} }
SocketIO::Get().SetAuthenticated(isAuth); //SocketIO::Get().SetAuthenticated(isAuth);
} }
} }
std::string THeartbeatThread::GenerateCall() { std::string THeartbeatThread::GenerateCall() {
@ -78,6 +78,7 @@ THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& S
: mResourceManager(ResourceManager) : mResourceManager(ResourceManager)
, mServer(Server) { , mServer(Server) {
Application::RegisterShutdownHandler([&] { mShutdown = true; }); Application::RegisterShutdownHandler([&] { mShutdown = true; });
Start();
} }
std::string THeartbeatThread::GetPlayers() { std::string THeartbeatThread::GetPlayers() {
std::string Return; std::string Return;

View File

@ -9,14 +9,15 @@ TLuaEngine::TLuaEngine(TServer& Server, TTCPServer& TCPServer, TUDPServer& UDPSe
: mTCPServer(TCPServer) : mTCPServer(TCPServer)
, mUDPServer(UDPServer) , mUDPServer(UDPServer)
, mServer(Server) { , mServer(Server) {
if (!fs::exists(Application::Settings.ResourceFolder)) { if (!fs::exists(Application::Settings.Resource)) {
fs::create_directory(Application::Settings.ResourceFolder); fs::create_directory(Application::Settings.Resource);
} }
std::string Path = Application::Settings.ResourceFolder + ("/Server"); std::string Path = Application::Settings.Resource + ("/Server");
if (!fs::exists(Path)) { if (!fs::exists(Path)) {
fs::create_directory(Path); fs::create_directory(Path);
} }
FolderList(Path, false); FolderList(Path, false);
Start();
} }
void TLuaEngine::operator()() { void TLuaEngine::operator()() {

View File

@ -5,6 +5,7 @@ TPPSMonitor::TPPSMonitor(TServer& Server)
: mServer(Server) { : mServer(Server) {
Application::SetPPS("-"); Application::SetPPS("-");
Application::RegisterShutdownHandler([&] { mShutdown = true; }); Application::RegisterShutdownHandler([&] { mShutdown = true; });
Start();
} }
void TPPSMonitor::operator()() { void TPPSMonitor::operator()() {
while (!mShutdown) { while (!mShutdown) {

View File

@ -20,6 +20,7 @@ TTCPServer::TTCPServer(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManage
, mPPSMonitor(PPSMonitor) , mPPSMonitor(PPSMonitor)
, mResourceManager(ResourceManager) { , mResourceManager(ResourceManager) {
Application::RegisterShutdownHandler([this] { mShutdown = true; }); Application::RegisterShutdownHandler([this] { mShutdown = true; });
Start();
} }
void TTCPServer::Identify(SOCKET TCPSock) { void TTCPServer::Identify(SOCKET TCPSock) {
@ -115,8 +116,8 @@ void TTCPServer::Authentication(SOCKET TCPSock) {
Cl->SetStatus(-2); Cl->SetStatus(-2);
return false; return false;
} }
return true;
} }
return true;
}); });
auto arg = std::make_unique<TLuaArg>(TLuaArg { { LockedClient->GetName(), LockedClient->GetRoles(), LockedClient->IsGuest() } }); auto arg = std::make_unique<TLuaArg>(TLuaArg { { LockedClient->GetName(), LockedClient->GetRoles(), LockedClient->IsGuest() } });
@ -284,6 +285,7 @@ void TTCPServer::UpdatePlayers() {
auto c = ClientPtr.lock(); auto c = ClientPtr.lock();
Packet += c->GetName() + ","; Packet += c->GetName() + ",";
} }
return true;
}); });
Packet = Packet.substr(0, Packet.length() - 1); Packet = Packet.substr(0, Packet.length() - 1);
UDPServer().SendToAll(nullptr, Packet, true, true); UDPServer().SendToAll(nullptr, Packet, true, true);
@ -327,8 +329,8 @@ int TTCPServer::OpenID() {
found = false; found = false;
ID++; ID++;
} }
return true;
} }
return true;
}); });
} while (!found); } while (!found);
return ID; return ID;

View File

@ -9,6 +9,7 @@ TUDPServer::TUDPServer(TServer& Server, TPPSMonitor& PPSMonitor, TTCPServer& TCP
: mServer(Server) : mServer(Server)
, mPPSMonitor(PPSMonitor) , mPPSMonitor(PPSMonitor)
, mTCPServer(TCPServer) { , mTCPServer(TCPServer) {
Start();
} }
void TUDPServer::operator()() { void TUDPServer::operator()() {