diff --git a/include/aoclient.h b/include/aoclient.h index 1424ea1..0f48c30 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -74,7 +74,8 @@ class AOClient : public QObject { const QMap commands { {"login", {false, 1}}, {"getareas", {false, 0 }}, - {"getarea", {false, 0}} + {"getarea", {false, 0}}, + {"ban", {true, 2}} }; void handlePacket(AOPacket packet); diff --git a/include/ban_manager.h b/include/ban_manager.h index 2a50085..42ceb40 100644 --- a/include/ban_manager.h +++ b/include/ban_manager.h @@ -37,6 +37,8 @@ public: QString getBanReason(QHostAddress ip); QString getBanReason(QString hdid); + void addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason); + private: const QString DRIVER; QSqlDatabase db; diff --git a/include/server.h b/include/server.h index ecada84..01b5fb9 100644 --- a/include/server.h +++ b/include/server.h @@ -48,6 +48,8 @@ class Server : public QObject { void broadcast(AOPacket packet, int area_index); void broadcast(AOPacket packet); + QVector clients; + int player_count; QStringList characters; QVector areas; @@ -66,8 +68,6 @@ class Server : public QObject { int port; int ws_port; - - QVector clients; }; #endif // SERVER_H diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 53bbddf..acb2f4a 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -350,6 +350,33 @@ void AOClient::handleCommand(QString command, int argc, QStringList argv) } sendServerMessage(entries.join("\n")); } + else if (command == "ban") { + QString ipid = argv[0]; + QHostAddress ip; + QString hdid; + unsigned long time = QDateTime::currentDateTime().toTime_t(); + QString reason = argv[1]; + + if (argc > 2) { + for (int i = 2; i < argv.length(); i++) { + reason += argv[i]; + } + } + + for (AOClient* client : server->clients) { + if (client->getIpid() == ipid) { + ip = client->remote_ip; + hdid = client->hwid; + server->ban_manager->addBan(ipid, ip, hdid, time, reason); + sendServerMessage("Banned user with ipid " + ipid + " for reason: " + reason); + sendPacket("KB", {reason}); + socket->close(); + return; + } + } + + sendServerMessage("User with ipid not found!"); + } } void AOClient::arup(ARUPType type, bool broadcast) diff --git a/src/ban_manager.cpp b/src/ban_manager.cpp index 5b72f7e..4368012 100644 --- a/src/ban_manager.cpp +++ b/src/ban_manager.cpp @@ -69,6 +69,18 @@ QString BanManager::getBanReason(QString hdid) } } +void BanManager::addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason) +{ + QSqlQuery query; + query.prepare("INSERT INTO BANS(IPID, HDID, IP, TIME, REASON) VALUES(?, ?, ?, ?, ?)"); + query.addBindValue(ipid); + query.addBindValue(hdid); + query.addBindValue(ip.toString()); + query.addBindValue(QString::number(time)); + query.addBindValue(reason); + query.exec(); +} + BanManager::~BanManager() { db.close();