diff --git a/include/server.h b/include/server.h index 14c4883..16f045a 100644 --- a/include/server.h +++ b/include/server.h @@ -46,7 +46,7 @@ class Server : public QObject { ~Server(); void start(); - AOClient* getClient(QString ipid); + QList getClientsByIpid(QString ipid); AOClient* getClientByID(int id); void updateCharsTaken(AreaData* area); void broadcast(AOPacket packet, int area_index); diff --git a/src/commands.cpp b/src/commands.cpp index 04243a9..6756859 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -95,6 +95,7 @@ void AOClient::cmdBan(int argc, QStringList argv) unsigned long time = QDateTime::currentDateTime().toTime_t(); QString reason = argv[1]; bool ban_logged = false; + int kick_counter = 0; if (argc > 2) { for (int i = 2; i < argv.length(); i++) { @@ -102,20 +103,21 @@ void AOClient::cmdBan(int argc, QStringList argv) } } - for (AOClient* client : server->clients) { - if (client->getIpid() == target_ipid) { - if (!ban_logged) { - ip = client->remote_ip; - hdid = client->hwid; - server->db_manager->addBan(target_ipid, ip, hdid, time, reason); - sendServerMessage("Banned user with ipid " + target_ipid + " for reason: " + reason); - ban_logged = true; - } - client->sendPacket("KB", {reason}); - client->socket->close(); + for (AOClient* client : server->getClientsByIpid(target_ipid)) { + if (!ban_logged) { + ip = client->remote_ip; + hdid = client->hwid; + server->db_manager->addBan(target_ipid, ip, hdid, time, reason); + sendServerMessage("Banned user with ipid " + target_ipid + " for reason: " + reason); + ban_logged = true; } + client->sendPacket("KB", {reason}); + client->socket->close(); + kick_counter++; } + if (kick_counter > 1) + sendServerMessage("Kicked " + QString::number(kick_counter) + " clients with matching ipids"); if (!ban_logged) sendServerMessage("User with ipid not found!"); } @@ -124,7 +126,7 @@ void AOClient::cmdKick(int argc, QStringList argv) { QString target_ipid = argv[0]; QString reason = argv[1]; - bool did_kick = false; + int kick_counter = 0; if (argc > 2) { for (int i = 2; i < argv.length(); i++) { @@ -132,16 +134,14 @@ void AOClient::cmdKick(int argc, QStringList argv) } } - for (AOClient* client : server->clients) { - if (client->getIpid() == target_ipid) { - client->sendPacket("KK", {reason}); - client->socket->close(); - did_kick = true; - } + for (AOClient* client : server->getClientsByIpid(target_ipid)) { + client->sendPacket("KK", {reason}); + client->socket->close(); + kick_counter++; } - if (did_kick) - sendServerMessage("Kicked user with ipid " + target_ipid + " for reason: " + reason); + if (kick_counter > 0) + sendServerMessage("Kicked " + QString::number(kick_counter) + " client(s) with ipid " + target_ipid + " for reason: " + reason); else sendServerMessage("User with ipid not found!"); } diff --git a/src/server.cpp b/src/server.cpp index 35d0281..17c6efc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -185,13 +185,14 @@ int Server::getDiceValue(QString value_type) return value; } -AOClient* Server::getClient(QString ipid) +QList Server::getClientsByIpid(QString ipid) { + QList return_clients; for (AOClient* client : clients) { if (client->getIpid() == ipid) - return client; + return_clients.append(client); } - return nullptr; + return return_clients; } AOClient* Server::getClientByID(int id)