From 8760d4b4fa6cab6862c243b6a61914417a73f35c Mon Sep 17 00:00:00 2001 From: ac_stef Date: Sat, 6 Dec 2008 17:37:13 +0000 Subject: [PATCH] escaping special characters for commandline arguments git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3887 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/protocol.cpp | 36 ++++++++++++++++++++++++++++++++++++ source/src/protos.h | 1 + source/src/server.cpp | 17 +++++++++-------- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index faba5ce2..c8655a1d 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -111,6 +111,42 @@ void filtertext(char *dst, const char *src, int whitespace, int len) *dst = '\0'; } +void filterrichtext(char *dst, const char *src, int len) +{ + int b, c; + unsigned long ul; + for(c = *src; c; c = *++src) + { + c &= 0x7F; // 7-bit ascii + if(c == '\\') + { + b = 0; + c = *++src; + switch(c) + { + case '\0': --src; continue; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'x': + b = 16; + c = *++src; + default: + if(isspace(c)) continue; + if(b == 0 && !isdigit(c)) break; + ul = strtoul(src, (char **) &src, b); + --src; + c = (int) ul; + if(!c) continue; // number conversion failed + break; + } + } + *dst++ = c; + if(!--len || !*src) break; + } + *dst = '\0'; +} + + const char *modefullnames[] = { "demo playback", diff --git a/source/src/protos.h b/source/src/protos.h index e4d38cee..de11136a 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -675,6 +675,7 @@ extern int getuint(ucharbuf &p); extern void sendstring(const char *t, ucharbuf &p); extern void getstring(char *t, ucharbuf &p, int len = MAXTRANS); extern void filtertext(char *dst, const char *src, int whitespace = 1, int len = sizeof(string)-1); +extern void filterrichtext(char *dst, char const *src, int len = sizeof(string)-1); extern void startintermission(); extern void restoreserverstate(vector &ents); extern uchar *retrieveservers(uchar *buf, int buflen); diff --git a/source/src/server.cpp b/source/src/server.cpp index ff1f8982..09b018b0 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -415,10 +415,10 @@ bool buildworldstate() } int maxclients = DEFAULTCLIENTS, kickthreshold = -5, banthreshold = -6; -string smapname, nextmapname; +string smapname, nextmapname, motd; int nextgamemode; -const char *adminpasswd = NULL, *motd = NULL; +const char *adminpasswd = NULL; int countclients(int type, bool exclude = false) { @@ -2456,7 +2456,7 @@ void welcomepacket(ucharbuf &p, int n, ENetPacket *packet, bool forcedeath) } putint(p, SV_AUTOTEAM); putint(p, autoteam ? 1 : 0); - if(motd) + if(motd[0]) { CHECKSPACE(5+2*(int)strlen(motd)+1); putint(p, SV_TEXT); @@ -3447,12 +3447,13 @@ void initserver(bool dedicated, int uprate, const char *sdesc, const char *sdesc if(passwd) s_strcpy(serverpassword, passwd); maxclients = maxcl > 0 ? min(maxcl, MAXCLIENTS) : DEFAULTCLIENTS; servermsinit(master ? master : AC_MASTER_URI, ip, CUBE_SERVINFO_PORT(serverport), sdesc, dedicated); - s_strcpy(servdesc_full, sdesc); - s_strcpy(servdesc_cur, sdesc); - s_strcpy(servdesc_pre, sdesc_pre); - s_strcpy(servdesc_suf, sdesc_suf); + filterrichtext(servdesc_full, sdesc); + filterrichtext(servdesc_cur, sdesc); + filterrichtext(servdesc_pre, sdesc_pre); + filterrichtext(servdesc_suf, sdesc_suf); s_strcpy(voteperm, voteperms && voteperms[0] ? voteperms : ""); s_strcpy(demopath, demop && demop[0] ? demop : ""); + motd[0] = '\0'; s_sprintfd(identity)("%s[%d]", ip && ip[0] ? ip : "local", serverport); logger = newlogger(identity); @@ -3469,7 +3470,7 @@ void initserver(bool dedicated, int uprate, const char *sdesc, const char *sdesc readscfg(maprot && maprot[0] ? maprot : "config/maprot.cfg"); if(adminpwd && adminpwd[0]) adminpasswd = adminpwd; - if(srvmsg && srvmsg[0]) motd = srvmsg; + if(srvmsg && srvmsg[0]) filterrichtext(motd, srvmsg); kickthreshold = min(-1, kthreshold); banthreshold = min(-1, bthreshold); readpwdfile(pwdfile && pwdfile[0] ? pwdfile : "config/serverpwd.cfg");