atrooney-online-2/src/aopacket.cpp
Crystalwarrior 7b88d4be95
Never send an unencoded packet to the server (#719)
* never send an unencoded packet to the server

* oops

* Improve packet validation to remove segfaults

* WARNING: commit breaks connecting to servers, need help
start fixing omniwhy caused by single fuckin string packets (AAAAAAAAAAAAAAAAA)

* Fix failed connections to servers (Thanks to @Iuvee for helping me figure this out!)

* Fix demoserver

* who the fuck still uses goto

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* ANOTHER GOTO????

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* braces

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* good bot Update src/packet_distribution.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fix demoserver harder

* Improve demo logging

* Fix memory leakage by deleting the packet
Fix useless demoserver wait packet creation when none of that packet is used

Co-authored-by: stonedDiscord <Tukz@gmx.de>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Salanto <62221668+Salanto@users.noreply.github.com>
2022-07-30 18:42:22 +02:00

43 lines
839 B
C++

#include "aopacket.h"
QString AOPacket::to_string(bool encoded)
{
QStringList contents = m_contents;
if (encoded) {
escape(contents);
}
// Our packet is just the header by itself
if (contents.isEmpty()) {
return m_header + "#%";
}
return m_header + "#" + contents.join("#") + "#%";
}
void AOPacket::net_encode()
{
escape(m_contents);
}
void AOPacket::net_decode()
{
unescape(m_contents);
}
void AOPacket::escape(QStringList &contents)
{
contents.replaceInStrings("#", "<num>")
.replaceInStrings("%", "<percent>")
.replaceInStrings("$", "<dollar>")
.replaceInStrings("&", "<and>");
}
void AOPacket::unescape(QStringList &contents)
{
contents.replaceInStrings("<num>", "#")
.replaceInStrings("<percent>", "%")
.replaceInStrings("<dollar>", "$")
.replaceInStrings("<and>", "&");
}