mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
assign IDs to new players earlier in the connection process
This commit is contained in:
parent
6a47521c7c
commit
056827546e
@ -46,7 +46,7 @@ private:
|
|||||||
void Looper(const std::weak_ptr<TClient>& c);
|
void Looper(const std::weak_ptr<TClient>& c);
|
||||||
int OpenID();
|
int OpenID();
|
||||||
void OnDisconnect(const std::weak_ptr<TClient>& ClientPtr);
|
void OnDisconnect(const std::weak_ptr<TClient>& ClientPtr);
|
||||||
void Parse(TClient& c, const std::vector<uint8_t>& Packet);
|
void HandleResourcePackets(TClient& c, const std::vector<uint8_t>& Packet);
|
||||||
void SendFile(TClient& c, const std::string& Name);
|
void SendFile(TClient& c, const std::string& Name);
|
||||||
static bool TCPSendRaw(TClient& C, ip::tcp::socket& socket, const uint8_t* Data, size_t Size);
|
static bool TCPSendRaw(TClient& C, ip::tcp::socket& socket, const uint8_t* Data, size_t Size);
|
||||||
static void SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name);
|
static void SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name);
|
||||||
|
@ -298,7 +298,7 @@ void LuaAPI::MP::PrintRaw(sol::variadic_args Args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int LuaAPI::PanicHandler(lua_State* State) {
|
int LuaAPI::PanicHandler(lua_State* State) {
|
||||||
//FIXME: unsafe operation, can cause stack overflow
|
// FIXME: unsafe operation, can cause stack overflow
|
||||||
beammp_lua_error("PANIC: " + sol::stack::get<std::string>(State, 1));
|
beammp_lua_error("PANIC: " + sol::stack::get<std::string>(State, 1));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,12 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
return Continue;
|
return Continue;
|
||||||
});
|
});
|
||||||
|
|
||||||
auto Futures = LuaAPI::MP::Engine->TriggerEvent("onPlayerAuth", "", Client->GetName(), Client->GetRoles(), Client->IsGuest(), Client->GetIdentifiers());
|
Client->SetID(OpenID());
|
||||||
|
beammp_info("Assigned ID " + std::to_string(Client->GetID()) + " to " + Client->GetName());
|
||||||
|
|
||||||
|
mServer.InsertClient(Client);
|
||||||
|
|
||||||
|
auto Futures = LuaAPI::MP::Engine->TriggerEvent("onPlayerAuth", "", Client->GetName(), Client->GetRoles(), Client->IsGuest(), Client->GetIdentifiers(), Client->GetID());
|
||||||
TLuaEngine::WaitForAll(Futures);
|
TLuaEngine::WaitForAll(Futures);
|
||||||
bool NotAllowed = std::any_of(Futures.begin(), Futures.end(),
|
bool NotAllowed = std::any_of(Futures.begin(), Futures.end(),
|
||||||
[](const std::shared_ptr<TLuaResult>& Result) {
|
[](const std::shared_ptr<TLuaResult>& Result) {
|
||||||
@ -317,22 +322,24 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (NotAllowed) {
|
bool fitsOnServer = mServer.ClientCount() < size_t(Application::GetSettingInt(StrMaxPlayers)); // || luaplayercountbypass;
|
||||||
ClientKick(*Client, "you are not allowed on the server!");
|
|
||||||
return {};
|
if (!NotAllowed && !NotAllowedWithReason && fitsOnServer) {
|
||||||
} else if (NotAllowedWithReason) {
|
beammp_info("Identification success");
|
||||||
ClientKick(*Client, Reason);
|
TCPClient(Client);
|
||||||
return {};
|
return Client;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mServer.ClientCount() < size_t(Application::GetSettingInt(StrMaxPlayers))) {
|
if (NotAllowed) {
|
||||||
beammp_info("Identification success");
|
ClientKick(*Client, "You are not allowed on the server!");
|
||||||
mServer.InsertClient(Client);
|
} else if (NotAllowedWithReason) {
|
||||||
TCPClient(Client);
|
ClientKick(*Client, Reason);
|
||||||
} else {
|
} else {
|
||||||
ClientKick(*Client, "Server full!");
|
ClientKick(*Client, "Server full!");
|
||||||
}
|
}
|
||||||
return Client;
|
|
||||||
|
mServer.RemoveClient(Client);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TClient> TNetwork::CreateClient(ip::tcp::socket&& TCPSock) {
|
std::shared_ptr<TClient> TNetwork::CreateClient(ip::tcp::socket&& TCPSock) {
|
||||||
@ -581,8 +588,6 @@ void TNetwork::OnConnect(const std::weak_ptr<TClient>& c) {
|
|||||||
beammp_assert(!c.expired());
|
beammp_assert(!c.expired());
|
||||||
beammp_info("Client connected");
|
beammp_info("Client connected");
|
||||||
auto LockedClient = c.lock();
|
auto LockedClient = c.lock();
|
||||||
LockedClient->SetID(OpenID());
|
|
||||||
beammp_info("Assigned ID " + std::to_string(LockedClient->GetID()) + " to " + LockedClient->GetName());
|
|
||||||
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerConnecting", "", LockedClient->GetID()));
|
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerConnecting", "", LockedClient->GetID()));
|
||||||
SyncResources(*LockedClient);
|
SyncResources(*LockedClient);
|
||||||
if (LockedClient->IsDisconnected())
|
if (LockedClient->IsDisconnected())
|
||||||
@ -605,11 +610,11 @@ void TNetwork::SyncResources(TClient& c) {
|
|||||||
constexpr std::string_view Done = "Done";
|
constexpr std::string_view Done = "Done";
|
||||||
if (std::equal(Data.begin(), Data.end(), Done.begin(), Done.end()))
|
if (std::equal(Data.begin(), Data.end(), Done.begin(), Done.end()))
|
||||||
break;
|
break;
|
||||||
Parse(c, Data);
|
HandleResourcePackets(c, Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TNetwork::Parse(TClient& c, const std::vector<uint8_t>& Packet) {
|
void TNetwork::HandleResourcePackets(TClient& c, const std::vector<uint8_t>& Packet) {
|
||||||
if (Packet.empty())
|
if (Packet.empty())
|
||||||
return;
|
return;
|
||||||
char Code = Packet.at(0), SubCode = 0;
|
char Code = Packet.at(0), SubCode = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user