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

Restrict minimum state for ClientInterface::sendToAll

This commit is contained in:
sfan5 2025-05-27 11:55:18 +02:00
parent 9ce9d7f433
commit b580c66b61
3 changed files with 15 additions and 26 deletions

View file

@ -1572,7 +1572,8 @@ void Server::SendChatMessage(session_t peer_id, const ChatMessage &message)
if (peer_id != PEER_ID_INEXISTENT) {
Send(&pkt);
} else {
m_clients.sendToAll(&pkt);
// If a client has completed auth but is still joining, still send chat
m_clients.sendToAll(&pkt, CS_InitDone);
}
}
@ -3183,9 +3184,7 @@ std::wstring Server::handleChat(const std::string &name,
ChatMessage chatmsg(line);
std::vector<session_t> clients = m_clients.getClientIDs();
for (u16 cid : clients)
SendChatMessage(cid, chatmsg);
SendChatMessage(PEER_ID_INEXISTENT, chatmsg);
return L"";
}

View file

@ -767,33 +767,22 @@ void ClientInterface::sendCustom(session_t peer_id, u8 channel, NetworkPacket *p
m_con->Send(peer_id, channel, pkt, reliable);
}
void ClientInterface::sendToAll(NetworkPacket *pkt)
void ClientInterface::sendToAll(NetworkPacket *pkt, ClientState state_min)
{
auto &ccf = clientCommandFactoryTable[pkt->getCommand()];
FATAL_ERROR_IF(!ccf.name, "packet type missing in table");
RecursiveMutexAutoLock clientslock(m_clients_mutex);
for (auto &client_it : m_clients) {
RemoteClient *client = client_it.second;
if (client->net_proto_version != 0) {
auto &ccf = clientCommandFactoryTable[pkt->getCommand()];
FATAL_ERROR_IF(!ccf.name, "packet type missing in table");
m_con->Send(client->peer_id, ccf.channel, pkt, ccf.reliable);
}
for (auto &[peer_id, client] : m_clients) {
if (client->getState() >= state_min)
m_con->Send(peer_id, ccf.channel, pkt, ccf.reliable);
}
}
RemoteClient* ClientInterface::getClientNoEx(session_t peer_id, ClientState state_min)
{
RecursiveMutexAutoLock clientslock(m_clients_mutex);
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if (n == m_clients.end())
return NULL;
if (n->second->getState() >= state_min)
return n->second;
return NULL;
RemoteClient *client = lockedGetClientNoEx(peer_id, state_min);
return client;
}
RemoteClient* ClientInterface::lockedGetClientNoEx(session_t peer_id, ClientState state_min)
@ -802,12 +791,13 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(session_t peer_id, ClientStat
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if (n == m_clients.end())
return NULL;
return nullptr;
assert(n->second->peer_id == peer_id);
if (n->second->getState() >= state_min)
return n->second;
return NULL;
return nullptr;
}
ClientState ClientInterface::getClientState(session_t peer_id)

View file

@ -458,7 +458,7 @@ public:
void sendCustom(session_t peer_id, u8 channel, NetworkPacket *pkt, bool reliable);
/* send to all clients */
void sendToAll(NetworkPacket *pkt);
void sendToAll(NetworkPacket *pkt, ClientState state_min = CS_Active);
/* delete a client */
void DeleteClient(session_t peer_id);