Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ SOURCES += \
src/packet/packet_rm.cpp \
src/packet/packet_rt.cpp \
src/packet/packet_setcase.cpp \
src/packet/packet_zz.cpp
src/packet/packet_zz.cpp \
src/packet/data/msdata.cpp

HEADERS += src/aoclient.h \
src/acl_roles_handler.h \
Expand Down Expand Up @@ -124,4 +125,5 @@ HEADERS += src/aoclient.h \
src/packet/packet_rm.h \
src/packet/packet_rt.h \
src/packet/packet_setcase.h \
src/packet/packet_zz.h
src/packet/packet_zz.h \
src/packet/data/msdata.h
9 changes: 5 additions & 4 deletions src/aoclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "acl_roles_handler.h"
#include "network/aopacket.h"
#include "network/network_socket.h"
#include "packet/data/msdata.h"

class AreaData;
class DBManager;
Expand Down Expand Up @@ -485,14 +486,14 @@ class AOClient : public QObject
*
* @param packet The MS-Packet being recorded with their color changed to green.
*/
void addStatement(QStringList packet);
void addStatement(ms2::OldMSFlatData packet);

/**
* @brief Updates the currently displayed IC-Message with the next one send
* @param packet The IC-Message that will overwrite the currently stored one.
* @return Returns the updated IC-Message to be send to the other users. It also changes the color to green.
*/
QStringList updateStatement(QStringList packet);
ms2::OldMSFlatData updateStatement(ms2::OldMSFlatData packet);

/**
* @brief Convenience function to generate a random integer number between the given minimum and maximum values.
Expand Down Expand Up @@ -575,12 +576,12 @@ class AOClient : public QObject
* @details This used to be just a plain number ranging from -100 to 100, but then Crystal mangled it by building some extra data into it.
* Cheers, love.
*/
QString m_offset = "";
ms2::OffsetData m_offset{0, 0};

/**
* @brief The last flipped state of the client.
*/
QString m_flipping = "";
bool m_flipping = false;

/**
* @brief The last reported position of the client.
Expand Down
15 changes: 8 additions & 7 deletions src/area_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//////////////////////////////////////////////////////////////////////////////////////

#include <QJsonDocument>
#include <algorithm>

#include "area_data.h"
Expand Down Expand Up @@ -364,14 +365,14 @@ void AreaData::toggleImmediate()
m_forceImmediate = !m_forceImmediate;
}

const QStringList &AreaData::lastICMessage() const
const ms2::OldMSFlatData &AreaData::lastICMessage() const
{
return m_lastICMessage;
}

void AreaData::updateLastICMessage(const QStringList &f_lastMessage_r)
{
m_lastICMessage = f_lastMessage_r;
ms2::OldMSFlatData::fromJson(QJsonDocument::fromJson(f_lastMessage_r.at(0).toUtf8()).object(), m_lastICMessage);
}

QStringList AreaData::judgelog() const
Expand All @@ -393,18 +394,18 @@ int AreaData::statement() const
return m_statement;
}

void AreaData::recordStatement(const QStringList &f_newStatement_r)
void AreaData::recordStatement(const ms2::OldMSFlatData &f_newStatement_r)
{
++m_statement;
m_testimony.append(f_newStatement_r);
}

void AreaData::addStatement(int f_position, const QStringList &f_newStatement_r)
void AreaData::addStatement(int f_position, const ms2::OldMSFlatData &f_newStatement_r)
{
m_testimony.insert(f_position, f_newStatement_r);
}

void AreaData::replaceStatement(int f_position, const QStringList &f_newStatement_r)
void AreaData::replaceStatement(int f_position, const ms2::OldMSFlatData &f_newStatement_r)
{
m_testimony.replace(f_position, f_newStatement_r);
}
Expand All @@ -415,7 +416,7 @@ void AreaData::removeStatement(int f_position)
--m_statement;
}

QPair<QStringList, AreaData::TestimonyProgress> AreaData::jumpToStatement(int f_position)
QPair<ms2::OldMSFlatData, AreaData::TestimonyProgress> AreaData::jumpToStatement(int f_position)
{
m_statement = f_position;

Expand All @@ -432,7 +433,7 @@ QPair<QStringList, AreaData::TestimonyProgress> AreaData::jumpToStatement(int f_
}
}

const QVector<QStringList> &AreaData::testimony() const
const QVector<ms2::OldMSFlatData> &AreaData::testimony() const
{
return m_testimony;
}
Expand Down
21 changes: 11 additions & 10 deletions src/area_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QTimer>

#include "network/aopacket.h"
#include "packet/data/msdata.h"

class ConfigManager;
class Logger;
Expand Down Expand Up @@ -771,7 +772,7 @@ class AreaData : public QObject
*
* @note Unlike most other getters, this one returns a reference, as it is expected to be used frequently.
*/
const QVector<QStringList> &testimony() const;
const QVector<ms2::OldMSFlatData> &testimony() const;

/**
* @brief Returns the index of the currently examined statement in the testimony.
Expand All @@ -785,23 +786,23 @@ class AreaData : public QObject
*
* @param f_newStatement_r The IC message packet to append to the testimony vector.
*/
void recordStatement(const QStringList &f_newStatement_r);
void recordStatement(const ms2::OldMSFlatData &f_newStatement_r);

/**
* @brief Adds a statement into the testimony to a given position.
*
* @param f_position The index to insert the statement to.
* @param f_newStatement_r The IC message packet to insert.
*/
void addStatement(int f_position, const QStringList &f_newStatement_r);
void addStatement(int f_position, const ms2::OldMSFlatData &f_newStatement_r);

/**
* @brief Replaces an already existing statement in the testimony in a given position with a new one.
*
* @param f_position The index of the statement to replace.
* @param f_newStatement_r The IC message packet to insert in the old one's stead.
*/
void replaceStatement(int f_position, const QStringList &f_newStatement_r);
void replaceStatement(int f_position, const ms2::OldMSFlatData &f_newStatement_r);

/**
* @brief Removes a statement from the testimony at a given position, and moves the statement index one backward.
Expand All @@ -821,10 +822,10 @@ class AreaData : public QObject
* @param f_position The index to jump to.
*
* @return A pair of values:
* * First, a `QStringList` that is the packet of the statement that was advanced to.
* * First, a `ms2::OldMSFlatData` that is the packet of the statement that was advanced to.
* * Then, a `TestimonyProgress` value that describes how the advancement happened.
*/
QPair<QStringList, AreaData::TestimonyProgress> jumpToStatement(int f_position);
QPair<ms2::OldMSFlatData, AreaData::TestimonyProgress> jumpToStatement(int f_position);

/**
* @brief Returns a copy of the judgelog in the area.
Expand All @@ -850,7 +851,7 @@ class AreaData : public QObject
*
* @return See short description.
*/
const QStringList &lastICMessage() const;
const ms2::OldMSFlatData &lastICMessage() const;

/**
* @brief Updates the last IC message sent in the area.
Expand Down Expand Up @@ -1171,8 +1172,8 @@ class AreaData : public QObject
*/
TestimonyRecording m_testimonyRecording;

QVector<QStringList> m_testimony; //!< Vector of all statements saved. Index 0 is always the title of the testimony.
int m_statement; //!< Keeps track of the currently played statement.
QVector<ms2::OldMSFlatData> m_testimony; //!< Vector of all statements saved. Index 0 is always the title of the testimony.
int m_statement; //!< Keeps track of the currently played statement.

/**
* @brief The judgelog of an area.
Expand All @@ -1184,7 +1185,7 @@ class AreaData : public QObject
/**
* @brief The last IC packet sent in an area.
*/
QStringList m_lastICMessage;
ms2::OldMSFlatData m_lastICMessage;

/**
* @brief Whether or not to force immediate text processing in this area.
Expand Down
20 changes: 12 additions & 8 deletions src/commands/casing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void AOClient::cmdExamine(int argc, QStringList argv)
else {
l_area->restartTestimony();
server->broadcast(PacketFactory::createPacket("RT", {"testimony2", "0"}), areaId());
server->broadcast(PacketFactory::createPacket("MS", {l_area->testimony()[0]}), areaId());
server->broadcast(PacketFactory::createPacket("MS", {QJsonDocument{l_area->testimony()[0].toJson()}.toJson()}), areaId());
return;
}
}
Expand All @@ -157,9 +157,8 @@ void AOClient::cmdTestimony(int argc, QStringList argv)

QString l_ooc_message;
for (int i = 1; i <= l_area->testimony().size() - 1; i++) {
QStringList l_packet = l_area->testimony().at(i);
QString l_ic_message = l_packet[4];
l_ooc_message.append("[" + QString::number(i) + "]" + l_ic_message + "\n");
auto l_statement = l_area->testimony().at(i);
l_ooc_message.append("[" + QString::number(i) + "]" + l_statement.m_message_text + "\n");
}
sendServerMessage(l_ooc_message);
}
Expand Down Expand Up @@ -246,7 +245,7 @@ void AOClient::cmdSaveTestimony(int argc, QStringList argv)
QTextStream l_out(&l_file);
if (l_file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
for (int i = 0; i <= l_area->testimony().size() - 1; i++) {
l_out << l_area->testimony().at(i).join("#") << "\n";
l_out << QJsonDocument{l_area->testimony().at(i).toJson()}.toJson(QJsonDocument::Compact) << "\n";
}
sendServerMessage("Testimony saved. To load it use /loadtestimony " + l_testimony_name);
m_testimony_saving = false;
Expand Down Expand Up @@ -286,9 +285,14 @@ void AOClient::cmdLoadTestimony(int argc, QStringList argv)
while (!l_in.atEnd()) {
if (l_testimony_lines <= ConfigManager::maxStatements()) {
QString line = l_in.readLine();
QStringList packet = line.split("#");
l_area->addStatement(l_area->testimony().size(), packet);
l_testimony_lines = l_testimony_lines + 1;
auto json = QJsonDocument::fromJson(line.toUtf8());
ms2::OldMSFlatData loadedMessage;
bool loaded = ms2::OldMSFlatData::fromJson(json.object(), loadedMessage);

if (loaded) {
l_area->addStatement(l_area->testimony().size(), loadedMessage);
l_testimony_lines = l_testimony_lines + 1;
}
}
else {
sendServerMessage("Testimony too large to be loaded.");
Expand Down
15 changes: 15 additions & 0 deletions src/network/aopacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "packet/packet_setcase.h"
#include "packet/packet_zz.h"

#include <QJsonDocument>

AOPacket::AOPacket(QStringList p_contents) :
m_content(p_contents),
m_escaped(false)
Expand Down Expand Up @@ -78,6 +80,19 @@ void AOPacket::setContentField(int f_content_index, QString f_content_data)
m_content[f_content_index] = f_content_data;
}

void AOPacket::setJsonContentField(const QString &f_key, const QString &f_value)
{
QJsonParseError l_error{};
auto l_jsonDocument = QJsonDocument::fromJson(m_content.at(0).toUtf8(), &l_error);
auto l_jsonObject = l_jsonDocument.object();

if (l_error.error == QJsonParseError::ParseError::NoError && l_jsonObject[f_key].isString()) {
l_jsonObject[f_key] = f_value;
}

m_content = QStringList{QJsonDocument{l_jsonObject}.toJson(QJsonDocument::Compact)};
}

void AOPacket::escapeContent()
{
m_content.replaceInStrings("#", "<num>")
Expand Down
5 changes: 5 additions & 0 deletions src/network/aopacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class AOPacket
*/
void setContentField(int f_content_index, QString f_content_data);

/**
* @brief As setContentField, but for packets that use JSON as their data.
*/
void setJsonContentField(const QString &f_key, const QString &f_value);

/**
* @brief Escapes the content of the packet using AO2's escape codes.
*
Expand Down
Loading
Loading