From a860cc58b027ba255595dab1bfbdc9b2346fd611 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Tue, 26 Jul 2016 15:41:40 +0200 Subject: [PATCH] add a map license and comment string to the map header Two new string variables, mapinfo_license and mapinfo_comment, are stored withing the header of a map file. The variables are automatically read and written during loading and saving maps. Default values are empty strings. The comment string is ignored, as long as no license string is set. The license string is meant to hold an abbreviated name of the license, picked from a list of known map licenses. DOCREF mapinfo_license mapinfo_comment --- source/src/clientgame.cpp | 1 + source/src/protocol.h | 2 ++ source/src/protos.h | 2 ++ source/src/worldio.cpp | 31 +++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index b2b87c47..af7f08c8 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -1085,6 +1085,7 @@ void resetmap(bool mrproper) deleted_ents.setsize(0); pinnedclosestent = false; particlereset(); + setmapinfo("", ""); if(mrproper) { audiomgr.clearworldsounds(); diff --git a/source/src/protocol.h b/source/src/protocol.h index 0ee90836..23e6ab1a 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -200,6 +200,8 @@ enum #define FTXT__ALIAS (FTXT_NOWHITE | FTXT_NOCOLOR | FTXT_SAFECS | FTXT_MAPNAME) #define FTXT__SERVDESC (FTXT_NOWHITE | FTXT_ALLOWBLANKS | FTXT_TABTOBLANK) #define FTXT__MAPMSG (FTXT_NOWHITE | FTXT_ALLOWBLANKS | FTXT_TABTOBLANK) +#define FTXT__MAPINFO_LICENSE (FTXT_NOWHITE | FTXT_NOCOLOR | FTXT_TOLOWER | FTXT_MAPNAME) +#define FTXT__MAPINFO_COMMENT (FTXT_NOWHITE | FTXT_NOCOLOR | FTXT_ALLOWBLANKS | FTXT_TABTOBLANK) #define FTXT__MAPNAME (FTXT_NOCOLOR | FTXT_MAPNAME | FTXT_TOLOWER) #define FTXT__MDLATTR (FTXT_NOWHITE | FTXT_ALLOWBLANKS | FTXT_TABTOBLANK | FTXT_NOCOLOR | FTXT_SAFECS) #define FTXT__DEMONAME (FTXT_NOCOLOR | FTXT_MAPNAME) diff --git a/source/src/protos.h b/source/src/protos.h index 599749ce..454db4f9 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -755,6 +755,8 @@ extern void clearheaderextras(); extern void automapconfig(); extern void flagmapconfigchange(); extern void getcurrentmapconfig(vector &f, bool onlysounds); +extern char *mapinfo_license, *mapinfo_comment; +extern void setmapinfo(const char *newlicense = NULL, const char *newcomment = NULL); extern void xmapbackup(const char *nickprefix, const char *nick); extern void writeallxmaps(); extern int loadallxmaps(); diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 61c4f301..7825154d 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -310,6 +310,13 @@ void parseheaderextra(bool clearnonpersist = true, int ignoretypes = 0) // pars break; case HX_MAPINFO: + { + string l, c; + getstring(l, q, MAXSTRLEN - 1); + getstring(c, q, MAXSTRLEN - 1); + setmapinfo(l, c); + break; + } case HX_MODEINFO: case HX_ARTIST: default: @@ -322,6 +329,18 @@ void parseheaderextra(bool clearnonpersist = true, int ignoretypes = 0) // pars ucharbuf packheaderextras(int ignoretypes = 0) // serialise all extra data packets to save with the map header { vector buf, tmp; + // rewrite some headers every time + if(!(ignoretypes & (1 << HX_MAPINFO))) + { + for(int n; (n = findheaderextra(HX_MAPINFO)) >= 0; ) deleteheaderextra(n); + if(mapinfo_license[0]) + { + sendstring(mapinfo_license, tmp); + sendstring(mapinfo_comment, tmp); + headerextras.add(new headerextra(tmp.length(), HX_MAPINFO|HX_FLAG_PERSIST, tmp.getbuf())); + tmp.setsize(0); + } + } loopv(headerextras) if(!(ignoretypes & (1 << (headerextras[i]->flags & HX_TYPEMASK)))) { // copy existing persistent hx packets addhxpacket(buf, headerextras[i]->len, headerextras[i]->flags, headerextras[i]->data); @@ -490,6 +509,18 @@ bool gotovantagepoint() } COMMANDF(gotovantagepoint, "", () { if(editmode) gotovantagepoint(); }); +void setmapinfo(const char *newlicense, const char *newcomment) +{ + string s; + filtertext(s, newlicense ? newlicense : mapinfo_license, FTXT__MAPINFO_LICENSE, 20); + mapinfo_license = exchangestr(mapinfo_license, s); + filtertext(s, newcomment ? newcomment : mapinfo_comment, FTXT__MAPINFO_COMMENT, 60); + mapinfo_comment = exchangestr(mapinfo_comment, s); +} + +SVARF(mapinfo_license, "", setmapinfo(); ); +SVARF(mapinfo_comment, "", setmapinfo(); ); + VAR(advancemaprevision, 1, 1, 100); VARP(mapbackupsonsave, 0, 1, 1);