add /bans

This commit is contained in:
in1tiate 2021-03-14 13:13:26 -05:00
parent 535c05f3e2
commit b5779b1aa5
4 changed files with 50 additions and 1 deletions

View File

@ -224,6 +224,7 @@ class AOClient : public QObject {
void cmdGM(int argc, QStringList argv);
void cmdMute(int argc, QStringList argv);
void cmdUnmute(int argc, QStringList argv);
void cmdBans(int argc, QStringList argv);
// Casing/RP
void cmdPlay(int argc, QStringList argv);
void cmdNeed(int argc, QStringList argv);
@ -315,7 +316,8 @@ class AOClient : public QObject {
{"m", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdM}},
{"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}},
{"mute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdMute}},
{"unmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnmute}}
{"unmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnmute}},
{"bans", {ACLFlags.value("BAN"), 0, &AOClient::cmdBans}}
};
QString partial_packet;

View File

@ -41,6 +41,16 @@ public:
long long getBanDuration(QString hdid);
long long getBanDuration(QHostAddress hdid);
struct BanInfo {
QString ipid;
QHostAddress ip;
QString hdid;
unsigned long time;
QString reason;
long long duration;
};
QList<BanInfo> getRecentBans();
void addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason, long long duration);
bool createUser(QString username, QString salt, QString password, unsigned long long acl);

View File

@ -971,6 +971,22 @@ void AOClient::cmdUnmute(int argc, QStringList argv)
server->getClientByID(uid)->is_muted = false;
}
void AOClient::cmdBans(int argc, QStringList argv)
{
QStringList recent_bans;
recent_bans << "Last 5 bans:";
recent_bans << "-----";
for (DBManager::BanInfo ban : server->db_manager->getRecentBans()) {
recent_bans << "Affected IPID: " + ban.ipid;
recent_bans << "Affected HDID: " + ban.hdid;
recent_bans << "Reason for ban: " + ban.reason;
recent_bans << "Date of ban: " + QDateTime::fromSecsSinceEpoch(ban.time).toString("dd.MM.yyyy, hh:mm");
recent_bans << "Ban lasts until: " + QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("dd.MM.yyyy, hh:mm");
recent_bans << "-----";
}
sendServerMessage(recent_bans.join("\n"));
}
QStringList AOClient::buildAreaList(int area_idx)
{
QStringList entries;

View File

@ -122,6 +122,27 @@ long long DBManager::getBanDuration(QHostAddress ip)
}
}
QList<DBManager::BanInfo> DBManager::getRecentBans()
{
QList<BanInfo> return_list;
QSqlQuery query;
query.prepare("SELECT TOP(5) * FROM BANS ORDER BY TIME DESC");
query.setForwardOnly(true);
query.exec();
while (query.next()) {
BanInfo ban;
ban.ipid = query.value(0).toString();
ban.hdid = query.value(1).toString();
ban.ip = QHostAddress(query.value(2).toString());
ban.time = static_cast<unsigned long>(query.value(3).toULongLong());
ban.reason = query.value(4).toString();
ban.duration = query.value(5).toLongLong();
return_list.append(ban);
}
std::reverse(return_list.begin(), return_list.end());
return return_list;
}
void DBManager::addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason, long long duration)
{
QSqlQuery query;