implement bans

This commit is contained in:
scatterflower 2020-09-27 17:44:32 -05:00
parent 594782d19c
commit 26cf130bd0
5 changed files with 45 additions and 3 deletions

View File

@ -74,7 +74,8 @@ class AOClient : public QObject {
const QMap<QString, CommandInfo> commands {
{"login", {false, 1}},
{"getareas", {false, 0 }},
{"getarea", {false, 0}}
{"getarea", {false, 0}},
{"ban", {true, 2}}
};
void handlePacket(AOPacket packet);

View File

@ -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;

View File

@ -48,6 +48,8 @@ class Server : public QObject {
void broadcast(AOPacket packet, int area_index);
void broadcast(AOPacket packet);
QVector<AOClient*> clients;
int player_count;
QStringList characters;
QVector<AreaData*> areas;
@ -66,8 +68,6 @@ class Server : public QObject {
int port;
int ws_port;
QVector<AOClient*> clients;
};
#endif // SERVER_H

View File

@ -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)

View File

@ -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();