mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-08-18 09:17:15 +00:00
Cleanup & optimizations
This commit is contained in:
parent
0580ad67fd
commit
f52308c439
@ -8,7 +8,7 @@
|
||||
class THeartbeatThread : public IThreaded {
|
||||
public:
|
||||
THeartbeatThread(TResourceManager& ResourceManager, TServer& Server);
|
||||
~THeartbeatThread();
|
||||
//~THeartbeatThread();
|
||||
void operator()() override;
|
||||
|
||||
private:
|
||||
|
@ -8,6 +8,7 @@ public:
|
||||
|
||||
[[nodiscard]] uint64_t MaxModSize() const { return mMaxModSize; }
|
||||
[[nodiscard]] std::string FileList() const { return mFileList; }
|
||||
[[nodiscard]] std::string TrimmedList() const { return mTrimmedList; }
|
||||
[[nodiscard]] std::string FileSizes() const { return mFileSizes; }
|
||||
[[nodiscard]] int ModsLoaded() const { return mModsLoaded; }
|
||||
|
||||
@ -15,5 +16,6 @@ private:
|
||||
uint64_t mMaxModSize = 0;
|
||||
std::string mFileSizes;
|
||||
std::string mFileList;
|
||||
std::string mTrimmedList;
|
||||
int mModsLoaded = 0;
|
||||
};
|
@ -12,7 +12,7 @@ class TResourceManager;
|
||||
class TTCPServer : public IThreaded {
|
||||
public:
|
||||
explicit TTCPServer(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& ResourceManager);
|
||||
~TTCPServer();
|
||||
//~TTCPServer();
|
||||
|
||||
void operator()() override;
|
||||
|
||||
@ -27,7 +27,7 @@ public:
|
||||
|
||||
TUDPServer& UDPServer() { return mUDPServer->get(); }
|
||||
|
||||
void SyncClient(std::weak_ptr<TClient> c);
|
||||
void SyncClient(const std::weak_ptr<TClient>& c);
|
||||
void Identify(SOCKET TCPSock);
|
||||
void Authentication(SOCKET TCPSock);
|
||||
bool CheckBytes(TClient& c, int32_t BytesRcv);
|
||||
@ -43,10 +43,10 @@ private:
|
||||
bool mShutdown { false };
|
||||
|
||||
void HandleDownload(SOCKET TCPSock);
|
||||
void OnConnect(std::weak_ptr<TClient> c);
|
||||
void TCPClient(std::weak_ptr<TClient> c);
|
||||
void OnConnect(const std::weak_ptr<TClient>& c);
|
||||
void TCPClient(const std::weak_ptr<TClient>& c);
|
||||
int OpenID();
|
||||
void OnDisconnect(std::weak_ptr<TClient> ClientPtr, bool kicked);
|
||||
void OnDisconnect(const std::weak_ptr<TClient>& ClientPtr, bool kicked);
|
||||
void Parse(TClient& c, const std::string& Packet);
|
||||
void SendFile(TClient& c, const std::string& Name);
|
||||
static bool TCPSendRaw(SOCKET C, char* Data, int32_t Size);
|
||||
|
@ -69,7 +69,7 @@ std::string THeartbeatThread::GenerateCall() {
|
||||
<< "&clientversion=" << Application::ClientVersion()
|
||||
<< "&name=" << Application::Settings.ServerName
|
||||
<< "&pps=" << Application::PPS()
|
||||
<< "&modlist=" << mResourceManager.FileList()
|
||||
<< "&modlist=" << mResourceManager.TrimmedList()
|
||||
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
||||
<< "&modstotal=" << mResourceManager.ModsLoaded()
|
||||
<< "&playerslist=" << GetPlayers()
|
||||
@ -91,7 +91,7 @@ THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& S
|
||||
}
|
||||
std::string THeartbeatThread::GetPlayers() {
|
||||
std::string Return;
|
||||
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||
if (!ClientPtr.expired()) {
|
||||
Return += ClientPtr.lock()->GetName() + ";";
|
||||
}
|
||||
@ -99,5 +99,5 @@ std::string THeartbeatThread::GetPlayers() {
|
||||
});
|
||||
return Return;
|
||||
}
|
||||
THeartbeatThread::~THeartbeatThread() {
|
||||
}
|
||||
/*THeartbeatThread::~THeartbeatThread() {
|
||||
}*/
|
||||
|
@ -10,17 +10,23 @@ TResourceManager::TResourceManager() {
|
||||
if (!fs::exists(Path))
|
||||
fs::create_directories(Path);
|
||||
for (const auto& entry : fs::directory_iterator(Path)) {
|
||||
auto pos = entry.path().string().find(".zip");
|
||||
if (pos != std::string::npos) {
|
||||
if (entry.path().string().length() - pos == 4) {
|
||||
mFileList += entry.path().string() + ";";
|
||||
mFileSizes += std::to_string(uint64_t(fs::file_size(entry.path()))) + ";";
|
||||
std::string File(entry.path().string());
|
||||
if (auto pos = File.find(".zip"); pos != std::string::npos) {
|
||||
if (File.length() - pos == 4) {
|
||||
std::replace(File.begin(), File.end(),'\\','/');
|
||||
mFileList += File + ';';
|
||||
if(auto i = File.find_last_of('/'); i != std::string::npos){
|
||||
++i;
|
||||
File = File.substr(i,pos-i);
|
||||
}
|
||||
mTrimmedList += File + ';';
|
||||
mFileSizes += std::to_string(uint64_t(fs::file_size(entry.path()))) + ';';
|
||||
mMaxModSize += uint64_t(fs::file_size(entry.path()));
|
||||
mModsLoaded++;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::replace(mFileList.begin(), mFileList.end(), '\\', '/');
|
||||
|
||||
if (mModsLoaded)
|
||||
info("Loaded " + std::to_string(mModsLoaded) + " Mods");
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ void TTCPServer::HandleDownload(SOCKET TCPSock) {
|
||||
return;
|
||||
}
|
||||
auto ID = uint8_t(D);
|
||||
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||
if (!ClientPtr.expired()) {
|
||||
auto c = ClientPtr.lock();
|
||||
if (c->GetID() == ID) {
|
||||
@ -264,7 +264,7 @@ void TTCPServer::ClientKick(TClient& c, const std::string& R) {
|
||||
CloseSocketProper(c.GetTCPSock());
|
||||
}
|
||||
|
||||
void TTCPServer::TCPClient(std::weak_ptr<TClient> c) {
|
||||
void TTCPServer::TCPClient(const std::weak_ptr<TClient>& c) {
|
||||
// TODO: the c.expired() might cause issues here, remove if you end up here with your debugger
|
||||
if (c.expired() || c.lock()->GetTCPSock() == -1) {
|
||||
mServer.RemoveClient(c);
|
||||
@ -290,7 +290,7 @@ void TTCPServer::TCPClient(std::weak_ptr<TClient> c) {
|
||||
|
||||
void TTCPServer::UpdatePlayer(TClient& Client) {
|
||||
std::string Packet = ("Ss") + std::to_string(mServer.ClientCount()) + "/" + std::to_string(Application::Settings.MaxPlayers) + ":";
|
||||
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||
if (!ClientPtr.expired()) {
|
||||
auto c = ClientPtr.lock();
|
||||
Packet += c->GetName() + ",";
|
||||
@ -301,7 +301,7 @@ void TTCPServer::UpdatePlayer(TClient& Client) {
|
||||
Respond(Client, Packet, true);
|
||||
}
|
||||
|
||||
void TTCPServer::OnDisconnect(std::weak_ptr<TClient> ClientPtr, bool kicked) {
|
||||
void TTCPServer::OnDisconnect(const std::weak_ptr<TClient>& ClientPtr, bool kicked) {
|
||||
Assert(!ClientPtr.expired());
|
||||
auto LockedClientPtr = ClientPtr.lock();
|
||||
TClient& c = *LockedClientPtr;
|
||||
@ -332,7 +332,7 @@ int TTCPServer::OpenID() {
|
||||
bool found;
|
||||
do {
|
||||
found = true;
|
||||
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||
if (!ClientPtr.expired()) {
|
||||
auto c = ClientPtr.lock();
|
||||
if (c->GetID() == ID) {
|
||||
@ -346,7 +346,7 @@ int TTCPServer::OpenID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
void TTCPServer::OnConnect(std::weak_ptr<TClient> c) {
|
||||
void TTCPServer::OnConnect(const std::weak_ptr<TClient>& c) {
|
||||
Assert(!c.expired());
|
||||
info("Client connected");
|
||||
auto LockedClient = c.lock();
|
||||
@ -522,7 +522,7 @@ void TTCPServer::Respond(TClient& c, const std::string& MSG, bool Rel) {
|
||||
}
|
||||
}
|
||||
|
||||
void TTCPServer::SyncClient(std::weak_ptr<TClient> c) {
|
||||
void TTCPServer::SyncClient(const std::weak_ptr<TClient>& c) {
|
||||
if (c.expired()) {
|
||||
return;
|
||||
}
|
||||
@ -535,7 +535,7 @@ void TTCPServer::SyncClient(std::weak_ptr<TClient> c) {
|
||||
UDPServer().SendToAll(LockedClient.get(), ("JWelcome ") + LockedClient->GetName() + "!", false, true);
|
||||
TriggerLuaEvent(("onPlayerJoin"), false, nullptr, std::make_unique<TLuaArg>(TLuaArg { { LockedClient->GetID() } }), false);
|
||||
bool Return = false;
|
||||
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||
if (!ClientPtr.expired()) {
|
||||
auto client = ClientPtr.lock();
|
||||
if (client != LockedClient) {
|
||||
@ -658,5 +658,5 @@ void TTCPServer::operator()() {
|
||||
CloseSocketProper(client);
|
||||
#endif
|
||||
}
|
||||
TTCPServer::~TTCPServer() {
|
||||
}
|
||||
/*TTCPServer::~TTCPServer() {
|
||||
}*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user