Handle packet decoding separately for SC packet (#433)
Should fix special (escaped) characters not being parsed correctly in character list.
This commit is contained in:
parent
f4c359733a
commit
5d9309b1b3
@ -17,6 +17,8 @@ public:
|
||||
void net_encode();
|
||||
void net_decode();
|
||||
|
||||
static void escape(QStringList &contents);
|
||||
static void unescape(QStringList &contents);
|
||||
private:
|
||||
|
||||
QString m_header;
|
||||
|
@ -12,25 +12,34 @@ QString AOPacket::to_string(bool encoded)
|
||||
{
|
||||
QStringList contents = m_contents;
|
||||
if (encoded)
|
||||
contents.replaceInStrings("#", "<num>")
|
||||
.replaceInStrings("%", "<percent>")
|
||||
.replaceInStrings("$", "<dollar>")
|
||||
.replaceInStrings("&", "<and>");
|
||||
escape(contents);
|
||||
return m_header + "#" + contents.join("#") + "#%";
|
||||
}
|
||||
|
||||
void AOPacket::net_encode()
|
||||
{
|
||||
m_contents.replaceInStrings("#", "<num>")
|
||||
.replaceInStrings("%", "<percent>")
|
||||
.replaceInStrings("$", "<dollar>")
|
||||
.replaceInStrings("&", "<and>");
|
||||
escape(m_contents);
|
||||
}
|
||||
|
||||
void AOPacket::net_decode()
|
||||
{
|
||||
m_contents.replaceInStrings("<num>", "#")
|
||||
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>", "&");
|
||||
|
||||
}
|
||||
|
@ -8,9 +8,12 @@
|
||||
|
||||
void AOApplication::ms_packet_received(AOPacket *p_packet)
|
||||
{
|
||||
p_packet->net_decode();
|
||||
|
||||
QString header = p_packet->get_header();
|
||||
|
||||
// Some packets need to handle decode/encode separately
|
||||
if (header != "SC") {
|
||||
p_packet->net_decode();
|
||||
}
|
||||
QStringList f_contents = p_packet->get_contents();
|
||||
|
||||
#ifdef DEBUG_NETWORK
|
||||
@ -333,6 +336,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
|
||||
for (int n_element = 0; n_element < f_contents.size(); ++n_element) {
|
||||
QStringList sub_elements = f_contents.at(n_element).split("&");
|
||||
|
||||
AOPacket::unescape(sub_elements);
|
||||
|
||||
char_type f_char;
|
||||
f_char.name = sub_elements.at(0);
|
||||
if (sub_elements.size() >= 2)
|
||||
|
Loading…
Reference in New Issue
Block a user