Corrected every error in the build

TODO: Documentation, test writing still.
This commit is contained in:
Cerapter 2021-05-01 22:51:51 +02:00
parent 08fd5896ba
commit 0a87f30287
12 changed files with 232 additions and 114 deletions

View File

@ -73,7 +73,7 @@ class AOClient : public QObject {
*
* @see #ipid
*/
QString getIpid();
QString getIpid() const;
/**
* @brief Calculates the client's IPID based on a hashed version of its IP.

View File

@ -18,7 +18,8 @@
#ifndef AREA_DATA_H
#define AREA_DATA_H
#include "include/logger.h"
#include "logger.h"
#include "aopacket.h"
#include <QMap>
#include <QString>
@ -193,6 +194,8 @@ class AreaData : public QObject {
PROSECUTOR,
};
static const QMap<QString, AreaData::Status> map_statuses;
/**
* @brief A client in the area has left the area.
*
@ -202,6 +205,8 @@ class AreaData : public QObject {
*/
void clientLeftArea(int f_charId);
void clientJoinedArea(int f_charId = -1);
QList<int> owners() const;
void addOwner(int f_clientId);
@ -226,6 +231,12 @@ class AreaData : public QObject {
LockStatus lockStatus() const;
void lock();
void unlock();
void spectatable();
/**
* @brief invite
* @param f_clientId
@ -235,8 +246,6 @@ class AreaData : public QObject {
int playerCount() const;
void changePlayerCount(bool f_increase);
QList<QTimer *> timers() const;
QString name() const;
@ -249,9 +258,9 @@ class AreaData : public QObject {
Status status() const;
QList<int> invited() const;
bool changeStatus(const QString& f_newStatus_r);
LockStatus locked() const;
QList<int> invited() const;
QString background() const;
@ -263,6 +272,8 @@ class AreaData : public QObject {
bool bgLocked() const;
void toggleBgLock();
QString document() const;
int defHP() const;
@ -283,6 +294,8 @@ class AreaData : public QObject {
void setTestimonyRecording(const TestimonyRecording &testimonyRecording);
void restartTestimony();
void clearTestimony();
QVector<QStringList> testimony() const;
@ -293,6 +306,8 @@ class AreaData : public QObject {
void addStatement(int f_position, const QStringList& f_newStatement);
void removeStatement(int f_statementNumber);
std::pair<QStringList, TestimonyProgress> advanceTestimony(bool f_forward = true);
QStringList jumpToStatement(int f_statementNr);
@ -311,6 +326,14 @@ class AreaData : public QObject {
void toggleMusic();
void log(const QString& f_clientName_r, const QString& f_clientIpid_r, const AOPacket& f_packet_r) const;
void logLogin(const QString &f_clientName_r, const QString &f_clientIpid_r, bool f_success, const QString& f_modname_r) const;
void flushLogs() const;
void setEviMod(const EvidenceMod &eviMod);
private:
/**
* @brief The list of timers available in the area.

View File

@ -35,18 +35,18 @@ public:
*
* @param f_max_length The maximum amount of entries the Logger can store at once.
*/
Logger(int f_max_length, const QString& f_logType_r) : m_maxLength(f_max_length), m_logType(f_logType_r) {};
Logger(QString f_area_name, int f_max_length, const QString& f_logType_r) :
m_areaName(f_area_name), m_maxLength(f_max_length), m_logType(f_logType_r) {};
public slots:
/**
* @brief Logs an IC message.
*
* @param f_areaName_r The name of the area where the event happened.
* @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(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r);
void logIC(const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r);
/**
* @brief Logs an OOC message.
@ -56,17 +56,16 @@ public slots:
* @param f_ipid_r The IPID of the aforementioned client.
* @param f_message_r The text of the OOC message.
*/
void logOOC(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r);
void logOOC(const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r);
/**
* @brief Logs a mod call message.
*
* @param f_areaName_r The name of the area where the event happened.
* @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(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_modcallReason_r);
void logModcall(const QString& f_charName_r, const QString& f_ipid_r, const QString& f_modcallReason_r);
/**
* @brief Logs a command called in OOC.
@ -74,33 +73,26 @@ public slots:
* @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.
*
* @param f_areaName_r The name of the area where the event happened.
* @param f_charName_r The character name of the client who sent the command.
* @param f_ipid_r The IPID of the aforementioned client.
* @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(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);
void logCmd(const QString& f_charName_r, const QString& f_ipid_r, const QString& f_oocMessage_r);
/**
* @brief Logs a login attempt.
*
* @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 f_modname_r If the client logged in with a modname, then this is it. Otherwise, it's `"moderator"`.
*/
void logLogin(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, bool success, const QString& f_modname_r);
void logLogin(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.
*
* @param f_areaName_r The name of the area where the event happened.
*/
void flush(const QString& f_areaName_r);
void flush();
/**
* @brief Contains entries that have not yet been flushed out into a log file.
@ -114,13 +106,12 @@ private:
* @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.
*
* @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.
* @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(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r,
void addEntry(const QString& f_charName_r, const QString& f_ipid_r,
const QString& f_type_r, const QString& f_message_r);
/**
@ -128,6 +119,8 @@ private:
*/
int m_maxLength;
QString m_areaName;
/**
* @brief Determines what kind of logging happens, `"full"` or `"modcall"`.
*

View File

@ -107,7 +107,7 @@ void AOClient::changeArea(int new_area)
sendServerMessage("You are already in area " + server->area_names[current_area]);
return;
}
if (server->areas[new_area]->locked == AreaData::LockStatus::LOCKED && !server->areas[new_area]->invited().contains(id)) {
if (server->areas[new_area]->lockStatus() == AreaData::LockStatus::LOCKED && !server->areas[new_area]->invited().contains(id)) {
sendServerMessage("Area " + server->area_names[new_area] + " is locked.");
return;
}
@ -116,8 +116,8 @@ void AOClient::changeArea(int new_area)
server->areas[current_area]->charactersTaken().removeAll(server->getCharID(current_char));
server->updateCharsTaken(server->areas[current_area]);
}
server->areas[new_area]->playerCount()++;
server->areas[current_area]->playerCount()--;
server->areas[new_area]->clientJoinedArea(char_id);
server->areas[current_area]->clientLeftArea(char_id);
current_area = new_area;
arup(ARUPType::PLAYER_COUNT, true);
sendEvidenceList(server->areas[new_area]);
@ -144,7 +144,7 @@ void AOClient::changeArea(int new_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]->lockStatus() == AreaData::LockStatus::SPECTATABLE)
sendServerMessage("Area " + server->area_names[current_area] + " is spectate-only; to chat IC you will need to be invited by the CM.");
}
@ -236,7 +236,7 @@ void AOClient::arup(ARUPType type, bool broadcast)
break;
}
case ARUPType::LOCKED: {
QString lock_status = QVariant::fromValue(area->locked()).toString();
QString lock_status = QVariant::fromValue(area->lockStatus()).toString();
arup_data.append(lock_status);
break;
}
@ -330,7 +330,7 @@ bool AOClient::checkAuth(unsigned long long acl_mask)
}
QString AOClient::getIpid() { return ipid; }
QString AOClient::getIpid() const { return ipid; }
Server* AOClient::getServer() { return server; }

View File

@ -55,7 +55,7 @@ AreaData::AreaData(QString p_name, int p_index) :
config_ini.endGroup();
if (log_size == 0)
log_size = 500;
m_logger = new Logger(log_size, l_logType);
m_logger = new Logger(m_name, log_size, l_logType);
QTimer* timer1 = new QTimer();
m_timers.append(timer1);
QTimer* timer2 = new QTimer();
@ -75,10 +75,32 @@ AreaData::AreaData(QString p_name, int p_index) :
m_eviMod = EvidenceMod::FFA;
}
const QMap<QString, AreaData::Status> AreaData::map_statuses = {
{"idle", AreaData::Status::IDLE },
{"rp", AreaData::Status::RP },
{"casing", AreaData::Status::CASING },
{"lfp", AreaData::Status::LOOKING_FOR_PLAYERS },
{"looking-for-players", AreaData::Status::LOOKING_FOR_PLAYERS },
{"recess", AreaData::Status::RECESS },
{"gaming", AreaData::Status::GAMING },
};
void AreaData::clientLeftArea(int f_charId)
{
--m_playerCount;
if (f_charId != -1) {
m_charactersTaken.removeAll(f_charId);
}
}
void AreaData::clientJoinedArea(int f_charId)
{
++m_playerCount;
if (f_charId != -1) {
m_charactersTaken.append(f_charId);
}
}
QList<int> AreaData::owners() const
@ -132,6 +154,21 @@ AreaData::LockStatus AreaData::lockStatus() const
return m_locked;
}
void AreaData::lock()
{
m_locked = LockStatus::LOCKED;
}
void AreaData::unlock()
{
m_locked = LockStatus::FREE;
}
void AreaData::spectatable()
{
m_locked = LockStatus::SPECTATABLE;
}
bool AreaData::invite(int f_clientId)
{
if (m_invited.contains(f_clientId)) {
@ -147,11 +184,6 @@ int AreaData::playerCount() const
return m_playerCount;
}
void AreaData::changePlayerCount(bool f_increase)
{
f_increase ? m_playerCount++: m_playerCount--;
}
QList<QTimer *> AreaData::timers() const
{
return m_timers;
@ -182,16 +214,21 @@ AreaData::Status AreaData::status() const
return m_status;
}
bool AreaData::changeStatus(const QString &f_newStatus_r)
{
if (AreaData::map_statuses.contains(f_newStatus_r)) {
m_status = AreaData::map_statuses[f_newStatus_r];
return true;
}
return false;
}
QList<int> AreaData::invited() const
{
return m_invited;
}
AreaData::LockStatus AreaData::locked() const
{
return m_locked;
}
bool AreaData::isMusicAllowed() const
{
return m_toggleMusic;
@ -202,11 +239,45 @@ void AreaData::toggleMusic()
m_toggleMusic = !m_toggleMusic;
}
void AreaData::log(const QString &f_clientName_r, const QString &f_clientIpid_r, const AOPacket &f_packet_r) const
{
auto l_header = f_packet_r.header;
if (l_header == "MS") {
m_logger->logIC(f_clientName_r, f_clientIpid_r, f_packet_r.contents.at(4));
} else if (l_header == "CT") {
m_logger->logCmd(f_clientName_r, f_clientIpid_r, f_packet_r.contents.at(1));
} else if (l_header == "ZZ") {
m_logger->logModcall(f_clientName_r, f_clientIpid_r, f_packet_r.contents.at(0));
}
}
void AreaData::logLogin(const QString &f_clientName_r, const QString &f_clientIpid_r, bool f_success, const QString& f_modname_r) const
{
m_logger->logLogin(f_clientName_r, f_clientIpid_r, f_success, f_modname_r);
}
void AreaData::flushLogs() const
{
m_logger->flush();
}
void AreaData::setEviMod(const EvidenceMod &eviMod)
{
m_eviMod = eviMod;
}
void AreaData::setTestimonyRecording(const TestimonyRecording &testimonyRecording)
{
m_testimonyRecording = testimonyRecording;
}
void AreaData::restartTestimony()
{
m_testimonyRecording = TestimonyRecording::PLAYBACK;
m_statement = 0;
}
void AreaData::clearTestimony()
{
m_testimonyRecording = AreaData::TestimonyRecording::STOPPED;
@ -255,6 +326,12 @@ void AreaData::addStatement(int f_position, const QStringList &f_newStatement)
m_testimony.insert(f_position, f_newStatement);
}
void AreaData::removeStatement(int f_statementNumber)
{
m_testimony.remove(f_statementNumber);
--m_statement;
}
std::pair<QStringList, AreaData::TestimonyProgress> AreaData::advanceTestimony(bool f_forward)
{
f_forward ? m_statement++: m_statement--;
@ -335,6 +412,11 @@ bool AreaData::bgLocked() const
return m_bgLocked;
}
void AreaData::toggleBgLock()
{
m_bgLocked = !m_bgLocked;
}
bool AreaData::iniswapAllowed() const
{
return m_iniswapAllowed;

View File

@ -149,7 +149,7 @@ void AOClient::cmdLock(int argc, QStringList argv)
return;
}
sendServerMessageArea("This area is now locked.");
area->locked() = AreaData::LockStatus::LOCKED;
area->lock();
for (AOClient* client : server->clients) {
if (client->current_area == current_area && client->joined) {
area->invited().append(client->id);
@ -166,7 +166,7 @@ void AOClient::cmdSpectatable(int argc, QStringList argv)
return;
}
sendServerMessageArea("This area is now spectatable.");
area->locked() = AreaData::LockStatus::SPECTATABLE;
area->spectatable();
for (AOClient* client : server->clients) {
if (client->current_area == current_area && client->joined) {
area->invited().append(client->id);
@ -178,12 +178,12 @@ void AOClient::cmdSpectatable(int argc, QStringList argv)
void AOClient::cmdUnLock(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
if (area->locked() == AreaData::LockStatus::FREE) {
if (area->lockStatus() == AreaData::LockStatus::FREE) {
sendServerMessage("This area is not locked.");
return;
}
sendServerMessageArea("This area is now unlocked.");
area->locked() = AreaData::LockStatus::FREE;
area->unlock();
arup(ARUPType::LOCKED, true);
}
@ -253,14 +253,22 @@ void AOClient::cmdSetBackground(int argc, QStringList argv)
void AOClient::cmdBgLock(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
area->bgLocked() = true;
if (area->bgLocked() == false) {
area->toggleBgLock();
};
server->broadcast(AOPacket("CT", {"Server", current_char + " locked the background.", "1"}), current_area);
}
void AOClient::cmdBgUnlock(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
area->bgLocked() = false;
if (area->bgLocked() == true) {
area->toggleBgLock();
};
server->broadcast(AOPacket("CT", {"Server", current_char + " unlocked the background.", "1"}), current_area);
}
@ -268,24 +276,14 @@ void AOClient::cmdStatus(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
QString arg = argv[0].toLower();
if (arg == "idle")
area->status() = AreaData::IDLE;
else if (arg == "rp")
area->status() = AreaData::RP;
else if (arg == "casing")
area->status() = AreaData::CASING;
else if (arg == "looking-for-players" || arg == "lfp")
area->status() = AreaData::LOOKING_FOR_PLAYERS;
else if (arg == "recess")
area->status() = AreaData::RECESS;
else if (arg == "gaming")
area->status() = AreaData::GAMING;
else {
sendServerMessage("That does not look like a valid status. Valid statuses are idle, rp, casing, lfp, recess, gaming");
return;
}
if (area->changeStatus(arg)) {
arup(ARUPType::STATUS, true);
sendServerMessageArea(ooc_name + " changed status to " + arg);
} else {
sendServerMessage("That does not look like a valid status. Valid statuses are " + AreaData::map_statuses.keys().join(", "));
return;
}
}
void AOClient::cmdJudgeLog(int argc, QStringList argv)

View File

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

View File

@ -46,13 +46,13 @@ void AOClient::cmdEvidenceMod(int argc, QStringList argv)
AreaData* area = server->areas[current_area];
argv[0] = argv[0].toLower();
if (argv[0] == "cm")
area->eviMod() = AreaData::EvidenceMod::CM;
area->setEviMod(AreaData::EvidenceMod::CM);
else if (argv[0] == "mod")
area->eviMod() = AreaData::EvidenceMod::MOD;
area->setEviMod(AreaData::EvidenceMod::MOD);
else if (argv[0] == "hiddencm")
area->eviMod() = AreaData::EvidenceMod::HIDDEN_CM;
area->setEviMod(AreaData::EvidenceMod::HIDDEN_CM);
else if (argv[0] == "ffa")
area->eviMod() = AreaData::EvidenceMod::FFA;
area->setEviMod(AreaData::EvidenceMod::FFA);
else {
sendServerMessage("Invalid evidence mod.");
return;
@ -107,7 +107,7 @@ void AOClient::cmdTestify(int argc, QStringList argv)
}
else {
clearTestimony();
area->testimonyRecording() = AreaData::TestimonyRecording::RECORDING;
area->setTestimonyRecording(AreaData::TestimonyRecording::RECORDING);
sendServerMessage("Started testimony recording.");
}
}
@ -117,10 +117,9 @@ void AOClient::cmdExamine(int argc, QStringList argv)
AreaData* area = server->areas[current_area];
if (area->testimony().size() -1 > 0)
{
area->testimonyRecording() = AreaData::TestimonyRecording::PLAYBACK;
area->restartTestimony();
server->broadcast(AOPacket("RT",{"testimony2"}), current_area);
server->broadcast(AOPacket("MS", {area->testimony()[0]}), current_area);
area->statement() = 0;
return;
}
if (area->testimonyRecording() == AreaData::TestimonyRecording::PLAYBACK)
@ -155,22 +154,21 @@ void AOClient::cmdDeleteStatement(int argc, QStringList argv)
sendServerMessage("Unable to delete statement. No statements saved in this area.");
}
if (c_statement > 0 && area->testimony().size() > 2) {
area->testimony().remove(c_statement);
area->statement() = c_statement - 1;
area->removeStatement(c_statement);
sendServerMessage("The statement with id " + QString::number(c_statement) + " has been deleted from the testimony.");
}
}
void AOClient::cmdUpdateStatement(int argc, QStringList argv)
{
server->areas[current_area]->testimonyRecording() = AreaData::TestimonyRecording::UPDATE;
server->areas[current_area]->setTestimonyRecording(AreaData::TestimonyRecording::UPDATE);
sendServerMessage("The next IC-Message will replace the last displayed replay message.");
}
void AOClient::cmdPauseTestimony(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
area->testimonyRecording() = AreaData::TestimonyRecording::STOPPED;
area->setTestimonyRecording(AreaData::TestimonyRecording::STOPPED);
server->broadcast(AOPacket("RT",{"testimony1#1"}), current_area);
sendServerMessage("Testimony has been stopped.");
}
@ -178,7 +176,7 @@ void AOClient::cmdPauseTestimony(int argc, QStringList argv)
void AOClient::cmdAddStatement(int argc, QStringList argv)
{
if (server->areas[current_area]->statement() < server->maximum_statements) {
server->areas[current_area]->testimonyRecording() = AreaData::TestimonyRecording::ADD;
server->areas[current_area]->setTestimonyRecording(AreaData::TestimonyRecording::ADD);
sendServerMessage("The next IC-Message will be inserted into the testimony.");
}
else

View File

@ -32,7 +32,7 @@ QStringList AOClient::buildAreaList(int area_idx)
QString area_name = server->area_names[area_idx];
AreaData* area = server->areas[area_idx];
entries.append("=== " + area_name + " ===");
switch (area->locked()) {
switch (area->lockStatus()) {
case AreaData::LockStatus::LOCKED:
entries.append("[LOCKED]");
break;

View File

@ -20,48 +20,52 @@
#include "include/logger.h"
void Logger::logIC(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r)
void Logger::logIC(const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r)
{
addEntry(f_areaName_r, f_charName_r, f_ipid_r, "IC", f_message_r);
addEntry(f_charName_r, f_ipid_r, "IC", f_message_r);
}
void Logger::logOOC(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r)
void Logger::logOOC(const QString& f_charName_r, const QString& f_ipid_r, const QString& f_message_r)
{
addEntry(f_areaName_r, f_charName_r, f_ipid_r, "OOC", f_message_r);
addEntry(f_charName_r, f_ipid_r, "OOC", f_message_r);
}
void Logger::logModcall(const QString& f_areaName_r, const QString& f_charName_r, const QString& f_ipid_r, const QString& f_modcallReason_r)
void Logger::logModcall(const QString& f_charName_r, const QString& f_ipid_r, const QString& f_modcallReason_r)
{
addEntry(f_areaName_r, f_charName_r, f_ipid_r, "MODCALL", f_modcallReason_r);
addEntry(f_charName_r, f_ipid_r, "MODCALL", f_modcallReason_r);
}
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)
void Logger::logCmd(const QString& f_charName_r, const QString& f_ipid_r, const QString& f_oocMessage_r)
{
// I don't like this, but oh well.
auto l_cmdArgs = f_oocMessage_r.split(" ", QString::SplitBehavior::SkipEmptyParts);
auto l_cmd = l_cmdArgs.at(0).trimmed().toLower();
l_cmd = l_cmd.right(l_cmd.length() - 1);
l_cmdArgs.removeFirst();
// Some commands contain sensitive data, like passwords
// These must be filtered out
if (f_cmd_r == "login") {
addEntry(f_areaName_r, f_charName_r, f_ipid_r, "LOGIN", "Attempted login");
if (l_cmd == "login") {
addEntry(f_charName_r, f_ipid_r, "LOGIN", "Attempted login");
}
else if (f_cmd_r == "rootpass") {
addEntry(f_areaName_r, f_charName_r, f_ipid_r, "USERS", "Root password created");
else if (l_cmd == "rootpass") {
addEntry(f_charName_r, f_ipid_r, "USERS", "Root password created");
}
else if (f_cmd_r == "adduser" && !f_cmdArgs_r.isEmpty()) {
addEntry(f_areaName_r, f_charName_r, f_ipid_r, "USERS", "Added user " + f_cmdArgs_r[0]);
else if (l_cmd == "adduser" && !l_cmdArgs.isEmpty()) {
addEntry(f_charName_r, f_ipid_r, "USERS", "Added user " + l_cmdArgs.at(0));
}
else {
logOOC(f_areaName_r, f_charName_r, f_ipid_r, f_oocMessage_r);
logOOC(f_charName_r, f_ipid_r, f_oocMessage_r);
}
}
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)
void Logger::logLogin(const QString& f_charName_r, const QString& f_ipid_r, bool success, const QString& f_modname_r)
{
QString l_message = success ? "Logged in as " + f_modname_r : "Failed to log in as " + f_modname_r;
addEntry(f_areaName_r, f_charName_r, f_ipid_r, "LOGIN", l_message);
addEntry(f_charName_r, f_ipid_r, "LOGIN", l_message);
}
void Logger::addEntry(
const QString& f_areaName_r,
const QString& f_charName_r,
const QString& f_ipid_r,
const QString& f_type_r,
@ -70,13 +74,13 @@ void Logger::addEntry(
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][%2][%6] %3(%4): %5\n")
.arg(l_time, f_areaName_r, f_charName_r, f_ipid_r, f_message_r, f_type_r);
.arg(l_time, m_areaName, f_charName_r, f_ipid_r, f_message_r, f_type_r);
if (m_buffer.length() < m_maxLength) {
m_buffer.enqueue(l_logEntry);
if (m_logType == "full") {
flush(f_areaName_r);
flush();
}
}
else {
@ -85,7 +89,7 @@ void Logger::addEntry(
}
}
void Logger::flush(const QString& f_areaName_r)
void Logger::flush()
{
QDir l_dir("logs/");
if (!l_dir.exists()) {
@ -95,7 +99,7 @@ void Logger::flush(const QString& f_areaName_r)
QFile l_logfile;
if (m_logType == "modcall") {
l_logfile.setFileName(QString("logs/report_%1_%2.log").arg(f_areaName_r, (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss"))));
l_logfile.setFileName(QString("logs/report_%1_%2.log").arg(m_areaName, (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss"))));
}
else if (m_logType == "full") {
l_logfile.setFileName(QString("logs/%1.log").arg(QDate::currentDate().toString("yyyy-MM-dd")));

View File

@ -96,7 +96,7 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack
}
server->player_count++;
area->changePlayerCount(true);
area->clientJoinedArea();
joined = true;
server->updateCharsTaken(area);
@ -164,7 +164,7 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
if (pos != "")
validated_packet.contents[5] = pos;
area->logger()->logIC(this, &validated_packet);
area->log(current_char, ipid, validated_packet);
server->broadcast(validated_packet, current_area);
area->updateLastICMessage(validated_packet.contents);
}
@ -195,13 +195,13 @@ void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket p
command = command.right(command.length() - 1);
cmd_argv.removeFirst();
int cmd_argc = cmd_argv.length();
area->logger()->logCmd(this, &final_packet, command, cmd_argv);
handleCommand(command, cmd_argc, cmd_argv);
}
else {
server->broadcast(final_packet, current_area);
area->logger()->logOOC(this, &final_packet);
}
area->log(current_char, ipid, final_packet);
}
void AOClient::pktPing(AreaData* area, int argc, QStringList argv, AOPacket packet)
@ -329,8 +329,8 @@ void AOClient::pktModCall(AreaData* area, int argc, QStringList argv, AOPacket p
if (client->authenticated)
client->sendPacket(packet);
}
area->logger()->logModcall(this, &packet);
area->logger()->flush();
area->log(current_char, ipid, packet);
area->flushLogs();
}
void AOClient::pktAddEvidence(AreaData* area, int argc, QStringList argv, AOPacket packet)
@ -469,7 +469,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
// Spectators cannot use IC
return invalid;
AreaData* area = server->areas[current_area];
if (area->locked() == AreaData::LockStatus::SPECTATABLE && !area->invited().contains(id))
if (area->lockStatus() == AreaData::LockStatus::SPECTATABLE && !area->invited().contains(id))
// Non-invited players cannot speak in spectatable areas
return invalid;

View File

@ -13,17 +13,37 @@ class Area : public QObject
Q_OBJECT
public:
AreaData* m_area;
private slots:
/**
* @test Example test case 1.
*/
void test_case1();
void init();
void cleanup();
void clientJoinLeave();
};
void Area::test_case1()
void Area::init()
{
QFAIL("Guaranteed failure -- testing tests subdirs setup");
m_area = new AreaData("Test Area", 0);
}
void Area::cleanup()
{
delete m_area;
}
void Area::clientJoinLeave()
{
m_area->clientJoinedArea(5);
// There must be exactly one client in the area, and it must have a charid of 5.
QCOMPARE(m_area->charactersTaken().size(), 1);
QCOMPARE(m_area->charactersTaken().at(0), 5);
m_area->clientLeftArea(5);
// No clients must be left in the area.
QCOMPARE(m_area->charactersTaken().size(), 0);
}
}