Skip to content

Commit

Permalink
Fix encoding not being performed on packets that are saved to the .de…
Browse files Browse the repository at this point in the history
…mo file, resulting in characters having something like "#1" in their message breaking that specific message
  • Loading branch information
Crystalwarrior committed Jan 9, 2021
1 parent 662a9e2 commit 16454df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/aopacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AOPacket {

QString get_header() { return m_header; }
QStringList &get_contents() { return m_contents; }
QString to_string();
QString to_string(bool encoded = false);

void net_encode();
void net_decode();
Expand Down
10 changes: 8 additions & 2 deletions src/aopacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ AOPacket::AOPacket(QString p_packet_string)
m_contents = packet_contents.mid(1, packet_contents.size()-2); // trims %
}

QString AOPacket::to_string()
QString AOPacket::to_string(bool encoded)
{
return m_header + "#" + m_contents.join("#") + "#%";
QString contents = m_contents;
if (encoded)
contents.replaceInStrings("#", "<num>")
.replaceInStrings("%", "<percent>")
.replaceInStrings("$", "<dollar>")
.replaceInStrings("&", "<and>");
return m_header + "#" + contents.join("#") + "#%";
}

void AOPacket::net_encode()
Expand Down
16 changes: 8 additions & 8 deletions src/packet_distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (get_auto_logging_enabled() && !log_filename.isEmpty())
{
QString path = log_filename.left(log_filename.size()).replace(".log", ".demo");
append_to_file(p_packet->to_string(), path, true);
append_to_file(p_packet->to_string(true), path, true);
if (!demo_timer.isValid())
demo_timer.start();
else
Expand Down Expand Up @@ -353,7 +353,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (get_auto_logging_enabled() && !log_filename.isEmpty())
{
QString path = log_filename.left(log_filename.size()).replace(".log", ".demo");
append_to_file(p_packet->to_string(), path, true);
append_to_file(p_packet->to_string(true), path, true);
if (!demo_timer.isValid())
demo_timer.start();
else
Expand Down Expand Up @@ -461,7 +461,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (get_auto_logging_enabled() && !log_filename.isEmpty())
{
QString path = log_filename.left(log_filename.size()).replace(".log", ".demo");
append_to_file(p_packet->to_string(), path, true);
append_to_file(p_packet->to_string(true), path, true);
if (!demo_timer.isValid())
demo_timer.start();
else
Expand All @@ -479,7 +479,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (get_auto_logging_enabled() && !log_filename.isEmpty())
{
QString path = log_filename.left(log_filename.size()).replace(".log", ".demo");
append_to_file(p_packet->to_string(), path, true);
append_to_file(p_packet->to_string(true), path, true);
if (!demo_timer.isValid())
demo_timer.start();
else
Expand Down Expand Up @@ -511,7 +511,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (get_auto_logging_enabled() && !log_filename.isEmpty())
{
QString path = log_filename.left(log_filename.size()).replace(".log", ".demo");
append_to_file(p_packet->to_string(), path, true);
append_to_file(p_packet->to_string(true), path, true);
if (!demo_timer.isValid())
demo_timer.start();
else
Expand All @@ -526,7 +526,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (get_auto_logging_enabled() && !log_filename.isEmpty())
{
QString path = log_filename.left(log_filename.size()).replace(".log", ".demo");
append_to_file(p_packet->to_string(), path, true);
append_to_file(p_packet->to_string(true), path, true);
if (!demo_timer.isValid())
demo_timer.start();
else
Expand All @@ -545,7 +545,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (get_auto_logging_enabled() && !log_filename.isEmpty())
{
QString path = log_filename.left(log_filename.size()).replace(".log", ".demo");
append_to_file(p_packet->to_string(), path, true);
append_to_file(p_packet->to_string(true), path, true);
if (!demo_timer.isValid())
demo_timer.start();
else
Expand All @@ -562,7 +562,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (get_auto_logging_enabled() && !log_filename.isEmpty())
{
QString path = log_filename.left(log_filename.size()).replace(".log", ".demo");
append_to_file(p_packet->to_string(), path, true);
append_to_file(p_packet->to_string(true), path, true);
if (!demo_timer.isValid())
demo_timer.start();
else
Expand Down

0 comments on commit 16454df

Please sign in to comment.