Add /baninfo command

- Adds getBanInfo() to db_manager, which queries bans by banid, hdid, or ipid
This commit is contained in:
MangosArentLiterature 2021-04-07 15:26:14 -05:00
parent ea0df75a88
commit 2d793f4a99
4 changed files with 102 additions and 0 deletions

View File

@ -1408,6 +1408,18 @@ class AOClient : public QObject {
*/ */
void cmdJudgeLog(int argc, QStringList argv); void cmdJudgeLog(int argc, QStringList argv);
/**
* @brief Looks up info on a ban.
*
* @details If it is called with **one argument**, that argument is the ban ID to look up.
*
* If it is called with **two arguments**, then the first argument is either a ban ID, an IPID,
* or an HDID, and the the second argument specifies the ID type.
*
* @iscommand
*/
void cmdBanInfo(int argc, QStringList argv);
///@} ///@}
/** /**
@ -1603,6 +1615,7 @@ class AOClient : public QObject {
{"lm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdLM}}, {"lm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdLM}},
{"judgelog", {ACLFlags.value("CM"), 0, &AOClient::cmdJudgeLog}}, {"judgelog", {ACLFlags.value("CM"), 0, &AOClient::cmdJudgeLog}},
{"allow_blankposting", {ACLFlags.value("MODCHAT"), 0, &AOClient::cmdAllow_Blankposting}}, {"allow_blankposting", {ACLFlags.value("MODCHAT"), 0, &AOClient::cmdAllow_Blankposting}},
{"baninfo", {ACLFlags.value("BAN"), 1, &AOClient::cmdBanInfo}},
}; };
/** /**

View File

@ -239,6 +239,15 @@ public:
*/ */
QStringList getUsers(); QStringList getUsers();
/**
* @brief Gets information on a ban.
*
* @param lookup_type The type of ID to search
*
* @param id A Ban ID, IPID, or HDID to search for
*/
QList<BanInfo> getBanInfo(QString lookup_type, QString id);
private: private:
/** /**
* @brief The name of the database connection driver. * @brief The name of the database connection driver.

View File

@ -1311,6 +1311,45 @@ void AOClient::cmdAllow_Blankposting(int argc, QStringList argv)
} }
} }
void AOClient::cmdBanInfo(int argc, QStringList argv)
{
QStringList ban_info;
ban_info << ("Ban Info for " + argv[0]);
ban_info << "-----";
QString lookup_type;
if (argc == 1) {
lookup_type = "banid";
}
else if (argc == 2) {
lookup_type = argv[1];
if (!((lookup_type == "banid") || (lookup_type == "ipid") || (lookup_type == "hdid"))) {
sendServerMessage("Invalid ID type.");
return;
}
}
else {
sendServerMessage("Invalid command.");
return;
}
QString id = argv[0];
for (DBManager::BanInfo ban : server->db_manager->getBanInfo(lookup_type, id)) {
QString banned_until;
if (ban.duration == -2)
banned_until = "The heat death of the universe";
else
banned_until = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("dd.MM.yyyy, hh:mm");
ban_info << "Affected IPID: " + ban.ipid;
ban_info << "Affected HDID: " + ban.hdid;
ban_info << "Reason for ban: " + ban.reason;
ban_info << "Date of ban: " + QDateTime::fromSecsSinceEpoch(ban.time).toString("dd.MM.yyyy, hh:mm");
ban_info << "Ban lasts until: " + banned_until;
ban_info << "-----";
}
sendServerMessage(ban_info.join("\n"));
}
QStringList AOClient::buildAreaList(int area_idx) QStringList AOClient::buildAreaList(int area_idx)
{ {
QStringList entries; QStringList entries;

View File

@ -325,6 +325,47 @@ QStringList DBManager::getUsers()
return users; return users;
} }
QList<DBManager::BanInfo> DBManager::getBanInfo(QString lookup_type, QString id)
{
QList<BanInfo> return_list;
QSqlQuery query;
QList<BanInfo> invalid;
if (lookup_type == "banid") {
query.prepare("SELECT * FROM BANS WHERE ID = ?");
query.addBindValue(id);
query.setForwardOnly(true);
query.exec();
}
else if (lookup_type == "hdid") {
query.prepare("SELECT * FROM BANS WHERE HDID = ?");
query.addBindValue(id);
query.setForwardOnly(true);
query.exec();
}
else if (lookup_type == "ipid") {
query.prepare("SELECT * FROM BANS WHERE IPID = ?");
query.addBindValue(id);
query.setForwardOnly(true);
query.exec();
}
else {
qCritical("Invalid ban lookup type!");
return invalid;
}
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;
}
DBManager::~DBManager() DBManager::~DBManager()
{ {
db.close(); db.close();