AOClient madness

This commit is contained in:
Salanto 2021-09-11 19:46:40 +02:00
parent 318d12eb7d
commit f523fc6ec0
12 changed files with 1092 additions and 1089 deletions

View File

@ -34,6 +34,8 @@
#include <QRandomGenerator>
#endif
class Server;
/**
* @brief Represents a client connected to the server running Attorney Online 2 or one of its derivatives.
*/
@ -51,7 +53,7 @@ class AOClient : public QObject {
AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr, int user_id = 0)
: QObject(parent), m_id(user_id), m_remote_ip(p_socket->peerAddress()), m_password(""),
m_joined(false), m_current_area(0), m_current_char(""), m_socket(p_socket), server(p_server),
is_partial(false), last_wtce_time(0) {
is_partial(false), m_last_wtce_time(0) {
m_afk_timer = new QTimer;
m_afk_timer->setSingleShot(true);
connect(m_afk_timer, SIGNAL(timeout()), this, SLOT(onAfkTimeout()));
@ -1894,7 +1896,7 @@ class AOClient : public QObject {
* @return The parsed text, converted into their respective durations, summed up, then converted into seconds.
*/
long long parseTime(QString input);
QString getReprimand(bool positive = false);
QString getReprimand(bool f_positive = false);
/**
* @brief Adds the last send IC-Message to QVector of the respective area.
@ -1935,7 +1937,7 @@ class AOClient : public QObject {
*
* @return True if the password meets the requirements, otherwise false.
*/
bool checkPasswordRequirements(QString username, QString password);
bool checkPasswordRequirements(QString f_username, QString f_password);
/**
* @brief Sends a server notice.
@ -1944,7 +1946,7 @@ class AOClient : public QObject {
*
* @param global Whether or not the notice should be server-wide.
*/
void sendNotice(QString notice, bool global = false);
void sendNotice(QString f_notice, bool f_global = false);
/**
@ -2143,14 +2145,14 @@ class AOClient : public QObject {
* @details Generated based on the client's own supplied hardware ID.
* The client supplied hardware ID is generally a machine unique ID.
*/
QString hwid;
QString m_hwid;
/**
* @brief The IPID of the client.
*
* @details Generated based on the client's IP, but cannot be reversed to identify the client's IP.
*/
QString ipid;
QString m_ipid;
/**
* @brief The time in seconds since the client last sent a Witness Testimony / Cross Examination
@ -2158,14 +2160,14 @@ class AOClient : public QObject {
*
* @details Used to filter out potential spam.
*/
long last_wtce_time;
long m_last_wtce_time;
/**
* @brief The text of the last in-character message that was sent by the client.
*
* @details Used to determine if the incoming message is a duplicate.
*/
QString last_message;
QString m_last_message;
/**
* @brief A helper function to add recorded packets to an area's judgelog.

View File

@ -19,31 +19,31 @@
void AOClient::clientData()
{
if (last_read + socket->bytesAvailable() > 30720) { // Client can send a max of 30KB to the server over two sequential reads
socket->close();
if (last_read + m_socket->bytesAvailable() > 30720) { // Client can send a max of 30KB to the server over two sequential reads
m_socket->close();
}
if (last_read == 0) { // i.e. this is the first packet we've been sent
if (!socket->waitForConnected(1000)) {
socket->close();
if (!m_socket->waitForConnected(1000)) {
m_socket->close();
}
}
QString data = QString::fromUtf8(socket->readAll());
last_read = data.size();
QString l_data = QString::fromUtf8(m_socket->readAll());
last_read = l_data.size();
if (is_partial) {
data = partial_packet + data;
l_data = partial_packet + l_data;
}
if (!data.endsWith("%")) {
if (!l_data.endsWith("%")) {
is_partial = true;
}
QStringList all_packets = data.split("%");
all_packets.removeLast(); // Remove the entry after the last delimiter
QStringList l_all_packets = l_data.split("%");
l_all_packets.removeLast(); // Remove the entry after the last delimiter
for (const QString &single_packet : qAsConst(all_packets)) {
AOPacket packet(single_packet);
handlePacket(packet);
for (const QString &l_single_packet : qAsConst(l_all_packets)) {
AOPacket l_packet(l_single_packet);
handlePacket(l_packet);
}
}
@ -52,20 +52,20 @@ void AOClient::clientDisconnected()
#ifdef NET_DEBUG
qDebug() << remote_ip.toString() << "disconnected";
#endif
if (joined) {
if (m_joined) {
server->m_player_count--;
server->m_areas[current_area]->clientLeftArea(server->getCharID(current_char));
server->m_areas[m_current_area]->clientLeftArea(server->getCharID(m_current_char));
arup(ARUPType::PLAYER_COUNT, true);
}
if (current_char != "") {
server->updateCharsTaken(server->m_areas[current_area]);
if (m_current_char != "") {
server->updateCharsTaken(server->m_areas[m_current_area]);
}
bool l_updateLocks = false;
for (AreaData* area : qAsConst(server->m_areas)) {
l_updateLocks = l_updateLocks || area->removeOwner(id);
for (AreaData* l_area : qAsConst(server->m_areas)) {
l_updateLocks = l_updateLocks || l_area->removeOwner(m_id);
}
if (l_updateLocks)
@ -78,105 +78,105 @@ void AOClient::handlePacket(AOPacket packet)
#ifdef NET_DEBUG
qDebug() << "Received packet:" << packet.header << ":" << packet.contents << "args length:" << packet.contents.length();
#endif
AreaData* area = server->m_areas[current_area];
PacketInfo info = packets.value(packet.header, {false, 0, &AOClient::pktDefault});
AreaData* l_area = server->m_areas[m_current_area];
PacketInfo l_info = packets.value(packet.header, {false, 0, &AOClient::pktDefault});
if (packet.contents.join("").size() > 16384) {
return;
}
if (!checkAuth(info.acl_mask)) {
if (!checkAuth(l_info.acl_mask)) {
return;
}
if (packet.header != "CH") {
if (is_afk)
if (m_is_afk)
sendServerMessage("You are no longer AFK.");
is_afk = false;
afk_timer->start(ConfigManager::afkTimeout() * 1000);
m_is_afk = false;
m_afk_timer->start(ConfigManager::afkTimeout() * 1000);
}
if (packet.contents.length() < info.minArgs) {
if (packet.contents.length() < l_info.minArgs) {
#ifdef NET_DEBUG
qDebug() << "Invalid packet args length. Minimum is" << info.minArgs << "but only" << packet.contents.length() << "were given.";
#endif
return;
}
(this->*(info.action))(area, packet.contents.length(), packet.contents, packet);
(this->*(l_info.action))(l_area, packet.contents.length(), packet.contents, packet);
}
void AOClient::changeArea(int new_area)
{
if (current_area == new_area) {
sendServerMessage("You are already in area " + server->m_area_names[current_area]);
if (m_current_area == new_area) {
sendServerMessage("You are already in area " + server->m_area_names[m_current_area]);
return;
}
if (server->m_areas[new_area]->lockStatus() == AreaData::LockStatus::LOCKED && !server->m_areas[new_area]->invited().contains(id) && !checkAuth(ACLFlags.value("BYPASS_LOCKS"))) {
if (server->m_areas[new_area]->lockStatus() == AreaData::LockStatus::LOCKED && !server->m_areas[new_area]->invited().contains(m_id) && !checkAuth(ACLFlags.value("BYPASS_LOCKS"))) {
sendServerMessage("Area " + server->m_area_names[new_area] + " is locked.");
return;
}
if (current_char != "") {
server->m_areas[current_area]->changeCharacter(server->getCharID(current_char), -1);
server->updateCharsTaken(server->m_areas[current_area]);
if (m_current_char != "") {
server->m_areas[m_current_area]->changeCharacter(server->getCharID(m_current_char), -1);
server->updateCharsTaken(server->m_areas[m_current_area]);
}
server->m_areas[current_area]->clientLeftArea(char_id);
bool character_taken = false;
if (server->m_areas[new_area]->charactersTaken().contains(server->getCharID(current_char))) {
current_char = "";
char_id = -1;
character_taken = true;
server->m_areas[m_current_area]->clientLeftArea(m_char_id);
bool l_character_taken = false;
if (server->m_areas[new_area]->charactersTaken().contains(server->getCharID(m_current_char))) {
m_current_char = "";
m_char_id = -1;
l_character_taken = true;
}
server->m_areas[new_area]->clientJoinedArea(char_id);
current_area = new_area;
server->m_areas[new_area]->clientJoinedArea(m_char_id);
m_current_area = new_area;
arup(ARUPType::PLAYER_COUNT, true);
sendEvidenceList(server->m_areas[new_area]);
sendPacket("HP", {"1", QString::number(server->m_areas[new_area]->defHP())});
sendPacket("HP", {"2", QString::number(server->m_areas[new_area]->proHP())});
sendPacket("BN", {server->m_areas[new_area]->background()});
if (character_taken) {
if (l_character_taken) {
sendPacket("DONE");
}
const QList<QTimer*> timers = server->m_areas[current_area]->timers();
for (QTimer* timer : timers) {
int timer_id = server->m_areas[current_area]->timers().indexOf(timer) + 1;
if (timer->isActive()) {
sendPacket("TI", {QString::number(timer_id), "2"});
sendPacket("TI", {QString::number(timer_id), "0", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(timer->remainingTime())))});
const QList<QTimer*> l_timers = server->m_areas[m_current_area]->timers();
for (QTimer* l_timer : l_timers) {
int l_timer_id = server->m_areas[m_current_area]->timers().indexOf(l_timer) + 1;
if (l_timer->isActive()) {
sendPacket("TI", {QString::number(l_timer_id), "2"});
sendPacket("TI", {QString::number(l_timer_id), "0", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(l_timer->remainingTime())))});
}
else {
sendPacket("TI", {QString::number(timer_id), "3"});
sendPacket("TI", {QString::number(l_timer_id), "3"});
}
}
sendServerMessage("You moved to area " + server->m_area_names[current_area]);
if (server->m_areas[current_area]->lockStatus() == AreaData::LockStatus::SPECTATABLE)
sendServerMessage("Area " + server->m_area_names[current_area] + " is spectate-only; to chat IC you will need to be invited by the CM.");
sendServerMessage("You moved to area " + server->m_area_names[m_current_area]);
if (server->m_areas[m_current_area]->lockStatus() == AreaData::LockStatus::SPECTATABLE)
sendServerMessage("Area " + server->m_area_names[m_current_area] + " is spectate-only; to chat IC you will need to be invited by the CM.");
}
bool AOClient::changeCharacter(int char_id)
{
AreaData* area = server->m_areas[current_area];
AreaData* l_area = server->m_areas[m_current_area];
if(char_id >= server->m_characters.length())
return false;
if (is_charcursed && !charcurse_list.contains(char_id)) {
if (m_is_charcursed && !m_charcurse_list.contains(char_id)) {
return false;
}
bool l_successfulChange = area->changeCharacter(server->getCharID(current_char), char_id);
bool l_successfulChange = l_area->changeCharacter(server->getCharID(m_current_char), char_id);
if (char_id < 0) {
current_char = "";
m_current_char = "";
}
if (l_successfulChange == true) {
QString char_selected = server->m_characters[char_id];
current_char = char_selected;
pos = "";
server->updateCharsTaken(area);
sendPacket("PV", {QString::number(id), "CID", QString::number(char_id)});
QString l_char_selected = server->m_characters[char_id];
m_current_char = l_char_selected;
m_pos = "";
server->updateCharsTaken(l_area);
sendPacket("PV", {QString::number(m_id), "CID", QString::number(char_id)});
return true;
}
return false;
@ -184,60 +184,60 @@ bool AOClient::changeCharacter(int char_id)
void AOClient::changePosition(QString new_pos)
{
pos = new_pos;
sendServerMessage("Position changed to " + pos + ".");
sendPacket("SP", {pos});
m_pos = new_pos;
sendServerMessage("Position changed to " + m_pos + ".");
sendPacket("SP", {m_pos});
}
void AOClient::handleCommand(QString command, int argc, QStringList argv)
{
CommandInfo info = commands.value(command, {false, -1, &AOClient::cmdDefault});
CommandInfo l_info = commands.value(command, {false, -1, &AOClient::cmdDefault});
if (!checkAuth(info.acl_mask)) {
if (!checkAuth(l_info.acl_mask)) {
sendServerMessage("You do not have permission to use that command.");
return;
}
if (argc < info.minArgs) {
if (argc < l_info.minArgs) {
sendServerMessage("Invalid command syntax.");
return;
}
(this->*(info.action))(argc, argv);
(this->*(l_info.action))(argc, argv);
}
void AOClient::arup(ARUPType type, bool broadcast)
{
QStringList arup_data;
arup_data.append(QString::number(type));
for (AreaData* area : qAsConst(server->m_areas)) {
QStringList l_arup_data;
l_arup_data.append(QString::number(type));
for (AreaData* l_area : qAsConst(server->m_areas)) {
switch(type) {
case ARUPType::PLAYER_COUNT: {
arup_data.append(QString::number(area->playerCount()));
l_arup_data.append(QString::number(l_area->playerCount()));
break;
}
case ARUPType::STATUS: {
QString area_status = QVariant::fromValue(area->status()).toString().replace("_", "-"); // LOOKING_FOR_PLAYERS to LOOKING-FOR-PLAYERS
arup_data.append(area_status);
QString l_area_status = QVariant::fromValue(l_area->status()).toString().replace("_", "-"); // LOOKING_FOR_PLAYERS to LOOKING-FOR-PLAYERS
l_arup_data.append(l_area_status);
break;
}
case ARUPType::CM: {
if (area->owners().isEmpty())
arup_data.append("FREE");
if (l_area->owners().isEmpty())
l_arup_data.append("FREE");
else {
QStringList area_owners;
const QList<int> owner_ids = area->owners();
for (int owner_id : owner_ids) {
AOClient* owner = server->getClientByID(owner_id);
area_owners.append("[" + QString::number(owner->id) + "] " + owner->current_char);
QStringList l_area_owners;
const QList<int> l_owner_ids = l_area->owners();
for (int l_owner_id : l_owner_ids) {
AOClient* l_owner = server->getClientByID(l_owner_id);
l_area_owners.append("[" + QString::number(l_owner->m_id) + "] " + l_owner->m_current_char);
}
arup_data.append(area_owners.join(", "));
l_arup_data.append(l_area_owners.join(", "));
}
break;
}
case ARUPType::LOCKED: {
QString lock_status = QVariant::fromValue(area->lockStatus()).toString();
arup_data.append(lock_status);
QString l_lock_status = QVariant::fromValue(l_area->lockStatus()).toString();
l_arup_data.append(l_lock_status);
break;
}
default: {
@ -246,9 +246,9 @@ void AOClient::arup(ARUPType type, bool broadcast)
}
}
if (broadcast)
server->broadcast(AOPacket("ARUP", arup_data));
server->broadcast(AOPacket("ARUP", l_arup_data));
else
sendPacket("ARUP", arup_data);
sendPacket("ARUP", l_arup_data);
}
void AOClient::fullArup() {
@ -268,8 +268,8 @@ void AOClient::sendPacket(AOPacket packet)
.replaceInStrings("$", "<dollar>");
if (packet.header != "LE")
packet.contents.replaceInStrings("&", "<and>");
socket->write(packet.toUtf8());
socket->flush();
m_socket->write(packet.toUtf8());
m_socket->flush();
}
void AOClient::sendPacket(QString header, QStringList contents)
@ -292,9 +292,9 @@ void AOClient::calculateIpid()
QCryptographicHash hash(QCryptographicHash::Md5); // Don't need security, just hashing for uniqueness
hash.addData(remote_ip.toString().toUtf8());
hash.addData(m_remote_ip.toString().toUtf8());
ipid = hash.result().toHex().right(8); // Use the last 8 characters (4 bytes)
m_ipid = hash.result().toHex().right(8); // Use the last 8 characters (4 bytes)
}
void AOClient::sendServerMessage(QString message)
@ -304,7 +304,7 @@ void AOClient::sendServerMessage(QString message)
void AOClient::sendServerMessageArea(QString message)
{
server->broadcast(AOPacket("CT", {ConfigManager::serverName(), message, "1"}), current_area);
server->broadcast(AOPacket("CT", {ConfigManager::serverName(), message, "1"}), m_current_area);
}
void AOClient::sendServerBroadcast(QString message)
@ -319,20 +319,20 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
#endif
if (acl_mask != ACLFlags.value("NONE")) {
if (acl_mask == ACLFlags.value("CM")) {
AreaData* area = server->m_areas[current_area];
if (area->owners().contains(id))
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->owners().contains(m_id))
return true;
}
else if (!authenticated) {
else if (!m_authenticated) {
return false;
}
switch (ConfigManager::authType()) {
case DataTypes::AuthType::SIMPLE:
return authenticated;
return m_authenticated;
break;
case DataTypes::AuthType::ADVANCED:
unsigned long long user_acl = server->db_manager->getACL(moderator_name);
return (user_acl & acl_mask) != 0;
unsigned long long l_user_acl = server->db_manager->getACL(m_moderator_name);
return (l_user_acl & acl_mask) != 0;
break;
}
}
@ -340,19 +340,19 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
}
QString AOClient::getIpid() const { return ipid; }
QString AOClient::getIpid() const { return m_ipid; }
QString AOClient::getHwid() const { return hwid; }
QString AOClient::getHwid() const { return m_hwid; }
Server* AOClient::getServer() { return server; }
void AOClient::onAfkTimeout()
{
if (!is_afk)
if (!m_is_afk)
sendServerMessage("You are now AFK.");
is_afk = true;
m_is_afk = true;
}
AOClient::~AOClient() {
socket->deleteLater();
m_socket->deleteLater();
}

View File

@ -25,7 +25,7 @@ void AOClient::cmdLogin(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
if (authenticated) {
if (m_authenticated) {
sendServerMessage("You are already logged in!");
return;
}
@ -37,13 +37,13 @@ void AOClient::cmdLogin(int argc, QStringList argv)
}
else {
sendServerMessage("Entering login prompt.\nPlease enter the server modpass.");
is_logging_in = true;
m_is_logging_in = true;
return;
}
break;
case DataTypes::AuthType::ADVANCED:
sendServerMessage("Entering login prompt.\nPlease enter your username and password.");
is_logging_in = true;
m_is_logging_in = true;
return;
break;
}
@ -73,20 +73,20 @@ void AOClient::cmdSetRootPass(int argc, QStringList argv)
}
sendServerMessage("Changing auth type and setting root password.\nLogin again with /login root [password]");
authenticated = false;
m_authenticated = false;
ConfigManager::setAuthType(DataTypes::AuthType::ADVANCED);
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
qsrand(QDateTime::currentMSecsSinceEpoch());
quint32 upper_salt = qrand();
quint32 lower_salt = qrand();
quint64 salt_number = (upper_salt << 32) | lower_salt;
quint32 l_upper_salt = qrand();
quint32 l_lower_salt = qrand();
quint64 l_salt_number = (upper_salt << 32) | lower_salt;
#else
quint64 salt_number = QRandomGenerator::system()->generate64();
quint64 l_salt_number = QRandomGenerator::system()->generate64();
#endif
QString salt = QStringLiteral("%1").arg(salt_number, 16, 16, QLatin1Char('0'));
QString l_salt = QStringLiteral("%1").arg(l_salt_number, 16, 16, QLatin1Char('0'));
server->db_manager->createUser("root", salt, argv[0], ACLFlags.value("SUPER"));
server->db_manager->createUser("root", l_salt, argv[0], ACLFlags.value("SUPER"));
}
void AOClient::cmdAddUser(int argc, QStringList argv)
@ -99,15 +99,15 @@ void AOClient::cmdAddUser(int argc, QStringList argv)
}
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
qsrand(QDateTime::currentMSecsSinceEpoch());
quint32 upper_salt = qrand();
quint32 lower_salt = qrand();
quint64 salt_number = (upper_salt << 32) | lower_salt;
quint32 l_upper_salt = qrand();
quint32 l_lower_salt = qrand();
quint64 l_salt_number = (upper_salt << 32) | lower_salt;
#else
quint64 salt_number = QRandomGenerator::system()->generate64();
quint64 l_salt_number = QRandomGenerator::system()->generate64();
#endif
QString salt = QStringLiteral("%1").arg(salt_number, 16, 16, QLatin1Char('0'));
QString l_salt = QStringLiteral("%1").arg(l_salt_number, 16, 16, QLatin1Char('0'));
if (server->db_manager->createUser(argv[0], salt, argv[1], ACLFlags.value("NONE")))
if (server->db_manager->createUser(argv[0], l_salt, argv[1], ACLFlags.value("NONE")))
sendServerMessage("Created user " + argv[0] + ".\nUse /addperm to modify their permissions.");
else
sendServerMessage("Unable to create user " + argv[0] + ".\nDoes a user with that name already exist?");
@ -125,60 +125,60 @@ void AOClient::cmdRemoveUser(int argc, QStringList argv)
void AOClient::cmdListPerms(int argc, QStringList argv)
{
unsigned long long user_acl = server->db_manager->getACL(moderator_name);
QStringList message;
const QStringList keys = ACLFlags.keys();
unsigned long long l_user_acl = server->db_manager->getACL(m_moderator_name);
QStringList l_message;
const QStringList l_keys = ACLFlags.keys();
if (argc == 0) {
// Just print out all permissions available to the user.
message.append("You have been given the following permissions:");
for (const QString &perm : keys) {
if (perm == "NONE"); // don't need to list this one
else if (perm == "SUPER") {
if (user_acl == ACLFlags.value("SUPER")) // This has to be checked separately, because SUPER & anything will always be truthy
message.append("SUPER (Be careful! This grants the user all permissions.)");
l_message.append("You have been given the following permissions:");
for (const QString &l_perm : l_keys) {
if (l_perm == "NONE"); // don't need to list this one
else if (l_perm == "SUPER") {
if (l_user_acl == ACLFlags.value("SUPER")) // This has to be checked separately, because SUPER & anything will always be truthy
l_message.append("SUPER (Be careful! This grants the user all permissions.)");
}
else if ((ACLFlags.value(perm) & user_acl) == 0); // user doesn't have this permission, don't print it
else if ((ACLFlags.value(l_perm) & l_user_acl) == 0); // user doesn't have this permission, don't print it
else
message.append(perm);
l_message.append(l_perm);
}
}
else {
if ((user_acl & ACLFlags.value("MODIFY_USERS")) == 0) {
if ((l_user_acl & ACLFlags.value("MODIFY_USERS")) == 0) {
sendServerMessage("You do not have permission to view other users' permissions.");
return;
}
message.append("User " + argv[0] + " has the following permissions:");
unsigned long long acl = server->db_manager->getACL(argv[0]);
if (acl == 0) {
l_message.append("User " + argv[0] + " has the following permissions:");
unsigned long long l_acl = server->db_manager->getACL(argv[0]);
if (l_acl == 0) {
sendServerMessage("This user either doesn't exist, or has no permissions set.");
return;
}
for (const QString &perm : keys) {
if ((ACLFlags.value(perm) & acl) != 0 && perm != "SUPER") {
message.append(perm);
for (const QString &l_perm : l_keys) {
if ((ACLFlags.value(l_perm) & l_acl) != 0 && l_perm != "SUPER") {
l_message.append(l_perm);
}
}
}
sendServerMessage(message.join("\n"));
sendServerMessage(l_message.join("\n"));
}
void AOClient::cmdAddPerms(int argc, QStringList argv)
{
Q_UNUSED(argc);
unsigned long long user_acl = server->db_manager->getACL(moderator_name);
unsigned long long l_user_acl = server->db_manager->getACL(m_moderator_name);
argv[1] = argv[1].toUpper();
const QStringList keys = ACLFlags.keys();
const QStringList l_keys = ACLFlags.keys();
if (!keys.contains(argv[1])) {
if (!l_keys.contains(argv[1])) {
sendServerMessage("That permission doesn't exist!");
return;
}
if (argv[1] == "SUPER") {
if (user_acl != ACLFlags.value("SUPER")) {
if (l_user_acl != ACLFlags.value("SUPER")) {
// This has to be checked separately, because SUPER & anything will always be truthy
sendServerMessage("You aren't allowed to add that permission!");
return;
@ -189,9 +189,9 @@ void AOClient::cmdAddPerms(int argc, QStringList argv)
return;
}
unsigned long long newperm = ACLFlags.value(argv[1]);
if ((newperm & user_acl) != 0) {
if (server->db_manager->updateACL(argv[0], newperm, true))
unsigned long long l_newperm = ACLFlags.value(argv[1]);
if ((l_newperm & l_user_acl) != 0) {
if (server->db_manager->updateACL(argv[0], l_newperm, true))
sendServerMessage("Successfully added permission " + argv[1] + " to user " + argv[0]);
else
sendServerMessage(argv[0] + " wasn't found!");
@ -205,12 +205,12 @@ void AOClient::cmdRemovePerms(int argc, QStringList argv)
{
Q_UNUSED(argc);
unsigned long long user_acl = server->db_manager->getACL(moderator_name);
unsigned long long l_user_acl = server->db_manager->getACL(m_moderator_name);
argv[1] = argv[1].toUpper();
const QStringList keys = ACLFlags.keys();
const QStringList l_keys = ACLFlags.keys();
if (!keys.contains(argv[1])) {
if (!l_keys.contains(argv[1])) {
sendServerMessage("That permission doesn't exist!");
return;
}
@ -221,7 +221,7 @@ void AOClient::cmdRemovePerms(int argc, QStringList argv)
}
if (argv[1] == "SUPER") {
if (user_acl != ACLFlags.value("SUPER")) {
if (l_user_acl != ACLFlags.value("SUPER")) {
// This has to be checked separately, because SUPER & anything will always be truthy
sendServerMessage("You aren't allowed to remove that permission!");
return;
@ -232,9 +232,9 @@ void AOClient::cmdRemovePerms(int argc, QStringList argv)
return;
}
unsigned long long newperm = ACLFlags.value(argv[1]);
if ((newperm & user_acl) != 0) {
if (server->db_manager->updateACL(argv[0], newperm, false))
unsigned long long l_newperm = ACLFlags.value(argv[1]);
if ((l_newperm & l_user_acl) != 0) {
if (server->db_manager->updateACL(argv[0], l_newperm, false))
sendServerMessage("Successfully removed permission " + argv[1] + " from user " + argv[0]);
else
sendServerMessage(argv[0] + " wasn't found!");
@ -249,8 +249,8 @@ void AOClient::cmdListUsers(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QStringList users = server->db_manager->getUsers();
sendServerMessage("All users:\n" + users.join("\n"));
QStringList l_users = server->db_manager->getUsers();
sendServerMessage("All users:\n" + l_users.join("\n"));
}
void AOClient::cmdLogout(int argc, QStringList argv)
@ -258,42 +258,42 @@ void AOClient::cmdLogout(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
if (!authenticated) {
if (!m_authenticated) {
sendServerMessage("You are not logged in!");
return;
}
authenticated = false;
moderator_name = "";
m_authenticated = false;
m_moderator_name = "";
sendPacket("AUTH", {"-1"}); // Client: "You were logged out."
}
void AOClient::cmdChangePassword(int argc, QStringList argv)
{
QString username;
QString password;
QString l_username;
QString l_password;
if (argc == 1) {
if (moderator_name.isEmpty()) {
if (m_moderator_name.isEmpty()) {
sendServerMessage("You are not logged in.");
return;
}
username = moderator_name;
password = argv[0];
l_username = m_moderator_name;
l_password = argv[0];
}
else if (argc == 2 && checkAuth(ACLFlags.value("SUPER"))) {
username = argv[0];
password = argv[1];
l_username = argv[0];
l_password = argv[1];
}
else {
sendServerMessage("Invalid command syntax.");
return;
}
if (!checkPasswordRequirements(username, password)) {
if (!checkPasswordRequirements(l_username, l_password)) {
sendServerMessage("Password does not meet server requirements.");
return;
}
if (server->db_manager->updatePassword(username, password)) {
if (server->db_manager->updatePassword(l_username, l_password)) {
sendServerMessage("Successfully changed password.");
}
else {

View File

@ -22,14 +22,14 @@
void AOClient::cmdDoc(int argc, QStringList argv)
{
QString sender_name = ooc_name;
AreaData* area = server->m_areas[current_area];
QString l_sender_name = m_ooc_name;
AreaData* l_area = server->m_areas[m_current_area];
if (argc == 0) {
sendServerMessage("Document: " + area->document());
sendServerMessage("Document: " + l_area->document());
}
else {
area->changeDoc(argv.join(" "));
sendServerMessageArea(sender_name + " changed the document.");
l_area->changeDoc(argv.join(" "));
sendServerMessageArea(l_sender_name + " changed the document.");
}
}
@ -38,26 +38,26 @@ void AOClient::cmdClearDoc(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QString sender_name = ooc_name;
AreaData* area = server->m_areas[current_area];
area->changeDoc("No document.");
sendServerMessageArea(sender_name + " cleared the document.");
QString l_sender_name = m_ooc_name;
AreaData* l_area = server->m_areas[m_current_area];
l_area->changeDoc("No document.");
sendServerMessageArea(l_sender_name + " cleared the document.");
}
void AOClient::cmdEvidenceMod(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* area = server->m_areas[current_area];
AreaData* l_area = server->m_areas[m_current_area];
argv[0] = argv[0].toLower();
if (argv[0] == "cm")
area->setEviMod(AreaData::EvidenceMod::CM);
l_area->setEviMod(AreaData::EvidenceMod::CM);
else if (argv[0] == "mod")
area->setEviMod(AreaData::EvidenceMod::MOD);
l_area->setEviMod(AreaData::EvidenceMod::MOD);
else if (argv[0] == "hiddencm")
area->setEviMod(AreaData::EvidenceMod::HIDDEN_CM);
l_area->setEviMod(AreaData::EvidenceMod::HIDDEN_CM);
else if (argv[0] == "ffa")
area->setEviMod(AreaData::EvidenceMod::FFA);
l_area->setEviMod(AreaData::EvidenceMod::FFA);
else {
sendServerMessage("Invalid evidence mod.");
return;
@ -65,36 +65,36 @@ void AOClient::cmdEvidenceMod(int argc, QStringList argv)
sendServerMessage("Changed evidence mod.");
// Resend evidence lists to everyone in the area
sendEvidenceList(area);
sendEvidenceList(l_area);
}
void AOClient::cmdEvidence_Swap(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* area = server->m_areas[current_area];
int ev_size = area->evidence().size() -1;
AreaData* l_area = server->m_areas[m_current_area];
int l_ev_size = l_area->evidence().size() -1;
if (ev_size < 0) {
if (l_ev_size < 0) {
sendServerMessage("No evidence in area.");
return;
}
bool ok, ok2;
int ev_id1 = argv[0].toInt(&ok), ev_id2 = argv[1].toInt(&ok2);
int l_ev_id1 = argv[0].toInt(&ok), l_ev_id2 = argv[1].toInt(&ok2);
if ((!ok || !ok2)) {
sendServerMessage("Invalid evidence ID.");
return;
}
if ((ev_id1 < 0) || (ev_id2 < 0)) {
if ((l_ev_id1 < 0) || (l_ev_id2 < 0)) {
sendServerMessage("Evidence ID can't be negative.");
return;
}
if ((ev_id2 <= ev_size) && (ev_id1 <= ev_size)) {
area->swapEvidence(ev_id1, ev_id2);
sendEvidenceList(area);
sendServerMessage("The evidence " + QString::number(ev_id1) + " and " + QString::number(ev_id2) + " have been swapped.");
if ((l_ev_id2 <= l_ev_size) && (l_ev_id1 <= l_ev_size)) {
l_area->swapEvidence(l_ev_id1, l_ev_id2);
sendEvidenceList(l_area);
sendServerMessage("The evidence " + QString::number(l_ev_id1) + " and " + QString::number(l_ev_id2) + " have been swapped.");
}
else {
sendServerMessage("Unable to swap evidence. Evidence ID out of range.");
@ -106,13 +106,13 @@ void AOClient::cmdTestify(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
if (area->testimonyRecording() == AreaData::TestimonyRecording::RECORDING) {
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->testimonyRecording() == AreaData::TestimonyRecording::RECORDING) {
sendServerMessage("Testimony recording is already in progress. Please stop it before starting a new one.");
}
else {
clearTestimony();
area->setTestimonyRecording(AreaData::TestimonyRecording::RECORDING);
l_area->setTestimonyRecording(AreaData::TestimonyRecording::RECORDING);
sendServerMessage("Started testimony recording.");
}
}
@ -122,15 +122,15 @@ void AOClient::cmdExamine(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
if (area->testimony().size() -1 > 0)
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->testimony().size() -1 > 0)
{
area->restartTestimony();
server->broadcast(AOPacket("RT",{"testimony2"}), current_area);
server->broadcast(AOPacket("MS", {area->testimony()[0]}), current_area);
l_area->restartTestimony();
server->broadcast(AOPacket("RT",{"testimony2"}), m_current_area);
server->broadcast(AOPacket("MS", {l_area->testimony()[0]}), m_current_area);
return;
}
if (area->testimonyRecording() == AreaData::TestimonyRecording::PLAYBACK)
if (l_area->testimonyRecording() == AreaData::TestimonyRecording::PLAYBACK)
sendServerMessage("Unable to examine while another examination is running");
else
sendServerMessage("Unable to start replay without prior examination.");
@ -141,20 +141,20 @@ void AOClient::cmdTestimony(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
if (area->testimony().size() -1 < 1) {
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->testimony().size() -1 < 1) {
sendServerMessage("Unable to display empty testimony.");
return;
}
QString ooc_message;
for (int i = 1; i <= area->testimony().size() -1; i++)
QString l_ooc_message;
for (int i = 1; i <= l_area->testimony().size() -1; i++)
{
QStringList packet = area->testimony().at(i);
QString ic_message = packet[4];
ooc_message.append( "[" + QString::number(i) + "]" + ic_message + "\n");
QStringList l_packet = l_area->testimony().at(i);
QString l_ic_message = l_packet[4];
l_ooc_message.append( "[" + QString::number(i) + "]" + l_ic_message + "\n");
}
sendServerMessage(ooc_message);
sendServerMessage(l_ooc_message);
}
void AOClient::cmdDeleteStatement(int argc, QStringList argv)
@ -162,14 +162,14 @@ void AOClient::cmdDeleteStatement(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
int c_statement = area->statement();
if (area->testimony().size() - 1 == 0) {
AreaData* l_area = server->m_areas[m_current_area];
int l_c_statement = l_area->statement();
if (l_area->testimony().size() - 1 == 0) {
sendServerMessage("Unable to delete statement. No statements saved in this area.");
}
if (c_statement > 0 && area->testimony().size() > 2) {
area->removeStatement(c_statement);
sendServerMessage("The statement with id " + QString::number(c_statement) + " has been deleted from the testimony.");
if (l_c_statement > 0 && l_area->testimony().size() > 2) {
l_area->removeStatement(l_c_statement);
sendServerMessage("The statement with id " + QString::number(l_c_statement) + " has been deleted from the testimony.");
}
}
@ -178,7 +178,7 @@ void AOClient::cmdUpdateStatement(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
server->m_areas[current_area]->setTestimonyRecording(AreaData::TestimonyRecording::UPDATE);
server->m_areas[m_current_area]->setTestimonyRecording(AreaData::TestimonyRecording::UPDATE);
sendServerMessage("The next IC-Message will replace the last displayed replay message.");
}
@ -187,9 +187,9 @@ void AOClient::cmdPauseTestimony(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
area->setTestimonyRecording(AreaData::TestimonyRecording::STOPPED);
server->broadcast(AOPacket("RT",{"testimony1", "1"}), current_area);
AreaData* l_area = server->m_areas[m_current_area];
l_area->setTestimonyRecording(AreaData::TestimonyRecording::STOPPED);
server->broadcast(AOPacket("RT",{"testimony1", "1"}), m_current_area);
sendServerMessage("Testimony has been stopped.");
}
@ -198,8 +198,8 @@ void AOClient::cmdAddStatement(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
if (server->m_areas[current_area]->statement() < ConfigManager::maxStatements()) {
server->m_areas[current_area]->setTestimonyRecording(AreaData::TestimonyRecording::ADD);
if (server->m_areas[m_current_area]->statement() < ConfigManager::maxStatements()) {
server->m_areas[m_current_area]->setTestimonyRecording(AreaData::TestimonyRecording::ADD);
sendServerMessage("The next IC-Message will be inserted into the testimony.");
}
else
@ -210,41 +210,41 @@ void AOClient::cmdSaveTestimony(int argc, QStringList argv)
{
Q_UNUSED(argc);
bool permission_found = false;
bool l_permission_found = false;
if (checkAuth(ACLFlags.value("SAVETEST")))
permission_found = true;
l_permission_found = true;
if (testimony_saving == true)
permission_found = true;
if (m_testimony_saving == true)
l_permission_found = true;
if (permission_found) {
AreaData* area = server->m_areas[current_area];
if (area->testimony().size() -1 <= 0) {
if (l_permission_found) {
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->testimony().size() -1 <= 0) {
sendServerMessage("Can't save an empty testimony.");
return;
}
QDir dir_testimony("storage/testimony");
if (!dir_testimony.exists()) {
dir_testimony.mkpath(".");
QDir l_dir_testimony("storage/testimony");
if (!l_dir_testimony.exists()) {
l_dir_testimony.mkpath(".");
}
QString testimony_name = argv[0].trimmed().toLower().replace("..",""); // :)
QFile file("storage/testimony/" + testimony_name + ".txt");
if (file.exists()) {
QString l_testimony_name = argv[0].trimmed().toLower().replace("..",""); // :)
QFile l_file("storage/testimony/" + l_testimony_name + ".txt");
if (l_file.exists()) {
sendServerMessage("Unable to save testimony. Testimony name already exists.");
return;
}
QTextStream out(&file);
out.setCodec("UTF-8");
if(file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
for (int i = 0; i <= area->testimony().size() -1; i++)
QTextStream l_out(&l_file);
l_out.setCodec("UTF-8");
if(l_file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
for (int i = 0; i <= l_area->testimony().size() -1; i++)
{
out << area->testimony().at(i).join("#") << "\n";
l_out << l_area->testimony().at(i).join("#") << "\n";
}
sendServerMessage("Testimony saved. To load it use /loadtestimony " + testimony_name);
testimony_saving = false;
sendServerMessage("Testimony saved. To load it use /loadtestimony " + l_testimony_name);
m_testimony_saving = false;
}
}
else {
@ -257,34 +257,34 @@ void AOClient::cmdLoadTestimony(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* area = server->m_areas[current_area];
QDir dir_testimony("storage/testimony");
if (!dir_testimony.exists()) {
AreaData* l_area = server->m_areas[m_current_area];
QDir l_dir_testimony("storage/testimony");
if (!l_dir_testimony.exists()) {
sendServerMessage("Unable to load testimonies. Testimony storage not found.");
return;
}
QString testimony_name = argv[0].trimmed().toLower().replace("..",""); // :)
QFile file("storage/testimony/" + testimony_name + ".txt");
if (!file.exists()) {
QString l_testimony_name = argv[0].trimmed().toLower().replace("..",""); // :)
QFile l_file("storage/testimony/" + l_testimony_name + ".txt");
if (!l_file.exists()) {
sendServerMessage("Unable to load testimony. Testimony name not found.");
return;
}
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
if (!l_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
sendServerMessage("Unable to load testimony. Permission denied.");
return;
}
clearTestimony();
int testimony_lines = 0;
QTextStream in(&file);
in.setCodec("UTF-8");
while (!in.atEnd()) {
if (testimony_lines <= ConfigManager::maxStatements()) {
QString line = in.readLine();
int l_testimony_lines = 0;
QTextStream l_in(&l_file);
l_in.setCodec("UTF-8");
while (!l_in.atEnd()) {
if (l_testimony_lines <= ConfigManager::maxStatements()) {
QString line = l_in.readLine();
QStringList packet = line.split("#");
area->addStatement(area->testimony().size(), packet);
testimony_lines = testimony_lines + 1;
l_area->addStatement(l_area->testimony().size(), packet);
l_testimony_lines = l_testimony_lines + 1;
}
else {
sendServerMessage("Testimony too large to be loaded.");

View File

@ -48,17 +48,17 @@ QStringList AOClient::buildAreaList(int area_idx)
}
entries.append("[" + QString::number(area->playerCount()) + " users][" + QVariant::fromValue(area->status()).toString().replace("_", "-") + "]");
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->current_area == area_idx && client->joined) {
QString char_entry = "[" + QString::number(client->id) + "] " + client->current_char;
if (client->current_char == "")
if (client->m_current_area == area_idx && client->m_joined) {
QString char_entry = "[" + QString::number(client->m_id) + "] " + client->m_current_char;
if (client->m_current_char == "")
char_entry += "Spectator";
if (client->showname != "")
char_entry += " (" + client->showname + ")";
if (area->owners().contains(client->id))
if (client->m_showname != "")
char_entry += " (" + client->m_showname + ")";
if (area->owners().contains(client->m_id))
char_entry.insert(0, "[CM] ");
if (authenticated)
char_entry += " (" + client->getIpid() + "): " + client->ooc_name;
if (client->is_afk)
if (m_authenticated)
char_entry += " (" + client->getIpid() + "): " + client->m_ooc_name;
if (client->m_is_afk)
char_entry += " [AFK]";
entries.append(char_entry);
}
@ -74,58 +74,57 @@ int AOClient::genRand(int min, int max)
return random_number;
#else
quint32 random_number = QRandomGenerator::system()->bounded(min, max + 1);
return random_number;
return QRandomGenerator::system()->bounded(min, max + 1);
#endif
}
void AOClient::diceThrower(int argc, QStringList argv, bool p_roll)
{
int sides = 6;
int dice = 1;
int l_sides = 6;
int l_dice = 1;
QStringList results;
if (argc >= 1)
sides = qBound(1, argv[0].toInt(), ConfigManager::diceMaxValue());
l_sides = qBound(1, argv[0].toInt(), ConfigManager::diceMaxValue());
if (argc == 2)
dice = qBound(1, argv[1].toInt(), ConfigManager::diceMaxDice());
for (int i = 1; i <= dice; i++) {
results.append(QString::number(AOClient::genRand(1, sides)));
l_dice = qBound(1, argv[1].toInt(), ConfigManager::diceMaxDice());
for (int i = 1; i <= l_dice; i++) {
results.append(QString::number(AOClient::genRand(1, l_sides)));
}
QString total_results = results.join(" ");
if (p_roll) {
sendServerMessage("You rolled a " + QString::number(dice) + "d" + QString::number(sides) + ". Results: " + total_results);
sendServerMessage("You rolled a " + QString::number(l_dice) + "d" + QString::number(l_sides) + ". Results: " + total_results);
return;
}
sendServerMessageArea(ooc_name + " rolled a " + QString::number(dice) + "d" + QString::number(sides) + ". Results: " + total_results);
sendServerMessageArea(m_ooc_name + " rolled a " + QString::number(l_dice) + "d" + QString::number(l_sides) + ". Results: " + total_results);
}
QString AOClient::getAreaTimer(int area_idx, int timer_idx)
{
AreaData* area = server->m_areas[area_idx];
QTimer* timer;
QString timer_name = (timer_idx == 0) ? "Global timer" : "Timer " + QString::number(timer_idx);
AreaData* l_area = server->m_areas[area_idx];
QTimer* l_timer;
QString l_timer_name = (timer_idx == 0) ? "Global timer" : "Timer " + QString::number(timer_idx);
if (timer_idx == 0)
timer = server->timer;
l_timer = server->timer;
else if (timer_idx > 0 && timer_idx <= 4)
timer = area->timers().at(timer_idx - 1);
l_timer = l_area->timers().at(timer_idx - 1);
else
return "Invalid timer ID.";
if (timer->isActive()) {
QTime current_time = QTime(0,0).addMSecs(timer->remainingTime());
if (l_timer->isActive()) {
QTime l_current_time = QTime(0,0).addMSecs(l_timer->remainingTime());
return timer_name + " is at " + current_time.toString("hh:mm:ss.zzz");
return l_timer_name + " is at " + l_current_time.toString("hh:mm:ss.zzz");
}
else {
return timer_name + " is inactive.";
return l_timer_name + " is inactive.";
}
}
long long AOClient::parseTime(QString input)
{
QRegularExpression regex("(?:(?:(?<year>.*?)y)*(?:(?<week>.*?)w)*(?:(?<day>.*?)d)*(?:(?<hr>.*?)h)*(?:(?<min>.*?)m)*(?:(?<sec>.*?)s)*)");
QRegularExpressionMatch match = regex.match(input);
QRegularExpression l_regex("(?:(?:(?<year>.*?)y)*(?:(?<week>.*?)w)*(?:(?<day>.*?)d)*(?:(?<hr>.*?)h)*(?:(?<min>.*?)m)*(?:(?<sec>.*?)s)*)");
QRegularExpressionMatch match = l_regex.match(input);
QString str_year, str_week, str_hour, str_day, str_minute, str_second;
int year, week, day, hour, minute, second;
@ -136,11 +135,11 @@ long long AOClient::parseTime(QString input)
str_minute = match.captured("min");
str_second = match.captured("sec");
bool is_well_formed = false;
bool l_is_well_formed = false;
QString concat_str(str_year + str_week + str_day + str_hour + str_minute + str_second);
concat_str.toInt(&is_well_formed);
concat_str.toInt(&l_is_well_formed);
if (!is_well_formed) {
if (!l_is_well_formed) {
return -1;
}
@ -151,23 +150,23 @@ long long AOClient::parseTime(QString input)
minute = str_minute.toInt();
second = str_second.toInt();
long long total = 0;
total += 31622400 * year;
total += 604800 * week;
total += 86400 * day;
total += 3600 * hour;
total += 60 * minute;
total += second;
long long l_total = 0;
l_total += 31622400 * year;
l_total += 604800 * week;
l_total += 86400 * day;
l_total += 3600 * hour;
l_total += 60 * minute;
l_total += second;
if (total < 0)
if (l_total < 0)
return -1;
return total;
return l_total;
}
QString AOClient::getReprimand(bool positive)
QString AOClient::getReprimand(bool f_positive)
{
if (positive) {
if (f_positive) {
return ConfigManager::praiseList().at(genRand(0, ConfigManager::praiseList().size() - 1));
}
else {
@ -175,53 +174,53 @@ QString AOClient::getReprimand(bool positive)
}
}
bool AOClient::checkPasswordRequirements(QString username, QString password)
bool AOClient::checkPasswordRequirements(QString f_username, QString f_password)
{
QString decoded_password = decodeMessage(password);
QString l_decoded_password = decodeMessage(f_password);
if (!ConfigManager::passwordRequirements())
return true;
if (ConfigManager::passwordMinLength() > decoded_password.length())
if (ConfigManager::passwordMinLength() > l_decoded_password.length())
return false;
if (ConfigManager::passwordMaxLength() < decoded_password.length() && ConfigManager::passwordMaxLength() != 0)
if (ConfigManager::passwordMaxLength() < l_decoded_password.length() && ConfigManager::passwordMaxLength() != 0)
return false;
else if (ConfigManager::passwordRequireMixCase()) {
if (decoded_password.toLower() == decoded_password)
if (l_decoded_password.toLower() == l_decoded_password)
return false;
if (decoded_password.toUpper() == decoded_password)
if (l_decoded_password.toUpper() == l_decoded_password)
return false;
}
else if (ConfigManager::passwordRequireNumbers()) {
QRegularExpression regex("[0123456789]");
QRegularExpressionMatch match = regex.match(decoded_password);
QRegularExpressionMatch match = regex.match(l_decoded_password);
if (!match.hasMatch())
return false;
}
else if (ConfigManager::passwordRequireSpecialCharacters()) {
QRegularExpression regex("[~!@#$%^&*_-+=`|\\(){}\[]:;\"'<>,.?/]");
QRegularExpressionMatch match = regex.match(decoded_password);
QRegularExpressionMatch match = regex.match(l_decoded_password);
if (!match.hasMatch())
return false;
}
else if (!ConfigManager::passwordCanContainUsername()) {
if (decoded_password.contains(username))
if (l_decoded_password.contains(f_username))
return false;
}
return true;
}
void AOClient::sendNotice(QString notice, bool global)
void AOClient::sendNotice(QString f_notice, bool f_global)
{
QString message = "A moderator sent this ";
if (global)
message += "server-wide ";
message += "notice:\n\n" + notice;
sendServerMessageArea(message);
AOPacket packet("BB", {message});
if (global)
server->broadcast(packet);
QString l_message = "A moderator sent this ";
if (f_global)
l_message += "server-wide ";
l_message += "notice:\n\n" + f_notice;
sendServerMessageArea(l_message);
AOPacket l_packet("BB", {l_message});
if (f_global)
server->broadcast(l_packet);
else
server->broadcast(packet, current_area);
server->broadcast(l_packet, m_current_area);
}

View File

@ -25,7 +25,7 @@ void AOClient::cmdPos(int argc, QStringList argv)
Q_UNUSED(argc);
changePosition(argv[0]);
updateEvidenceList(server->m_areas[current_area]);
updateEvidenceList(server->m_areas[m_current_area]);
}
void AOClient::cmdForcePos(int argc, QStringList argv)
@ -33,17 +33,17 @@ void AOClient::cmdForcePos(int argc, QStringList argv)
Q_UNUSED(argc);
bool ok;
QList<AOClient*> targets;
int target_id = argv[1].toInt(&ok);
int forced_clients = 0;
QList<AOClient*> l_targets;
int l_target_id = argv[1].toInt(&ok);
int l_forced_clients = 0;
if (!ok && argv[1] != "*") {
sendServerMessage("That does not look like a valid ID.");
return;
}
else if (ok) {
AOClient* target_client = server->getClientByID(target_id);
if (target_client != nullptr)
targets.append(target_client);
AOClient* l_target_client = server->getClientByID(l_target_id);
if (l_target_client != nullptr)
l_targets.append(l_target_client);
else {
sendServerMessage("Target ID not found!");
return;
@ -52,28 +52,28 @@ void AOClient::cmdForcePos(int argc, QStringList argv)
else if (argv[1] == "*") { // force all clients in the area
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->current_area == current_area)
targets.append(client);
if (client->m_current_area == m_current_area)
l_targets.append(client);
}
}
for (AOClient* target : targets) {
target->sendServerMessage("Position forcibly changed by CM.");
target->changePosition(argv[0]);
forced_clients++;
for (AOClient* l_target : l_targets) {
l_target->sendServerMessage("Position forcibly changed by CM.");
l_target->changePosition(argv[0]);
l_forced_clients++;
}
sendServerMessage("Forced " + QString::number(forced_clients) + " into pos " + argv[0] + ".");
sendServerMessage("Forced " + QString::number(l_forced_clients) + " into pos " + argv[0] + ".");
}
void AOClient::cmdG(int argc, QStringList argv)
{
Q_UNUSED(argc);
QString sender_name = ooc_name;
QString sender_area = server->m_area_names.value(current_area);
QString sender_message = argv.join(" ");
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->global_enabled)
client->sendPacket("CT", {"[G][" + sender_area + "]" + sender_name, sender_message});
QString l_sender_name = m_ooc_name;
QString l_sender_area = server->m_area_names.value(m_current_area);
QString l_sender_message = argv.join(" ");
for (AOClient* l_client : qAsConst(server->m_clients)) {
if (l_client->m_global_enabled)
l_client->sendPacket("CT", {"[G][" + l_sender_area + "]" + l_sender_name, l_sender_message});
}
return;
}
@ -82,11 +82,11 @@ void AOClient::cmdNeed(int argc, QStringList argv)
{
Q_UNUSED(argc);
QString sender_area = server->m_area_names.value(current_area);
QString sender_message = argv.join(" ");
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->advert_enabled) {
client->sendServerMessage({"=== Advert ===\n[" + sender_area + "] needs " + sender_message+ "."});
QString l_sender_area = server->m_area_names.value(m_current_area);
QString l_sender_message = argv.join(" ");
for (AOClient* l_client : qAsConst(server->m_clients)) {
if (l_client->m_advert_enabled) {
l_client->sendServerMessage({"=== Advert ===\n[" + l_sender_area + "] needs " + l_sender_message+ "."});
}
}
}
@ -95,13 +95,13 @@ void AOClient::cmdSwitch(int argc, QStringList argv)
{
Q_UNUSED(argc);
int selected_char_id = server->getCharID(argv.join(" "));
if (selected_char_id == -1) {
int l_selected_char_id = server->getCharID(argv.join(" "));
if (l_selected_char_id == -1) {
sendServerMessage("That does not look like a valid character.");
return;
}
if (changeCharacter(selected_char_id)) {
char_id = selected_char_id;
if (changeCharacter(l_selected_char_id)) {
m_char_id = l_selected_char_id;
}
else {
sendServerMessage("The character you picked is either taken or invalid.");
@ -113,17 +113,17 @@ void AOClient::cmdRandomChar(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
int selected_char_id;
bool taken = true;
while (taken) {
selected_char_id = genRand(0, server->m_characters.size() - 1);
if (!area->charactersTaken().contains(selected_char_id)) {
taken = false;
AreaData* l_area = server->m_areas[m_current_area];
int l_selected_char_id;
bool l_taken = true;
while (l_taken) {
l_selected_char_id = genRand(0, server->m_characters.size() - 1);
if (!l_area->charactersTaken().contains(l_selected_char_id)) {
l_taken = false;
}
}
if (changeCharacter(selected_char_id)) {
char_id = selected_char_id;
if (changeCharacter(l_selected_char_id)) {
m_char_id = l_selected_char_id;
}
}
@ -132,9 +132,9 @@ void AOClient::cmdToggleGlobal(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
global_enabled = !global_enabled;
QString str_en = global_enabled ? "shown" : "hidden";
sendServerMessage("Global chat set to " + str_en);
m_global_enabled = !m_global_enabled;
QString l_str_en = m_global_enabled ? "shown" : "hidden";
sendServerMessage("Global chat set to " + l_str_en);
}
void AOClient::cmdPM(int argc, QStringList argv)
@ -142,23 +142,23 @@ void AOClient::cmdPM(int argc, QStringList argv)
Q_UNUSED(argc);
bool ok;
int target_id = argv.takeFirst().toInt(&ok); // using takeFirst removes the ID from our list of arguments...
int l_target_id = argv.takeFirst().toInt(&ok); // using takeFirst removes the ID from our list of arguments...
if (!ok) {
sendServerMessage("That does not look like a valid ID.");
return;
}
AOClient* target_client = server->getClientByID(target_id);
if (target_client == nullptr) {
AOClient* l_target_client = server->getClientByID(l_target_id);
if (l_target_client == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (target_client->pm_mute) {
if (l_target_client->m_pm_mute) {
sendServerMessage("That user is not recieving PMs.");
return;
}
QString message = argv.join(" "); //...which means it will not end up as part of the message
target_client->sendServerMessage("Message from " + ooc_name + " (" + QString::number(id) + "): " + message);
sendServerMessage("PM sent to " + QString::number(target_id) +". Message: " + message);
QString l_message = argv.join(" "); //...which means it will not end up as part of the message
l_target_client->sendServerMessage("Message from " + m_ooc_name + " (" + QString::number(m_id) + "): " + l_message);
sendServerMessage("PM sent to " + QString::number(l_target_id) +". Message: " + l_message);
}
void AOClient::cmdAnnounce(int argc, QStringList argv)
@ -172,11 +172,11 @@ void AOClient::cmdM(int argc, QStringList argv)
{
Q_UNUSED(argc);
QString sender_name = ooc_name;
QString sender_message = argv.join(" ");
QString l_sender_name = m_ooc_name;
QString l_sender_message = argv.join(" ");
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->checkAuth(ACLFlags.value("MODCHAT")))
client->sendPacket("CT", {"[M]" + sender_name, sender_message});
client->sendPacket("CT", {"[M]" + l_sender_name, l_sender_message});
}
return;
}
@ -185,12 +185,12 @@ void AOClient::cmdGM(int argc, QStringList argv)
{
Q_UNUSED(argc);
QString sender_name = ooc_name;
QString sender_area = server->m_area_names.value(current_area);
QString sender_message = argv.join(" ");
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->global_enabled) {
client->sendPacket("CT", {"[G][" + sender_area + "]" + "["+sender_name+"][M]", sender_message});
QString l_sender_name = m_ooc_name;
QString l_sender_area = server->m_area_names.value(m_current_area);
QString l_sender_message = argv.join(" ");
for (AOClient* l_client : qAsConst(server->m_clients)) {
if (l_client->m_global_enabled) {
l_client->sendPacket("CT", {"[G][" + l_sender_area + "]" + "["+ l_sender_name+"][M]", l_sender_message});
}
}
}
@ -199,9 +199,9 @@ void AOClient::cmdLM(int argc, QStringList argv)
{
Q_UNUSED(argc);
QString sender_name = ooc_name;
QString sender_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"["+sender_name+"][M]", sender_message}), current_area);
QString l_sender_name = m_ooc_name;
QString l_sender_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"["+ l_sender_name +"][M]", l_sender_message}), m_current_area);
}
void AOClient::cmdGimp(int argc, QStringList argv)
@ -209,26 +209,26 @@ void AOClient::cmdGimp(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (target->is_gimped)
if (l_target->m_is_gimped)
sendServerMessage("That player is already gimped!");
else {
sendServerMessage("Gimped player.");
target->sendServerMessage("You have been gimped! " + getReprimand());
l_target->sendServerMessage("You have been gimped! " + getReprimand());
}
target->is_gimped = true;
l_target->m_is_gimped = true;
}
void AOClient::cmdUnGimp(int argc, QStringList argv)
@ -236,26 +236,26 @@ void AOClient::cmdUnGimp(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (!(target->is_gimped))
if (!(l_target->m_is_gimped))
sendServerMessage("That player is not gimped!");
else {
sendServerMessage("Ungimped player.");
target->sendServerMessage("A moderator has ungimped you! " + getReprimand(true));
l_target->sendServerMessage("A moderator has ungimped you! " + getReprimand(true));
}
target->is_gimped = false;
l_target->m_is_gimped = false;
}
void AOClient::cmdDisemvowel(int argc, QStringList argv)
@ -263,26 +263,26 @@ void AOClient::cmdDisemvowel(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (target->is_disemvoweled)
if (l_target->m_is_disemvoweled)
sendServerMessage("That player is already disemvoweled!");
else {
sendServerMessage("Disemvoweled player.");
target->sendServerMessage("You have been disemvoweled! " + getReprimand());
l_target->sendServerMessage("You have been disemvoweled! " + getReprimand());
}
target->is_disemvoweled = true;
l_target->m_is_disemvoweled = true;
}
void AOClient::cmdUnDisemvowel(int argc, QStringList argv)
@ -290,26 +290,26 @@ void AOClient::cmdUnDisemvowel(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (!(target->is_disemvoweled))
if (!(l_target->m_is_disemvoweled))
sendServerMessage("That player is not disemvoweled!");
else {
sendServerMessage("Undisemvoweled player.");
target->sendServerMessage("A moderator has undisemvoweled you! " + getReprimand(true));
l_target->sendServerMessage("A moderator has undisemvoweled you! " + getReprimand(true));
}
target->is_disemvoweled = false;
l_target->m_is_disemvoweled = false;
}
void AOClient::cmdShake(int argc, QStringList argv)
@ -317,26 +317,26 @@ void AOClient::cmdShake(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (target->is_shaken)
if (l_target->m_is_shaken)
sendServerMessage("That player is already shaken!");
else {
sendServerMessage("Shook player.");
target->sendServerMessage("A moderator has shaken your words! " + getReprimand());
l_target->sendServerMessage("A moderator has shaken your words! " + getReprimand());
}
target->is_shaken = true;
l_target->m_is_shaken = true;
}
void AOClient::cmdUnShake(int argc, QStringList argv)
@ -344,26 +344,26 @@ void AOClient::cmdUnShake(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (!(target->is_shaken))
if (!(l_target->m_is_shaken))
sendServerMessage("That player is not shaken!");
else {
sendServerMessage("Unshook player.");
target->sendServerMessage("A moderator has unshook you! " + getReprimand(true));
l_target->sendServerMessage("A moderator has unshook you! " + getReprimand(true));
}
target->is_shaken = false;
l_target->m_is_shaken = false;
}
void AOClient::cmdMutePM(int argc, QStringList argv)
@ -371,9 +371,9 @@ void AOClient::cmdMutePM(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
pm_mute = !pm_mute;
QString str_en = pm_mute ? "muted" : "unmuted";
sendServerMessage("PM's are now " + str_en);
m_pm_mute = !m_pm_mute;
QString l_str_en = m_pm_mute ? "muted" : "unmuted";
sendServerMessage("PM's are now " + l_str_en);
}
void AOClient::cmdToggleAdverts(int argc, QStringList argv)
@ -381,9 +381,9 @@ void AOClient::cmdToggleAdverts(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
advert_enabled = !advert_enabled;
QString str_en = advert_enabled ? "on" : "off";
sendServerMessage("Advertisements turned " + str_en);
m_advert_enabled = !m_advert_enabled;
QString l_str_en = m_advert_enabled ? "on" : "off";
sendServerMessage("Advertisements turned " + l_str_en);
}
void AOClient::cmdAfk(int argc, QStringList argv)
@ -391,62 +391,62 @@ void AOClient::cmdAfk(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
is_afk = true;
m_is_afk = true;
sendServerMessage("You are now AFK.");
}
void AOClient::cmdCharCurse(int argc, QStringList argv)
{
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (target->is_charcursed) {
if (l_target->m_is_charcursed) {
sendServerMessage("That player is already charcursed!");
return;
}
if (argc == 1) {
target->charcurse_list.append(server->getCharID(target->current_char));
l_target->m_charcurse_list.append(server->getCharID(l_target->m_current_char));
}
else {
argv.removeFirst();
QStringList char_names = argv.join(" ").split(",");
QStringList l_char_names = argv.join(" ").split(",");
target->charcurse_list.clear();
for (const QString &char_name : qAsConst(char_names)) {
int char_id = server->getCharID(char_name);
l_target->m_charcurse_list.clear();
for (const QString &l_char_name : qAsConst(l_char_names)) {
int char_id = server->getCharID(l_char_name);
if (char_id == -1) {
sendServerMessage("Could not find character: " + char_name);
sendServerMessage("Could not find character: " + l_char_name);
return;
}
target->charcurse_list.append(char_id);
l_target->m_charcurse_list.append(char_id);
}
}
target->is_charcursed = true;
l_target->m_is_charcursed = true;
//Kick back to char select screen
if (!target->charcurse_list.contains(server->getCharID(target->current_char))) {
target->changeCharacter(-1);
server->updateCharsTaken(server->m_areas.value(current_area));
target->sendPacket("DONE");
if (!l_target->m_charcurse_list.contains(server->getCharID(l_target->m_current_char))) {
l_target->changeCharacter(-1);
server->updateCharsTaken(server->m_areas.value(m_current_area));
l_target->sendPacket("DONE");
}
else {
server->updateCharsTaken(server->m_areas.value(current_area));
server->updateCharsTaken(server->m_areas.value(m_current_area));
}
target->sendServerMessage("You have been charcursed!");
l_target->sendServerMessage("You have been charcursed!");
sendServerMessage("Charcursed player.");
}
@ -455,28 +455,28 @@ void AOClient::cmdUnCharCurse(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (!target->is_charcursed) {
if (!l_target->m_is_charcursed) {
sendServerMessage("That player is not charcursed!");
return;
}
target->is_charcursed = false;
target->charcurse_list.clear();
server->updateCharsTaken(server->m_areas.value(current_area));
l_target->m_is_charcursed = false;
l_target->m_charcurse_list.clear();
server->updateCharsTaken(server->m_areas.value(m_current_area));
sendServerMessage("Uncharcursed player.");
target->sendServerMessage("You were uncharcursed.");
l_target->sendServerMessage("You were uncharcursed.");
}
void AOClient::cmdCharSelect(int argc, QStringList argv)
@ -492,17 +492,17 @@ void AOClient::cmdCharSelect(int argc, QStringList argv)
}
bool ok = false;
int target_id = argv[0].toInt(&ok);
int l_target_id = argv[0].toInt(&ok);
if (!ok)
return;
AOClient* target = server->getClientByID(target_id);
AOClient* l_target = server->getClientByID(l_target_id);
if (target == nullptr)
if (l_target == nullptr)
return;
target->changeCharacter(-1);
target->sendPacket("DONE");
l_target->changeCharacter(-1);
l_target->sendPacket("DONE");
}
}
@ -511,35 +511,35 @@ void AOClient::cmdA(int argc, QStringList argv)
Q_UNUSED(argc);
bool ok;
int area_id = argv[0].toInt(&ok);
int l_area_id = argv[0].toInt(&ok);
if (!ok) {
sendServerMessage("This does not look like a valid AreaID.");
return;
}
AreaData* area = server->m_areas[area_id];
if (!area->owners().contains(id)) {
AreaData* l_area = server->m_areas[l_area_id];
if (!l_area->owners().contains(m_id)) {
sendServerMessage("You are not CM in that area.");
return;
}
argv.removeAt(0);
QString sender_name = ooc_name;
QString ooc_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"[CM]" + sender_name, ooc_message}), area_id);
QString l_sender_name = m_ooc_name;
QString l_ooc_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"[CM]" + l_sender_name, l_ooc_message}), l_area_id);
}
void AOClient::cmdS(int argc, QStringList argv)
{
Q_UNUSED(argc);
int all_areas = server->m_areas.size() - 1;
QString sender_name = ooc_name;
QString ooc_message = argv.join(" ");
int l_all_areas = server->m_areas.size() - 1;
QString l_sender_name = m_ooc_name;
QString l_ooc_message = argv.join(" ");
for (int i = 0; i <= all_areas; i++) {
if (server->m_areas[i]->owners().contains(id))
server->broadcast(AOPacket("CT", {"[CM]" + sender_name, ooc_message}), i);
for (int i = 0; i <= l_all_areas; i++) {
if (server->m_areas[i]->owners().contains(m_id))
server->broadcast(AOPacket("CT", {"[CM]" + l_sender_name, l_ooc_message}), i);
}
}
@ -548,7 +548,7 @@ void AOClient::cmdFirstPerson(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
first_person = !first_person;
QString str_en = first_person ? "enabled" : "disabled";
sendServerMessage("First person mode " + str_en + ".");
m_first_person = !m_first_person;
QString l_str_en = m_first_person ? "enabled" : "disabled";
sendServerMessage("First person mode " + l_str_en + ".");
}

View File

@ -22,104 +22,104 @@
void AOClient::cmdBan(int argc, QStringList argv)
{
QString args_str = argv[2];
QString l_args_str = argv[2];
if (argc > 3) {
for (int i = 3; i < argc; i++)
args_str += " " + argv[i];
l_args_str += " " + argv[i];
}
DBManager::BanInfo ban;
DBManager::BanInfo l_ban;
long long duration_seconds = 0;
long long l_duration_seconds = 0;
if (argv[1] == "perma")
duration_seconds = -2;
l_duration_seconds = -2;
else
duration_seconds = parseTime(argv[1]);
l_duration_seconds = parseTime(argv[1]);
if (duration_seconds == -1) {
if (l_duration_seconds == -1) {
sendServerMessage("Invalid time format. Format example: 1h30m");
return;
}
ban.duration = duration_seconds;
ban.ipid = argv[0];
ban.reason = args_str;
ban.time = QDateTime::currentDateTime().toSecsSinceEpoch();
bool ban_logged = false;
int kick_counter = 0;
l_ban.duration = l_duration_seconds;
l_ban.ipid = argv[0];
l_ban.reason = l_args_str;
l_ban.time = QDateTime::currentDateTime().toSecsSinceEpoch();
bool l_ban_logged = false;
int l_kick_counter = 0;
switch (ConfigManager::authType()) {
case DataTypes::AuthType::SIMPLE:
ban.moderator = "moderator";
l_ban.moderator = "moderator";
break;
case DataTypes::AuthType::ADVANCED:
ban.moderator = moderator_name;
l_ban.moderator = m_moderator_name;
break;
}
const QList<AOClient*> targets = server->getClientsByIpid(ban.ipid);
for (AOClient* client : targets) {
if (!ban_logged) {
ban.ip = client->remote_ip;
ban.hdid = client->hwid;
server->db_manager->addBan(ban);
sendServerMessage("Banned user with ipid " + ban.ipid + " for reason: " + ban.reason);
ban_logged = true;
const QList<AOClient*> l_targets = server->getClientsByIpid(l_ban.ipid);
for (AOClient* client : l_targets) {
if (!l_ban_logged) {
l_ban.ip = client->m_remote_ip;
l_ban.hdid = client->m_hwid;
server->db_manager->addBan(l_ban);
sendServerMessage("Banned user with ipid " + l_ban.ipid + " for reason: " + l_ban.reason);
l_ban_logged = true;
}
QString ban_duration;
if (!(ban.duration == -2)) {
ban_duration = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("MM/dd/yyyy, hh:mm");
QString l_ban_duration;
if (!(l_ban.duration == -2)) {
l_ban_duration = QDateTime::fromSecsSinceEpoch(l_ban.time).addSecs(l_ban.duration).toString("MM/dd/yyyy, hh:mm");
}
else {
ban_duration = "The heat death of the universe.";
l_ban_duration = "The heat death of the universe.";
}
int ban_id = server->db_manager->getBanID(ban.ip);
client->sendPacket("KB", {ban.reason + "\nID: " + QString::number(ban_id) + "\nUntil: " + ban_duration});
client->socket->close();
kick_counter++;
int l_ban_id = server->db_manager->getBanID(l_ban.ip);
client->sendPacket("KB", {l_ban.reason + "\nID: " + QString::number(l_ban_id) + "\nUntil: " + l_ban_duration});
client->m_socket->close();
l_kick_counter++;
emit logBan(ban.moderator,ban.ipid,ban_duration,ban.reason);
emit logBan(l_ban.moderator,l_ban.ipid,l_ban_duration,l_ban.reason);
if (ConfigManager::discordBanWebhookEnabled())
emit server->banWebhookRequest(ban.ipid, ban.moderator, ban_duration, ban.reason, ban_id);
emit server->banWebhookRequest(l_ban.ipid, l_ban.moderator, l_ban_duration, l_ban.reason, l_ban_id);
}
if (kick_counter > 1)
sendServerMessage("Kicked " + QString::number(kick_counter) + " clients with matching ipids.");
if (l_kick_counter > 1)
sendServerMessage("Kicked " + QString::number(l_kick_counter) + " clients with matching ipids.");
// We're banning someone not connected.
if (!ban_logged) {
server->db_manager->addBan(ban);
sendServerMessage("Banned " + ban.ipid + " for reason: " + ban.reason);
if (!l_ban_logged) {
server->db_manager->addBan(l_ban);
sendServerMessage("Banned " + l_ban.ipid + " for reason: " + l_ban.reason);
}
}
void AOClient::cmdKick(int argc, QStringList argv)
{
QString target_ipid = argv[0];
QString reason = argv[1];
int kick_counter = 0;
QString l_target_ipid = argv[0];
QString l_reason = argv[1];
int l_kick_counter = 0;
if (argc > 2) {
for (int i = 2; i < argv.length(); i++) {
reason += " " + argv[i];
l_reason += " " + argv[i];
}
}
const QList<AOClient*> targets = server->getClientsByIpid(target_ipid);
for (AOClient* client : targets) {
client->sendPacket("KK", {reason});
client->socket->close();
kick_counter++;
const QList<AOClient*> l_targets = server->getClientsByIpid(l_target_ipid);
for (AOClient* client : l_targets) {
client->sendPacket("KK", {l_reason});
client->m_socket->close();
l_kick_counter++;
}
if (kick_counter > 0) {
if (l_kick_counter > 0) {
if (ConfigManager::authType() == DataTypes::AuthType::ADVANCED){
emit logKick(moderator_name, target_ipid, reason);
emit logKick(m_moderator_name, l_target_ipid, l_reason);
}
else {
emit logKick("Moderator",target_ipid,reason);
emit logKick("Moderator", l_target_ipid, l_reason);
}
sendServerMessage("Kicked " + QString::number(kick_counter) + " client(s) with ipid " + target_ipid + " for reason: " + reason);
sendServerMessage("Kicked " + QString::number(l_kick_counter) + " client(s) with ipid " + l_target_ipid + " for reason: " + l_reason);
}
else
sendServerMessage("User with ipid not found!");
@ -130,23 +130,23 @@ void AOClient::cmdMods(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QStringList entries;
int online_count = 0;
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->authenticated) {
entries << "---";
QStringList l_entries;
int l_online_count = 0;
for (AOClient* l_client : qAsConst(server->m_clients)) {
if (l_client->m_authenticated) {
l_entries << "---";
if (ConfigManager::authType() != DataTypes::AuthType::SIMPLE)
entries << "Moderator: " + client->moderator_name;
entries << "OOC name: " + client->ooc_name;
entries << "ID: " + QString::number(client->id);
entries << "Area: " + QString::number(client->current_area);
entries << "Character: " + client->current_char;
online_count++;
l_entries << "Moderator: " + l_client->m_moderator_name;
l_entries << "OOC name: " + l_client->m_ooc_name;
l_entries << "ID: " + QString::number(l_client->m_id);
l_entries << "Area: " + QString::number(l_client->m_current_area);
l_entries << "Character: " + l_client->m_current_char;
l_online_count++;
}
}
entries << "---";
entries << "Total online: " << QString::number(online_count);
sendServerMessage(entries.join("\n"));
l_entries << "---";
l_entries << "Total online: " << QString::number(l_online_count);
sendServerMessage(l_entries.join("\n"));
}
void AOClient::cmdHelp(int argc, QStringList argv)
@ -154,16 +154,16 @@ void AOClient::cmdHelp(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QStringList entries;
entries << "Allowed commands:";
QStringList l_entries;
l_entries << "Allowed commands:";
QMap<QString, CommandInfo>::const_iterator i;
for (i = commands.constBegin(); i!= commands.constEnd(); ++i) {
CommandInfo info = i.value();
if (checkAuth(info.acl_mask)) { // if we are allowed to use this command
entries << "/" + i.key();
l_entries << "/" + i.key();
}
}
sendServerMessage(entries.join("\n"));
sendServerMessage(l_entries.join("\n"));
}
void AOClient::cmdMOTD(int argc, QStringList argv)
@ -173,8 +173,8 @@ void AOClient::cmdMOTD(int argc, QStringList argv)
}
else if (argc > 0) {
if (checkAuth(ACLFlags.value("MOTD"))) {
QString MOTD = argv.join(" ");
ConfigManager::setMotd(MOTD);
QString l_MOTD = argv.join(" ");
ConfigManager::setMotd(l_MOTD);
sendServerMessage("MOTD has been changed.");
}
else {
@ -188,26 +188,26 @@ void AOClient::cmdBans(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QStringList recent_bans;
recent_bans << "Last 5 bans:";
recent_bans << "-----";
const QList<DBManager::BanInfo> bans_list = server->db_manager->getRecentBans();
for (const DBManager::BanInfo &ban : bans_list) {
QString banned_until;
if (ban.duration == -2)
banned_until = "The heat death of the universe";
QStringList l_recent_bans;
l_recent_bans << "Last 5 bans:";
l_recent_bans << "-----";
const QList<DBManager::BanInfo> l_bans_list = server->db_manager->getRecentBans();
for (const DBManager::BanInfo &l_ban : l_bans_list) {
QString l_banned_until;
if (l_ban.duration == -2)
l_banned_until = "The heat death of the universe";
else
banned_until = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("MM/dd/yyyy, hh:mm");
recent_bans << "Ban ID: " + QString::number(ban.id);
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("MM/dd/yyyy, hh:mm");
recent_bans << "Ban lasts until: " + banned_until;
recent_bans << "Moderator: " + ban.moderator;
recent_bans << "-----";
l_banned_until = QDateTime::fromSecsSinceEpoch(l_ban.time).addSecs(l_ban.duration).toString("MM/dd/yyyy, hh:mm");
l_recent_bans << "Ban ID: " + QString::number(l_ban.id);
l_recent_bans << "Affected IPID: " + l_ban.ipid;
l_recent_bans << "Affected HDID: " + l_ban.hdid;
l_recent_bans << "Reason for ban: " + l_ban.reason;
l_recent_bans << "Date of ban: " + QDateTime::fromSecsSinceEpoch(l_ban.time).toString("MM/dd/yyyy, hh:mm");
l_recent_bans << "Ban lasts until: " + l_banned_until;
l_recent_bans << "Moderator: " + l_ban.moderator;
l_recent_bans << "-----";
}
sendServerMessage(recent_bans.join("\n"));
sendServerMessage(l_recent_bans.join("\n"));
}
void AOClient::cmdUnBan(int argc, QStringList argv)
@ -215,12 +215,12 @@ void AOClient::cmdUnBan(int argc, QStringList argv)
Q_UNUSED(argc);
bool ok;
int target_ban = argv[0].toInt(&ok);
int l_target_ban = argv[0].toInt(&ok);
if (!ok) {
sendServerMessage("Invalid ban ID.");
return;
}
else if (server->db_manager->invalidateBan(target_ban))
else if (server->db_manager->invalidateBan(l_target_ban))
sendServerMessage("Successfully invalidated ban " + argv[0] + ".");
else
sendServerMessage("Couldn't invalidate ban " + argv[0] + ", are you sure it exists?");
@ -239,26 +239,26 @@ void AOClient::cmdMute(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* target = server->getClientByID(l_uid);
if (target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (target->is_muted)
if (target->m_is_muted)
sendServerMessage("That player is already muted!");
else {
sendServerMessage("Muted player.");
target->sendServerMessage("You were muted by a moderator. " + getReprimand());
}
target->is_muted = true;
target->m_is_muted = true;
}
void AOClient::cmdUnMute(int argc, QStringList argv)
@ -266,26 +266,26 @@ void AOClient::cmdUnMute(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (!target->is_muted)
if (!l_target->m_is_muted)
sendServerMessage("That player is not muted!");
else {
sendServerMessage("Unmuted player.");
target->sendServerMessage("You were unmuted by a moderator. " + getReprimand(true));
l_target->sendServerMessage("You were unmuted by a moderator. " + getReprimand(true));
}
target->is_muted = false;
l_target->m_is_muted = false;
}
void AOClient::cmdOocMute(int argc, QStringList argv)
@ -293,26 +293,26 @@ void AOClient::cmdOocMute(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (target->is_ooc_muted)
if (l_target->m_is_ooc_muted)
sendServerMessage("That player is already OOC muted!");
else {
sendServerMessage("OOC muted player.");
target->sendServerMessage("You were OOC muted by a moderator. " + getReprimand());
l_target->sendServerMessage("You were OOC muted by a moderator. " + getReprimand());
}
target->is_ooc_muted = true;
l_target->m_is_ooc_muted = true;
}
void AOClient::cmdOocUnMute(int argc, QStringList argv)
@ -320,26 +320,26 @@ void AOClient::cmdOocUnMute(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (!target->is_ooc_muted)
if (!l_target->m_is_ooc_muted)
sendServerMessage("That player is not OOC muted!");
else {
sendServerMessage("OOC unmuted player.");
target->sendServerMessage("You were OOC unmuted by a moderator. " + getReprimand(true));
l_target->sendServerMessage("You were OOC unmuted by a moderator. " + getReprimand(true));
}
target->is_ooc_muted = false;
l_target->m_is_ooc_muted = false;
}
void AOClient::cmdBlockWtce(int argc, QStringList argv)
@ -347,26 +347,26 @@ void AOClient::cmdBlockWtce(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (target->is_wtce_blocked)
if (l_target->m_is_wtce_blocked)
sendServerMessage("That player is already judge blocked!");
else {
sendServerMessage("Revoked player's access to judge controls.");
target->sendServerMessage("A moderator revoked your judge controls access. " + getReprimand());
l_target->sendServerMessage("A moderator revoked your judge controls access. " + getReprimand());
}
target->is_wtce_blocked = true;
l_target->m_is_wtce_blocked = true;
}
void AOClient::cmdUnBlockWtce(int argc, QStringList argv)
@ -374,26 +374,26 @@ void AOClient::cmdUnBlockWtce(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (!target->is_wtce_blocked)
if (!l_target->m_is_wtce_blocked)
sendServerMessage("That player is not judge blocked!");
else {
sendServerMessage("Restored player's access to judge controls.");
target->sendServerMessage("A moderator restored your judge controls access. " + getReprimand(true));
l_target->sendServerMessage("A moderator restored your judge controls access. " + getReprimand(true));
}
target->is_wtce_blocked = false;
l_target->m_is_wtce_blocked = false;
}
void AOClient::cmdAllowBlankposting(int argc, QStringList argv)
@ -401,30 +401,30 @@ void AOClient::cmdAllowBlankposting(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QString sender_name = ooc_name;
AreaData* area = server->m_areas[current_area];
area->toggleBlankposting();
if (area->blankpostingAllowed() == false) {
sendServerMessageArea(sender_name + " has set blankposting in the area to forbidden.");
QString l_sender_name = m_ooc_name;
AreaData* l_area = server->m_areas[m_current_area];
l_area->toggleBlankposting();
if (l_area->blankpostingAllowed() == false) {
sendServerMessageArea(l_sender_name + " has set blankposting in the area to forbidden.");
}
else {
sendServerMessageArea(sender_name + " has set blankposting in the area to allowed.");
sendServerMessageArea(l_sender_name + " has set blankposting in the area to allowed.");
}
}
void AOClient::cmdBanInfo(int argc, QStringList argv)
{
QStringList ban_info;
ban_info << ("Ban Info for " + argv[0]);
ban_info << "-----";
QString lookup_type;
QStringList l_ban_info;
l_ban_info << ("Ban Info for " + argv[0]);
l_ban_info << "-----";
QString l_lookup_type;
if (argc == 1) {
lookup_type = "banid";
l_lookup_type = "banid";
}
else if (argc == 2) {
lookup_type = argv[1];
if (!((lookup_type == "banid") || (lookup_type == "ipid") || (lookup_type == "hdid"))) {
l_lookup_type = argv[1];
if (!((l_lookup_type == "banid") || (l_lookup_type == "ipid") || (l_lookup_type == "hdid"))) {
sendServerMessage("Invalid ID type.");
return;
}
@ -433,24 +433,24 @@ void AOClient::cmdBanInfo(int argc, QStringList argv)
sendServerMessage("Invalid command.");
return;
}
QString id = argv[0];
const QList<DBManager::BanInfo> bans = server->db_manager->getBanInfo(lookup_type, id);
for (const DBManager::BanInfo &ban : bans) {
QString banned_until;
if (ban.duration == -2)
banned_until = "The heat death of the universe";
QString l_id = argv[0];
const QList<DBManager::BanInfo> l_bans = server->db_manager->getBanInfo(l_lookup_type, l_id);
for (const DBManager::BanInfo &l_ban : l_bans) {
QString l_banned_until;
if (l_ban.duration == -2)
l_banned_until = "The heat death of the universe";
else
banned_until = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("MM/dd/yyyy, hh:mm");
ban_info << "Ban ID: " + QString::number(ban.id);
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("MM/dd/yyyy, hh:mm");
ban_info << "Ban lasts until: " + banned_until;
ban_info << "Moderator: " + ban.moderator;
ban_info << "-----";
l_banned_until = QDateTime::fromSecsSinceEpoch(l_ban.time).addSecs(l_ban.duration).toString("MM/dd/yyyy, hh:mm");
l_ban_info << "Ban ID: " + QString::number(l_ban.id);
l_ban_info << "Affected IPID: " + l_ban.ipid;
l_ban_info << "Affected HDID: " + l_ban.hdid;
l_ban_info << "Reason for ban: " + l_ban.reason;
l_ban_info << "Date of ban: " + QDateTime::fromSecsSinceEpoch(l_ban.time).toString("MM/dd/yyyy, hh:mm");
l_ban_info << "Ban lasts until: " + l_banned_until;
l_ban_info << "Moderator: " + l_ban.moderator;
l_ban_info << "-----";
}
sendServerMessage(ban_info.join("\n"));
sendServerMessage(l_ban_info.join("\n"));
}
void AOClient::cmdReload(int argc, QStringList argv)
@ -470,10 +470,10 @@ void AOClient::cmdForceImmediate(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
area->toggleImmediate();
QString state = area->forceImmediate() ? "on." : "off.";
sendServerMessage("Forced immediate text processing in this area is now " + state);
AreaData* l_area = server->m_areas[m_current_area];
l_area->toggleImmediate();
QString l_state = l_area->forceImmediate() ? "on." : "off.";
sendServerMessage("Forced immediate text processing in this area is now " + l_state);
}
void AOClient::cmdAllowIniswap(int argc, QStringList argv)
@ -481,9 +481,9 @@ void AOClient::cmdAllowIniswap(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
area->toggleIniswap();
QString state = area->iniswapAllowed() ? "allowed." : "disallowed.";
AreaData* l_area = server->m_areas[m_current_area];
l_area->toggleIniswap();
QString state = l_area->iniswapAllowed() ? "allowed." : "disallowed.";
sendServerMessage("Iniswapping in this area is now " + state);
}
@ -491,77 +491,77 @@ void AOClient::cmdPermitSaving(int argc, QStringList argv)
{
Q_UNUSED(argc);
AOClient* client = server->getClientByID(argv[0].toInt());
if (client == nullptr) {
AOClient* l_client = server->getClientByID(argv[0].toInt());
if (l_client == nullptr) {
sendServerMessage("Invalid ID.");
return;
}
client->testimony_saving = true;
l_client->m_testimony_saving = true;
sendServerMessage("Testimony saving has been enabled for client " + QString::number(l_client->m_id));
}
void AOClient::cmdKickUid(int argc, QStringList argv)
{
QString reason = argv[1];
QString l_reason = argv[1];
if (argc > 2) {
for (int i = 2; i < argv.length(); i++) {
reason += " " + argv[i];
l_reason += " " + argv[i];
}
}
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
if (target == nullptr) {
AOClient* l_target = server->getClientByID(l_uid);
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
target->sendPacket("KK", {reason});
target->socket->close();
sendServerMessage("Kicked client with UID " + argv[0] + " for reason: " + reason);
l_target->sendPacket("KK", {l_reason});
l_target->m_socket->close();
sendServerMessage("Kicked client with UID " + argv[0] + " for reason: " + l_reason);
}
void AOClient::cmdUpdateBan(int argc, QStringList argv)
{
bool conv_ok = false;
int ban_id = argv[0].toInt(&conv_ok);
int l_ban_id = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid ban ID.");
return;
}
QVariant updated_info;
QVariant l_updated_info;
if (argv[1] == "duration") {
long long duration_seconds = 0;
long long l_duration_seconds = 0;
if (argv[2] == "perma")
duration_seconds = -2;
l_duration_seconds = -2;
else
duration_seconds = parseTime(argv[2]);
if (duration_seconds == -1) {
l_duration_seconds = parseTime(argv[2]);
if (l_duration_seconds == -1) {
sendServerMessage("Invalid time format. Format example: 1h30m");
return;
}
updated_info = QVariant(duration_seconds);
l_updated_info = QVariant(l_duration_seconds);
}
else if (argv[1] == "reason") {
QString args_str = argv[2];
QString l_args_str = argv[2];
if (argc > 3) {
for (int i = 3; i < argc; i++)
args_str += " " + argv[i];
l_args_str += " " + argv[i];
}
updated_info = QVariant(args_str);
l_updated_info = QVariant(l_args_str);
}
else {
sendServerMessage("Invalid update type.");
return;
}
if (!server->db_manager->updateBan(ban_id, argv[1], updated_info)) {
if (!server->db_manager->updateBan(l_ban_id, argv[1], l_updated_info)) {
sendServerMessage("There was an error updating the ban. Please confirm the ban ID is valid.");
return;
}

View File

@ -24,16 +24,16 @@ void AOClient::cmdPlay(int argc, QStringList argv)
{
Q_UNUSED(argc);
if (is_dj_blocked) {
if (m_is_dj_blocked) {
sendServerMessage("You are blocked from changing the music.");
return;
}
AreaData* area = server->m_areas[current_area];
QString song = argv.join(" ");
area->currentMusic() = song;
area->musicPlayerBy() = showname;
AOPacket music_change("MC", {song, QString::number(server->getCharID(current_char)), showname, "1", "0"});
server->broadcast(music_change, current_area);
AreaData* l_area = server->m_areas[m_current_area];
QString l_song = argv.join(" ");
l_area->currentMusic() = l_song;
l_area->musicPlayerBy() = m_showname;
AOPacket music_change("MC", {l_song, QString::number(server->getCharID(m_current_char)), m_showname, "1", "0"});
server->broadcast(music_change, m_current_area);
}
void AOClient::cmdCurrentMusic(int argc, QStringList argv)
@ -41,9 +41,9 @@ void AOClient::cmdCurrentMusic(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
if (area->currentMusic() != "" && area->currentMusic() != "~stop.mp3") // dummy track for stopping music
sendServerMessage("The current song is " + area->currentMusic() + " played by " + area->musicPlayerBy());
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->currentMusic() != "" && l_area->currentMusic() != "~stop.mp3") // dummy track for stopping music
sendServerMessage("The current song is " + l_area->currentMusic() + " played by " + l_area->musicPlayerBy());
else
sendServerMessage("There is no music playing.");
}
@ -53,26 +53,26 @@ void AOClient::cmdBlockDj(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (target->is_dj_blocked)
if (l_target->m_is_dj_blocked)
sendServerMessage("That player is already DJ blocked!");
else {
sendServerMessage("DJ blocked player.");
target->sendServerMessage("You were blocked from changing the music by a moderator. " + getReprimand());
l_target->sendServerMessage("You were blocked from changing the music by a moderator. " + getReprimand());
}
target->is_dj_blocked = true;
l_target->m_is_dj_blocked = true;
}
void AOClient::cmdUnBlockDj(int argc, QStringList argv)
@ -80,26 +80,26 @@ void AOClient::cmdUnBlockDj(int argc, QStringList argv)
Q_UNUSED(argc);
bool conv_ok = false;
int uid = argv[0].toInt(&conv_ok);
int l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
AOClient* target = server->getClientByID(uid);
AOClient* l_target = server->getClientByID(l_uid);
if (target == nullptr) {
if (l_target == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
if (!target->is_dj_blocked)
if (!l_target->m_is_dj_blocked)
sendServerMessage("That player is not DJ blocked!");
else {
sendServerMessage("DJ permissions restored to player.");
target->sendServerMessage("A moderator restored your music permissions. " + getReprimand(true));
l_target->sendServerMessage("A moderator restored your music permissions. " + getReprimand(true));
}
target->is_dj_blocked = false;
l_target->m_is_dj_blocked = false;
}
void AOClient::cmdToggleMusic(int argc, QStringList argv)
@ -107,8 +107,8 @@ void AOClient::cmdToggleMusic(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
area->toggleMusic();
QString state = area->isMusicAllowed() ? "allowed." : "disallowed.";
sendServerMessage("Music in this area is now " + state);
AreaData* l_area = server->m_areas[m_current_area];
l_area->toggleMusic();
QString l_state = l_area->isMusicAllowed() ? "allowed." : "disallowed.";
sendServerMessage("Music in this area is now " + l_state);
}

View File

@ -25,10 +25,10 @@ void AOClient::cmdFlip(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QString sender_name = ooc_name;
QStringList faces = {"heads","tails"};
QString face = faces[AOClient::genRand(0,1)];
sendServerMessageArea(sender_name + " flipped a coin and got " + face + ".");
QString l_sender_name = m_ooc_name;
QStringList l_faces = {"heads","tails"};
QString l_face = l_faces[AOClient::genRand(0,1)];
sendServerMessageArea(l_sender_name + " flipped a coin and got " + l_face + ".");
}
void AOClient::cmdRoll(int argc, QStringList argv)
@ -43,24 +43,24 @@ void AOClient::cmdRollP(int argc, QStringList argv)
void AOClient::cmdTimer(int argc, QStringList argv)
{
AreaData* area = server->m_areas[current_area];
AreaData* l_area = server->m_areas[m_current_area];
// Called without arguments
// Shows a brief of all timers
if (argc == 0) {
QStringList timers;
timers.append("Currently active timers:");
QStringList l_timers;
l_timers.append("Currently active timers:");
for (int i = 0; i <= 4; i++) {
timers.append(getAreaTimer(area->index(), i));
l_timers.append(getAreaTimer(l_area->index(), i));
}
sendServerMessage(timers.join("\n"));
sendServerMessage(l_timers.join("\n"));
return;
}
// Called with more than one argument
bool ok;
int timer_id = argv[0].toInt(&ok);
if (!ok || timer_id < 0 || timer_id > 4) {
int l_timer_id = argv[0].toInt(&ok);
if (!ok || l_timer_id < 0 || l_timer_id > 4) {
sendServerMessage("Invalid timer ID. Timer ID must be a whole number between 0 and 4.");
return;
}
@ -68,7 +68,7 @@ void AOClient::cmdTimer(int argc, QStringList argv)
// Called with one argument
// Shows the status of one timer
if (argc == 1) {
sendServerMessage(getAreaTimer(area->index(), timer_id));
sendServerMessage(getAreaTimer(l_area->index(), l_timer_id));
return;
}
@ -77,55 +77,55 @@ void AOClient::cmdTimer(int argc, QStringList argv)
// Select the proper timer
// Check against permissions if global timer is selected
QTimer* requested_timer;
if (timer_id == 0) {
QTimer* l_requested_timer;
if (l_timer_id == 0) {
if (!checkAuth(ACLFlags.value("GLOBAL_TIMER"))) {
sendServerMessage("You are not authorized to alter the global timer.");
return;
}
requested_timer = server->timer;
l_requested_timer = server->timer;
}
else
requested_timer = area->timers().at(timer_id - 1);
l_requested_timer = l_area->timers().at(l_timer_id - 1);
AOPacket show_timer("TI", {QString::number(timer_id), "2"});
AOPacket hide_timer("TI", {QString::number(timer_id), "3"});
bool is_global = timer_id == 0;
AOPacket l_show_timer("TI", {QString::number(l_timer_id), "2"});
AOPacket l_hide_timer("TI", {QString::number(l_timer_id), "3"});
bool l_is_global = l_timer_id == 0;
// Set the timer's time remaining if the second
// argument is a valid time
QTime requested_time = QTime::fromString(argv[1], "hh:mm:ss");
if (requested_time.isValid()) {
requested_timer->setInterval(QTime(0,0).msecsTo(requested_time));
requested_timer->start();
sendServerMessage("Set timer " + QString::number(timer_id) + " to " + argv[1] + ".");
AOPacket update_timer("TI", {QString::number(timer_id), "0", QString::number(QTime(0,0).msecsTo(requested_time))});
is_global ? server->broadcast(show_timer) : server->broadcast(show_timer, current_area); // Show the timer
is_global ? server->broadcast(update_timer) : server->broadcast(update_timer, current_area);
QTime l_requested_time = QTime::fromString(argv[1], "hh:mm:ss");
if (l_requested_time.isValid()) {
l_requested_timer->setInterval(QTime(0,0).msecsTo(l_requested_time));
l_requested_timer->start();
sendServerMessage("Set timer " + QString::number(l_timer_id) + " to " + argv[1] + ".");
AOPacket l_update_timer("TI", {QString::number(l_timer_id), "0", QString::number(QTime(0,0).msecsTo(l_requested_time))});
l_is_global ? server->broadcast(l_show_timer) : server->broadcast(l_show_timer, m_current_area); // Show the timer
l_is_global ? server->broadcast(l_update_timer) : server->broadcast(l_update_timer, m_current_area);
return;
}
// Otherwise, update the state of the timer
else {
if (argv[1] == "start") {
requested_timer->start();
sendServerMessage("Started timer " + QString::number(timer_id) + ".");
AOPacket update_timer("TI", {QString::number(timer_id), "0", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(requested_timer->remainingTime())))});
is_global ? server->broadcast(show_timer) : server->broadcast(show_timer, current_area);
is_global ? server->broadcast(update_timer) : server->broadcast(update_timer, current_area);
l_requested_timer->start();
sendServerMessage("Started timer " + QString::number(l_timer_id) + ".");
AOPacket l_update_timer("TI", {QString::number(l_timer_id), "0", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(l_requested_timer->remainingTime())))});
l_is_global ? server->broadcast(l_show_timer) : server->broadcast(l_show_timer, m_current_area);
l_is_global ? server->broadcast(l_update_timer) : server->broadcast(l_update_timer, m_current_area);
}
else if (argv[1] == "pause" || argv[1] == "stop") {
requested_timer->setInterval(requested_timer->remainingTime());
requested_timer->stop();
sendServerMessage("Stopped timer " + QString::number(timer_id) + ".");
AOPacket update_timer("TI", {QString::number(timer_id), "1", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(requested_timer->interval())))});
is_global ? server->broadcast(update_timer) : server->broadcast(update_timer, current_area);
l_requested_timer->setInterval(l_requested_timer->remainingTime());
l_requested_timer->stop();
sendServerMessage("Stopped timer " + QString::number(l_timer_id) + ".");
AOPacket l_update_timer("TI", {QString::number(l_timer_id), "1", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(l_requested_timer->interval())))});
l_is_global ? server->broadcast(l_update_timer) : server->broadcast(l_update_timer, m_current_area);
}
else if (argv[1] == "hide" || argv[1] == "unset") {
requested_timer->setInterval(0);
requested_timer->stop();
sendServerMessage("Hid timer " + QString::number(timer_id) + ".");
l_requested_timer->setInterval(0);
l_requested_timer->stop();
sendServerMessage("Hid timer " + QString::number(l_timer_id) + ".");
// Hide the timer
is_global ? server->broadcast(hide_timer) : server->broadcast(hide_timer, current_area);
l_is_global ? server->broadcast(l_hide_timer) : server->broadcast(l_hide_timer, m_current_area);
}
}
}
@ -134,10 +134,10 @@ void AOClient::cmdNoteCard(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* area = server->m_areas[current_area];
QString notecard = argv.join(" ");
area->addNotecard(current_char, notecard);
sendServerMessageArea(current_char + " wrote a note card.");
AreaData* l_area = server->m_areas[m_current_area];
QString l_notecard = argv.join(" ");
l_area->addNotecard(m_current_char, l_notecard);
sendServerMessageArea(m_current_char + " wrote a note card.");
}
void AOClient::cmdNoteCardClear(int argc, QStringList argv)
@ -145,9 +145,9 @@ void AOClient::cmdNoteCardClear(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
if (!area->addNotecard(current_char, QString())) {
sendServerMessageArea(current_char + " erased their note card.");
AreaData* l_area = server->m_areas[m_current_area];
if (!l_area->addNotecard(m_current_char, QString())) {
sendServerMessageArea(m_current_char + " erased their note card.");
}
}
@ -156,18 +156,18 @@ void AOClient::cmdNoteCardReveal(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->m_areas[current_area];
const QStringList l_notecards = area->getNotecards();
AreaData* l_area = server->m_areas[m_current_area];
const QStringList l_notecards = l_area->getNotecards();
if (l_notecards.isEmpty()) {
sendServerMessage("There are no cards to reveal in this area.");
return;
}
QString message("Note cards have been revealed.\n");
message.append(l_notecards.join("\n") + "\n");
QString l_message("Note cards have been revealed.\n");
l_message.append(l_notecards.join("\n") + "\n");
sendServerMessageArea(message);
sendServerMessageArea(l_message);
}
void AOClient::cmd8Ball(int argc, QStringList argv)
@ -179,11 +179,11 @@ void AOClient::cmd8Ball(int argc, QStringList argv)
sendServerMessage("8ball.txt is empty.");
}
else {
QString response = ConfigManager::magic8BallAnswers().at((genRand(1, ConfigManager::magic8BallAnswers().size() - 1)));
QString sender_name = ooc_name;
QString sender_message = argv.join(" ");
QString l_response = ConfigManager::magic8BallAnswers().at((genRand(1, ConfigManager::magic8BallAnswers().size() - 1)));
QString l_sender_name = m_ooc_name;
QString l_sender_message = argv.join(" ");
sendServerMessageArea(sender_name + " asked the magic 8-ball, \"" + sender_message + "\" and the answer is: " + response);
sendServerMessageArea(l_sender_name + " asked the magic 8-ball, \"" + l_sender_message + "\" and the answer is: " + l_response);
}
}
@ -191,10 +191,10 @@ void AOClient::cmdSubTheme(int argc, QStringList argv)
{
Q_UNUSED(argc);
QString subtheme = argv.join(" ");
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->current_area == current_area)
client->sendPacket("ST", {subtheme, "1"});
QString l_subtheme = argv.join(" ");
for (AOClient* l_client : qAsConst(server->m_clients)) {
if (l_client->m_current_area == m_current_area)
l_client->sendPacket("ST", {l_subtheme, "1"});
}
sendServerMessageArea("Subtheme was set to " + subtheme);
sendServerMessageArea("Subtheme was set to " + l_subtheme);
}

File diff suppressed because it is too large Load Diff

View File

@ -104,7 +104,7 @@ void Server::clientConnected()
int user_id;
QList<int> user_ids;
for (AOClient* client : qAsConst(m_clients)) {
user_ids.append(client->id);
user_ids.append(client->m_id);
}
for (user_id = 0; user_id <= m_player_count; user_id++) {
if (user_ids.contains(user_id))
@ -120,11 +120,11 @@ void Server::clientConnected()
auto ban = db_manager->isIPBanned(client->getIpid());
bool is_banned = ban.first;
for (AOClient* joined_client : qAsConst(m_clients)) {
if (client->remote_ip.isEqual(joined_client->remote_ip))
if (client->m_remote_ip.isEqual(joined_client->m_remote_ip))
multiclient_count++;
}
if (multiclient_count > ConfigManager::multiClientLimit() && !client->remote_ip.isLoopback()) // TODO: make this configurable
if (multiclient_count > ConfigManager::multiClientLimit() && !client->m_remote_ip.isLoopback()) // TODO: make this configurable
is_at_multiclient_limit = true;
if (is_banned) {
@ -170,8 +170,8 @@ void Server::updateCharsTaken(AreaData* area)
AOPacket response_cc("CharsCheck", chars_taken);
for (AOClient* client : qAsConst(m_clients)) {
if (client->current_area == area->index()){
if (!client->is_charcursed)
if (client->m_current_area == area->index()){
if (!client->m_is_charcursed)
client->sendPacket(response_cc);
else {
QStringList chars_taken_cursed = getCursedCharsTaken(client, chars_taken);
@ -186,7 +186,7 @@ QStringList Server::getCursedCharsTaken(AOClient* client, QStringList chars_take
{
QStringList chars_taken_cursed;
for (int i = 0; i < chars_taken.length(); i++) {
if (!client->charcurse_list.contains(i))
if (!client->m_charcurse_list.contains(i))
chars_taken_cursed.append("-1");
else
chars_taken_cursed.append(chars_taken.value(i));
@ -197,7 +197,7 @@ QStringList Server::getCursedCharsTaken(AOClient* client, QStringList chars_take
void Server::broadcast(AOPacket packet, int area_index)
{
for (AOClient* client : qAsConst(m_clients)) {
if (client->current_area == area_index)
if (client->m_current_area == area_index)
client->sendPacket(packet);
}
}
@ -222,7 +222,7 @@ QList<AOClient*> Server::getClientsByIpid(QString ipid)
AOClient* Server::getClientByID(int id)
{
for (AOClient* client : qAsConst(m_clients)) {
if (client->id == id)
if (client->m_id == id)
return client;
}
return nullptr;

View File

@ -22,7 +22,7 @@ void AOClient::addStatement(QStringList packet)
if (checkTestimonySymbols(packet[4])) {
return;
}
AreaData* area = server->m_areas[current_area];
AreaData* area = server->m_areas[m_current_area];
int c_statement = area->statement();
if (c_statement >= -1) {
if (area->testimonyRecording() == AreaData::TestimonyRecording::RECORDING) {
@ -55,7 +55,7 @@ QStringList AOClient::updateStatement(QStringList packet)
if (checkTestimonySymbols(packet[4])) {
return packet;
}
AreaData* area = server->m_areas[current_area];
AreaData* area = server->m_areas[m_current_area];
int c_statement = area->statement();
area->setTestimonyRecording(AreaData::TestimonyRecording::PLAYBACK);
if (c_statement <= 0 || area->testimony()[c_statement].empty())
@ -71,7 +71,7 @@ QStringList AOClient::updateStatement(QStringList packet)
void AOClient::clearTestimony()
{
AreaData* area = server->m_areas[current_area];
AreaData* area = server->m_areas[m_current_area];
area->clearTestimony();
}