1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +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

@ -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)