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:
parent
9ce9d7f433
commit
b580c66b61
3 changed files with 15 additions and 26 deletions
|
@ -1572,7 +1572,8 @@ void Server::SendChatMessage(session_t peer_id, const ChatMessage &message)
|
||||||
if (peer_id != PEER_ID_INEXISTENT) {
|
if (peer_id != PEER_ID_INEXISTENT) {
|
||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
} else {
|
} 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);
|
ChatMessage chatmsg(line);
|
||||||
|
|
||||||
std::vector<session_t> clients = m_clients.getClientIDs();
|
SendChatMessage(PEER_ID_INEXISTENT, chatmsg);
|
||||||
for (u16 cid : clients)
|
|
||||||
SendChatMessage(cid, chatmsg);
|
|
||||||
|
|
||||||
return L"";
|
return L"";
|
||||||
}
|
}
|
||||||
|
|
|
@ -767,33 +767,22 @@ void ClientInterface::sendCustom(session_t peer_id, u8 channel, NetworkPacket *p
|
||||||
m_con->Send(peer_id, channel, pkt, reliable);
|
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);
|
RecursiveMutexAutoLock clientslock(m_clients_mutex);
|
||||||
for (auto &client_it : m_clients) {
|
for (auto &[peer_id, client] : m_clients) {
|
||||||
RemoteClient *client = client_it.second;
|
if (client->getState() >= state_min)
|
||||||
|
m_con->Send(peer_id, ccf.channel, pkt, ccf.reliable);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteClient* ClientInterface::getClientNoEx(session_t peer_id, ClientState state_min)
|
RemoteClient* ClientInterface::getClientNoEx(session_t peer_id, ClientState state_min)
|
||||||
{
|
{
|
||||||
RecursiveMutexAutoLock clientslock(m_clients_mutex);
|
RecursiveMutexAutoLock clientslock(m_clients_mutex);
|
||||||
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
|
RemoteClient *client = lockedGetClientNoEx(peer_id, state_min);
|
||||||
// The client may not exist; clients are immediately removed if their
|
return client;
|
||||||
// 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* ClientInterface::lockedGetClientNoEx(session_t peer_id, ClientState state_min)
|
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
|
// The client may not exist; clients are immediately removed if their
|
||||||
// access is denied, and this event occurs later then.
|
// access is denied, and this event occurs later then.
|
||||||
if (n == m_clients.end())
|
if (n == m_clients.end())
|
||||||
return NULL;
|
return nullptr;
|
||||||
|
|
||||||
|
assert(n->second->peer_id == peer_id);
|
||||||
if (n->second->getState() >= state_min)
|
if (n->second->getState() >= state_min)
|
||||||
return n->second;
|
return n->second;
|
||||||
|
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientState ClientInterface::getClientState(session_t peer_id)
|
ClientState ClientInterface::getClientState(session_t peer_id)
|
||||||
|
|
|
@ -458,7 +458,7 @@ public:
|
||||||
void sendCustom(session_t peer_id, u8 channel, NetworkPacket *pkt, bool reliable);
|
void sendCustom(session_t peer_id, u8 channel, NetworkPacket *pkt, bool reliable);
|
||||||
|
|
||||||
/* send to all clients */
|
/* send to all clients */
|
||||||
void sendToAll(NetworkPacket *pkt);
|
void sendToAll(NetworkPacket *pkt, ClientState state_min = CS_Active);
|
||||||
|
|
||||||
/* delete a client */
|
/* delete a client */
|
||||||
void DeleteClient(session_t peer_id);
|
void DeleteClient(session_t peer_id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue