add /unban and /removeuser

This commit is contained in:
in1tiate 2021-03-14 13:44:12 -05:00
parent b562b77be9
commit 9b32188cc6
4 changed files with 64 additions and 1 deletions

View File

@ -193,6 +193,7 @@ class AOClient : public QObject {
void cmdChangeAuth(int argc, QStringList argv);
void cmdSetRootPass(int argc, QStringList argv);
void cmdAddUser(int argc, QStringList argv);
void cmdRemoveUser(int argc, QStringList argv);
void cmdListPerms(int argc, QStringList argv);
void cmdAddPerms(int argc, QStringList argv);
void cmdRemovePerms(int argc, QStringList argv);
@ -218,6 +219,7 @@ class AOClient : public QObject {
// Moderation
void cmdMods(int argc, QStringList argv);
void cmdBan(int argc, QStringList argv);
void cmdUnBan(int argc, QStringList argv);
void cmdKick(int argc, QStringList argv);
void cmdAnnounce(int argc, QStringList argv);
void cmdM(int argc, QStringList argv);
@ -317,7 +319,10 @@ class AOClient : public QObject {
{"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}},
{"mute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdMute}},
{"unmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnmute}},
{"bans", {ACLFlags.value("BAN"), 0, &AOClient::cmdBans}}
{"bans", {ACLFlags.value("BAN"), 0, &AOClient::cmdBans}},
{"unban", {ACLFlags.value("BAN"), 1, &AOClient::cmdUnBan}},
{"removeuser", {ACLFlags.value("MODIFY_USERS"), 1, &AOClient::cmdRemoveUser}},
};
QString partial_packet;

View File

@ -54,8 +54,10 @@ public:
QList<BanInfo> getRecentBans();
void addBan(BanInfo ban);
bool invalidateBan(int id);
bool createUser(QString username, QString salt, QString password, unsigned long long acl);
bool deleteUser(QString username);
unsigned long long getACL(QString moderator_name);
bool authenticate(QString username, QString password);
bool updateACL(QString username, unsigned long long acl, bool mode);

View File

@ -269,6 +269,14 @@ void AOClient::cmdAddUser(int argc, QStringList argv)
sendServerMessage("Unable to create user " + argv[0] + ".\nDoes a user with that name already exist?");
}
void AOClient::cmdRemoveUser(int argc, QStringList argv)
{
if (server->db_manager->deleteUser(argv[0]))
sendServerMessage("Successfully removed user " + argv[0] + ".");
else
sendServerMessage("Unable to remove user " + argv[0] + ".\nDoes it exist?");
}
void AOClient::cmdListPerms(int argc, QStringList argv)
{
unsigned long long user_acl = server->db_manager->getACL(moderator_name);
@ -988,6 +996,20 @@ void AOClient::cmdBans(int argc, QStringList argv)
sendServerMessage(recent_bans.join("\n"));
}
void AOClient::cmdUnBan(int argc, QStringList argv)
{
bool ok;
int target_ban = argv[0].toInt(&ok);
if (!ok) {
sendServerMessage("Invalid ban ID.");
return;
}
else if (server->db_manager->invalidateBan(target_ban))
sendServerMessage("Successfully invalidated ban " + argv[0] + ".");
else
sendServerMessage("Couldn't invalidate ban " + argv[0] + ", are you sure it exists?");
}
QStringList AOClient::buildAreaList(int area_idx)
{
QStringList entries;

View File

@ -187,6 +187,23 @@ void DBManager::addBan(BanInfo ban)
qDebug() << "SQL Error:" << query.lastError().text();
}
bool DBManager::invalidateBan(int id)
{
QSqlQuery ban_exists;
ban_exists.prepare("SELECT DURATION FROM bans WHERE ID = ?");
ban_exists.addBindValue(id);
ban_exists.exec();
if (ban_exists.first())
return false;
QSqlQuery query;
query.prepare("UPDATE bans SET DURATION = 0 WHERE ID = ?");
query.addBindValue(id);
query.exec();
return true;
}
bool DBManager::createUser(QString username, QString salt, QString password, unsigned long long acl)
{
QSqlQuery username_exists;
@ -215,6 +232,23 @@ bool DBManager::createUser(QString username, QString salt, QString password, uns
return true;
}
bool DBManager::deleteUser(QString username)
{
QSqlQuery username_exists;
username_exists.prepare("SELECT ACL FROM users WHERE USERNAME = ?");
username_exists.addBindValue(username);
username_exists.exec();
if (username_exists.first())
return false;
QSqlQuery query;
query.prepare("DELETE FROM users WHERE USERNAME = ?");
username_exists.addBindValue(username);
username_exists.exec();
return true;
}
unsigned long long DBManager::getACL(QString moderator_name)
{
if (moderator_name == "")