1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Extend check for lingering clinets

This commit is contained in:
sfan5 2025-05-27 11:31:16 +02:00
parent 957ebf7368
commit 9ce9d7f433
4 changed files with 12 additions and 11 deletions

View file

@ -302,6 +302,7 @@ void Server::handleCommand_Init2(NetworkPacket* pkt)
sendMediaAnnouncement(peer_id, lang); sendMediaAnnouncement(peer_id, lang);
RemoteClient *client = getClient(peer_id, CS_InitDone); RemoteClient *client = getClient(peer_id, CS_InitDone);
assert(client);
// Keep client language for server translations // Keep client language for server translations
client->setLangCode(lang); client->setLangCode(lang);

View file

@ -261,7 +261,7 @@ int ModApiServer::l_get_player_information(lua_State *L)
lua_settable(L, table); lua_settable(L, table);
lua_pushstring(L,"state"); lua_pushstring(L,"state");
lua_pushstring(L, ClientInterface::state2Name(info.state).c_str()); lua_pushstring(L, ClientInterface::state2Name(info.state));
lua_settable(L, table); lua_settable(L, table);
#endif #endif

View file

@ -47,7 +47,7 @@ const char *ClientInterface::statenames[] = {
"SudoMode", "SudoMode",
}; };
std::string ClientInterface::state2Name(ClientState state) const char *ClientInterface::state2Name(ClientState state)
{ {
return statenames[state]; return statenames[state];
} }
@ -703,16 +703,13 @@ void ClientInterface::step(float dtime)
RecursiveMutexAutoLock clientslock(m_clients_mutex); RecursiveMutexAutoLock clientslock(m_clients_mutex);
for (const auto &it : m_clients) { for (const auto &it : m_clients) {
auto state = it.second->getState(); auto state = it.second->getState();
if (state >= CS_HelloSent) if (state >= CS_InitDone)
continue; continue;
if (it.second->uptime() <= LINGER_TIMEOUT) if (it.second->uptime() <= LINGER_TIMEOUT)
continue; continue;
// CS_Created means nobody has even noticed the client is there // Complain louder if this situation is unexpected
// (this is before on_prejoinplayer runs) auto &os = state == CS_Disconnecting || state == CS_Denied ?
// CS_Invalid should not happen infostream : warningstream;
// -> log those as warning, the rest as info
std::ostream &os = state == CS_Created || state == CS_Invalid ?
warningstream : infostream;
try { try {
Address addr = m_con->GetPeerAddress(it.second->peer_id); Address addr = m_con->GetPeerAddress(it.second->peer_id);
os << "Disconnecting lingering client from " os << "Disconnecting lingering client from "

View file

@ -495,7 +495,8 @@ public:
m_env = env; m_env = env;
} }
static std::string state2Name(ClientState state); static const char *state2Name(ClientState state);
protected: protected:
class AutoLock { class AutoLock {
public: public:
@ -526,5 +527,7 @@ private:
static const char *statenames[]; static const char *statenames[];
static constexpr int LINGER_TIMEOUT = 10; // Note that this puts a fixed timeout on the init & auth phase for a client.
// (lingering is enforced until CS_InitDone)
static constexpr int LINGER_TIMEOUT = 12;
}; };