Merge pull request #198 from Salanto/The-Salanto-Cleanup-Project

Enforce a more consistent variable naming sheme and move some config loading into ConfigManager
This commit is contained in:
Rosemary Witchaven 2021-09-12 02:28:15 -05:00 committed by GitHub
commit 95cf31f656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 1499 additions and 1402 deletions

View File

@ -51,12 +51,12 @@ class AOClient : public QObject {
* @param parent Qt-based parent, passed along to inherited constructor from QObject.
*/
AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr, int user_id = 0)
: QObject(parent), id(user_id), remote_ip(p_socket->peerAddress()), password(""),
joined(false), current_area(0), current_char(""), socket(p_socket), server(p_server),
is_partial(false), last_wtce_time(0) {
afk_timer = new QTimer;
afk_timer->setSingleShot(true);
connect(afk_timer, SIGNAL(timeout()), this, SLOT(onAfkTimeout()));
: 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), m_last_wtce_time(0) {
m_afk_timer = new QTimer;
m_afk_timer->setSingleShot(true);
connect(m_afk_timer, SIGNAL(timeout()), this, SLOT(onAfkTimeout()));
};
/**
@ -103,17 +103,17 @@ class AOClient : public QObject {
/**
* @brief The user ID of the client.
*/
int id;
int m_id;
/**
* @brief The IP address of the client.
*/
QHostAddress remote_ip;
QHostAddress m_remote_ip;
/**
* @brief The stored character password for the client, used to be able to select passworded characters.
*/
QString password;
QString m_password;
/**
* @brief True if the client is actually in the server.
@ -124,78 +124,78 @@ class AOClient : public QObject {
* The purpose of this variable is to determine if the user isn't just doing that, but has actually double-clicked the server, and
* its client has sent the standard handshake packets, which does signify that the client intended to 'join' this server.
*/
bool joined;
bool m_joined;
/**
* @brief The ID of the area the client is currently in.
*/
int current_area;
int m_current_area;
/**
* @brief The internal name of the character the client is currently using.
*/
QString current_char;
QString m_current_char;
/**
* @brief The internal name of the character the client is iniswapped to.
*
* @note This will be the same as current_char if the client is not iniswapped.
*/
QString current_iniswap;
QString m_current_iniswap;
/**
* @brief If true, the client is a logged-in moderator.
*/
bool authenticated = false;
bool m_authenticated = false;
/**
* @brief If using advanced authentication, this is the moderator name that the client has logged in with.
*/
QString moderator_name = "";
QString m_moderator_name = "";
/**
* @brief The out-of-character name of the client, generally the nickname of the user themself.
*/
QString ooc_name = "";
QString m_ooc_name = "";
/**
* @brief The custom showname of the client, used when "renaming" already existing characters in-character.
*/
QString showname = "";
QString m_showname = "";
/**
* @brief If true, the client is willing to receive global messages.
*
* @see AOClient::cmdG and AOClient::cmdToggleGlobal
*/
bool global_enabled = true;
bool m_global_enabled = true;
/**
* @brief If true, the client's messages will be sent in first-person mode.
*
* @see AOClient::cmdFirstPerson
*/
bool first_person = false;
bool m_first_person = false;
/**
* @brief If true, the client may not use in-character chat.
*/
bool is_muted = false;
bool m_is_muted = false;
/**
* @brief If true, the client may not use out-of-character chat.
*/
bool is_ooc_muted = false;
bool m_is_ooc_muted = false;
/**
* @brief If true, the client may not use the music list.
*/
bool is_dj_blocked = false;
bool m_is_dj_blocked = false;
/**
* @brief If true, the client may not use the judge controls.
*/
bool is_wtce_blocked = false;
bool m_is_wtce_blocked = false;
/**
* @brief Represents the client's client software, and its version.
@ -215,7 +215,7 @@ class AOClient : public QObject {
*
* @see The struct itself for more details.
*/
ClientVersion version;
ClientVersion m_version;
/**
* @brief The authorisation bitflag, representing what permissions a client can have.
@ -248,63 +248,63 @@ class AOClient : public QObject {
/**
* @brief A list of 5 casing preferences (def, pro, judge, jury, steno)
*/
QList<bool> casing_preferences = {false, false, false, false, false};
QList<bool> m_casing_preferences = {false, false, false, false, false};
/**
* @brief If true, the client's in-character messages will have their word order randomised.
*/
bool is_shaken = false;
bool m_is_shaken = false;
/**
* @brief If true, the client's in-character messages will have their vowels (English alphabet only) removed.
*/
bool is_disemvoweled = false;
bool m_is_disemvoweled = false;
/**
* @brief If true, the client's in-character messages will be overwritten by a randomly picked predetermined message.
*/
bool is_gimped = false;
bool m_is_gimped = false;
/**
* @brief If true, the client will be marked as AFK in /getarea. Automatically applied when a configurable
* amount of time has passed since the last interaction, or manually applied by /afk.
*/
bool is_afk = false;
bool m_is_afk = false;
/**
* @brief If true, the client will not recieve PM messages.
*/
bool pm_mute = false;
bool m_pm_mute = false;
/**
* @brief If true, the client will recieve advertisements.
*/
bool advert_enabled = true;
bool m_advert_enabled = true;
/**
* @brief If true, the client is restricted to only changing into certain characters.
*/
bool is_charcursed = false;
bool m_is_charcursed = false;
/**
* @brief Timer for tracking user interaction. Automatically restarted whenever a user interacts (i.e. sends any packet besides CH)
*/
QTimer* afk_timer;
QTimer* m_afk_timer;
/**
* @brief The list of char IDs a charcursed player is allowed to switch to.
*/
QList<int> charcurse_list;
QList<int> m_charcurse_list;
/**
* @brief Temporary client permission if client is allowed to save a testimony to server storage.
*/
bool testimony_saving = false;
bool m_testimony_saving = false;
/**
* @brief If true, the client's next OOC message will be interpreted as a moderator login.
*/
bool is_logging_in = false;
bool m_is_logging_in = false;
public slots:
/**
@ -343,7 +343,7 @@ class AOClient : public QObject {
/**
* @brief The TCP socket used to communicate with the client.
*/
QTcpSocket* socket;
QTcpSocket* m_socket;
/**
* @brief A pointer to the Server, used for updating server variables that depend on the client (e.g. amount of players in an area).
@ -609,7 +609,7 @@ class AOClient : public QObject {
*
* In general, the client assumes that this is a continuous block starting from 0.
*/
int char_id = -1;
int m_char_id = -1;
/**
* @brief The character ID of the other character that the client wants to pair up with.
@ -618,7 +618,7 @@ class AOClient : public QObject {
* Furthermore, the owner of that character ID must also do the reverse to this client, making their `pairing_with` equal
* to this client's character ID.
*/
int pairing_with = -1;
int m_pairing_with = -1;
/**
* @brief The name of the emote last used by the client. No extension.
@ -626,7 +626,7 @@ class AOClient : public QObject {
* @details This is used for pairing mainly, for the server to be able to craft a smooth-looking transition from one
* paired-up client talking to the next.
*/
QString emote = "";
QString m_emote = "";
/**
* @brief The amount the client was last offset by.
@ -634,17 +634,17 @@ class AOClient : public QObject {
* @details This used to be just a plain number ranging from -100 to 100, but then Crystal mangled it by building some extra data into it.
* Cheers, love.
*/
QString offset = "";
QString m_offset = "";
/**
* @brief The last flipped state of the client.
*/
QString flipping = "";
QString m_flipping = "";
/**
* @brief The last reported position of the client.
*/
QString pos = "";
QString m_pos = "";
///@}
@ -1896,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.
@ -1937,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.
@ -1946,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);
/**
@ -2145,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
@ -2160,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

@ -44,6 +44,53 @@ class ConfigManager {
*/
static bool verifyServerConfig();
/**
* @brief Returns the IP the TCP Server binds to.
*
* @return See short description
*/
static QString bindIP();
/**
* @brief Returns the character list of the server.
*
* @return See short description.
*/
static QStringList charlist();
/**
* @brief Returns the a QStringList of the available backgrounds.
*
* @return See short description.
*/
static QStringList backgrounds();
/**
* @brief Returns a QStringlist of the available songs.
*
* @return See short description.
*/
static QStringList musiclist();
/**
* @brief Returns the content of
* @return
*/
static QSettings *areaData();
/**
* @brief Returns a sanitized QStringList of the areas.
*
* @return See short description.
*/
static QStringList sanitizedAreaNames();
/**
* @brief Returns the raw arealist
*
* @return See short description.
*/
static QStringList rawAreaNames();
/**
* @brief Returns true if the server should advertise to the master server.
*
@ -424,6 +471,11 @@ private:
*/
static QSettings* m_discord;
/**
* @brief Stores all of the area valus.
*/
static QSettings* m_areas;
/**
* @brief Pointer to QElapsedTimer to track the uptime of the server.
*/

View File

@ -69,7 +69,7 @@ public slots:
* @brief Reads the information send as a reply for further error handling.
* @param reply Response data from the masterserver. Information contained is send to the console if debug is enabled.
*/
void msRequestFinished(QNetworkReply *reply);
void msRequestFinished(QNetworkReply *f_reply);
/**
* @brief Sets the values being advertised to masterserver.

View File

@ -55,41 +55,41 @@ public slots:
/**
* @brief Adds an IC log entry to the area buffer and writes it to the respective log format.
*/
void logIC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid,
const QString& f_areaName, const QString &f_message);
void logIC(const QString& f_char_name, const QString& f_ooc_name, const QString& f_ipid,
const QString& f_area_name, const QString &f_message);
/**
* @brief Adds an OOC log entry to the area buffer and writes it to the respective log format.
*/
void logOOC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid,
const QString& f_areaName, const QString& f_message);
const QString& f_area_name, const QString& f_message);
/**
* @brief Adds an login attempt to the area buffer and writes it to the respective log format.
*/
void logLogin(const QString& f_charName, const QString& f_oocName, const QString& f_moderatorName,
const QString& f_ipid, const QString &f_areaName, const bool& f_success);
void logLogin(const QString& f_char_name, const QString& f_ooc_name, const QString& f_moderator_name,
const QString& f_ipid, const QString &f_area_name, const bool& f_success);
/**
* @brief Adds a command usage to the area buffer and writes it to the respective log format.
*/
void logCMD(const QString& f_charName, const QString &f_ipid, const QString& f_oocName, const QString f_command,
const QStringList f_args, const QString f_areaName);
void logCMD(const QString& f_char_name, const QString &f_ipid, const QString& f_ooc_name, const QString& f_command,
const QStringList& f_args, const QString& f_area_name);
/**
* @brief Adds a player kick to the area buffer and writes it to the respective log format.
*/
void logKick(const QString& f_moderator, const QString& f_targetIPID);
void logKick(const QString& f_moderator, const QString& f_target_ipid);
/**
* @brief Adds a player ban to the area buffer and writes it to the respective log format.
*/
void logBan(const QString& f_moderator, const QString& f_targetIPID, const QString &f_duration);
void logBan(const QString& f_moderator, const QString& f_target_ipid, const QString &f_duration);
/**
* @brief Adds a modcall event to the area buffer, also triggers modcall writing.
*/
void logModcall(const QString& f_charName, const QString &f_ipid, const QString& f_oocName, const QString& f_areaName);
void logModcall(const QString& f_charName, const QString &f_ipid, const QString& f_oocName, const QString& f_area_name);
/**
* @brief Logs any connection attempt to the server, wether sucessful or not.
@ -103,7 +103,7 @@ private:
* @param Name of the area which buffer is modified.
* @param Formatted QString to be added into the buffer.
*/
void updateAreaBuffer(const QString& f_areaName, const QString& f_logEntry);
void updateAreaBuffer(const QString& f_areaName, const QString& f_log_entry);
/**
* @brief QMap of all available area buffers.

View File

@ -55,7 +55,7 @@ public:
* @param Preformatted QString which will be written into the logfile
* @param Area name of the target logfile.
*/
void flush(const QString f_entry, const QString f_areaName);
void flush(const QString f_entry, const QString f_area_name);
private:
/**

View File

@ -51,7 +51,7 @@ public:
* @param QQueue of the area that will be written into the logfile.
* @param Name of the area for the filename.
*/
void flush(const QString f_areaName, QQueue<QString> f_buffer);
void flush(const QString f_area_name, QQueue<QString> f_buffer);
private:
/**

View File

@ -157,22 +157,22 @@ class Server : public QObject {
/**
* @brief The collection of all currently connected clients.
*/
QVector<AOClient*> clients;
QVector<AOClient*> m_clients;
/**
* @brief The overall player count in the server.
*/
int player_count;
int m_player_count;
/**
* @brief The characters available on the server to use.
*/
QStringList characters;
QStringList m_characters;
/**
* @brief The areas on the server.
*/
QVector<AreaData*> areas;
QVector<AreaData*> m_areas;
/**
* @brief The names of the areas on the server.
@ -180,7 +180,7 @@ class Server : public QObject {
* @details Equivalent to iterating over #areas and getting the area names individually, but grouped together
* here for faster access.
*/
QStringList area_names;
QStringList m_area_names;
/**
* @brief The available songs on the server.
@ -188,12 +188,12 @@ class Server : public QObject {
* @details Does **not** include the area names, the actual music list packet should be constructed from
* #area_names and this combined.
*/
QStringList music_list;
QStringList m_music_list;
/**
* @brief The backgrounds on the server that may be used in areas.
*/
QStringList backgrounds;
QStringList m_backgrounds;
/**
* @brief The database manager on the server, used to store users' bans and authorisation details.

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) {
server->player_count--;
server->areas[current_area]->clientLeftArea(server->getCharID(current_char));
if (m_joined) {
server->m_player_count--;
server->m_areas[m_current_area]->clientLeftArea(server->getCharID(m_current_char));
arup(ARUPType::PLAYER_COUNT, true);
}
if (current_char != "") {
server->updateCharsTaken(server->areas[current_area]);
if (m_current_char != "") {
server->updateCharsTaken(server->m_areas[m_current_area]);
}
bool l_updateLocks = false;
for (AreaData* area : qAsConst(server->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->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->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->areas[new_area]->lockStatus() == AreaData::LockStatus::LOCKED && !server->areas[new_area]->invited().contains(id) && !checkAuth(ACLFlags.value("BYPASS_LOCKS"))) {
sendServerMessage("Area " + server->area_names[new_area] + " is locked.");
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->areas[current_area]->changeCharacter(server->getCharID(current_char), -1);
server->updateCharsTaken(server->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->areas[current_area]->clientLeftArea(char_id);
bool character_taken = false;
if (server->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->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->areas[new_area]);
sendPacket("HP", {"1", QString::number(server->areas[new_area]->defHP())});
sendPacket("HP", {"2", QString::number(server->areas[new_area]->proHP())});
sendPacket("BN", {server->areas[new_area]->background()});
if (character_taken) {
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 (l_character_taken) {
sendPacket("DONE");
}
const QList<QTimer*> timers = server->areas[current_area]->timers();
for (QTimer* timer : timers) {
int timer_id = server->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->area_names[current_area]);
if (server->areas[current_area]->lockStatus() == AreaData::LockStatus::SPECTATABLE)
sendServerMessage("Area " + server->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->areas[current_area];
AreaData* l_area = server->m_areas[m_current_area];
if(char_id >= server->characters.length())
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->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->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->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

@ -35,23 +35,20 @@ AreaData::AreaData(QString p_name, int p_index) :
QStringList name_split = p_name.split(":");
name_split.removeFirst();
m_name = name_split.join(":");
QSettings areas_ini("config/areas.ini", QSettings::IniFormat);
areas_ini.setIniCodec("UTF-8");
areas_ini.beginGroup(p_name);
m_background = areas_ini.value("background", "gs4").toString();
m_isProtected = areas_ini.value("protected_area", "false").toBool();
m_iniswapAllowed = areas_ini.value("iniswap_allowed", "true").toBool();
m_bgLocked = areas_ini.value("bg_locked", "false").toBool();
m_eviMod = QVariant(areas_ini.value("evidence_mod", "FFA").toString().toUpper()).value<EvidenceMod>();
m_blankpostingAllowed = areas_ini.value("blankposting_allowed","true").toBool();
m_forceImmediate = areas_ini.value("force_immediate", "false").toBool();
m_toggleMusic = areas_ini.value("toggle_music", "true").toBool();
m_shownameAllowed = areas_ini.value("shownames_allowed", "true").toBool();
m_ignoreBgList = areas_ini.value("ignore_bglist", "false").toBool();
areas_ini.endGroup();
int log_size = ConfigManager::logBuffer();
if (log_size == 0)
log_size = 500;
QSettings* areas_ini = ConfigManager::areaData();
areas_ini->setIniCodec("UTF-8");
areas_ini->beginGroup(p_name);
m_background = areas_ini->value("background", "gs4").toString();
m_isProtected = areas_ini->value("protected_area", "false").toBool();
m_iniswapAllowed = areas_ini->value("iniswap_allowed", "true").toBool();
m_bgLocked = areas_ini->value("bg_locked", "false").toBool();
m_eviMod = QVariant(areas_ini->value("evidence_mod", "FFA").toString().toUpper()).value<EvidenceMod>();
m_blankpostingAllowed = areas_ini->value("blankposting_allowed","true").toBool();
m_forceImmediate = areas_ini->value("force_immediate", "false").toBool();
m_toggleMusic = areas_ini->value("toggle_music", "true").toBool();
m_shownameAllowed = areas_ini->value("shownames_allowed", "true").toBool();
m_ignoreBgList = areas_ini->value("ignore_bglist", "false").toBool();
areas_ini->endGroup();
QTimer* timer1 = new QTimer();
m_timers.append(timer1);
QTimer* timer2 = new QTimer();

View File

@ -23,33 +23,33 @@
void AOClient::cmdCM(int argc, QStringList argv)
{
QString sender_name = ooc_name;
AreaData* area = server->areas[current_area];
if (area->isProtected()) {
QString l_sender_name = m_ooc_name;
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->isProtected()) {
sendServerMessage("This area is protected, you may not become CM.");
return;
}
else if (area->owners().isEmpty()) { // no one owns this area, and it's not protected
area->addOwner(id);
sendServerMessageArea(sender_name + " is now CM in this area.");
else if (l_area->owners().isEmpty()) { // no one owns this area, and it's not protected
l_area->addOwner(m_id);
sendServerMessageArea(l_sender_name + " is now CM in this area.");
arup(ARUPType::CM, true);
}
else if (!area->owners().contains(id)) { // there is already a CM, and it isn't us
else if (!l_area->owners().contains(m_id)) { // there is already a CM, and it isn't us
sendServerMessage("You cannot become a CM in this area.");
}
else if (argc == 1) { // we are CM, and we want to make ID argv[0] also CM
bool ok;
AOClient* owner_candidate = server->getClientByID(argv[0].toInt(&ok));
AOClient* l_owner_candidate = server->getClientByID(argv[0].toInt(&ok));
if (!ok) {
sendServerMessage("That doesn't look like a valid ID.");
return;
}
if (owner_candidate == nullptr) {
if (l_owner_candidate == nullptr) {
sendServerMessage("Unable to find client with ID " + argv[0] + ".");
return;
}
area->addOwner(owner_candidate->id);
sendServerMessageArea(owner_candidate->ooc_name + " is now CM in this area.");
l_area->addOwner(l_owner_candidate->m_id);
sendServerMessageArea(l_owner_candidate->m_ooc_name + " is now CM in this area.");
arup(ARUPType::CM, true);
}
else {
@ -59,41 +59,41 @@ void AOClient::cmdCM(int argc, QStringList argv)
void AOClient::cmdUnCM(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
int uid;
AreaData* l_area = server->m_areas[m_current_area];
int l_uid;
if (area->owners().isEmpty()) {
if (l_area->owners().isEmpty()) {
sendServerMessage("There are no CMs in this area.");
return;
}
else if (argc == 0) {
uid = id;
l_uid = m_id;
sendServerMessage("You are no longer CM in this area.");
}
else if (checkAuth(ACLFlags.value("UNCM")) && argc == 1) {
bool conv_ok = false;
uid = argv[0].toInt(&conv_ok);
l_uid = argv[0].toInt(&conv_ok);
if (!conv_ok) {
sendServerMessage("Invalid user ID.");
return;
}
if (!area->owners().contains(uid)) {
if (!l_area->owners().contains(l_uid)) {
sendServerMessage("That user is not CMed.");
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->sendServerMessage("You have been unCMed by a moderator.");
l_target->sendServerMessage("You have been unCMed by a moderator.");
}
else {
sendServerMessage("Invalid command.");
return;
}
if (area->removeOwner(uid)) {
if (l_area->removeOwner(l_uid)) {
arup(ARUPType::LOCKED, true);
}
@ -104,54 +104,54 @@ void AOClient::cmdInvite(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* area = server->areas[current_area];
AreaData* l_area = server->m_areas[m_current_area];
bool ok;
int invited_id = argv[0].toInt(&ok);
int l_invited_id = argv[0].toInt(&ok);
if (!ok) {
sendServerMessage("That does not look like a valid ID.");
return;
}
AOClient* target_client = server->getClientByID(invited_id);
AOClient* target_client = server->getClientByID(l_invited_id);
if (target_client == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
else if (!area->invite(invited_id)) {
else if (!l_area->invite(l_invited_id)) {
sendServerMessage("That ID is already on the invite list.");
return;
}
sendServerMessage("You invited ID " + argv[0]);
target_client->sendServerMessage("You were invited and given access to " + area->name());
target_client->sendServerMessage("You were invited and given access to " + l_area->name());
}
void AOClient::cmdUnInvite(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* area = server->areas[current_area];
AreaData* l_area = server->m_areas[m_current_area];
bool ok;
int uninvited_id = argv[0].toInt(&ok);
int l_uninvited_id = argv[0].toInt(&ok);
if (!ok) {
sendServerMessage("That does not look like a valid ID.");
return;
}
AOClient* target_client = server->getClientByID(uninvited_id);
AOClient* target_client = server->getClientByID(l_uninvited_id);
if (target_client == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
else if (area->owners().contains(uninvited_id)) {
else if (l_area->owners().contains(l_uninvited_id)) {
sendServerMessage("You cannot uninvite a CM!");
return;
}
else if (!area->uninvite(uninvited_id)) {
else if (!l_area->uninvite(l_uninvited_id)) {
sendServerMessage("That ID is not on the invite list.");
return;
}
sendServerMessage("You uninvited ID " + argv[0]);
target_client->sendServerMessage("You were uninvited from " + area->name());
target_client->sendServerMessage("You were uninvited from " + l_area->name());
}
void AOClient::cmdLock(int argc, QStringList argv)
@ -159,16 +159,16 @@ void AOClient::cmdLock(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->areas[current_area];
AreaData* area = server->m_areas[m_current_area];
if (area->lockStatus() == AreaData::LockStatus::LOCKED) {
sendServerMessage("This area is already locked.");
return;
}
sendServerMessageArea("This area is now locked.");
area->lock();
for (AOClient* client : qAsConst(server->clients)) { // qAsConst here avoids detaching the container
if (client->current_area == current_area && client->joined) {
area->invite(client->id);
for (AOClient* client : qAsConst(server->m_clients)) { // qAsConst here avoids detaching the container
if (client->m_current_area == m_current_area && client->m_joined) {
area->invite(client->m_id);
}
}
arup(ARUPType::LOCKED, true);
@ -179,16 +179,16 @@ void AOClient::cmdSpectatable(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->areas[current_area];
if (area->lockStatus() == AreaData::LockStatus::SPECTATABLE) {
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->lockStatus() == AreaData::LockStatus::SPECTATABLE) {
sendServerMessage("This area is already in spectate mode.");
return;
}
sendServerMessageArea("This area is now spectatable.");
area->spectatable();
for (AOClient* client : qAsConst(server->clients)) {
if (client->current_area == current_area && client->joined) {
area->invite(client->id);
l_area->spectatable();
for (AOClient* client : qAsConst(server->m_clients)) {
if (client->m_current_area == m_current_area && client->m_joined) {
l_area->invite(client->m_id);
}
}
arup(ARUPType::LOCKED, true);
@ -199,13 +199,13 @@ void AOClient::cmdUnLock(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->areas[current_area];
if (area->lockStatus() == AreaData::LockStatus::FREE) {
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->lockStatus() == AreaData::LockStatus::FREE) {
sendServerMessage("This area is not locked.");
return;
}
sendServerMessageArea("This area is now unlocked.");
area->unlock();
l_area->unlock();
arup(ARUPType::LOCKED, true);
}
@ -214,13 +214,13 @@ void AOClient::cmdGetAreas(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QStringList entries;
entries.append("== Area List ==");
for (int i = 0; i < server->area_names.length(); i++) {
QStringList cur_area_lines = buildAreaList(i);
entries.append(cur_area_lines);
QStringList l_entries;
l_entries.append("== Area List ==");
for (int i = 0; i < server->m_area_names.length(); i++) {
QStringList l_cur_area_lines = buildAreaList(i);
l_entries.append(l_cur_area_lines);
}
sendServerMessage(entries.join("\n"));
sendServerMessage(l_entries.join("\n"));
}
void AOClient::cmdGetArea(int argc, QStringList argv)
@ -228,8 +228,8 @@ void AOClient::cmdGetArea(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
QStringList entries = buildAreaList(current_area);
sendServerMessage(entries.join("\n"));
QStringList l_entries = buildAreaList(m_current_area);
sendServerMessage(l_entries.join("\n"));
}
void AOClient::cmdArea(int argc, QStringList argv)
@ -237,41 +237,41 @@ void AOClient::cmdArea(int argc, QStringList argv)
Q_UNUSED(argc);
bool ok;
int new_area = argv[0].toInt(&ok);
if (!ok || new_area >= server->areas.size() || new_area < 0) {
int l_new_area = argv[0].toInt(&ok);
if (!ok || l_new_area >= server->m_areas.size() || l_new_area < 0) {
sendServerMessage("That does not look like a valid area ID.");
return;
}
changeArea(new_area);
changeArea(l_new_area);
}
void AOClient::cmdAreaKick(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* area = server->areas[current_area];
AreaData* l_area = server->m_areas[m_current_area];
bool ok;
int idx = argv[0].toInt(&ok);
int l_idx = argv[0].toInt(&ok);
if (!ok) {
sendServerMessage("That does not look like a valid ID.");
return;
}
if (server->areas[current_area]->owners().contains(idx)) {
if (server->m_areas[m_current_area]->owners().contains(l_idx)) {
sendServerMessage("You cannot kick another CM!");
return;
}
AOClient* client_to_kick = server->getClientByID(idx);
if (client_to_kick == nullptr) {
AOClient* l_client_to_kick = server->getClientByID(l_idx);
if (l_client_to_kick == nullptr) {
sendServerMessage("No client with that ID found.");
return;
}
else if (client_to_kick->current_area != current_area) {
else if (l_client_to_kick->m_current_area != m_current_area) {
sendServerMessage("That client is not in this area.");
return;
}
client_to_kick->changeArea(0);
area->uninvite(client_to_kick->id);
l_client_to_kick->changeArea(0);
l_area->uninvite(l_client_to_kick->m_id);
sendServerMessage("Client " + argv[0] + " kicked back to area 0.");
}
@ -281,12 +281,12 @@ void AOClient::cmdSetBackground(int argc, QStringList argv)
Q_UNUSED(argc);
QString f_background = argv.join(" ");
AreaData* area = server->areas[current_area];
if (authenticated || !area->bgLocked()) {
if (server->backgrounds.contains(f_background, Qt::CaseInsensitive) || area->ignoreBgList() == true) {
AreaData* area = server->m_areas[m_current_area];
if (m_authenticated || !area->bgLocked()) {
if (server->m_backgrounds.contains(f_background, Qt::CaseInsensitive) || area->ignoreBgList() == true) {
area->setBackground(f_background);
server->broadcast(AOPacket("BN", {f_background}), current_area);
sendServerMessageArea(current_char + " changed the background to " + f_background);
server->broadcast(AOPacket("BN", {f_background}), m_current_area);
sendServerMessageArea(m_current_char + " changed the background to " + f_background);
}
else {
sendServerMessage("Invalid background name.");
@ -302,13 +302,13 @@ void AOClient::cmdBgLock(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->areas[current_area];
AreaData* l_area = server->m_areas[m_current_area];
if (area->bgLocked() == false) {
area->toggleBgLock();
if (l_area->bgLocked() == false) {
l_area->toggleBgLock();
};
server->broadcast(AOPacket("CT", {ConfigManager::serverName(), current_char + " locked the background.", "1"}), current_area);
server->broadcast(AOPacket("CT", {ConfigManager::serverName(), m_current_char + " locked the background.", "1"}), m_current_area);
}
void AOClient::cmdBgUnlock(int argc, QStringList argv)
@ -316,25 +316,25 @@ void AOClient::cmdBgUnlock(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->areas[current_area];
AreaData* l_area = server->m_areas[m_current_area];
if (area->bgLocked() == true) {
area->toggleBgLock();
if (l_area->bgLocked() == true) {
l_area->toggleBgLock();
};
server->broadcast(AOPacket("CT", {ConfigManager::serverName(), current_char + " unlocked the background.", "1"}), current_area);
server->broadcast(AOPacket("CT", {ConfigManager::serverName(), m_current_char + " unlocked the background.", "1"}), m_current_area);
}
void AOClient::cmdStatus(int argc, QStringList argv)
{
Q_UNUSED(argc);
AreaData* area = server->areas[current_area];
QString arg = argv[0].toLower();
AreaData* l_area = server->m_areas[m_current_area];
QString l_arg = argv[0].toLower();
if (area->changeStatus(arg)) {
if (l_area->changeStatus(l_arg)) {
arup(ARUPType::STATUS, true);
server->broadcast(AOPacket("CT", {ConfigManager::serverName(), current_char + " changed status to " + arg.toUpper(), "1"}), current_area);
server->broadcast(AOPacket("CT", {ConfigManager::serverName(), m_current_char + " changed status to " + l_arg.toUpper(), "1"}), m_current_area);
} else {
const QStringList keys = AreaData::map_statuses.keys();
sendServerMessage("That does not look like a valid status. Valid statuses are " + keys.join(", "));
@ -346,18 +346,18 @@ void AOClient::cmdJudgeLog(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->areas[current_area];
if (area->judgelog().isEmpty()) {
AreaData* l_area = server->m_areas[m_current_area];
if (l_area->judgelog().isEmpty()) {
sendServerMessage("There have been no judge actions in this area.");
return;
}
QString message = area->judgelog().join("\n");
QString l_message = l_area->judgelog().join("\n");
//Judgelog contains an IPID, so we shouldn't send that unless the caller has appropriate permissions
if (checkAuth(ACLFlags.value("KICK")) == 1 || checkAuth(ACLFlags.value("BAN")) == 1) {
sendServerMessage(message);
sendServerMessage(l_message);
}
else {
QString filteredmessage = message.remove(QRegularExpression("[(].*[)]")); //Filter out anything between two parentheses. This should only ever be the IPID
QString filteredmessage = l_message.remove(QRegularExpression("[(].*[)]")); //Filter out anything between two parentheses. This should only ever be the IPID
sendServerMessage(filteredmessage);
}
}
@ -367,8 +367,8 @@ void AOClient::cmdIgnoreBgList(int argc, QStringList argv)
Q_UNUSED(argc);
Q_UNUSED(argv);
AreaData* area = server->areas[current_area];
area->toggleIgnoreBgList();
QString state = area->ignoreBgList() ? "ignored." : "enforced.";
sendServerMessage("BG list in this area is now " + state);
AreaData* l_area = server->m_areas[m_current_area];
l_area->toggleIgnoreBgList();
QString l_state = l_area->ignoreBgList() ? "ignored." : "enforced.";
sendServerMessage("BG list in this area is now " + l_state);
}

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->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->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->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->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->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->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->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->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->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->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->areas[current_area]->statement() < ConfigManager::maxStatements()) {
server->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->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->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

@ -32,8 +32,8 @@ void AOClient::cmdDefault(int argc, QStringList argv)
QStringList AOClient::buildAreaList(int area_idx)
{
QStringList entries;
QString area_name = server->area_names[area_idx];
AreaData* area = server->areas[area_idx];
QString area_name = server->m_area_names[area_idx];
AreaData* area = server->m_areas[area_idx];
entries.append("=== " + area_name + " ===");
switch (area->lockStatus()) {
case AreaData::LockStatus::LOCKED:
@ -47,18 +47,18 @@ QStringList AOClient::buildAreaList(int area_idx)
break;
}
entries.append("[" + QString::number(area->playerCount()) + " users][" + QVariant::fromValue(area->status()).toString().replace("_", "-") + "]");
for (AOClient* client : qAsConst(server->clients)) {
if (client->current_area == area_idx && client->joined) {
QString char_entry = "[" + QString::number(client->id) + "] " + client->current_char;
if (client->current_char == "")
for (AOClient* client : qAsConst(server->m_clients)) {
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->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->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;
@ -51,29 +51,29 @@ void AOClient::cmdForcePos(int argc, QStringList argv)
}
else if (argv[1] == "*") { // force all clients in the area
for (AOClient* client : qAsConst(server->clients)) {
if (client->current_area == current_area)
targets.append(client);
for (AOClient* client : qAsConst(server->m_clients)) {
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->area_names.value(current_area);
QString sender_message = argv.join(" ");
for (AOClient* client : qAsConst(server->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->area_names.value(current_area);
QString sender_message = argv.join(" ");
for (AOClient* client : qAsConst(server->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->areas[current_area];
int selected_char_id;
bool taken = true;
while (taken) {
selected_char_id = genRand(0, server->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(" ");
for (AOClient* client : qAsConst(server->clients)) {
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->area_names.value(current_area);
QString sender_message = argv.join(" ");
for (AOClient* client : qAsConst(server->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->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->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->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->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->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->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->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->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->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->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->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->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->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->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->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->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->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->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);
}

View File

@ -21,6 +21,7 @@
QSettings* ConfigManager::m_settings = new QSettings("config/config.ini", QSettings::IniFormat);
QSettings* ConfigManager::m_discord = new QSettings("config/discord.ini", QSettings::IniFormat);
QSettings* ConfigManager::m_areas = new QSettings("config/areas.ini", QSettings::IniFormat);
ConfigManager::CommandSettings* ConfigManager::m_commands = new CommandSettings();
QElapsedTimer* ConfigManager::m_uptimeTimer = new QElapsedTimer;
@ -93,6 +94,75 @@ bool ConfigManager::verifyServerConfig()
return true;
}
QString ConfigManager::bindIP()
{
return m_settings->value("Options/bind_ip","all").toString();
}
QStringList ConfigManager::charlist()
{
QStringList l_charlist;
QFile l_file("config/characters.txt");
l_file.open(QIODevice::ReadOnly | QIODevice::Text);
while (!l_file.atEnd()) {
l_charlist.append(l_file.readLine().trimmed());
}
l_file.close();
return l_charlist;
}
QStringList ConfigManager::backgrounds()
{
QStringList l_backgrounds;
QFile l_file("config/backgrounds.txt");
l_file.open(QIODevice::ReadOnly | QIODevice::Text);
while (!l_file.atEnd()) {
l_backgrounds.append(l_file.readLine().trimmed());
}
l_file.close();
return l_backgrounds;
}
QStringList ConfigManager::musiclist()
{
QStringList l_music_list;
QFile l_file("config/music.txt");
l_file.open(QIODevice::ReadOnly | QIODevice::Text);
while (!l_file.atEnd()) {
l_music_list.append(l_file.readLine().trimmed());
}
l_file.close();
if(l_music_list[0].contains(".")) // Add a default category if none exists
l_music_list.insert(0, "==Music==");
return l_music_list;
}
QSettings* ConfigManager::areaData()
{
return m_areas;
}
QStringList ConfigManager::sanitizedAreaNames()
{
QStringList l_area_names = m_areas->childGroups(); // invisibly does a lexicographical sort, because Qt is great like that
std::sort(l_area_names.begin(), l_area_names.end(), [] (const QString &a, const QString &b) {return a.split(":")[0].toInt() < b.split(":")[0].toInt();});
QStringList l_sanitized_area_names;
for (const QString &areaName : qAsConst(l_area_names)) {
QStringList l_nameSplit = areaName.split(":");
l_nameSplit.removeFirst();
QString l_area_name_sanitized = l_nameSplit.join(":");
l_sanitized_area_names.append(l_area_name_sanitized);
}
return l_sanitized_area_names;
}
QStringList ConfigManager::rawAreaNames()
{
return m_areas->childGroups();
}
void ConfigManager::reloadSettings()
{
m_settings->sync();
@ -102,12 +172,12 @@ void ConfigManager::reloadSettings()
QStringList ConfigManager::loadConfigFile(const QString filename)
{
QStringList stringlist;
QFile file("config/text/" + filename + ".txt");
file.open(QIODevice::ReadOnly | QIODevice::Text);
while (!(file.atEnd())) {
stringlist.append(file.readLine().trimmed());
QFile l_file("config/text/" + filename + ".txt");
l_file.open(QIODevice::ReadOnly | QIODevice::Text);
while (!(l_file.atEnd())) {
stringlist.append(l_file.readLine().trimmed());
}
file.close();
l_file.close();
return stringlist;
}

View File

@ -20,20 +20,20 @@ void HTTPAdvertiser::msAdvertiseServer()
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QJsonObject json;
json["port"] = m_port;
QJsonObject l_json;
l_json["port"] = m_port;
if (m_ws_port != -1) {
json["ws_port"] = m_ws_port;
l_json["ws_port"] = m_ws_port;
}
json["players"] = m_players;
json["name"] = m_name;
l_json["players"] = m_players;
l_json["name"] = m_name;
if (!m_description.isEmpty()) {
json["description"] = m_description;
l_json["description"] = m_description;
}
m_manager->post(request, QJsonDocument(json).toJson());
m_manager->post(request, QJsonDocument(l_json).toJson());
if (m_debug)
qDebug().noquote() << "Advertised Server";
@ -45,25 +45,25 @@ void HTTPAdvertiser::msAdvertiseServer()
}
void HTTPAdvertiser::msRequestFinished(QNetworkReply *reply)
void HTTPAdvertiser::msRequestFinished(QNetworkReply *f_reply)
{
if (m_debug) {
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) {
if (f_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) {
qDebug().noquote() << "Succesfully advertised server.";
}
else {
QJsonDocument json = QJsonDocument::fromJson(reply->readAll());
QJsonDocument json = QJsonDocument::fromJson(f_reply->readAll());
if (json.isNull()) {
qCritical().noquote() << "Invalid JSON response from" << reply->url();
reply->deleteLater();
qCritical().noquote() << "Invalid JSON response from" << f_reply->url();
f_reply->deleteLater();
return;
}
qDebug().noquote() << "Got valid response from" << reply->url();
qDebug().noquote() << "Got valid response from" << f_reply->url();
qDebug() << json;
}
}
reply->deleteLater();
f_reply->deleteLater();
}
void HTTPAdvertiser::setAdvertiserSettings(advertiser_config config)

View File

@ -44,36 +44,36 @@ ULogger::~ULogger()
}
}
void ULogger::logIC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid,
const QString& f_areaName, const QString& f_message)
void ULogger::logIC(const QString& f_char_name, const QString& f_ooc_name, const QString& f_ipid,
const QString& f_area_name, const QString& f_message)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][%5][IC][%2(%3)][%4]%6\n")
.arg(l_time, f_charName, f_oocName, f_ipid, f_areaName, f_message);
updateAreaBuffer(f_areaName,l_logEntry);
.arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message);
updateAreaBuffer(f_area_name,l_logEntry);
}
void ULogger::logOOC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid,
const QString& f_areaName, const QString& f_message)
void ULogger::logOOC(const QString& f_char_name, const QString& f_ooc_name, const QString& f_ipid,
const QString& f_area_name, const QString& f_message)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][%5][OOC][%2(%3)][%4]%6\n")
.arg(l_time, f_charName, f_oocName, f_ipid, f_areaName, f_message);
updateAreaBuffer(f_areaName,l_logEntry);
.arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message);
updateAreaBuffer(f_area_name,l_logEntry);
}
void ULogger::logLogin(const QString& f_charName, const QString& f_oocName, const QString& f_moderatorName,
const QString& f_ipid, const QString& f_areaName, const bool &f_success)
void ULogger::logLogin(const QString& f_char_name, const QString& f_ooc_name, const QString& f_moderator_name,
const QString& f_ipid, const QString& f_area_name, const bool &f_success)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_success = f_success ? "SUCCESS][" + f_moderatorName : "FAILED][" + f_moderatorName;
QString l_success = f_success ? "SUCCESS][" + f_moderator_name : "FAILED][" + f_moderator_name;
QString l_logEntry = QStringLiteral("[%1][LOGIN][%2][%3][%4(%5)]\n")
.arg(l_time, l_success, f_ipid, f_charName, f_oocName);
updateAreaBuffer(f_areaName, l_logEntry);
.arg(l_time, l_success, f_ipid, f_char_name, f_ooc_name);
updateAreaBuffer(f_area_name, l_logEntry);
}
void ULogger::logCMD(const QString& f_charName,const QString& f_ipid, const QString& f_oocName, const QString f_command,
const QStringList f_args, const QString f_areaName)
void ULogger::logCMD(const QString& f_char_name,const QString& f_ipid, const QString& f_ooc_name, const QString& f_command,
const QStringList& f_args, const QString& f_area_name)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry;
@ -81,48 +81,48 @@ void ULogger::logCMD(const QString& f_charName,const QString& f_ipid, const QStr
// These must be filtered out
if (f_command == "login") {
l_logEntry = QStringLiteral("[%1][%2][LOGIN][%5][%3(%4)]\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_ipid);
.arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid);
}
else if (f_command == "rootpass") {
l_logEntry = QStringLiteral("[%1][%2][ROOTPASS][%5][%3(%4)]\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_ipid);
.arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid);
}
else if (f_command == "adduser" && !f_args.isEmpty()) {
l_logEntry = QStringLiteral("[%1][%2][USERADD][%6][%3(%4)]%5\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_args.at(0), f_ipid);
.arg(l_time, f_area_name, f_char_name, f_ooc_name, f_args.at(0), f_ipid);
}
else {
l_logEntry = QStringLiteral("[%1][%2][CMD][%7][%3(%4)]/%5 %6\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_command, f_args.join(" "), f_ipid);
.arg(l_time, f_area_name, f_char_name, f_ooc_name, f_command, f_args.join(" "), f_ipid);
}
updateAreaBuffer(f_areaName,l_logEntry);
updateAreaBuffer(f_area_name,l_logEntry);
}
void ULogger::logKick(const QString& f_moderator, const QString& f_targetIPID)
void ULogger::logKick(const QString& f_moderator, const QString& f_target_ipid)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][%2][KICK][%3]\n")
.arg(l_time, f_moderator, f_targetIPID);
.arg(l_time, f_moderator, f_target_ipid);
updateAreaBuffer("SERVER",l_logEntry);
}
void ULogger::logBan(const QString &f_moderator, const QString &f_targetIPID, const QString &f_duration)
void ULogger::logBan(const QString &f_moderator, const QString &f_target_ipid, const QString &f_duration)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][%2][BAN][%3][%4]\n")
.arg(l_time, f_moderator, f_targetIPID, f_duration);
.arg(l_time, f_moderator, f_target_ipid, f_duration);
updateAreaBuffer("SERVER",l_logEntry);
}
void ULogger::logModcall(const QString &f_charName, const QString &f_ipid, const QString &f_oocName, const QString &f_areaName)
void ULogger::logModcall(const QString &f_char_name, const QString &f_ipid, const QString &f_oocName, const QString &f_area_name)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEvent = QStringLiteral("[%1][%2][MODCALL][%5][%3(%4)]\n")
.arg(l_time, f_areaName, f_charName, f_oocName, f_ipid);
updateAreaBuffer(f_areaName, l_logEvent);
.arg(l_time, f_area_name, f_char_name, f_oocName, f_ipid);
updateAreaBuffer(f_area_name, l_logEvent);
if (ConfigManager::loggingType() == DataTypes::LogType::MODCALL) {
writerModcall->flush(f_areaName, buffer(f_areaName));
writerModcall->flush(f_area_name, buffer(f_area_name));
}
}
@ -134,28 +134,28 @@ void ULogger::logConnectionAttempt(const QString& f_ip_address, const QString& f
updateAreaBuffer("SERVER",l_logEntry);
}
void ULogger::updateAreaBuffer(const QString& f_areaName, const QString& f_logEntry)
void ULogger::updateAreaBuffer(const QString& f_area_name, const QString& f_log_entry)
{
QQueue<QString>l_buffer = m_bufferMap.value(f_areaName);
QQueue<QString>l_buffer = m_bufferMap.value(f_area_name);
if (l_buffer.length() <= ConfigManager::logBuffer()) {
l_buffer.enqueue(f_logEntry);
l_buffer.enqueue(f_log_entry);
}
else {
l_buffer.dequeue();
l_buffer.enqueue(f_logEntry);
l_buffer.enqueue(f_log_entry);
}
m_bufferMap.insert(f_areaName, l_buffer);
m_bufferMap.insert(f_area_name, l_buffer);
if (ConfigManager::loggingType() == DataTypes::LogType::FULL){
writerFull->flush(f_logEntry);
writerFull->flush(f_log_entry);
}
if (ConfigManager::loggingType() == DataTypes::LogType::FULLAREA) {
writerFull->flush(f_logEntry, f_areaName);
writerFull->flush(f_log_entry, f_area_name);
}
}
QQueue<QString> ULogger::buffer(const QString& f_areaName)
QQueue<QString> ULogger::buffer(const QString& f_area_name)
{
return m_bufferMap.value(f_areaName);
return m_bufferMap.value(f_area_name);
}

View File

@ -37,9 +37,9 @@ void WriterFull::flush(const QString f_entry)
l_logfile.close();
}
void WriterFull::flush(const QString f_entry, const QString f_areaName)
void WriterFull::flush(const QString f_entry, const QString f_area_name)
{
l_logfile.setFileName(QString("logs/%1_%2.log").arg(f_areaName, QDate::currentDate().toString("yyyy-MM-dd")));
l_logfile.setFileName(QString("logs/%1_%2.log").arg(f_area_name, QDate::currentDate().toString("yyyy-MM-dd")));
if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
QTextStream file_stream(&l_logfile);

View File

@ -31,9 +31,9 @@ WriterModcall::WriterModcall(QObject* parent) :
}
}
void WriterModcall::flush(const QString f_areaName, QQueue<QString> f_buffer)
void WriterModcall::flush(const QString f_area_name, QQueue<QString> f_buffer)
{
l_logfile.setFileName(QString("logs/modcall/report_%1_%2.log").arg(f_areaName, (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss"))));
l_logfile.setFileName(QString("logs/modcall/report_%1_%2.log").arg(f_area_name, (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss"))));
if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
QTextStream file_stream(&l_logfile);

File diff suppressed because it is too large Load Diff

View File

@ -19,24 +19,31 @@
Server::Server(int p_port, int p_ws_port, QObject* parent) :
QObject(parent),
player_count(0),
m_player_count(0),
port(p_port),
ws_port(p_ws_port)
{
server = new QTcpServer(this);
connect(server, SIGNAL(newConnection()), this, SLOT(clientConnected()));
proxy = new WSProxy(port, ws_port, this);
if(ws_port != -1)
proxy->start();
timer = new QTimer();
db_manager = new DBManager();
//We create it, even if its not used later on.
discord = new Discord(this);
logger = new ULogger(this);
connect(this, &Server::logConnectionAttempt,
logger, &ULogger::logConnectionAttempt);
}
void Server::start()
{
QSettings config("config/config.ini", QSettings::IniFormat);
config.beginGroup("Options");
QString bind_ip = config.value("ip", "all").toString();
QString bind_ip = ConfigManager::bindIP();
QHostAddress bind_addr;
if (bind_ip == "all")
bind_addr = QHostAddress::Any;
@ -52,9 +59,10 @@ void Server::start()
qDebug() << "Server listening on" << port;
}
discord = new Discord(this);
//Checks if any Discord webhooks are enabled.
handleDiscordIntegration();
//Construct modern advertiser if enabled in config
if (ConfigManager::advertiseHTTPServer()) {
httpAdvertiserTimer = new QTimer(this);
httpAdvertiser = new HTTPAdvertiser();
@ -69,53 +77,24 @@ void Server::start()
httpAdvertiserTimer->start(300000);
}
logger = new ULogger(this);
connect(this, &Server::logConnectionAttempt,
logger, &ULogger::logConnectionAttempt);
//Get characters from config file
m_characters = ConfigManager::charlist();
proxy = new WSProxy(port, ws_port, this);
if(ws_port != -1)
proxy->start();
//Get musiclist from config file
m_music_list = ConfigManager::musiclist();
QFile char_list("config/characters.txt");
char_list.open(QIODevice::ReadOnly | QIODevice::Text);
while (!char_list.atEnd()) {
characters.append(char_list.readLine().trimmed());
}
char_list.close();
//Get backgrounds from config file
m_backgrounds = ConfigManager::backgrounds();
QFile music_file("config/music.txt");
music_file.open(QIODevice::ReadOnly | QIODevice::Text);
while (!music_file.atEnd()) {
music_list.append(music_file.readLine().trimmed());
}
music_file.close();
if(music_list[0].contains(".")) // Add a default category if none exists
music_list.insert(0, "==Music==");
QFile bg_file("config/backgrounds.txt");
bg_file.open(QIODevice::ReadOnly | QIODevice::Text);
while (!bg_file.atEnd()) {
backgrounds.append(bg_file.readLine().trimmed());
}
bg_file.close();
QSettings areas_ini("config/areas.ini", QSettings::IniFormat);
area_names = areas_ini.childGroups(); // invisibly does a lexicographical sort, because Qt is great like that
std::sort(area_names.begin(), area_names.end(), [] (const QString &a, const QString &b) {return a.split(":")[0].toInt() < b.split(":")[0].toInt();});
QStringList sanitized_area_names;
QStringList raw_area_names = area_names;
for (const QString &area_name : qAsConst(area_names)) {
QStringList name_split = area_name.split(":");
name_split.removeFirst();
QString area_name_sanitized = name_split.join(":");
sanitized_area_names.append(area_name_sanitized);
}
area_names = sanitized_area_names;
//Assembles the area list
m_area_names = ConfigManager::sanitizedAreaNames();
QStringList raw_area_names = ConfigManager::rawAreaNames();
for (int i = 0; i < raw_area_names.length(); i++) {
QString area_name = raw_area_names[i];
areas.insert(i, new AreaData(area_name, i));
m_areas.insert(i, new AreaData(area_name, i));
}
//Rate-Limiter for IC-Chat
connect(&next_message_timer, SIGNAL(timeout()), this, SLOT(allowMessage()));
}
@ -124,10 +103,10 @@ void Server::clientConnected()
QTcpSocket* socket = server->nextPendingConnection();
int user_id;
QList<int> user_ids;
for (AOClient* client : qAsConst(clients)) {
user_ids.append(client->id);
for (AOClient* client : qAsConst(m_clients)) {
user_ids.append(client->m_id);
}
for (user_id = 0; user_id <= player_count; user_id++) {
for (user_id = 0; user_id <= m_player_count; user_id++) {
if (user_ids.contains(user_id))
continue;
else
@ -140,12 +119,12 @@ void Server::clientConnected()
client->calculateIpid();
auto ban = db_manager->isIPBanned(client->getIpid());
bool is_banned = ban.first;
for (AOClient* joined_client : qAsConst(clients)) {
if (client->remote_ip.isEqual(joined_client->remote_ip))
for (AOClient* joined_client : qAsConst(m_clients)) {
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) {
@ -160,11 +139,11 @@ void Server::clientConnected()
return;
}
clients.append(client);
m_clients.append(client);
connect(socket, &QTcpSocket::disconnected, client,
&AOClient::clientDisconnected);
connect(socket, &QTcpSocket::disconnected, this, [=] {
clients.removeAll(client);
m_clients.removeAll(client);
client->deleteLater();
});
connect(socket, &QTcpSocket::readyRead, client, &AOClient::clientData);
@ -182,7 +161,7 @@ void Server::clientConnected()
void Server::updateCharsTaken(AreaData* area)
{
QStringList chars_taken;
for (const QString &cur_char : qAsConst(characters)) {
for (const QString &cur_char : qAsConst(m_characters)) {
chars_taken.append(area->charactersTaken().contains(getCharID(cur_char))
? QStringLiteral("-1")
: QStringLiteral("0"));
@ -190,9 +169,9 @@ void Server::updateCharsTaken(AreaData* area)
AOPacket response_cc("CharsCheck", chars_taken);
for (AOClient* client : qAsConst(clients)) {
if (client->current_area == area->index()){
if (!client->is_charcursed)
for (AOClient* client : qAsConst(m_clients)) {
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);
@ -207,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));
@ -217,15 +196,15 @@ QStringList Server::getCursedCharsTaken(AOClient* client, QStringList chars_take
void Server::broadcast(AOPacket packet, int area_index)
{
for (AOClient* client : qAsConst(clients)) {
if (client->current_area == area_index)
for (AOClient* client : qAsConst(m_clients)) {
if (client->m_current_area == area_index)
client->sendPacket(packet);
}
}
void Server::broadcast(AOPacket packet)
{
for (AOClient* client : qAsConst(clients)) {
for (AOClient* client : qAsConst(m_clients)) {
client->sendPacket(packet);
}
}
@ -233,7 +212,7 @@ void Server::broadcast(AOPacket packet)
QList<AOClient*> Server::getClientsByIpid(QString ipid)
{
QList<AOClient*> return_clients;
for (AOClient* client : qAsConst(clients)) {
for (AOClient* client : qAsConst(m_clients)) {
if (client->getIpid() == ipid)
return_clients.append(client);
}
@ -242,8 +221,8 @@ QList<AOClient*> Server::getClientsByIpid(QString ipid)
AOClient* Server::getClientByID(int id)
{
for (AOClient* client : qAsConst(clients)) {
if (client->id == id)
for (AOClient* client : qAsConst(m_clients)) {
if (client->m_id == id)
return client;
}
return nullptr;
@ -251,9 +230,9 @@ AOClient* Server::getClientByID(int id)
int Server::getCharID(QString char_name)
{
for (const QString &character : qAsConst(characters)) {
for (const QString &character : qAsConst(m_characters)) {
if (character.toLower() == char_name.toLower()) {
return characters.indexOf(QRegExp(character, Qt::CaseInsensitive));
return m_characters.indexOf(QRegExp(character, Qt::CaseInsensitive));
}
}
return -1; // character does not exist
@ -336,7 +315,7 @@ void Server::hookupLogger(AOClient* client)
Server::~Server()
{
for (AOClient* client : qAsConst(clients)) {
for (AOClient* client : qAsConst(m_clients)) {
client->deleteLater();
}
server->deleteLater();

View File

@ -17,14 +17,12 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/aoclient.h"
//
void AOClient::addStatement(QStringList packet)
{
if (checkTestimonySymbols(packet[4])) {
return;
}
AreaData* area = server->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) {
@ -57,7 +55,7 @@ QStringList AOClient::updateStatement(QStringList packet)
if (checkTestimonySymbols(packet[4])) {
return packet;
}
AreaData* area = server->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())
@ -73,7 +71,7 @@ QStringList AOClient::updateStatement(QStringList packet)
void AOClient::clearTestimony()
{
AreaData* area = server->areas[current_area];
AreaData* area = server->m_areas[m_current_area];
area->clearTestimony();
}