From 29dd50bde6b549159fb9c79df4590dcd2fe078c1 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sun, 25 May 2014 00:35:22 +0200 Subject: [PATCH] fix: keep path and uppercase in demo filenames votes now distinguish between demo and map votecalls and filter the filename appropriately also: remove paths from map names cleanly --- source/src/clients2c.cpp | 8 ++++++-- source/src/menus.cpp | 3 +-- source/src/protocol.cpp | 4 ++-- source/src/protocol.h | 4 +++- source/src/server.cpp | 5 +++-- source/src/serverbrowser.cpp | 4 ++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 62180db1..a31ff2c9 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -1234,12 +1234,16 @@ void parsemessages(int cn, playerent *d, ucharbuf &p, bool demo = false) switch(type) { case SA_MAP: + { getstring(text, p); - filtertext(text, text, FTXT__MAPNAME); - itoa(a1, getint(p)); + int mode = getint(p); + if(m_isdemo(mode)) filtertext(text, text, FTXT__DEMONAME); + else filtertext(text, behindpath(text), FTXT__MAPNAME); + itoa(a1, mode); defformatstring(t)("%d", getint(p)); v = newvotedisplayinfo(d, type, text, a1, t); break; + } case SA_KICK: case SA_BAN: { diff --git a/source/src/menus.cpp b/source/src/menus.cpp index 0f19ba9e..f7e4b098 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -1280,9 +1280,8 @@ void gmenu::init() } } defformatstring(fullname)("%s%s%s", dirlist->dir[0]?dirlist->dir+diroffset:"", dirlist->dir[0]?"/":"", f); - defformatstring(caction)("map %s", fullname); defformatstring(title)("%s", f); - items.add(new mitemmapload(this, newstring(fullname), newstring(title), newstring(caction), NULL, NULL, NULL)); + items.add(new mitemmapload(this, newstring(fullname), newstring(title), newstring(dirlist->action), NULL, NULL, NULL)); } else items.add(new mitemtext(this, f, newstring(dirlist->action), NULL, NULL, d)); } diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index 629e9fbe..d2fd3ca5 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -169,7 +169,7 @@ char *filtertext(char *dst, const char *src, int flags, int len) if(filename) { const char *org = "*?![]{};:/\\", - *asc = "__o()()____", // 'o' -> ignore + *asc = "__o()()__oo", // 'o' -> ignore *a = strchr(org, c); if(a) { @@ -196,7 +196,7 @@ char *filtertext(char *dst, const char *src, int flags, int len) } pass = true; } - if(mapname && !islower(c) && !isdigit(c) && !strchr("_-.", c)) continue; + if(mapname && !isalnum(c) && !strchr("_-./\\", c)) continue; if(isspace(c)) { if(nowhite && !((c == ' ' && allowblanks) || (c == '\n' && allownl)) && !pass) continue; diff --git a/source/src/protocol.h b/source/src/protocol.h index 9b72e391..9e4863b9 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -134,6 +134,7 @@ enum #define m_demo (gamemode==-1) #define m_coop (gamemode==1) #define m_flags (m_ctf || m_htf || m_ktf) +#define m_isdemo(x) ((x) == -1) // single filter modes #define FTXT_NOWHITE (1<<8) @@ -152,7 +153,8 @@ enum // character classes #define FTXT__SERVDESC (FTXT_NOWHITE | FTXT_ALLOWBLANKS | FTXT_TABTOBLANK) #define FTXT__MAPMSG (FTXT_NOWHITE | FTXT_ALLOWBLANKS | FTXT_TABTOBLANK) -#define FTXT__MAPNAME (FTXT_NOCOLOR | FTXT_MAPNAME | FTXT_TOLOWER) // FTXT_FILENAME and FTXT_NOCOLOR not needed, since FTXT_MAPNAME is very strict; can not be used with paths +#define FTXT__MAPNAME (FTXT_NOCOLOR | FTXT_MAPNAME | FTXT_TOLOWER) +#define FTXT__DEMONAME (FTXT_NOCOLOR | FTXT_MAPNAME) #define FTXT__PLAYERNAME (FTXT_NOWHITE | FTXT_NOCOLOR) #define FTXT__SERVERINFO (FTXT_ALLOWTAB) #define FTXT__MOTD (FTXT_TABTOBLANK) diff --git a/source/src/server.cpp b/source/src/server.cpp index e3421293..5359a766 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -3450,11 +3450,12 @@ void process(ENetPacket *packet, int sender, int chan) case SA_MAP: { getstring(text, p); - filtertext(text, text, FTXT__MAPNAME); int mode = getint(p), time = getint(p); + vi->gonext = text[0]=='+' && text[1]=='1'; + if(m_isdemo(mode)) filtertext(text, text, FTXT__DEMONAME); + else filtertext(text, behindpath(text), FTXT__MAPNAME); if(time <= 0) time = -1; time = min(time, 60); - vi->gonext = text[0]=='+' && text[1]=='1'; if (vi->gonext) { int ccs = mode ? maprot.next(false,false) : maprot.get_next(); diff --git a/source/src/serverbrowser.cpp b/source/src/serverbrowser.cpp index b78f89e7..b4453324 100644 --- a/source/src/serverbrowser.cpp +++ b/source/src/serverbrowser.cpp @@ -487,7 +487,7 @@ void checkpings() si->numplayers = getint(p); si->minremain = getint(p); getstring(text, p); - filtertext(si->map, text, FTXT__MAPNAME); + filtertext(si->map, behindpath(text), FTXT__MAPNAME); getstring(text, p); filtertext(si->sdesc, text, FTXT__SERVDESC); copystring(si->description, si->sdesc); @@ -552,7 +552,7 @@ void checkpings() while(p.remaining()) { getstring(text, p); - filtertext(text, text, FTXT__MAPNAME); + filtertext(text, behindpath(text), FTXT__MAPNAME); if(*text && !p.overread()) { text[MAXINFOLINELEN] = '\0';