From 97528e641ccd77bee8d411724126c1d20450a568 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Sat, 18 Jun 2022 01:39:27 +0200 Subject: [PATCH] Expand kick_other to consider the hwid --- core/include/aoclient.h | 3 +++ core/include/server.h | 9 +++++++++ core/src/commands/moderation.cpp | 20 +++++++++++++++----- core/src/server.cpp | 10 ++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/core/include/aoclient.h b/core/include/aoclient.h index 60f65d2..130f64f 100644 --- a/core/include/aoclient.h +++ b/core/include/aoclient.h @@ -1367,6 +1367,9 @@ class AOClient : public QObject * * @details This command gracefully removes all multiclients from the server, disconnecting them and freeing their used character. * + * @arg argv This command allows the user to specify if it should look for IPID or HWID matches. This is useful when a client mayb + * have been connected over IPv6 and the second connection is made over IPv4 + * * @iscommand */ void cmdKickOther(int argc, QStringList argv); diff --git a/core/include/server.h b/core/include/server.h index fd1404a..7b690e6 100644 --- a/core/include/server.h +++ b/core/include/server.h @@ -117,6 +117,15 @@ class Server : public QObject */ QList getClientsByIpid(QString ipid); + /** + * @brief Gets a list of pointers to all clients with the given HWID. + * + * @param HWID The HWID to look for. + * + * @return A list of clients whose HWID match. List may be empty. + */ + QList getClientsByHwid(QString f_hwid); + /** * @brief Gets a pointer to a client by user ID. * diff --git a/core/src/commands/moderation.cpp b/core/src/commands/moderation.cpp index 8216b56..fb68b01 100644 --- a/core/src/commands/moderation.cpp +++ b/core/src/commands/moderation.cpp @@ -638,12 +638,22 @@ void AOClient::cmdKickOther(int argc, QStringList argv) int l_kick_counter = 0; - const QList l_target_clients = server->getClientsByIpid(m_ipid); - for (AOClient *l_target_client : l_target_clients) { - if (l_target_client != this) { - l_target_client->m_socket->close(); - l_kick_counter++; + QList l_target_clients; + const QList l_targets_hwid = server->getClientsByHwid(m_hwid); + l_target_clients = server->getClientsByIpid(m_ipid); + + // Merge both lookups into one single list.) + for (AOClient *l_target_candidate : qAsConst(l_targets_hwid)) { + if (!l_target_clients.contains(l_target_candidate)) { + l_target_clients.append(l_target_candidate); } } + + // The list is unique, we can only have on instance of the current client. + l_target_clients.removeOne(this); + for (AOClient *l_target_client : qAsConst(l_target_clients)) { + l_target_client->m_socket->close(); + l_kick_counter++; + } sendServerMessage("Kicked " + QString::number(l_kick_counter) + " multiclients from the server."); } diff --git a/core/src/server.cpp b/core/src/server.cpp index a74b829..00827a8 100644 --- a/core/src/server.cpp +++ b/core/src/server.cpp @@ -456,6 +456,16 @@ QList Server::getClientsByIpid(QString ipid) return return_clients; } +QList Server::getClientsByHwid(QString f_hwid) +{ + QList return_clients; + for (AOClient *l_client : qAsConst(m_clients)) { + if (l_client->getHwid() == f_hwid) + return_clients.append(l_client); + } + return return_clients; +} + AOClient *Server::getClientByID(int id) { return m_clients_ids.value(id);