diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index d9a38e878..e16494652 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -302,6 +302,7 @@ void Server::handleCommand_Init2(NetworkPacket* pkt) sendMediaAnnouncement(peer_id, lang); RemoteClient *client = getClient(peer_id, CS_InitDone); + assert(client); // Keep client language for server translations client->setLangCode(lang); diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 74ee5e5c9..698b2dba6 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -261,7 +261,7 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_settable(L, table); lua_pushstring(L,"state"); - lua_pushstring(L, ClientInterface::state2Name(info.state).c_str()); + lua_pushstring(L, ClientInterface::state2Name(info.state)); lua_settable(L, table); #endif diff --git a/src/server/clientiface.cpp b/src/server/clientiface.cpp index 13cf14c07..6b5f66456 100644 --- a/src/server/clientiface.cpp +++ b/src/server/clientiface.cpp @@ -47,7 +47,7 @@ const char *ClientInterface::statenames[] = { "SudoMode", }; -std::string ClientInterface::state2Name(ClientState state) +const char *ClientInterface::state2Name(ClientState state) { return statenames[state]; } @@ -703,16 +703,13 @@ void ClientInterface::step(float dtime) RecursiveMutexAutoLock clientslock(m_clients_mutex); for (const auto &it : m_clients) { auto state = it.second->getState(); - if (state >= CS_HelloSent) + if (state >= CS_InitDone) continue; if (it.second->uptime() <= LINGER_TIMEOUT) continue; - // CS_Created means nobody has even noticed the client is there - // (this is before on_prejoinplayer runs) - // CS_Invalid should not happen - // -> log those as warning, the rest as info - std::ostream &os = state == CS_Created || state == CS_Invalid ? - warningstream : infostream; + // Complain louder if this situation is unexpected + auto &os = state == CS_Disconnecting || state == CS_Denied ? + infostream : warningstream; try { Address addr = m_con->GetPeerAddress(it.second->peer_id); os << "Disconnecting lingering client from " diff --git a/src/server/clientiface.h b/src/server/clientiface.h index 44b278e63..30b0454ef 100644 --- a/src/server/clientiface.h +++ b/src/server/clientiface.h @@ -495,7 +495,8 @@ public: m_env = env; } - static std::string state2Name(ClientState state); + static const char *state2Name(ClientState state); + protected: class AutoLock { public: @@ -526,5 +527,7 @@ private: 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; };