mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-03 14:26:09 +00:00
add lua engine, lua file, server, client, vehicle data, other stuff
This commit is contained in:
committed by
Anonymous275
parent
e5e447c7af
commit
459814a6ec
49
src/TServer.cpp
Normal file
49
src/TServer.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "TServer.h"
|
||||
#include "Client.h"
|
||||
#include "Common.h"
|
||||
|
||||
TServer::TServer(int argc, char** argv) {
|
||||
info("BeamMP Server running version " + Application::ServerVersion());
|
||||
if (argc > 1) {
|
||||
Application::Settings.CustomIP = argv[1];
|
||||
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();
|
||||
warn("IP Specified is invalid! Ignoring");
|
||||
} else {
|
||||
info("server started with custom IP");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TServer::RemoveClient(std::weak_ptr<TClient> WeakClientPtr) {
|
||||
if (!WeakClientPtr.expired()) {
|
||||
TClient& Client = *WeakClientPtr.lock();
|
||||
debug("removing client " + Client.GetName() + " (" + std::to_string(ClientCount()) + ")");
|
||||
Client.ClearCars();
|
||||
WriteLock Lock(_ClientsMutex);
|
||||
_Clients.erase(WeakClientPtr.lock());
|
||||
}
|
||||
}
|
||||
|
||||
std::weak_ptr<TClient> TServer::InsertNewClient() {
|
||||
debug("inserting new client (" + std::to_string(ClientCount()) + ")");
|
||||
WriteLock Lock(_ClientsMutex);
|
||||
auto [Iter, Replaced] = _Clients.insert(std::make_shared<TClient>());
|
||||
return *Iter;
|
||||
}
|
||||
|
||||
void TServer::ForEachClient(std::function<bool(std::weak_ptr<TClient>)> Fn) {
|
||||
ReadLock Lock(_ClientsMutex);
|
||||
for (auto& Client : _Clients) {
|
||||
if (!Fn(Client)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t TServer::ClientCount() const {
|
||||
ReadLock Lock(_ClientsMutex);
|
||||
return _Clients.size();
|
||||
}
|
||||
Reference in New Issue
Block a user