mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-04 14:56:04 +00:00
Cleanup & optimizations
This commit is contained in:
committed by
Anonymous275
parent
0580ad67fd
commit
f52308c439
@@ -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() {
|
||||
}*/
|
||||
|
||||
Reference in New Issue
Block a user