AreaData acccess rework, from direct to through getters

Literal hell.
This commit is contained in:
Cerapter 2021-05-01 15:29:58 +02:00
parent 3aeff2d72d
commit 5a0c291825
16 changed files with 597 additions and 505 deletions

View File

@ -53,40 +53,6 @@ class AreaData : public QObject {
QString image; //!< A path originating from `base/evidence/` that points to an image file. QString image; //!< A path originating from `base/evidence/` that points to an image file.
}; };
/**
* @brief The list of timers available in the area.
*/
QList<QTimer*> timers;
/**
* @brief The user-facing and internal name of the area.
*/
QString name;
/**
* @brief The index of the area in the server's area list.
*/
int index;
/**
* @brief A list of the character IDs of all characters taken.
*/
QList<int> characters_taken;
/**
* @brief A list of Evidence currently available in the area's court record.
*
* @details This contains *all* evidence, not just the ones a given side can see.
*
* @see HIDDEN_CM
*/
QList<Evidence> evidence;
/**
* @brief The amount of clients inside the area.
*/
int player_count;
/** /**
* @brief The status of an area. * @brief The status of an area.
* *
@ -105,25 +71,6 @@ class AreaData : public QObject {
/// Exposes the metadata of the Status enum. /// Exposes the metadata of the Status enum.
Q_ENUM(Status); Q_ENUM(Status);
/**
* @brief The status of the area.
*
* @see Status
*/
Status status;
/**
* @brief The IDs of all the owners (or Case Makers / CMs) of the area.
*/
QList<int> owners;
/**
* @brief The list of clients invited to the area.
*
* @see LOCKED and SPECTATABLE for the benefits of being invited.
*/
QList<int> invited;
/** /**
* @brief Determines who may traverse and communicate in the area. * @brief Determines who may traverse and communicate in the area.
*/ */
@ -157,86 +104,6 @@ class AreaData : public QObject {
/// Exposes the metadata of the LockStatus enum. /// Exposes the metadata of the LockStatus enum.
Q_ENUM(LockStatus); Q_ENUM(LockStatus);
/**
* @brief The status of the area's accessibility to clients.
*
* @see LockStatus
*/
LockStatus locked;
/**
* @brief The background of the area.
*
* @details Represents a directory's name in `base/background/` clientside.
*/
QString background;
/**
* @brief If true, nobody may become the CM of this area.
*/
bool is_protected;
/**
* @brief If true, clients are allowed to put on "shownames", custom names
* in place of their character's normally displayed name.
*/
bool showname_allowed;
/**
* @brief If true, clients are allowed to use the cursed art of iniswapping in the area.
*/
bool iniswap_allowed;
/**
* @brief If true, clients are allowed to send empty IC messages
*/
bool blankposting_allowed;
/**
* @brief If true, the background of the area cannot be changed except by a moderator.
*/
bool bg_locked;
/**
* @brief The hyperlink to the document of the area.
*
* @details Documents are generally used for cases or roleplays, where they contain the related game's
* rules. #document can also be something like "None" if there is no case or roleplay being run.
*/
QString document;
/**
* @brief The Confidence Gauge's value for the Defence side.
*
* @details Unit is 10%, and the values range from 0 (= 0%) to 10 (= 100%).
*/
int def_hp;
/**
* @brief The Confidence Gauge's value for the Prosecutor side.
*
* @copydetails #def_hp
*/
int pro_hp;
/**
* @brief The title of the music currently being played in the area.
*
* @details Title is a path to the music file, with the starting point on
* `base/sounds/music/` clientside, with file extension.
*/
QString current_music;
/**
* @brief The name of the client (or client's character) that started the currently playing music.
*/
QString music_played_by;
/**
* @brief A pointer to a Logger, used to send requests to log data.
*/
Logger* logger;
/** /**
* @brief The level of "authorisation" needed to be able to modify, add, and remove evidence in the area. * @brief The level of "authorisation" needed to be able to modify, add, and remove evidence in the area.
*/ */
@ -270,14 +137,6 @@ class AreaData : public QObject {
* where `XXX` is either a position, of a list of positions separated by `,`. * where `XXX` is either a position, of a list of positions separated by `,`.
*/ */
/**
* @brief The evidence mod of the area.
*
* @see EvidenceMod
*/
EvidenceMod evi_mod;
QMap<QString, QString> notecards;
/** /**
* @brief The five "states" the testimony recording system can have in an area. * @brief The five "states" the testimony recording system can have in an area.
*/ */
@ -322,38 +181,215 @@ class AreaData : public QObject {
/// Exposes the metadata of the TestimonyRecording enum. /// Exposes the metadata of the TestimonyRecording enum.
Q_ENUM(TestimonyRecording); Q_ENUM(TestimonyRecording);
TestimonyRecording test_rec;
/**
* @brief A client in the area has left the area.
*
* @details This function counts down the playercount and removes the character from the list of taken characters.
*
* @param f_charId The character ID of the area.
*/
void clientLeftArea(int f_charId);
QList<int> owners() const;
void addOwner(int f_clientId);
/**
* @brief Removes the target client from the list of owners.
*
* @param f_clientId The ID of the client to remove from the owners.
*
* @return True if because of this removal, an ARUP message must be sent out about the locks.
*
* @note This function *does not* imply that the client also left the area, only that they are no longer its owner.
* See clientLeftArea() for that.
*/
bool removeOwner(int f_clientId);
bool blankpostingAllowed() const;
bool isProtected() const;
LockStatus lockStatus() const;
/**
* @brief invite
* @param f_clientId
* @return True if the client was successfully invited. False if they were already in the list of invited people.
*/
bool invite(int f_clientId);
private:
/**
* @brief The list of timers available in the area.
*/
QList<QTimer*> m_timers;
/**
* @brief The user-facing and internal name of the area.
*/
QString m_name;
/**
* @brief The index of the area in the server's area list.
*/
int m_index;
/**
* @brief A list of the character IDs of all characters taken.
*/
QList<int> m_charactersTaken;
/**
* @brief A list of Evidence currently available in the area's court record.
*
* @details This contains *all* evidence, not just the ones a given side can see.
*
* @see HIDDEN_CM
*/
QList<Evidence> m_evidence;
/**
* @brief The amount of clients inside the area.
*/
int m_playerCount;
/**
* @brief The status of the area.
*
* @see Status
*/
Status m_status;
/**
* @brief The IDs of all the owners (or Case Makers / CMs) of the area.
*/
QList<int> m_owners;
/**
* @brief The list of clients invited to the area.
*
* @see LOCKED and SPECTATABLE for the benefits of being invited.
*/
QList<int> m_invited;
/**
* @brief The status of the area's accessibility to clients.
*
* @see LockStatus
*/
LockStatus m_locked;
/**
* @brief The background of the area.
*
* @details Represents a directory's name in `base/background/` clientside.
*/
QString m_background;
/**
* @brief If true, nobody may become the CM of this area.
*/
bool m_isProtected;
/**
* @brief If true, clients are allowed to put on "shownames", custom names
* in place of their character's normally displayed name.
*/
bool m_shownameAllowed;
/**
* @brief If true, clients are allowed to use the cursed art of iniswapping in the area.
*/
bool m_iniswapAllowed;
/**
* @brief If true, clients are allowed to send empty IC messages
*/
bool m_blankpostingAllowed;
/**
* @brief If true, the background of the area cannot be changed except by a moderator.
*/
bool m_bgLocked;
/**
* @brief The hyperlink to the document of the area.
*
* @details Documents are generally used for cases or roleplays, where they contain the related game's
* rules. #document can also be something like "None" if there is no case or roleplay being run.
*/
QString m_document;
/**
* @brief The Confidence Gauge's value for the Defence side.
*
* @details Unit is 10%, and the values range from 0 (= 0%) to 10 (= 100%).
*/
int m_defHP;
/**
* @brief The Confidence Gauge's value for the Prosecutor side.
*
* @copydetails #def_hp
*/
int m_proHP;
/**
* @brief The title of the music currently being played in the area.
*
* @details Title is a path to the music file, with the starting point on
* `base/sounds/music/` clientside, with file extension.
*/
QString m_currentMusic;
/**
* @brief The name of the client (or client's character) that started the currently playing music.
*/
QString m_musicPlayerBy;
/**
* @brief A pointer to a Logger, used to send requests to log data.
*/
Logger* m_logger;
/**
* @brief The evidence mod of the area.
*
* @see EvidenceMod
*/
EvidenceMod m_eviMod;
QMap<QString, QString> m_notecards;
TestimonyRecording m_testimonyRecording;
QVector<QStringList> testimony; //!< Vector of all statements saved. Index 0 is always the title of the testimony. QVector<QStringList> m_testimony; //!< Vector of all statements saved. Index 0 is always the title of the testimony.
int statement; //!< Keeps track of the currently played statement. int m_statement; //!< Keeps track of the currently played statement.
/** /**
* @brief The judgelog of an area. * @brief The judgelog of an area.
* *
* @details This list contains up to 10 recorded packets of the most recent judge actions (WT/CE or penalty updates) in an area. * @details This list contains up to 10 recorded packets of the most recent judge actions (WT/CE or penalty updates) in an area.
*/ */
QStringList judgelog; QStringList m_judgelog;
/** /**
* @brief The last IC packet sent in an area. * @brief The last IC packet sent in an area.
*/ */
QStringList last_ic_message; QStringList m_lastICMessage;
/**
* @brief The value of logger in config.ini.
*/
QString log_type;
/** /**
* @brief Whether or not to force immediate text processing in this area. * @brief Whether or not to force immediate text processing in this area.
*/ */
bool force_immediate; bool m_forceImmediate;
/** /**
* @brief Whether or not music is allowed in this area. If false, only CMs can change the music. * @brief Whether or not music is allowed in this area. If false, only CMs can change the music.
*/ */
bool toggle_music; bool m_toggleMusic;
}; };
#endif // AREA_DATA_H #endif // AREA_DATA_H

View File

@ -18,19 +18,12 @@
#ifndef LOGGER_H #ifndef LOGGER_H
#define LOGGER_H #define LOGGER_H
#include "include/aoclient.h"
#include "include/aopacket.h"
#include "include/area_data.h"
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QString> #include <QString>
#include <QQueue> #include <QQueue>
#include <QDateTime> #include <QDateTime>
class AOClient;
class AreaData;
/** /**
* @brief A class associated with an AreaData class to log various events happening inside the latter. * @brief A class associated with an AreaData class to log various events happening inside the latter.
*/ */
@ -40,34 +33,40 @@ public:
/** /**
* @brief Constructs a Logger instance. * @brief Constructs a Logger instance.
* *
* @param p_max_length The maximum amount of entries the Logger can store at once. * @param f_max_length The maximum amount of entries the Logger can store at once.
* @param p_area The area associated with the Logger from which it should log entries.
*/ */
Logger(int p_max_length, AreaData* p_area) : max_length(p_max_length), area(p_area) {}; Logger(int f_max_length, const QString& f_logType_r) : m_maxLength(f_max_length), m_logType(f_logType_r) {};
public slots:
/** /**
* @brief Logs an IC message. * @brief Logs an IC message.
* *
* @param client The client who sent the IC message. * @param f_areaName_r The name of the area where the event happened.
* @param packet The IC packet itself, used to grab the text of the IC message. * @param f_charName_r The character name of the client who sent the IC message.
* @param f_ipid_r The IPID of the aforementioned client.
* @param f_message_r The text of the IC message.
*/ */
void logIC(AOClient* client, AOPacket* packet); void logIC(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r);
/** /**
* @brief Logs an OOC message. * @brief Logs an OOC message.
* *
* @param client The client who sent the OOC message. * @param f_areaName_r The name of the area where the event happened.
* @param packet The OOC packet itself, used to grab the text of the OOC message. * @param f_charName_r The character name of the client who sent the OOC message.
* @param f_ipid_r The IPID of the aforementioned client.
* @param f_message_r The text of the OOC message.
*/ */
void logOOC(AOClient* client, AOPacket* packet); void logOOC(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r);
/** /**
* @brief Logs a mod call message. * @brief Logs a mod call message.
* *
* @param client The client who sent the mod call. * @param f_areaName_r The name of the area where the event happened.
* @param packet The ZZ packet itself, used to grab the reason field of the modcall. * @param f_charName_r The character name of the client who sent the mod call.
* @param f_ipid_r The IPID of the aforementioned client.
* @param f_modcallReason_r The reason for the modcall.
*/ */
void logModcall(AOClient* client, AOPacket* packet); void logModcall(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_modcallReason_r);
/** /**
* @brief Logs a command called in OOC. * @brief Logs a command called in OOC.
@ -75,69 +74,67 @@ public:
* @details If the command is not one of any of the 'special' ones, it defaults to logOOC(). * @details If the command is not one of any of the 'special' ones, it defaults to logOOC().
* The only thing that makes a command 'special' if it is handled differently in here. * The only thing that makes a command 'special' if it is handled differently in here.
* *
* @param client The client who sent the command. * @param f_areaName_r The name of the area where the event happened.
* @param packet The OOC packet. Passed to logOOC() if the command is not 'special' (see details). * @param f_charName_r The character name of the client who sent the command.
* @param cmd The command called in the OOC -- this is the first word after the `/` character. * @param f_ipid_r The IPID of the aforementioned client.
* @param args The arguments interpreted for the command, every word separated by a whitespace. * @param f_oocMessage_r The text of the OOC message. Passed to logOOC() if the command is not 'special' (see details).
* @param f_cmd_r The command called in the OOC -- this is the first word after the `/` character.
* @param f_cmdArgs_r The arguments interpreted for the command, every word separated by a whitespace.
*/ */
void logCmd(AOClient* client, AOPacket* packet, QString cmd, QStringList args); void logCmd(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r,
const QString& f_oocMessage_r, const QString& f_cmd_r, const QStringList& f_cmdArgs_r);
/** /**
* @brief Logs a login attempt. * @brief Logs a login attempt.
* *
* @param client The client that attempted to login. * @param f_areaName_r The name of the area where the event happened.
* @param f_charName_r The character name of the client that attempted to login.
* @param f_ipid_r The IPID of the aforementioned client.
* @param success True if the client successfully authenticated as a mod. * @param success True if the client successfully authenticated as a mod.
* @param modname If the client logged in with a modname, then this is it. Otherwise, it's `"moderator"`. * @param f_modname_r If the client logged in with a modname, then this is it. Otherwise, it's `"moderator"`.
*
* @note Why does this exist? logCmd() already does this in part.
*/ */
void logLogin(AOClient* client, bool success, QString modname); void logLogin(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, bool success, const QString& f_modname_r);
/** /**
* @brief Appends the contents of #buffer into `config/server.log`, emptying the former. * @brief Appends the contents of #buffer into `config/server.log`, emptying the former.
*
* @param f_areaName_r The name of the area where the event happened.
*/ */
void flush(); void flush(const QString& f_areaName_r);
/**
* @brief Contains entries that have not yet been flushed out into a log file.
*/
QQueue<QString> m_buffer;
private: private:
/**
* @brief Convenience function to format entries to the acceptable standard for logging.
*
* @param client The client who 'caused' the source event for the entry to happen.
* @param type The type of entry that is being built, something that uniquely identifies entries of similar being.
* @param message Any additional information related to the entry.
*
* @return A formatted string representation of the entry.
*/
QString buildEntry(AOClient* client, QString type, QString message);
/** /**
* @brief Convenience function to add an entry to #buffer. * @brief Convenience function to add an entry to #buffer.
* *
* @details If the buffer's size is equal to #max_length, the first entry in the queue is removed, * @details If the buffer's size is equal to #max_length, the first entry in the queue is removed,
* and the newest entry is added to the end. * and the newest entry is added to the end.
* *
* @param entry The string representation of the entry to add. * @param f_areaName_r The name of the area where the loggable entry happened.
* * @param f_charName_r The character name of the client who 'caused' the source event for the entry to happen.
* @pre You would probably call buildEntry() to format the entry before adding it to the buffer. * @param f_ipid_r The IPID of the aforementioned client.
* @param f_type_r The type of entry that is being built, something that uniquely identifies entries of similar being.
* @param f_message_r Any additional information related to the entry.
*/ */
void addEntry(QString entry); void addEntry(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r,
const QString& f_type_r, const QString& f_message_r);
/** /**
* @brief The max amount of entries that may be contained in #buffer. * @brief The max amount of entries that may be contained in #buffer.
*/ */
int max_length; int m_maxLength;
/** /**
* @brief Contains entries that have not yet been flushed out into a log file. * @brief Determines what kind of logging happens, `"full"` or `"modcall"`.
*/
QQueue<QString> buffer;
/**
* @brief A pointer to the area this logger is associated with.
* *
* @details Used for logging in what area did a given packet event happen. * @details This largely influences the resulting log file's name, and in case of a `"full"` setup,
* the in-memory buffer is auto-dumped to said file if full.
*/ */
AreaData* area; QString m_logType;
}; };
#endif // LOGGER_H #endif // LOGGER_H

View File

@ -49,23 +49,21 @@ void AOClient::clientDisconnected()
#endif #endif
if (joined) { if (joined) {
server->player_count--; server->player_count--;
server->areas[current_area]->player_count--; server->areas[current_area]->clientLeftArea(server->getCharID(current_char));
arup(ARUPType::PLAYER_COUNT, true); arup(ARUPType::PLAYER_COUNT, true);
} }
if (current_char != "") { if (current_char != "") {
server->areas[current_area]->characters_taken.removeAll(server->getCharID(current_char));
server->updateCharsTaken(server->areas[current_area]); server->updateCharsTaken(server->areas[current_area]);
} }
bool update_locks;
bool l_updateLocks = false;
for (AreaData* area : server->areas) { for (AreaData* area : server->areas) {
area->owners.removeAll(id); l_updateLocks = l_updateLocks || area->removeOwner(id);
area->invited.removeAll(id);
if (area->owners.isEmpty() && area->locked != AreaData::FREE) {
area->locked = AreaData::FREE;
update_locks = true;
} }
}
if (update_locks) if (l_updateLocks)
arup(ARUPType::LOCKED, true); arup(ARUPType::LOCKED, true);
arup(ARUPType::CM, true); arup(ARUPType::CM, true);
} }
@ -109,34 +107,34 @@ void AOClient::changeArea(int new_area)
sendServerMessage("You are already in area " + server->area_names[current_area]); sendServerMessage("You are already in area " + server->area_names[current_area]);
return; return;
} }
if (server->areas[new_area]->locked == AreaData::LockStatus::LOCKED && !server->areas[new_area]->invited.contains(id)) { if (server->areas[new_area]->m_locked == AreaData::LockStatus::LOCKED && !server->areas[new_area]->m_invited.contains(id)) {
sendServerMessage("Area " + server->area_names[new_area] + " is locked."); sendServerMessage("Area " + server->area_names[new_area] + " is locked.");
return; return;
} }
if (current_char != "") { if (current_char != "") {
server->areas[current_area]->characters_taken.removeAll(server->getCharID(current_char)); server->areas[current_area]->m_charactersTaken.removeAll(server->getCharID(current_char));
server->updateCharsTaken(server->areas[current_area]); server->updateCharsTaken(server->areas[current_area]);
} }
server->areas[new_area]->player_count++; server->areas[new_area]->m_playerCount++;
server->areas[current_area]->player_count--; server->areas[current_area]->m_playerCount--;
current_area = new_area; current_area = new_area;
arup(ARUPType::PLAYER_COUNT, true); arup(ARUPType::PLAYER_COUNT, true);
sendEvidenceList(server->areas[new_area]); sendEvidenceList(server->areas[new_area]);
sendPacket("HP", {"1", QString::number(server->areas[new_area]->def_hp)}); sendPacket("HP", {"1", QString::number(server->areas[new_area]->m_defHP)});
sendPacket("HP", {"2", QString::number(server->areas[new_area]->pro_hp)}); sendPacket("HP", {"2", QString::number(server->areas[new_area]->m_proHP)});
sendPacket("BN", {server->areas[new_area]->background}); sendPacket("BN", {server->areas[new_area]->m_background});
if (server->areas[current_area]->characters_taken.contains(server->getCharID(current_char))) { if (server->areas[current_area]->m_charactersTaken.contains(server->getCharID(current_char))) {
server->updateCharsTaken(server->areas[current_area]); server->updateCharsTaken(server->areas[current_area]);
current_char = ""; current_char = "";
sendPacket("DONE"); sendPacket("DONE");
} }
else { else {
server->areas[current_area]->characters_taken.append(server->getCharID(current_char)); server->areas[current_area]->m_charactersTaken.append(server->getCharID(current_char));
server->updateCharsTaken(server->areas[current_area]); server->updateCharsTaken(server->areas[current_area]);
} }
for (QTimer* timer : server->areas[current_area]->timers) { for (QTimer* timer : server->areas[current_area]->m_timer) {
int timer_id = server->areas[current_area]->timers.indexOf(timer) + 1; int timer_id = server->areas[current_area]->m_timer.indexOf(timer) + 1;
if (timer->isActive()) { if (timer->isActive()) {
sendPacket("TI", {QString::number(timer_id), "2"}); 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())))}); sendPacket("TI", {QString::number(timer_id), "0", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(timer->remainingTime())))});
@ -146,7 +144,7 @@ void AOClient::changeArea(int new_area)
} }
} }
sendServerMessage("You moved to area " + server->area_names[current_area]); sendServerMessage("You moved to area " + server->area_names[current_area]);
if (server->areas[current_area]->locked == AreaData::LockStatus::SPECTATABLE) if (server->areas[current_area]->m_locked == 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("Area " + server->area_names[current_area] + " is spectate-only; to chat IC you will need to be invited by the CM.");
} }
@ -162,16 +160,16 @@ bool AOClient::changeCharacter(int char_id)
} }
if (current_char != "") { if (current_char != "") {
area->characters_taken.removeAll(server->getCharID(current_char)); area->m_charactersTaken.removeAll(server->getCharID(current_char));
} }
if (char_id >= 0) { if (char_id >= 0) {
QString char_selected = server->characters[char_id]; QString char_selected = server->characters[char_id];
bool taken = area->characters_taken.contains(char_id); bool taken = area->m_charactersTaken.contains(char_id);
if (taken || char_selected == "") if (taken || char_selected == "")
return false; return false;
area->characters_taken.append(char_id); area->m_charactersTaken.append(char_id);
current_char = char_selected; current_char = char_selected;
} }
else { else {
@ -216,20 +214,20 @@ void AOClient::arup(ARUPType type, bool broadcast)
for (AreaData* area : server->areas) { for (AreaData* area : server->areas) {
switch(type) { switch(type) {
case ARUPType::PLAYER_COUNT: { case ARUPType::PLAYER_COUNT: {
arup_data.append(QString::number(area->player_count)); arup_data.append(QString::number(area->m_playerCount));
break; break;
} }
case ARUPType::STATUS: { case ARUPType::STATUS: {
QString area_status = QVariant::fromValue(area->status).toString().replace("_", "-"); // LOOKING_FOR_PLAYERS to LOOKING-FOR-PLAYERS QString area_status = QVariant::fromValue(area->m_status).toString().replace("_", "-"); // LOOKING_FOR_PLAYERS to LOOKING-FOR-PLAYERS
arup_data.append(area_status); arup_data.append(area_status);
break; break;
} }
case ARUPType::CM: { case ARUPType::CM: {
if (area->owners.isEmpty()) if (area->m_owners.isEmpty())
arup_data.append("FREE"); arup_data.append("FREE");
else { else {
QStringList area_owners; QStringList area_owners;
for (int owner_id : area->owners) { for (int owner_id : area->m_owners) {
AOClient* owner = server->getClientByID(owner_id); AOClient* owner = server->getClientByID(owner_id);
area_owners.append("[" + QString::number(owner->id) + "] " + owner->current_char); area_owners.append("[" + QString::number(owner->id) + "] " + owner->current_char);
} }
@ -238,7 +236,7 @@ void AOClient::arup(ARUPType type, bool broadcast)
break; break;
} }
case ARUPType::LOCKED: { case ARUPType::LOCKED: {
QString lock_status = QVariant::fromValue(area->locked).toString(); QString lock_status = QVariant::fromValue(area->m_locked).toString();
arup_data.append(lock_status); arup_data.append(lock_status);
break; break;
} }
@ -314,7 +312,7 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
if (acl_mask != ACLFlags.value("NONE")) { if (acl_mask != ACLFlags.value("NONE")) {
if (acl_mask == ACLFlags.value("CM")) { if (acl_mask == ACLFlags.value("CM")) {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->owners.contains(id)) if (area->m_owners.contains(id))
return true; return true;
} }
else if (!authenticated) { else if (!authenticated) {

View File

@ -18,56 +18,123 @@
#include "include/area_data.h" #include "include/area_data.h"
AreaData::AreaData(QString p_name, int p_index) : AreaData::AreaData(QString p_name, int p_index) :
index(p_index), m_index(p_index),
player_count(0), m_playerCount(0),
status(IDLE), m_status(IDLE),
locked(FREE), m_locked(FREE),
document("No document."), m_document("No document."),
def_hp(10), m_defHP(10),
pro_hp(10), m_proHP(10),
judgelog(), m_judgelog(),
last_ic_message() m_lastICMessage()
{ {
QStringList name_split = p_name.split(":"); QStringList name_split = p_name.split(":");
name_split.removeFirst(); name_split.removeFirst();
name = name_split.join(":"); m_name = name_split.join(":");
QSettings areas_ini("config/areas.ini", QSettings::IniFormat); QSettings areas_ini("config/areas.ini", QSettings::IniFormat);
areas_ini.setIniCodec("UTF-8"); areas_ini.setIniCodec("UTF-8");
areas_ini.beginGroup(p_name); areas_ini.beginGroup(p_name);
background = areas_ini.value("background", "gs4").toString(); m_background = areas_ini.value("background", "gs4").toString();
is_protected = areas_ini.value("protected_area", "false").toBool(); m_isProtected = areas_ini.value("protected_area", "false").toBool();
iniswap_allowed = areas_ini.value("iniswap_allowed", "true").toBool(); m_iniswapAllowed = areas_ini.value("iniswap_allowed", "true").toBool();
bg_locked = areas_ini.value("bg_locked", "false").toBool(); m_bgLocked = areas_ini.value("bg_locked", "false").toBool();
QString configured_evi_mod = areas_ini.value("evidence_mod", "FFA").toString().toLower(); QString configured_evi_mod = areas_ini.value("evidence_mod", "FFA").toString().toLower();
blankposting_allowed = areas_ini.value("blankposting_allowed","true").toBool(); m_blankpostingAllowed = areas_ini.value("blankposting_allowed","true").toBool();
force_immediate = areas_ini.value("force_immediate", "false").toBool(); m_forceImmediate = areas_ini.value("force_immediate", "false").toBool();
toggle_music = areas_ini.value("toggle_music", "true").toBool(); m_toggleMusic = areas_ini.value("toggle_music", "true").toBool();
showname_allowed = areas_ini.value("shownames_allowed", "true").toBool(); m_shownameAllowed = areas_ini.value("shownames_allowed", "true").toBool();
areas_ini.endGroup(); areas_ini.endGroup();
QSettings config_ini("config/config.ini", QSettings::IniFormat); QSettings config_ini("config/config.ini", QSettings::IniFormat);
config_ini.setIniCodec("UTF-8"); config_ini.setIniCodec("UTF-8");
config_ini.beginGroup("Options"); config_ini.beginGroup("Options");
int log_size = config_ini.value("logbuffer", 50).toInt(); int log_size = config_ini.value("logbuffer", 50).toInt();
log_type = config_ini.value("logger","modcall").toString(); QString l_logType = config_ini.value("logger","modcall").toString();
config_ini.endGroup(); config_ini.endGroup();
if (log_size == 0) if (log_size == 0)
log_size = 500; log_size = 500;
logger = new Logger(log_size, this); m_logger = new Logger(log_size, l_logType);
QTimer* timer1 = new QTimer(); QTimer* timer1 = new QTimer();
timers.append(timer1); m_timers.append(timer1);
QTimer* timer2 = new QTimer(); QTimer* timer2 = new QTimer();
timers.append(timer2); m_timers.append(timer2);
QTimer* timer3 = new QTimer(); QTimer* timer3 = new QTimer();
timers.append(timer3); m_timers.append(timer3);
QTimer* timer4 = new QTimer(); QTimer* timer4 = new QTimer();
timers.append(timer4); m_timers.append(timer4);
if (configured_evi_mod == "cm") if (configured_evi_mod == "cm")
evi_mod = EvidenceMod::CM; m_eviMod = EvidenceMod::CM;
else if (configured_evi_mod == "mod") else if (configured_evi_mod == "mod")
evi_mod = EvidenceMod::MOD; m_eviMod = EvidenceMod::MOD;
else if (configured_evi_mod == "hiddencm") else if (configured_evi_mod == "hiddencm")
evi_mod = EvidenceMod::HIDDEN_CM; m_eviMod = EvidenceMod::HIDDEN_CM;
else else
evi_mod = EvidenceMod::FFA; m_eviMod = EvidenceMod::FFA;
}
void AreaData::clientLeftArea(int f_charId)
{
--m_playerCount;
m_charactersTaken.removeAll(f_charId);
}
QList<int> AreaData::owners() const
{
QString l_test;
const auto& l_buffer = m_logger->m_buffer;
for (const auto& l_item : l_buffer)
{
l_test.append(l_item + "\n");
}
return m_owners;
}
void AreaData::addOwner(int f_clientId)
{
m_owners.append(f_clientId);
m_invited.append(f_clientId);
}
bool AreaData::removeOwner(int f_clientId)
{
m_owners.removeAll(f_clientId);
m_invited.removeAll(f_clientId);
if (m_owners.isEmpty() && m_locked != AreaData::FREE) {
m_locked = AreaData::FREE;
return true;
}
return false;
}
bool AreaData::blankpostingAllowed() const
{
return m_blankpostingAllowed;
}
bool AreaData::isProtected() const
{
return m_isProtected;
}
AreaData::LockStatus AreaData::lockStatus() const
{
return m_locked;
}
bool AreaData::invite(int f_clientId)
{
if (m_invited.contains(f_clientId)) {
return false;
}
m_invited.append(f_clientId);
return true;
}
int AreaData::playerCount() const
{
return m_playerCount;
} }

View File

@ -25,17 +25,16 @@ void AOClient::cmdCM(int argc, QStringList argv)
{ {
QString sender_name = ooc_name; QString sender_name = ooc_name;
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->is_protected) { if (area->isProtected()) {
sendServerMessage("This area is protected, you may not become CM."); sendServerMessage("This area is protected, you may not become CM.");
return; return;
} }
else if (area->owners.isEmpty()) { // no one owns this area, and it's not protected else if (area->owners().isEmpty()) { // no one owns this area, and it's not protected
area->owners.append(id); area->addOwner(id);
area->invited.append(id);
sendServerMessageArea(sender_name + " is now CM in this area."); sendServerMessageArea(sender_name + " is now CM in this area.");
arup(ARUPType::CM, true); arup(ARUPType::CM, true);
} }
else if (!area->owners.contains(id)) { // there is already a CM, and it isn't us else if (!area->owners().contains(id)) { // there is already a CM, and it isn't us
sendServerMessage("You cannot become a CM in this area."); 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 else if (argc == 1) { // we are CM, and we want to make ID argv[0] also CM
@ -49,7 +48,7 @@ void AOClient::cmdCM(int argc, QStringList argv)
sendServerMessage("Unable to find client with ID " + argv[0] + "."); sendServerMessage("Unable to find client with ID " + argv[0] + ".");
return; return;
} }
area->owners.append(owner_candidate->id); area->addOwner(owner_candidate->id);
sendServerMessageArea(owner_candidate->ooc_name + " is now CM in this area."); sendServerMessageArea(owner_candidate->ooc_name + " is now CM in this area.");
arup(ARUPType::CM, true); arup(ARUPType::CM, true);
} }
@ -63,7 +62,7 @@ void AOClient::cmdUnCM(int argc, QStringList argv)
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
int uid; int uid;
if (area->owners.isEmpty()) { if (area->owners().isEmpty()) {
sendServerMessage("There are no CMs in this area."); sendServerMessage("There are no CMs in this area.");
return; return;
} }
@ -78,7 +77,7 @@ void AOClient::cmdUnCM(int argc, QStringList argv)
sendServerMessage("Invalid user ID."); sendServerMessage("Invalid user ID.");
return; return;
} }
if (!area->owners.contains(uid)) { if (!area->owners().contains(uid)) {
sendServerMessage("That user is not CMed."); sendServerMessage("That user is not CMed.");
return; return;
} }
@ -89,16 +88,12 @@ void AOClient::cmdUnCM(int argc, QStringList argv)
sendServerMessage("Invalid command."); sendServerMessage("Invalid command.");
return; return;
} }
area->owners.removeAll(uid);
area->invited.removeAll(uid); if (area->removeOwner(uid)) {
arup(ARUPType::CM, true);
if (area->owners.isEmpty()) {
area->invited.clear();
if (area->locked != AreaData::FREE) {
area->locked = AreaData::FREE;
arup(ARUPType::LOCKED, true); arup(ARUPType::LOCKED, true);
} }
}
arup(ARUPType::CM, true);
} }
void AOClient::cmdInvite(int argc, QStringList argv) void AOClient::cmdInvite(int argc, QStringList argv)
@ -114,11 +109,10 @@ void AOClient::cmdInvite(int argc, QStringList argv)
sendServerMessage("No client with that ID found."); sendServerMessage("No client with that ID found.");
return; return;
} }
else if (area->invited.contains(invited_id)) { else if (!area->invite(invited_id)) {
sendServerMessage("That ID is already on the invite list."); sendServerMessage("That ID is already on the invite list.");
return; return;
} }
area->invited.append(invited_id);
sendServerMessage("You invited ID " + argv[0]); sendServerMessage("You invited ID " + argv[0]);
} }
@ -135,30 +129,30 @@ void AOClient::cmdUnInvite(int argc, QStringList argv)
sendServerMessage("No client with that ID found."); sendServerMessage("No client with that ID found.");
return; return;
} }
else if (area->owners.contains(uninvited_id)) { else if (area->owners().contains(uninvited_id)) {
sendServerMessage("You cannot uninvite a CM!"); sendServerMessage("You cannot uninvite a CM!");
return; return;
} }
else if (!area->invited.contains(uninvited_id)) { else if (!area->m_invited.contains(uninvited_id)) {
sendServerMessage("That ID is not on the invite list."); sendServerMessage("That ID is not on the invite list.");
return; return;
} }
area->invited.removeAll(uninvited_id); area->m_invited.removeAll(uninvited_id);
sendServerMessage("You uninvited ID " + argv[0]); sendServerMessage("You uninvited ID " + argv[0]);
} }
void AOClient::cmdLock(int argc, QStringList argv) void AOClient::cmdLock(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->locked == AreaData::LockStatus::LOCKED) { if (area->lockStatus() == AreaData::LockStatus::LOCKED) {
sendServerMessage("This area is already locked."); sendServerMessage("This area is already locked.");
return; return;
} }
sendServerMessageArea("This area is now locked."); sendServerMessageArea("This area is now locked.");
area->locked = AreaData::LockStatus::LOCKED; area->m_locked = AreaData::LockStatus::LOCKED;
for (AOClient* client : server->clients) { for (AOClient* client : server->clients) {
if (client->current_area == current_area && client->joined) { if (client->current_area == current_area && client->joined) {
area->invited.append(client->id); area->m_invited.append(client->id);
} }
} }
arup(ARUPType::LOCKED, true); arup(ARUPType::LOCKED, true);
@ -167,15 +161,15 @@ void AOClient::cmdLock(int argc, QStringList argv)
void AOClient::cmdSpectatable(int argc, QStringList argv) void AOClient::cmdSpectatable(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->locked == AreaData::LockStatus::SPECTATABLE) { if (area->lockStatus() == AreaData::LockStatus::SPECTATABLE) {
sendServerMessage("This area is already in spectate mode."); sendServerMessage("This area is already in spectate mode.");
return; return;
} }
sendServerMessageArea("This area is now spectatable."); sendServerMessageArea("This area is now spectatable.");
area->locked = AreaData::LockStatus::SPECTATABLE; area->m_locked = AreaData::LockStatus::SPECTATABLE;
for (AOClient* client : server->clients) { for (AOClient* client : server->clients) {
if (client->current_area == current_area && client->joined) { if (client->current_area == current_area && client->joined) {
area->invited.append(client->id); area->m_invited.append(client->id);
} }
} }
arup(ARUPType::LOCKED, true); arup(ARUPType::LOCKED, true);
@ -184,12 +178,12 @@ void AOClient::cmdSpectatable(int argc, QStringList argv)
void AOClient::cmdUnLock(int argc, QStringList argv) void AOClient::cmdUnLock(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->locked == AreaData::LockStatus::FREE) { if (area->m_locked == AreaData::LockStatus::FREE) {
sendServerMessage("This area is not locked."); sendServerMessage("This area is not locked.");
return; return;
} }
sendServerMessageArea("This area is now unlocked."); sendServerMessageArea("This area is now unlocked.");
area->locked = AreaData::LockStatus::FREE; area->m_locked = AreaData::LockStatus::FREE;
arup(ARUPType::LOCKED, true); arup(ARUPType::LOCKED, true);
} }
@ -241,9 +235,9 @@ void AOClient::cmdAreaKick(int argc, QStringList argv)
void AOClient::cmdSetBackground(int argc, QStringList argv) void AOClient::cmdSetBackground(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (authenticated || !area->bg_locked) { if (authenticated || !area->m_bgLocked) {
if (server->backgrounds.contains(argv[0])) { if (server->backgrounds.contains(argv[0])) {
area->background = argv[0]; area->m_background = argv[0];
server->broadcast(AOPacket("BN", {argv[0]}), current_area); server->broadcast(AOPacket("BN", {argv[0]}), current_area);
sendServerMessageArea(current_char + " changed the background to " + argv[0]); sendServerMessageArea(current_char + " changed the background to " + argv[0]);
} }
@ -259,14 +253,14 @@ void AOClient::cmdSetBackground(int argc, QStringList argv)
void AOClient::cmdBgLock(int argc, QStringList argv) void AOClient::cmdBgLock(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
area->bg_locked = true; area->m_bgLocked = true;
server->broadcast(AOPacket("CT", {"Server", current_char + " locked the background.", "1"}), current_area); server->broadcast(AOPacket("CT", {"Server", current_char + " locked the background.", "1"}), current_area);
} }
void AOClient::cmdBgUnlock(int argc, QStringList argv) void AOClient::cmdBgUnlock(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
area->bg_locked = false; area->m_bgLocked = false;
server->broadcast(AOPacket("CT", {"Server", current_char + " unlocked the background.", "1"}), current_area); server->broadcast(AOPacket("CT", {"Server", current_char + " unlocked the background.", "1"}), current_area);
} }
@ -275,17 +269,17 @@ void AOClient::cmdStatus(int argc, QStringList argv)
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
QString arg = argv[0].toLower(); QString arg = argv[0].toLower();
if (arg == "idle") if (arg == "idle")
area->status = AreaData::IDLE; area->m_status = AreaData::IDLE;
else if (arg == "rp") else if (arg == "rp")
area->status = AreaData::RP; area->m_status = AreaData::RP;
else if (arg == "casing") else if (arg == "casing")
area->status = AreaData::CASING; area->m_status = AreaData::CASING;
else if (arg == "looking-for-players" || arg == "lfp") else if (arg == "looking-for-players" || arg == "lfp")
area->status = AreaData::LOOKING_FOR_PLAYERS; area->m_status = AreaData::LOOKING_FOR_PLAYERS;
else if (arg == "recess") else if (arg == "recess")
area->status = AreaData::RECESS; area->m_status = AreaData::RECESS;
else if (arg == "gaming") else if (arg == "gaming")
area->status = AreaData::GAMING; area->m_status = AreaData::GAMING;
else { else {
sendServerMessage("That does not look like a valid status. Valid statuses are idle, rp, casing, lfp, recess, gaming"); sendServerMessage("That does not look like a valid status. Valid statuses are idle, rp, casing, lfp, recess, gaming");
return; return;
@ -297,11 +291,11 @@ void AOClient::cmdStatus(int argc, QStringList argv)
void AOClient::cmdJudgeLog(int argc, QStringList argv) void AOClient::cmdJudgeLog(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->judgelog.isEmpty()) { if (area->m_judgelog.isEmpty()) {
sendServerMessage("There have been no judge actions in this area."); sendServerMessage("There have been no judge actions in this area.");
return; return;
} }
QString message = area->judgelog.join("\n"); QString message = area->m_judgelog.join("\n");
//Judgelog contains an IPID, so we shouldn't send that unless the caller has appropriate permissions //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) { if (checkAuth(ACLFlags.value("KICK")) == 1 || checkAuth(ACLFlags.value("BAN")) == 1) {
sendServerMessage(message); sendServerMessage(message);

View File

@ -40,7 +40,7 @@ void AOClient::cmdLogin(int argc, QStringList argv)
sendPacket("AUTH", {"0"}); // Client: "Login unsuccessful." sendPacket("AUTH", {"0"}); // Client: "Login unsuccessful."
sendServerMessage("Incorrect password."); sendServerMessage("Incorrect password.");
} }
server->areas.value(current_area)->logger->logLogin(this, authenticated, "moderator"); server->areas.value(current_area)->m_logger->logLogin(this, authenticated, "moderator");
} }
else if (server->auth_type == "advanced") { else if (server->auth_type == "advanced") {
if (argc < 2) { if (argc < 2) {
@ -61,7 +61,7 @@ void AOClient::cmdLogin(int argc, QStringList argv)
sendPacket("AUTH", {"0"}); // Client: "Login unsuccessful." sendPacket("AUTH", {"0"}); // Client: "Login unsuccessful."
sendServerMessage("Incorrect password."); sendServerMessage("Incorrect password.");
} }
server->areas.value(current_area)->logger->logLogin(this, authenticated, username); server->areas.value(current_area)->m_logger->logLogin(this, authenticated, username);
} }
else { else {
qWarning() << "config.ini has an unrecognized auth_type!"; qWarning() << "config.ini has an unrecognized auth_type!";

View File

@ -25,10 +25,10 @@ void AOClient::cmdDoc(int argc, QStringList argv)
QString sender_name = ooc_name; QString sender_name = ooc_name;
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (argc == 0) { if (argc == 0) {
sendServerMessage("Document: " + area->document); sendServerMessage("Document: " + area->m_document);
} }
else { else {
area->document = argv.join(" "); area->m_document = argv.join(" ");
sendServerMessageArea(sender_name + " changed the document."); sendServerMessageArea(sender_name + " changed the document.");
} }
} }
@ -37,7 +37,7 @@ void AOClient::cmdClearDoc(int argc, QStringList argv)
{ {
QString sender_name = ooc_name; QString sender_name = ooc_name;
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
area->document = "No document."; area->m_document = "No document.";
sendServerMessageArea(sender_name + " cleared the document."); sendServerMessageArea(sender_name + " cleared the document.");
} }
@ -46,13 +46,13 @@ void AOClient::cmdEvidenceMod(int argc, QStringList argv)
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
argv[0] = argv[0].toLower(); argv[0] = argv[0].toLower();
if (argv[0] == "cm") if (argv[0] == "cm")
area->evi_mod = AreaData::EvidenceMod::CM; area->m_eviMod = AreaData::EvidenceMod::CM;
else if (argv[0] == "mod") else if (argv[0] == "mod")
area->evi_mod = AreaData::EvidenceMod::MOD; area->m_eviMod = AreaData::EvidenceMod::MOD;
else if (argv[0] == "hiddencm") else if (argv[0] == "hiddencm")
area->evi_mod = AreaData::EvidenceMod::HIDDEN_CM; area->m_eviMod = AreaData::EvidenceMod::HIDDEN_CM;
else if (argv[0] == "ffa") else if (argv[0] == "ffa")
area->evi_mod = AreaData::EvidenceMod::FFA; area->m_eviMod = AreaData::EvidenceMod::FFA;
else { else {
sendServerMessage("Invalid evidence mod."); sendServerMessage("Invalid evidence mod.");
return; return;
@ -66,7 +66,7 @@ void AOClient::cmdEvidenceMod(int argc, QStringList argv)
void AOClient::cmdEvidence_Swap(int argc, QStringList argv) void AOClient::cmdEvidence_Swap(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
int ev_size = area->evidence.size() -1; int ev_size = area->m_evidence.size() -1;
if (ev_size < 0) { if (ev_size < 0) {
sendServerMessage("No evidence in area."); sendServerMessage("No evidence in area.");
@ -89,7 +89,7 @@ void AOClient::cmdEvidence_Swap(int argc, QStringList argv)
//swapItemsAt does not exist in Qt older than 5.13 //swapItemsAt does not exist in Qt older than 5.13
area->evidence.swap(ev_id1, ev_id2); area->evidence.swap(ev_id1, ev_id2);
#else #else
area->evidence.swapItemsAt(ev_id1, ev_id2); area->m_evidence.swapItemsAt(ev_id1, ev_id2);
#endif #endif
sendEvidenceList(area); sendEvidenceList(area);
sendServerMessage("The evidence " + QString::number(ev_id1) + " and " + QString::number(ev_id2) + " have been swapped."); sendServerMessage("The evidence " + QString::number(ev_id1) + " and " + QString::number(ev_id2) + " have been swapped.");
@ -102,12 +102,12 @@ void AOClient::cmdEvidence_Swap(int argc, QStringList argv)
void AOClient::cmdTestify(int argc, QStringList argv) void AOClient::cmdTestify(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->test_rec == AreaData::TestimonyRecording::RECORDING) { if (area->m_testimonyRecording == AreaData::TestimonyRecording::RECORDING) {
sendServerMessage("Testimony recording is already in progress. Please stop it before starting a new one."); sendServerMessage("Testimony recording is already in progress. Please stop it before starting a new one.");
} }
else { else {
clearTestimony(); clearTestimony();
area->test_rec = AreaData::TestimonyRecording::RECORDING; area->m_testimonyRecording = AreaData::TestimonyRecording::RECORDING;
sendServerMessage("Started testimony recording."); sendServerMessage("Started testimony recording.");
} }
} }
@ -115,15 +115,15 @@ void AOClient::cmdTestify(int argc, QStringList argv)
void AOClient::cmdExamine(int argc, QStringList argv) void AOClient::cmdExamine(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->testimony.size() -1 > 0) if (area->m_testimony.size() -1 > 0)
{ {
area->test_rec = AreaData::TestimonyRecording::PLAYBACK; area->m_testimonyRecording = AreaData::TestimonyRecording::PLAYBACK;
server->broadcast(AOPacket("RT",{"testimony2"}), current_area); server->broadcast(AOPacket("RT",{"testimony2"}), current_area);
server->broadcast(AOPacket("MS", {area->testimony[0]}), current_area); server->broadcast(AOPacket("MS", {area->m_testimony[0]}), current_area);
area->statement = 0; area->m_statement = 0;
return; return;
} }
if (area->test_rec == AreaData::TestimonyRecording::PLAYBACK) if (area->m_testimonyRecording == AreaData::TestimonyRecording::PLAYBACK)
sendServerMessage("Unable to examine while another examination is running"); sendServerMessage("Unable to examine while another examination is running");
else else
sendServerMessage("Unable to start replay without prior examination."); sendServerMessage("Unable to start replay without prior examination.");
@ -132,15 +132,15 @@ void AOClient::cmdExamine(int argc, QStringList argv)
void AOClient::cmdTestimony(int argc, QStringList argv) void AOClient::cmdTestimony(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->testimony.size() -1 < 1) { if (area->m_testimony.size() -1 < 1) {
sendServerMessage("Unable to display empty testimony."); sendServerMessage("Unable to display empty testimony.");
return; return;
} }
QString ooc_message; QString ooc_message;
for (int i = 1; i <= area->testimony.size() -1; i++) for (int i = 1; i <= area->m_testimony.size() -1; i++)
{ {
QStringList packet = area->testimony.at(i); QStringList packet = area->m_testimony.at(i);
QString ic_message = packet[4]; QString ic_message = packet[4];
ooc_message.append( "[" + QString::number(i) + "]" + ic_message + "\n"); ooc_message.append( "[" + QString::number(i) + "]" + ic_message + "\n");
} }
@ -150,35 +150,35 @@ void AOClient::cmdTestimony(int argc, QStringList argv)
void AOClient::cmdDeleteStatement(int argc, QStringList argv) void AOClient::cmdDeleteStatement(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
int c_statement = area->statement; int c_statement = area->m_statement;
if (area->testimony.size() - 1 == 0) { if (area->m_testimony.size() - 1 == 0) {
sendServerMessage("Unable to delete statement. No statements saved in this area."); sendServerMessage("Unable to delete statement. No statements saved in this area.");
} }
if (c_statement > 0 && area->testimony.size() > 2) { if (c_statement > 0 && area->m_testimony.size() > 2) {
area->testimony.remove(c_statement); area->m_testimony.remove(c_statement);
area->statement = c_statement - 1; area->m_statement = c_statement - 1;
sendServerMessage("The statement with id " + QString::number(c_statement) + " has been deleted from the testimony."); sendServerMessage("The statement with id " + QString::number(c_statement) + " has been deleted from the testimony.");
} }
} }
void AOClient::cmdUpdateStatement(int argc, QStringList argv) void AOClient::cmdUpdateStatement(int argc, QStringList argv)
{ {
server->areas[current_area]->test_rec = AreaData::TestimonyRecording::UPDATE; server->areas[current_area]->m_testimonyRecording = AreaData::TestimonyRecording::UPDATE;
sendServerMessage("The next IC-Message will replace the last displayed replay message."); sendServerMessage("The next IC-Message will replace the last displayed replay message.");
} }
void AOClient::cmdPauseTestimony(int argc, QStringList argv) void AOClient::cmdPauseTestimony(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
area->test_rec = AreaData::TestimonyRecording::STOPPED; area->m_testimonyRecording = AreaData::TestimonyRecording::STOPPED;
server->broadcast(AOPacket("RT",{"testimony1#1"}), current_area); server->broadcast(AOPacket("RT",{"testimony1#1"}), current_area);
sendServerMessage("Testimony has been stopped."); sendServerMessage("Testimony has been stopped.");
} }
void AOClient::cmdAddStatement(int argc, QStringList argv) void AOClient::cmdAddStatement(int argc, QStringList argv)
{ {
if (server->areas[current_area]->statement < server->maximum_statements) { if (server->areas[current_area]->m_statement < server->maximum_statements) {
server->areas[current_area]->test_rec = AreaData::TestimonyRecording::ADD; server->areas[current_area]->m_testimonyRecording = AreaData::TestimonyRecording::ADD;
sendServerMessage("The next IC-Message will be inserted into the testimony."); sendServerMessage("The next IC-Message will be inserted into the testimony.");
} }
else else
@ -196,7 +196,7 @@ void AOClient::cmdSaveTestimony(int argc, QStringList argv)
if (permission_found) { if (permission_found) {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->testimony.size() -1 <= 0) { if (area->m_testimony.size() -1 <= 0) {
sendServerMessage("Can't save an empty testimony."); sendServerMessage("Can't save an empty testimony.");
return; return;
} }
@ -216,9 +216,9 @@ void AOClient::cmdSaveTestimony(int argc, QStringList argv)
QTextStream out(&file); QTextStream out(&file);
out.setCodec("UTF-8"); out.setCodec("UTF-8");
if(file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) { if(file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
for (int i = 0; i <= area->testimony.size() -1; i++) for (int i = 0; i <= area->m_testimony.size() -1; i++)
{ {
out << area->testimony.at(i).join("#") << "\n"; out << area->m_testimony.at(i).join("#") << "\n";
} }
sendServerMessage("Testimony saved. To load it use /loadtestimony " + testimony_name); sendServerMessage("Testimony saved. To load it use /loadtestimony " + testimony_name);
testimony_saving = false; testimony_saving = false;
@ -258,7 +258,7 @@ void AOClient::cmdLoadTestimony(int argc, QStringList argv)
if (testimony_lines <= server->maximum_statements) { if (testimony_lines <= server->maximum_statements) {
QString line = in.readLine(); QString line = in.readLine();
QStringList packet = line.split("#"); QStringList packet = line.split("#");
area->testimony.append(packet); area->m_testimony.append(packet);
testimony_lines = testimony_lines + 1; testimony_lines = testimony_lines + 1;
} }
else { else {

View File

@ -32,7 +32,7 @@ QStringList AOClient::buildAreaList(int area_idx)
QString area_name = server->area_names[area_idx]; QString area_name = server->area_names[area_idx];
AreaData* area = server->areas[area_idx]; AreaData* area = server->areas[area_idx];
entries.append("=== " + area_name + " ==="); entries.append("=== " + area_name + " ===");
switch (area->locked) { switch (area->locked()) {
case AreaData::LockStatus::LOCKED: case AreaData::LockStatus::LOCKED:
entries.append("[LOCKED]"); entries.append("[LOCKED]");
break; break;
@ -43,13 +43,13 @@ QStringList AOClient::buildAreaList(int area_idx)
default: default:
break; break;
} }
entries.append("[" + QString::number(area->player_count) + " users][" + QVariant::fromValue(area->status).toString().replace("_", "-") + "]"); entries.append("[" + QString::number(area->m_playerCount) + " users][" + QVariant::fromValue(area->m_status).toString().replace("_", "-") + "]");
for (AOClient* client : server->clients) { for (AOClient* client : server->clients) {
if (client->current_area == area_idx && client->joined) { if (client->current_area == area_idx && client->joined) {
QString char_entry = "[" + QString::number(client->id) + "] " + client->current_char; QString char_entry = "[" + QString::number(client->id) + "] " + client->current_char;
if (client->current_char == "") if (client->current_char == "")
char_entry += "Spectator"; char_entry += "Spectator";
if (area->owners.contains(client->id)) if (area->m_owners.contains(client->id))
char_entry.insert(0, "[CM] "); char_entry.insert(0, "[CM] ");
if (authenticated) if (authenticated)
char_entry += " (" + client->getIpid() + "): " + client->ooc_name; char_entry += " (" + client->getIpid() + "): " + client->ooc_name;
@ -103,7 +103,7 @@ QString AOClient::getAreaTimer(int area_idx, int timer_idx)
if (timer_idx == 0) if (timer_idx == 0)
timer = server->timer; timer = server->timer;
else if (timer_idx > 0 && timer_idx <= 4) else if (timer_idx > 0 && timer_idx <= 4)
timer = area->timers[timer_idx - 1]; timer = area->m_timer[timer_idx - 1];
else else
return "Invalid timer ID."; return "Invalid timer ID.";

View File

@ -106,7 +106,7 @@ void AOClient::cmdRandomChar(int argc, QStringList argv)
bool taken = true; bool taken = true;
while (taken) { while (taken) {
selected_char_id = genRand(0, server->characters.size() - 1); selected_char_id = genRand(0, server->characters.size() - 1);
if (!area->characters_taken.contains(selected_char_id)) { if (!area->m_charactersTaken.contains(selected_char_id)) {
taken = false; taken = false;
} }
} }
@ -423,7 +423,7 @@ void AOClient::cmdA(int argc, QStringList argv)
} }
AreaData* area = server->areas[area_id]; AreaData* area = server->areas[area_id];
if (!area->owners.contains(id)) { if (!area->m_owners.contains(id)) {
sendServerMessage("You are not CM in that area."); sendServerMessage("You are not CM in that area.");
return; return;
} }
@ -441,7 +441,7 @@ void AOClient::cmdS(int argc, QStringList argv)
QString ooc_message = argv.join(" "); QString ooc_message = argv.join(" ");
for (int i = 0; i <= all_areas; i++) { for (int i = 0; i <= all_areas; i++) {
if (server->areas[i]->owners.contains(id)) if (server->areas[i]->m_owners.contains(id))
server->broadcast(AOPacket("CT", {"[CM]" + sender_name, ooc_message}), i); server->broadcast(AOPacket("CT", {"[CM]" + sender_name, ooc_message}), i);
} }
} }

View File

@ -333,8 +333,8 @@ void AOClient::cmdAllowBlankposting(int argc, QStringList argv)
{ {
QString sender_name = ooc_name; QString sender_name = ooc_name;
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
area->blankposting_allowed = !area->blankposting_allowed; area->m_blankpostingAllowed = !area->m_blankpostingAllowed;
if (area->blankposting_allowed == false) { if (area->blankpostingAllowed() == false) {
sendServerMessageArea(sender_name + " has set blankposting in the area to forbidden."); sendServerMessageArea(sender_name + " has set blankposting in the area to forbidden.");
} }
else { else {
@ -391,16 +391,16 @@ void AOClient::cmdReload(int argc, QStringList argv)
void AOClient::cmdForceImmediate(int argc, QStringList argv) void AOClient::cmdForceImmediate(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
area->force_immediate = !area->force_immediate; area->m_forceImmediate = !area->m_forceImmediate;
QString state = area->force_immediate ? "on." : "off."; QString state = area->m_forceImmediate ? "on." : "off.";
sendServerMessage("Forced immediate text processing in this area is now " + state); sendServerMessage("Forced immediate text processing in this area is now " + state);
} }
void AOClient::cmdAllowIniswap(int argc, QStringList argv) void AOClient::cmdAllowIniswap(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
area->iniswap_allowed = !area->iniswap_allowed; area->m_iniswapAllowed = !area->m_iniswapAllowed;
QString state = area->iniswap_allowed ? "allowed." : "disallowed."; QString state = area->m_iniswapAllowed ? "allowed." : "disallowed.";
sendServerMessage("Iniswapping in this area is now " + state); sendServerMessage("Iniswapping in this area is now " + state);
} }

View File

@ -28,8 +28,8 @@ void AOClient::cmdPlay(int argc, QStringList argv)
} }
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
QString song = argv.join(" "); QString song = argv.join(" ");
area->current_music = song; area->m_currentMusic = song;
area->music_played_by = showname; area->m_musicPlayerBy = showname;
AOPacket music_change("MC", {song, QString::number(server->getCharID(current_char)), showname, "1", "0"}); AOPacket music_change("MC", {song, QString::number(server->getCharID(current_char)), showname, "1", "0"});
server->broadcast(music_change, current_area); server->broadcast(music_change, current_area);
} }
@ -37,8 +37,8 @@ void AOClient::cmdPlay(int argc, QStringList argv)
void AOClient::cmdCurrentMusic(int argc, QStringList argv) void AOClient::cmdCurrentMusic(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->current_music != "" && area->current_music != "~stop.mp3") // dummy track for stopping music if (area->m_currentMusic != "" && area->m_currentMusic != "~stop.mp3") // dummy track for stopping music
sendServerMessage("The current song is " + area->current_music + " played by " + area->music_played_by); sendServerMessage("The current song is " + area->m_currentMusic + " played by " + area->m_musicPlayerBy);
else else
sendServerMessage("There is no music playing."); sendServerMessage("There is no music playing.");
} }
@ -86,7 +86,7 @@ void AOClient::cmdUnBlockDj(int argc, QStringList argv)
void AOClient::cmdToggleMusic(int argc, QStringList argv) void AOClient::cmdToggleMusic(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
area->toggle_music = !area->toggle_music; area->m_toggleMusic = !area->m_toggleMusic;
QString state = area->toggle_music ? "allowed." : "disallowed."; QString state = area->m_toggleMusic ? "allowed." : "disallowed.";
sendServerMessage("Music in this area is now " + state); sendServerMessage("Music in this area is now " + state);
} }

View File

@ -48,7 +48,7 @@ void AOClient::cmdTimer(int argc, QStringList argv)
QStringList timers; QStringList timers;
timers.append("Currently active timers:"); timers.append("Currently active timers:");
for (int i = 0; i <= 4; i++) { for (int i = 0; i <= 4; i++) {
timers.append(getAreaTimer(area->index, i)); timers.append(getAreaTimer(area->m_index, i));
} }
sendServerMessage(timers.join("\n")); sendServerMessage(timers.join("\n"));
return; return;
@ -65,7 +65,7 @@ void AOClient::cmdTimer(int argc, QStringList argv)
// Called with one argument // Called with one argument
// Shows the status of one timer // Shows the status of one timer
if (argc == 1) { if (argc == 1) {
sendServerMessage(getAreaTimer(area->index, timer_id)); sendServerMessage(getAreaTimer(area->m_index, timer_id));
return; return;
} }
@ -83,7 +83,7 @@ void AOClient::cmdTimer(int argc, QStringList argv)
requested_timer = server->timer; requested_timer = server->timer;
} }
else else
requested_timer = area->timers[timer_id - 1]; requested_timer = area->m_timers[timer_id - 1];
AOPacket show_timer("TI", {QString::number(timer_id), "2"}); AOPacket show_timer("TI", {QString::number(timer_id), "2"});
AOPacket hide_timer("TI", {QString::number(timer_id), "3"}); AOPacket hide_timer("TI", {QString::number(timer_id), "3"});
@ -130,18 +130,18 @@ void AOClient::cmdTimer(int argc, QStringList argv)
void AOClient::cmdNoteCard(int argc, QStringList argv) void AOClient::cmdNoteCard(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->notecards.keys().contains(current_char)) if (area->m_notecards.keys().contains(current_char))
area->notecards.remove(current_char); area->m_notecards.remove(current_char);
QString notecard = argv.join(" "); QString notecard = argv.join(" ");
area->notecards[current_char] = notecard; area->m_notecards[current_char] = notecard;
sendServerMessageArea(current_char + " wrote a note card."); sendServerMessageArea(current_char + " wrote a note card.");
} }
void AOClient::cmdNoteCardClear(int argc, QStringList argv) void AOClient::cmdNoteCardClear(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->notecards.keys().contains(current_char)) { if (area->m_notecards.keys().contains(current_char)) {
area->notecards.remove(current_char); area->m_notecards.remove(current_char);
sendServerMessageArea(current_char + " erased their note card."); sendServerMessageArea(current_char + " erased their note card.");
} }
else else
@ -151,17 +151,17 @@ void AOClient::cmdNoteCardClear(int argc, QStringList argv)
void AOClient::cmdNoteCardReveal(int argc, QStringList argv) void AOClient::cmdNoteCardReveal(int argc, QStringList argv)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->notecards.isEmpty()) { if (area->m_notecards.isEmpty()) {
sendServerMessage("There are no cards to reveal in this area."); sendServerMessage("There are no cards to reveal in this area.");
return; return;
} }
QStringList message; QStringList message;
message << "Note cards have been revealed."; message << "Note cards have been revealed.";
QMap<QString, QString>::iterator i; QMap<QString, QString>::iterator i;
for (i = area->notecards.begin(); i != area->notecards.end(); ++i) for (i = area->m_notecards.begin(); i != area->m_notecards.end(); ++i)
message << i.key() + ": " + i.value(); message << i.key() + ": " + i.value();
sendServerMessageArea(message.join("\n")); sendServerMessageArea(message.join("\n"));
area->notecards.clear(); area->m_notecards.clear();
} }
void AOClient::cmd8Ball(int argc, QStringList argv) void AOClient::cmd8Ball(int argc, QStringList argv)

View File

@ -15,101 +15,101 @@
// You should have received a copy of the GNU Affero General Public License // // You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. // // along with this program. If not, see <https://www.gnu.org/licenses/>. //
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
#include <QDir>
#include "include/logger.h" #include "include/logger.h"
void Logger::logIC(AOClient *client, AOPacket *packet) void Logger::logIC(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r)
{ {
QString message = packet->contents[4]; addEntry(f_areaName_r, f_charName_r, f_ipid_r, "IC", f_message_r);
addEntry(buildEntry(client, "IC", message));
} }
void Logger::logOOC(AOClient* client, AOPacket* packet) void Logger::logOOC(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r)
{ {
QString message = packet->contents[1]; addEntry(f_areaName_r, f_charName_r, f_ipid_r, "OOC", f_message_r);
addEntry(buildEntry(client, "OOC", message));
} }
void Logger::logModcall(AOClient* client, AOPacket* packet) void Logger::logModcall(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_modcallReason_r)
{ {
QString message = packet->contents[0]; addEntry(f_areaName_r, f_charName_r, f_ipid_r, "MODCALL", f_modcallReason_r);
addEntry(buildEntry(client, "MODCALL", message));
} }
void Logger::logCmd(AOClient *client, AOPacket *packet, QString cmd, QStringList args) void Logger::logCmd(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r,
const QString& f_oocMessage_r, const QString& f_cmd_r, const QStringList& f_cmdArgs_r)
{ {
// Some commands contain sensitive data, like passwords // Some commands contain sensitive data, like passwords
// These must be filtered out // These must be filtered out
if (cmd == "login") { if (f_cmd_r == "login") {
addEntry(buildEntry(client, "LOGIN", "Attempted login")); addEntry(f_areaName_r, f_charName_r, f_ipid_r, "LOGIN", "Attempted login");
} }
else if (cmd == "rootpass") { else if (f_cmd_r == "rootpass") {
addEntry(buildEntry(client, "USERS", "Root password created")); addEntry(f_areaName_r, f_charName_r, f_ipid_r, "USERS", "Root password created");
} }
else if (cmd == "adduser" && !args.isEmpty()) { else if (f_cmd_r == "adduser" && !f_cmdArgs_r.isEmpty()) {
addEntry(buildEntry(client, "USERS", "Added user " + args[0])); addEntry(f_areaName_r, f_charName_r, f_ipid_r, "USERS", "Added user " + f_cmdArgs_r[0]);
}
else {
logOOC(f_areaName_r, f_charName_r, f_ipid_r, f_oocMessage_r);
} }
else
logOOC(client, packet);
} }
void Logger::logLogin(AOClient *client, bool success, QString modname) void Logger::logLogin(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, bool success, const QString& f_modname_r)
{ {
QString message = success ? "Logged in as " + modname : "Failed to log in as " + modname; QString l_message = success ? "Logged in as " + f_modname_r : "Failed to log in as " + f_modname_r;
addEntry(buildEntry(client, "LOGIN", message)); addEntry(f_areaName_r, f_charName_r, f_ipid_r, "LOGIN", l_message);
} }
QString Logger::buildEntry(AOClient *client, QString type, QString message) void Logger::addEntry(
const QString& f_areaName_r,
const QString& f_charName_r,
const QString& f_ipid_r,
const QString& f_type_r,
const QString& f_message_r)
{ {
QString time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString area_name = area->name;
QString char_name = client->current_char;
QString ipid = client->getIpid();
QString log_entry = QStringLiteral("[%1][%2][%6] %3(%4): %5\n") QString l_logEntry = QStringLiteral("[%1][%2][%6] %3(%4): %5\n")
.arg(time) .arg(l_time, f_areaName_r, f_charName_r, f_ipid_r, f_message_r, f_type_r);
.arg(area_name)
.arg(char_name)
.arg(ipid)
.arg(message)
.arg(type);
return log_entry;
}
void Logger::addEntry(QString entry) if (m_buffer.length() < m_maxLength) {
{ m_buffer.enqueue(l_logEntry);
if (buffer.length() < max_length) {
buffer.enqueue(entry); if (m_logType == "full") {
if (area->log_type == "full") { flush(f_areaName_r);
flush();
} }
} }
else { else {
buffer.dequeue(); m_buffer.dequeue();
buffer.enqueue(entry); m_buffer.enqueue(l_logEntry);
} }
} }
void Logger::flush() void Logger::flush(const QString& f_areaName_r)
{ {
QDir dir("logs/"); QDir l_dir("logs/");
if (!dir.exists()) { if (!l_dir.exists()) {
dir.mkpath("."); l_dir.mkpath(".");
} }
QFile logfile; QFile l_logfile;
if (area->log_type == "modcall") {
logfile.setFileName(QString("logs/report_%1_%2.log").arg((area->name), (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss")))); if (m_logType == "modcall") {
l_logfile.setFileName(QString("logs/report_%1_%2.log").arg(f_areaName_r, (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss"))));
} }
else if (area->log_type == "full") { else if (m_logType == "full") {
logfile.setFileName(QString("logs/%1.log").arg(QDate::currentDate().toString("yyyy-MM-dd"))); l_logfile.setFileName(QString("logs/%1.log").arg(QDate::currentDate().toString("yyyy-MM-dd")));
} }
else { else {
qCritical("Invalid logger set!"); qCritical("Invalid logger set!");
} }
if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
QTextStream file_stream(&logfile); if (l_logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
while (!buffer.isEmpty()) QTextStream file_stream(&l_logfile);
file_stream << buffer.dequeue();
while (!m_buffer.isEmpty())
file_stream << m_buffer.dequeue();
} }
logfile.close();
l_logfile.close();
} }

View File

@ -96,19 +96,19 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack
} }
server->player_count++; server->player_count++;
area->player_count++; area->m_playerCount++;
joined = true; joined = true;
server->updateCharsTaken(area); server->updateCharsTaken(area);
arup(ARUPType::PLAYER_COUNT, true); // Tell everyone there is a new player arup(ARUPType::PLAYER_COUNT, true); // Tell everyone there is a new player
sendEvidenceList(area); sendEvidenceList(area);
sendPacket("HP", {"1", QString::number(area->def_hp)}); sendPacket("HP", {"1", QString::number(area->m_defHP)});
sendPacket("HP", {"2", QString::number(area->pro_hp)}); sendPacket("HP", {"2", QString::number(area->m_proHP)});
sendPacket("FA", server->area_names); sendPacket("FA", server->area_names);
sendPacket("OPPASS", {"DEADBEEF"}); sendPacket("OPPASS", {"DEADBEEF"});
sendPacket("DONE"); sendPacket("DONE");
sendPacket("BN", {area->background}); sendPacket("BN", {area->m_background});
sendServerMessage("=== MOTD ===\r\n" + server->MOTD + "\r\n============="); sendServerMessage("=== MOTD ===\r\n" + server->MOTD + "\r\n=============");
@ -120,8 +120,8 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack
else { else {
sendPacket("TI", {"0", "3"}); sendPacket("TI", {"0", "3"});
} }
for (QTimer* timer : area->timers) { for (QTimer* timer : area->m_timer) {
int timer_id = area->timers.indexOf(timer) + 1; int timer_id = area->m_timer.indexOf(timer) + 1;
if (timer->isActive()) { if (timer->isActive()) {
sendPacket("TI", {QString::number(timer_id), "2"}); 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())))}); sendPacket("TI", {QString::number(timer_id), "0", QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(timer->remainingTime())))});
@ -164,10 +164,10 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
if (pos != "") if (pos != "")
validated_packet.contents[5] = pos; validated_packet.contents[5] = pos;
area->logger->logIC(this, &validated_packet); area->m_logger->logIC(this, &validated_packet);
server->broadcast(validated_packet, current_area); server->broadcast(validated_packet, current_area);
area->last_ic_message.clear(); area->m_lastICMessage.clear();
area->last_ic_message.append(validated_packet.contents); area->m_lastICMessage.append(validated_packet.contents);
} }
void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet) void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet)
@ -196,12 +196,12 @@ void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket p
command = command.right(command.length() - 1); command = command.right(command.length() - 1);
cmd_argv.removeFirst(); cmd_argv.removeFirst();
int cmd_argc = cmd_argv.length(); int cmd_argc = cmd_argv.length();
area->logger->logCmd(this, &final_packet, command, cmd_argv); area->m_logger->logCmd(this, &final_packet, command, cmd_argv);
handleCommand(command, cmd_argc, cmd_argv); handleCommand(command, cmd_argc, cmd_argv);
} }
else { else {
server->broadcast(final_packet, current_area); server->broadcast(final_packet, current_area);
area->logger->logOOC(this, &final_packet); area->m_logger->logOOC(this, &final_packet);
} }
} }
@ -230,7 +230,7 @@ void AOClient::pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPack
sendServerMessage("You are blocked from changing the music."); sendServerMessage("You are blocked from changing the music.");
return; return;
} }
if (!area->toggle_music && !checkAuth(ACLFlags.value("CM"))) { if (!area->m_toggleMusic && !checkAuth(ACLFlags.value("CM"))) {
sendServerMessage("Music is disabled in this area."); sendServerMessage("Music is disabled in this area.");
return; return;
} }
@ -245,8 +245,8 @@ void AOClient::pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPack
else else
final_song = argument; final_song = argument;
AOPacket music_change("MC", {final_song, argv[1], showname, "1", "0", effects}); AOPacket music_change("MC", {final_song, argv[1], showname, "1", "0", effects});
area->current_music = final_song; area->m_currentMusic = final_song;
area->music_played_by = showname; area->m_musicPlayerBy = showname;
server->broadcast(music_change, current_area); server->broadcast(music_change, current_area);
return; return;
} }
@ -281,13 +281,13 @@ void AOClient::pktHpBar(AreaData* area, int argc, QStringList argv, AOPacket pac
return; return;
} }
if (argv[0] == "1") { if (argv[0] == "1") {
area->def_hp = std::min(std::max(0, argv[1].toInt()), 10); area->m_defHP = std::min(std::max(0, argv[1].toInt()), 10);
} }
else if (argv[0] == "2") { else if (argv[0] == "2") {
area->pro_hp = std::min(std::max(0, argv[1].toInt()), 10); area->m_proHP = std::min(std::max(0, argv[1].toInt()), 10);
} }
server->broadcast(AOPacket("HP", {"1", QString::number(area->def_hp)}), area->index); server->broadcast(AOPacket("HP", {"1", QString::number(area->m_defHP)}), area->m_index);
server->broadcast(AOPacket("HP", {"2", QString::number(area->pro_hp)}), area->index); server->broadcast(AOPacket("HP", {"2", QString::number(area->m_proHP)}), area->m_index);
updateJudgeLog(area, this, "updated the penalties"); updateJudgeLog(area, this, "updated the penalties");
} }
@ -326,8 +326,8 @@ void AOClient::pktModCall(AreaData* area, int argc, QStringList argv, AOPacket p
if (client->authenticated) if (client->authenticated)
client->sendPacket(packet); client->sendPacket(packet);
} }
area->logger->logModcall(this, &packet); area->m_logger->logModcall(this, &packet);
area->logger->flush(); area->m_logger->flush();
} }
void AOClient::pktAddEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet) void AOClient::pktAddEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet)
@ -335,7 +335,7 @@ void AOClient::pktAddEvidence(AreaData* area, int argc, QStringList argv, AOPack
if (!checkEvidenceAccess(area)) if (!checkEvidenceAccess(area))
return; return;
AreaData::Evidence evi = {argv[0], argv[1], argv[2]}; AreaData::Evidence evi = {argv[0], argv[1], argv[2]};
area->evidence.append(evi); area->m_evidence.append(evi);
sendEvidenceList(area); sendEvidenceList(area);
} }
@ -345,8 +345,8 @@ void AOClient::pktRemoveEvidence(AreaData* area, int argc, QStringList argv, AOP
return; return;
bool is_int = false; bool is_int = false;
int idx = argv[0].toInt(&is_int); int idx = argv[0].toInt(&is_int);
if (is_int && idx <= area->evidence.size() && idx >= 0) { if (is_int && idx <= area->m_evidence.size() && idx >= 0) {
area->evidence.removeAt(idx); area->m_evidence.removeAt(idx);
} }
sendEvidenceList(area); sendEvidenceList(area);
} }
@ -358,8 +358,8 @@ void AOClient::pktEditEvidence(AreaData* area, int argc, QStringList argv, AOPac
bool is_int = false; bool is_int = false;
int idx = argv[0].toInt(&is_int); int idx = argv[0].toInt(&is_int);
AreaData::Evidence evi = {argv[1], argv[2], argv[3]}; AreaData::Evidence evi = {argv[1], argv[2], argv[3]};
if (is_int && idx <= area->evidence.size() && idx >= 0) { if (is_int && idx <= area->m_evidence.size() && idx >= 0) {
area->evidence.replace(idx, evi); area->m_evidence.replace(idx, evi);
} }
sendEvidenceList(area); sendEvidenceList(area);
} }
@ -430,8 +430,8 @@ void AOClient::updateEvidenceList(AreaData* area)
QStringList evidence_list; QStringList evidence_list;
QString evidence_format("%1&%2&%3"); QString evidence_format("%1&%2&%3");
for (AreaData::Evidence evidence : area->evidence) { for (AreaData::Evidence evidence : area->m_evidence) {
if (!checkAuth(ACLFlags.value("CM")) && area->evi_mod == AreaData::EvidenceMod::HIDDEN_CM) { if (!checkAuth(ACLFlags.value("CM")) && area->m_eviMod == AreaData::EvidenceMod::HIDDEN_CM) {
QRegularExpression regex("<owner=(.*?)>"); QRegularExpression regex("<owner=(.*?)>");
QRegularExpressionMatch match = regex.match(evidence.description); QRegularExpressionMatch match = regex.match(evidence.description);
if (match.hasMatch()) { if (match.hasMatch()) {
@ -466,7 +466,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
// Spectators cannot use IC // Spectators cannot use IC
return invalid; return invalid;
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
if (area->locked == AreaData::LockStatus::SPECTATABLE && !area->invited.contains(id)) if (area->m_locked == AreaData::LockStatus::SPECTATABLE && !area->m_invited.contains(id))
// Non-invited players cannot speak in spectatable areas // Non-invited players cannot speak in spectatable areas
return invalid; return invalid;
@ -491,7 +491,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
if (current_char != incoming_args[2].toString()) { if (current_char != incoming_args[2].toString()) {
// Selected char is different from supplied folder name // Selected char is different from supplied folder name
// This means the user is INI-swapped // This means the user is INI-swapped
if (!area->iniswap_allowed) { if (!area->m_iniswapAllowed) {
if (!server->characters.contains(incoming_args[2].toString())) if (!server->characters.contains(incoming_args[2].toString()))
return invalid; return invalid;
} }
@ -509,12 +509,12 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
return invalid; return invalid;
QString incoming_msg = dezalgo(incoming_args[4].toString().trimmed()); QString incoming_msg = dezalgo(incoming_args[4].toString().trimmed());
if (!area->last_ic_message.isEmpty() if (!area->m_lastICMessage.isEmpty()
&& incoming_msg == area->last_ic_message[4] && incoming_msg == area->m_lastICMessage[4]
&& incoming_msg != "") && incoming_msg != "")
return invalid; return invalid;
if (incoming_msg == "" && area->blankposting_allowed == false) { if (incoming_msg == "" && area->m_blankpostingAllowed == false) {
sendServerMessage("Blankposting has been forbidden in this area."); sendServerMessage("Blankposting has been forbidden in this area.");
return invalid; return invalid;
} }
@ -587,7 +587,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
// evidence // evidence
int evi_idx = incoming_args[11].toInt(); int evi_idx = incoming_args[11].toInt();
if (evi_idx > area->evidence.length()) if (evi_idx > area->m_evidence.length())
return invalid; return invalid;
args.append(QString::number(evi_idx)); args.append(QString::number(evi_idx));
@ -614,7 +614,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
if (incoming_args.length() > 15) { if (incoming_args.length() > 15) {
// showname // showname
QString incoming_showname = dezalgo(incoming_args[15].toString().trimmed()); QString incoming_showname = dezalgo(incoming_args[15].toString().trimmed());
if (!(incoming_showname == current_char || incoming_showname.isEmpty()) && !area->showname_allowed) { if (!(incoming_showname == current_char || incoming_showname.isEmpty()) && !area->m_shownameAllowed) {
sendServerMessage("Shownames are not allowed in this area!"); sendServerMessage("Shownames are not allowed in this area!");
return invalid; return invalid;
} }
@ -680,7 +680,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
// immediate text processing // immediate text processing
int immediate = incoming_args[18].toInt(); int immediate = incoming_args[18].toInt();
if (area->force_immediate) if (area->m_forceImmediate)
immediate = 1; immediate = 1;
if (immediate != 1 && immediate != 0) if (immediate != 1 && immediate != 0)
return invalid; return invalid;
@ -714,10 +714,10 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
int additive = incoming_args[24].toInt(); int additive = incoming_args[24].toInt();
if (additive != 0 && additive != 1) if (additive != 0 && additive != 1)
return invalid; return invalid;
else if (area->last_ic_message.isEmpty()){ else if (area->m_lastICMessage.isEmpty()){
additive = 0; additive = 0;
} }
else if (!(char_id == area->last_ic_message[8].toInt())) { else if (!(char_id == area->m_lastICMessage[8].toInt())) {
additive = 0; additive = 0;
} }
else if (additive == 1) { else if (additive == 1) {
@ -730,29 +730,29 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
} }
//Testimony playback //Testimony playback
if (area->test_rec == AreaData::TestimonyRecording::RECORDING || area->test_rec == AreaData::TestimonyRecording::ADD) { if (area->m_testimonyRecording == AreaData::TestimonyRecording::RECORDING || area->m_testimonyRecording == AreaData::TestimonyRecording::ADD) {
if (args[5] != "wit") if (args[5] != "wit")
return AOPacket("MS", args); return AOPacket("MS", args);
if (area->statement == -1) { if (area->m_statement == -1) {
args[4] = "~~\\n-- " + args[4] + " --"; args[4] = "~~\\n-- " + args[4] + " --";
args[14] = "3"; args[14] = "3";
server->broadcast(AOPacket("RT",{"testimony1"}), current_area); server->broadcast(AOPacket("RT",{"testimony1"}), current_area);
} }
addStatement(args); addStatement(args);
} }
else if (area->test_rec == AreaData::TestimonyRecording::UPDATE) { else if (area->m_testimonyRecording == AreaData::TestimonyRecording::UPDATE) {
args = updateStatement(args); args = updateStatement(args);
} }
else if (area->test_rec == AreaData::TestimonyRecording::PLAYBACK) { else if (area->m_testimonyRecording == AreaData::TestimonyRecording::PLAYBACK) {
if (args[4] == ">") { if (args[4] == ">") {
pos = "wit"; pos = "wit";
area->statement = area->statement + 1; area->m_statement = area->m_statement + 1;
args = playTestimony(); args = playTestimony();
} }
if (args[4] == "<") { if (args[4] == "<") {
pos = "wit"; pos = "wit";
area->statement = area->statement - 1; area->m_statement = area->m_statement - 1;
args = playTestimony(); args = playTestimony();
} }
QString decoded_message = decodeMessage(args[4]); //Get rid of that pesky encoding first. QString decoded_message = decodeMessage(args[4]); //Get rid of that pesky encoding first.
@ -760,7 +760,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
QRegularExpressionMatch match = jump.match(decoded_message); QRegularExpressionMatch match = jump.match(decoded_message);
if (match.hasMatch()) { if (match.hasMatch()) {
pos = "wit"; pos = "wit";
area->statement = match.captured("int").toInt(); area->m_statement = match.captured("int").toInt();
args= playTestimony(); args= playTestimony();
} }
} }
@ -777,7 +777,7 @@ QString AOClient::dezalgo(QString p_text)
bool AOClient::checkEvidenceAccess(AreaData *area) bool AOClient::checkEvidenceAccess(AreaData *area)
{ {
switch(area->evi_mod) { switch(area->m_eviMod) {
case AreaData::EvidenceMod::FFA: case AreaData::EvidenceMod::FFA:
return true; return true;
case AreaData::EvidenceMod::CM: case AreaData::EvidenceMod::CM:
@ -798,12 +798,12 @@ void AOClient::updateJudgeLog(AreaData* area, AOClient* client, QString action)
QString ipid = client->getIpid(); QString ipid = client->getIpid();
QString message = action; QString message = action;
QString logmessage = QString("[%1]: [%2] %3 (%4) %5").arg(timestamp, uid, char_name, ipid, message); QString logmessage = QString("[%1]: [%2] %3 (%4) %5").arg(timestamp, uid, char_name, ipid, message);
int size = area->judgelog.size(); int size = area->m_judgelog.size();
if (size == 10) { if (size == 10) {
area->judgelog.removeFirst(); area->m_judgelog.removeFirst();
area->judgelog.append(logmessage); area->m_judgelog.append(logmessage);
} }
else area->judgelog.append(logmessage); else area->m_judgelog.append(logmessage);
} }
QString AOClient::decodeMessage(QString incoming_message) QString AOClient::decodeMessage(QString incoming_message)

View File

@ -160,7 +160,7 @@ void Server::updateCharsTaken(AreaData* area)
{ {
QStringList chars_taken; QStringList chars_taken;
for (QString cur_char : characters) { for (QString cur_char : characters) {
chars_taken.append(area->characters_taken.contains(getCharID(cur_char)) chars_taken.append(area->m_charactersTaken.contains(getCharID(cur_char))
? QStringLiteral("-1") ? QStringLiteral("-1")
: QStringLiteral("0")); : QStringLiteral("0"));
} }
@ -168,7 +168,7 @@ void Server::updateCharsTaken(AreaData* area)
AOPacket response_cc("CharsCheck", chars_taken); AOPacket response_cc("CharsCheck", chars_taken);
for (AOClient* client : clients) { for (AOClient* client : clients) {
if (client->current_area == area->index){ if (client->current_area == area->m_index){
if (!client->is_charcursed) if (!client->is_charcursed)
client->sendPacket(response_cc); client->sendPacket(response_cc);
else { else {

View File

@ -22,30 +22,30 @@
void AOClient::addStatement(QStringList packet) void AOClient::addStatement(QStringList packet)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
int c_statement = area->statement; int c_statement = area->m_statement;
if (c_statement >= -1) { if (c_statement >= -1) {
if (area->test_rec == AreaData::TestimonyRecording::RECORDING) { if (area->m_testimonyRecording == AreaData::TestimonyRecording::RECORDING) {
if (c_statement <= server->maximum_statements) { if (c_statement <= server->maximum_statements) {
if (c_statement == -1) if (c_statement == -1)
packet[14] = "3"; packet[14] = "3";
else else
packet[14] = "1"; packet[14] = "1";
area->statement = c_statement + 1; area->m_statement = c_statement + 1;
area->testimony.append(packet); area->m_testimony.append(packet);
return; return;
} }
else { else {
sendServerMessage("Unable to add more statements. The maximum amount of statements has been reached."); sendServerMessage("Unable to add more statements. The maximum amount of statements has been reached.");
} }
} }
else if (area->test_rec == AreaData::TestimonyRecording::ADD) { else if (area->m_testimonyRecording == AreaData::TestimonyRecording::ADD) {
packet[14] = "1"; packet[14] = "1";
area->testimony.insert(c_statement,packet); area->m_testimony.insert(c_statement,packet);
area->test_rec = AreaData::TestimonyRecording::PLAYBACK; area->m_testimonyRecording = AreaData::TestimonyRecording::PLAYBACK;
} }
else { else {
sendServerMessage("Unable to add more statements. The maximum amount of statements has been reached."); sendServerMessage("Unable to add more statements. The maximum amount of statements has been reached.");
area->test_rec = AreaData::TestimonyRecording::PLAYBACK; area->m_testimonyRecording = AreaData::TestimonyRecording::PLAYBACK;
} }
} }
} }
@ -53,15 +53,15 @@ void AOClient::addStatement(QStringList packet)
QStringList AOClient::updateStatement(QStringList packet) QStringList AOClient::updateStatement(QStringList packet)
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
int c_statement = area->statement; int c_statement = area->m_statement;
area->test_rec = AreaData::TestimonyRecording::PLAYBACK; area->m_testimonyRecording = AreaData::TestimonyRecording::PLAYBACK;
if (c_statement <= 0 || area->testimony[c_statement].empty()) if (c_statement <= 0 || area->m_testimony[c_statement].empty())
sendServerMessage("Unable to update an empty statement. Please use /addtestimony."); sendServerMessage("Unable to update an empty statement. Please use /addtestimony.");
else { else {
packet[14] = "1"; packet[14] = "1";
area->testimony.replace(c_statement, packet); area->m_testimony.replace(c_statement, packet);
sendServerMessage("Updated current statement."); sendServerMessage("Updated current statement.");
return area->testimony[c_statement]; return area->m_testimony[c_statement];
} }
return packet; return packet;
} }
@ -69,28 +69,28 @@ QStringList AOClient::updateStatement(QStringList packet)
void AOClient::clearTestimony() void AOClient::clearTestimony()
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
area->test_rec = AreaData::TestimonyRecording::STOPPED; area->m_testimonyRecording = AreaData::TestimonyRecording::STOPPED;
area->statement = -1; area->m_statement = -1;
area->testimony.clear(); //!< Empty out the QVector area->m_testimony.clear(); //!< Empty out the QVector
area->testimony.squeeze(); //!< Release memory. Good idea? God knows, I do not. area->m_testimony.squeeze(); //!< Release memory. Good idea? God knows, I do not.
} }
QStringList AOClient::playTestimony() QStringList AOClient::playTestimony()
{ {
AreaData* area = server->areas[current_area]; AreaData* area = server->areas[current_area];
int c_statement = area->statement; int c_statement = area->m_statement;
if (c_statement > area->testimony.size() - 1) { if (c_statement > area->m_testimony.size() - 1) {
sendServerMessageArea("Last statement reached. Looping to first statement."); sendServerMessageArea("Last statement reached. Looping to first statement.");
area->statement = 1; area->m_statement = 1;
return area->testimony[area->statement]; return area->m_testimony[area->m_statement];
} }
if (c_statement <= 0) { if (c_statement <= 0) {
sendServerMessage("First statement reached."); sendServerMessage("First statement reached.");
area->statement = 1; area->m_statement = 1;
return area->testimony[area->statement = 1]; return area->m_testimony[area->m_statement = 1];
} }
else { else {
return area->testimony[c_statement]; return area->m_testimony[c_statement];
} }
} }