rework getClient into getClientsByIpid, alter /ban and /kick to report number of clients affected

This commit is contained in:
in1tiate 2021-03-14 12:11:18 -05:00
parent 18f76d68ea
commit 2a8ed66c4f
3 changed files with 25 additions and 24 deletions

View File

@ -46,7 +46,7 @@ class Server : public QObject {
~Server(); ~Server();
void start(); void start();
AOClient* getClient(QString ipid); QList<AOClient*> getClientsByIpid(QString ipid);
AOClient* getClientByID(int id); AOClient* getClientByID(int id);
void updateCharsTaken(AreaData* area); void updateCharsTaken(AreaData* area);
void broadcast(AOPacket packet, int area_index); void broadcast(AOPacket packet, int area_index);

View File

@ -95,6 +95,7 @@ void AOClient::cmdBan(int argc, QStringList argv)
unsigned long time = QDateTime::currentDateTime().toTime_t(); unsigned long time = QDateTime::currentDateTime().toTime_t();
QString reason = argv[1]; QString reason = argv[1];
bool ban_logged = false; bool ban_logged = false;
int kick_counter = 0;
if (argc > 2) { if (argc > 2) {
for (int i = 2; i < argv.length(); i++) { for (int i = 2; i < argv.length(); i++) {
@ -102,20 +103,21 @@ void AOClient::cmdBan(int argc, QStringList argv)
} }
} }
for (AOClient* client : server->clients) { for (AOClient* client : server->getClientsByIpid(target_ipid)) {
if (client->getIpid() == target_ipid) { if (!ban_logged) {
if (!ban_logged) { ip = client->remote_ip;
ip = client->remote_ip; hdid = client->hwid;
hdid = client->hwid; server->db_manager->addBan(target_ipid, ip, hdid, time, reason);
server->db_manager->addBan(target_ipid, ip, hdid, time, reason); sendServerMessage("Banned user with ipid " + target_ipid + " for reason: " + reason);
sendServerMessage("Banned user with ipid " + target_ipid + " for reason: " + reason); ban_logged = true;
ban_logged = true;
}
client->sendPacket("KB", {reason});
client->socket->close();
} }
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) if (!ban_logged)
sendServerMessage("User with ipid not found!"); sendServerMessage("User with ipid not found!");
} }
@ -124,7 +126,7 @@ void AOClient::cmdKick(int argc, QStringList argv)
{ {
QString target_ipid = argv[0]; QString target_ipid = argv[0];
QString reason = argv[1]; QString reason = argv[1];
bool did_kick = false; int kick_counter = 0;
if (argc > 2) { if (argc > 2) {
for (int i = 2; i < argv.length(); i++) { for (int i = 2; i < argv.length(); i++) {
@ -132,16 +134,14 @@ void AOClient::cmdKick(int argc, QStringList argv)
} }
} }
for (AOClient* client : server->clients) { for (AOClient* client : server->getClientsByIpid(target_ipid)) {
if (client->getIpid() == target_ipid) { client->sendPacket("KK", {reason});
client->sendPacket("KK", {reason}); client->socket->close();
client->socket->close(); kick_counter++;
did_kick = true;
}
} }
if (did_kick) if (kick_counter > 0)
sendServerMessage("Kicked user with ipid " + target_ipid + " for reason: " + reason); sendServerMessage("Kicked " + QString::number(kick_counter) + " client(s) with ipid " + target_ipid + " for reason: " + reason);
else else
sendServerMessage("User with ipid not found!"); sendServerMessage("User with ipid not found!");
} }

View File

@ -185,13 +185,14 @@ int Server::getDiceValue(QString value_type)
return value; return value;
} }
AOClient* Server::getClient(QString ipid) QList<AOClient*> Server::getClientsByIpid(QString ipid)
{ {
QList<AOClient*> return_clients;
for (AOClient* client : clients) { for (AOClient* client : clients) {
if (client->getIpid() == ipid) if (client->getIpid() == ipid)
return client; return_clients.append(client);
} }
return nullptr; return return_clients;
} }
AOClient* Server::getClientByID(int id) AOClient* Server::getClientByID(int id)