summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/core/packet.cpp4
-rw-r--r--src/network/core/packet.h2
-rw-r--r--src/network/network_content.cpp2
-rw-r--r--src/string.cpp9
-rw-r--r--src/string_func.h2
5 files changed, 13 insertions, 6 deletions
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp
index 21d8cf5df..5c06ab488 100644
--- a/src/network/core/packet.cpp
+++ b/src/network/core/packet.cpp
@@ -233,7 +233,7 @@ uint64 Packet::Recv_uint64()
}
/** Reads a string till it finds a '\0' in the stream */
-void Packet::Recv_string(char *buffer, size_t size)
+void Packet::Recv_string(char *buffer, size_t size, bool allow_newlines)
{
PacketSize pos;
char *bufp = buffer;
@@ -253,7 +253,7 @@ void Packet::Recv_string(char *buffer, size_t size)
}
this->pos = pos;
- str_validate(bufp);
+ str_validate(bufp, allow_newlines);
}
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/packet.h b/src/network/core/packet.h
index 1dd35a70d..f0202eee6 100644
--- a/src/network/core/packet.h
+++ b/src/network/core/packet.h
@@ -62,7 +62,7 @@ public:
uint16 Recv_uint16();
uint32 Recv_uint32();
uint64 Recv_uint64();
- void Recv_string(char *buffer, size_t size);
+ void Recv_string(char *buffer, size_t size, bool allow_newlines = false);
};
Packet *NetworkSend_Init(PacketType type);
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index d49e09282..26a92324f 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -53,7 +53,7 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_INFO)
p->Recv_string(ci->name, lengthof(ci->name));
p->Recv_string(ci->version, lengthof(ci->name));
p->Recv_string(ci->url, lengthof(ci->url));
- p->Recv_string(ci->description, lengthof(ci->description));
+ p->Recv_string(ci->description, lengthof(ci->description), true);
ci->unique_id = p->Recv_uint32();
for (uint j = 0; j < sizeof(ci->md5sum); j++) {
diff --git a/src/string.cpp b/src/string.cpp
index 016a4990f..f3ab41623 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -98,7 +98,7 @@ char *CDECL str_fmt(const char *str, ...)
}
-void str_validate(char *str)
+void str_validate(char *str, bool allow_newlines)
{
char *dst = str;
WChar c;
@@ -113,7 +113,14 @@ void str_validate(char *str)
do {
*dst++ = *str++;
} while (--len != 0);
+ } else if (allow_newlines && c == '\n') {
+ *dst++ = *str++;
} else {
+ if (allow_newlines && c == '\r' && str[1] == '\n') {
+ str += len;
+ continue;
+ }
+ assert(c != '\r');
/* Replace the undesirable character with a question mark */
str += len;
*dst++ = '?';
diff --git a/src/string_func.h b/src/string_func.h
index 04f752921..a8bf897a8 100644
--- a/src/string_func.h
+++ b/src/string_func.h
@@ -95,7 +95,7 @@ char *CDECL str_fmt(const char *str, ...);
/** Scans the string for valid characters and if it finds invalid ones,
* replaces them with a question mark '?' */
-void str_validate(char *str);
+void str_validate(char *str, bool allow_newlines = false);
/** Scans the string for colour codes and strips them */
void str_strip_colours(char *str);