From 590c4f38ab7152a792935ab9131ae00f8150e256 Mon Sep 17 00:00:00 2001 From: WPMGPRoSToTeMa Date: Tue, 2 Feb 2016 07:19:56 +0300 Subject: [PATCH] Added replacing escape sequences in kick reason (#154) --- rehlds/engine/sv_main.cpp | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 0baa695..8f3031f 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -6059,6 +6059,42 @@ void SV_BanId_f(void) host_client = save; } +#ifdef REHLDS_FIXES +void ReplaceEscapeSequences(char *str) +{ + size_t len = 0; + for (size_t i = 0; str[i] != '\0'; i++) + { + if (str[i] == '\\') + { + switch (str[++i]) + { + case 't': + str[len++] = '\t'; + break; + case 'n': + str[len++] = '\n'; + break; + case '\\': + str[len++] = '\\'; + break; + // TODO: or ignore it? + default: + str[len++] = '\\'; + str[len++] = str[i]; + break; + } + } + else + { + str[len++] = str[i]; + } + } + + str[len] = '\0'; +} +#endif // REHLDS_FIXES + /* ../engine/sv_main.c:8040 */ void Host_Kick_f(void) { @@ -6201,6 +6237,13 @@ void Host_Kick_f(void) const char *message = dataLen + p; if (message) { +#ifdef REHLDS_FIXES + char reason[256]; + Q_strncpy(reason, message, sizeof(reason) - 1); + reason[sizeof(reason) - 1] = '\0'; + ReplaceEscapeSequences(reason); + message = reason; +#endif // REHLDS_FIXES SV_ClientPrintf("Kicked by %s: %s\n", who, message); Log_Printf( "Kick: \"%s<%i><%s><>\" was kicked by \"%s\" (message \"%s\")\n",