atrooney-online-2/src/aopacket.cpp
TrickyLeifa c9f52b7223 Ported to CMake, ...
* Ported the project to CMake
  * Android and Mac support dropped for the time
being.
  * Tests, BASS and Discord-RPC are now options
* Restructured and reformated the project.
  * Merged `include` and `src`
  * Renamed `resource` to `data`
  * Renamed various files
  * External libraries headers are no longer included in `src`
  * Replaced header guards with #pragma once
  * Multiple refactors (keywords, headers)
  * Added Qt6 compatibility
* Removed various unused functions and headers
* Reworked AOPacket
  * When content is passed to AOPacket, it should be ensured that the content is already decoded.
  * Encoding/decoding are now static methods.
* Fixed various memory leaks
* Removed animation code for AOImage
  * AOImage is always using static images
* Simplified ChatLogPiece
2024-05-15 00:04:16 +02:00

49 lines
918 B
C++

#include "aopacket.h"
QString AOPacket::encode(QString data)
{
return data.replace("#", "<num>").replace("%", "<percent>").replace("$", "<dollar>").replace("&", "<and>");
}
QString AOPacket::decode(QString data)
{
return data.replace("<num>", "#").replace("<percent>", "%").replace("<dollar>", "$").replace("<and>", "&");
}
AOPacket::AOPacket(QString header)
: m_header(header)
{}
AOPacket::AOPacket(QString header, QStringList content)
: m_header(header)
, m_content(content)
{}
QString AOPacket::get_header()
{
return m_header;
}
QStringList &AOPacket::get_content()
{
return m_content;
}
QString AOPacket::to_string(bool ensureEncoded)
{
QString message = m_header;
if (!m_content.isEmpty())
{
for (QString item : qAsConst(m_content))
{
if (ensureEncoded)
{
item = encode(item);
}
message += "#" + item;
}
}
return message + "#%";
}