From b650fca2cabab6aba0f4f5020e2f77d59ac699b0 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Fri, 5 May 2017 15:50:59 +0200 Subject: [PATCH] persistidents cleanup Restore the old persistidents system from AC 1.0, since it's working as intended - if used properly. As a reminder: * aliases created by "const" and "tempalias" are never persistent * aliases created or altered by "alias" or "=" become persistent, if the persistidents flag is set during that operation * persistidents if false during the execution of almost all config files during game start - those files can create aliases with default values which will not be persistent (until changed later while the flag is set) * before saved.cfg is executed, the flag is set and stays set all throughout the game - which means, that all changes (from menus, for example) will change the altered alias to "persistent" * exceptions for map or model config files are unnecessary, since those run restricted and can't create aliases anyway * exceptions are necessary for "late run" config files like those in config/opt/ The new command "persistidents" may be used to manually set or clear the flag. It also returns the current state of the flag. If used in a config file, the flag is restored to its original value when the file ends execution. In short: only late-run config files (meaning: run after saved.cfg was restored) may need to manually set/reset the flag. Use const and tempalias where appropriate and clear persistidents before creating an alias with a not-to-save default value that may be changed and made persistent later. DOCREF persistidents --- config/admin.cfg | 3 --- config/favourites.cfg | 3 --- config/font.cfg | 3 +-- config/menus.cfg | 3 --- config/menus_bot.cfg | 3 --- config/menus_edit.cfg | 4 ---- config/menus_multiplayer.cfg | 3 --- config/menus_settings.cfg | 6 +----- config/menus_voicecom.cfg | 4 ---- config/opt/autosave.cfg | 4 +--- config/opt/compatibility.cfg | 3 --- config/opt/convmap.cfg | 4 ++-- config/opt/survival.cfg | 5 ++--- config/prefabs.cfg | 3 --- config/resetbinds.cfg | 3 --- config/scontext.cfg | 4 +--- config/scripts.cfg | 4 ---- source/src/command.cpp | 13 ++++++++----- source/src/main.cpp | 8 ++++---- source/src/md2.h | 5 +---- source/src/md3.h | 6 +----- source/src/protos.h | 2 +- source/src/serverbrowser.cpp | 6 +++--- source/src/world.cpp | 4 ---- source/src/worldio.cpp | 8 -------- 25 files changed, 26 insertions(+), 88 deletions(-) diff --git a/config/admin.cfg b/config/admin.cfg index 4cdb266d..9484ee7e 100644 --- a/config/admin.cfg +++ b/config/admin.cfg @@ -1,5 +1,3 @@ -persistidents 0 - const kick [if $numargs [if (> $numargs 1) [loop i (- $numargs 2) [alias arg2 (concat $arg2 (getalias (concatword arg (+ $i 3)))) ] ] [] ; callvote 0 $arg1 $arg2 ] ] const ban [if $numargs [if (> $numargs 1) [loop i (- $numargs 2) [alias arg2 (concat $arg2 (getalias (concatword arg (+ $i 3)))) ] ] [] ; callvote 1 $arg1 $arg2 ] ] const removebans [ callvote 2 $arg1 ] @@ -25,4 +23,3 @@ const demo [ ] ] -persistidents 1 diff --git a/config/favourites.cfg b/config/favourites.cfg index 7ef945e0..9e8b83b4 100644 --- a/config/favourites.cfg +++ b/config/favourites.cfg @@ -41,8 +41,6 @@ // arg1: mapname, arg2: gamemode number, arg3: ping, arg4: minutesremaining, arg5: number of players, arg6: maxclients, arg7: IP, arg8: port, arg9: pongflags // pongflags is bit-coded: bit 0: passworded, bit 1: banned, bit 2: blacklisted, bit 6: mastermode -persistidents 0 - offmap = [ (+ 1 (findlist $defaultmaps $arg1)) ] @@ -107,4 +105,3 @@ sbfavourite_SEARCH_alpha = 0 sbfavourite_SEARCH_weight = 1 sbfavourite_SEARCH_ignore = 1 -persistidents 1 diff --git a/config/font.cfg b/config/font.cfg index 5fc3d9c6..87941035 100644 --- a/config/font.cfg +++ b/config/font.cfg @@ -1,5 +1,4 @@ // To add your own fonts, create a seperate font file and execute like this: -persistidents 0 exec config/font_default.cfg // Must be executed! DO NOT MODIFY. exec config/font_monospace.cfg // Must be executed! DO NOT MODIFY. @@ -75,4 +74,4 @@ fontchar 0 192 64 64 //M red circle fontchar 64 192 64 64 //N blue circle fontchar 128 192 64 64 //O green circle -persistidents 1 + diff --git a/config/menus.cfg b/config/menus.cfg index 9a641202..ce352921 100644 --- a/config/menus.cfg +++ b/config/menus.cfg @@ -1,5 +1,3 @@ -persistidents 0 - // standard menu definitions newmenu main @@ -137,4 +135,3 @@ exec config/menus_multiplayer.cfg exec config/menus_voicecom.cfg exec config/favourites.cfg -persistidents 1 diff --git a/config/menus_bot.cfg b/config/menus_bot.cfg index e0ff485c..5a6b1034 100644 --- a/config/menus_bot.cfg +++ b/config/menus_bot.cfg @@ -1,7 +1,5 @@ // bot menus and tools -persistidents 0 - newmenu botmaps const genbotmaps [ @@ -177,4 +175,3 @@ menuinit [ delallwps = 0 ] // Ensures this menu works correctly. menuitemcheckbox "Yes, delete all waypoints: " [delallwps = 1] [delallwps = $arg1] menuitem "\f2\t\t Apply!" [ if $delallwps wpclear [ showmenu [] ] ] -persistidents 1 diff --git a/config/menus_edit.cfg b/config/menus_edit.cfg index 410cea96..60a660ff 100644 --- a/config/menus_edit.cfg +++ b/config/menus_edit.cfg @@ -1,5 +1,3 @@ -persistidents 0 - newmenu editing menuinit [ if (! $editing) [menuheader "" "\f3You are not in edit mode"] [menuheader] ] @@ -1188,5 +1186,3 @@ menuinit [ ] ] - -persistidents 1 diff --git a/config/menus_multiplayer.cfg b/config/menus_multiplayer.cfg index b69112c1..a3d528fc 100644 --- a/config/menus_multiplayer.cfg +++ b/config/menus_multiplayer.cfg @@ -1,5 +1,3 @@ -persistidents 0 - // Decides whether to open the admin or normal in-game menu. const ingamemenu [ if (player1 role) [ showmenu [In-game admin] ] [ showmenu In-game ] ] @@ -257,4 +255,3 @@ menuitem "\f2 [ Download the servers map version and join the game ]" [ g menuitem "\f3 [ Keep the local map version and disconnect from the server ]" [ showmenu ""; disconnect ] menuinitselection 4 -persistidents 1 diff --git a/config/menus_settings.cfg b/config/menus_settings.cfg index 893d7b9a..a44e2fdd 100644 --- a/config/menus_settings.cfg +++ b/config/menus_settings.cfg @@ -1,5 +1,3 @@ -persistidents 0 - newmenu settings menuitem [Video settings] [ showmenu video ] @@ -580,7 +578,7 @@ menuitemslider [ Radar zoom: ] 5 500 [ menuitemslider [ Votes: ] 0 2 "$hidevote" 1 ["Always show" "Show until you vote" "Never show"] [ hidevote $arg1 ] menuitemslider [ Graphics statistics: ] 0 2 "$showstats" 1 [None "FPS Only" All] [ showstats $arg1 ] menuitemslider [ Game time: ] 0 2 "$gametimedisplay" 1 [None "Count backward" "Count forward"] [ gametimedisplay $arg1 ] -menuitemslider [ Wall clock: ] 0 6 [findlist $wallclockformatlist $wallclockformat] 1 [None "HH:MM (local, 24h)" "HH:MM:SS (local, 24h)" "HH:MM (local, 12h)" "HH:MM:SS (local, 12h)" "HH:MM (UTC/GMT)" "HH:MM:SS (UTC/GMT)"] [ persistidents 1; alias wallclockformat (at $wallclockformatlist $arg1); persistidents 0 ] +menuitemslider [ Wall clock: ] 0 6 [findlist $wallclockformatlist $wallclockformat] 1 [None "HH:MM (local, 24h)" "HH:MM:SS (local, 24h)" "HH:MM (local, 12h)" "HH:MM:SS (local, 12h)" "HH:MM (UTC/GMT)" "HH:MM:SS (UTC/GMT)"] [ alias wallclockformat (at $wallclockformatlist $arg1)] menuitemslider [ Extra messages: ] 0 3 "$hudextras" 1 ["No extra messages" "Show extra messages in console" "Pop up extra messages!" "SPAM EXTRA MESSAGES!"] [ hudextras $arg1 ] menuitemslider [ Hand alignment: ] 0 1 "$righthanded" 1 [Left-handed Right-handed] [ righthanded $arg1 ] menuitemslider [ Max-roll: ] 0 (getvarrange max maxroll) "$maxroll" 1 [] [ maxroll $arg1 ] @@ -916,5 +914,3 @@ const checkaccount [ ] ] ] - -persistidents 1 diff --git a/config/menus_voicecom.cfg b/config/menus_voicecom.cfg index 67d66c90..b2b61eee 100644 --- a/config/menus_voicecom.cfg +++ b/config/menus_voicecom.cfg @@ -1,5 +1,3 @@ -persistidents 0 - newmenu voicecom 1 1 menuitem [1. Team Replies] [ showmenu [Team Replies] ] @@ -66,5 +64,3 @@ newmenu [Public Talk] 1 1 genvcitem [Nice shot] niceshot 1 genvcitem [Thanks! "Thanks, man"] [thanks_1 thanks_2] 2 genvcitem [Awesome Awesome!] [awesome_1 awesome_2] 3 - -persistidents 1 diff --git a/config/opt/autosave.cfg b/config/opt/autosave.cfg index 651d31fe..e3ec13f3 100644 --- a/config/opt/autosave.cfg +++ b/config/opt/autosave.cfg @@ -1,7 +1,7 @@ // old autosave system (superseded by autosaved xmaps) // (write "load_autosave" into your autoexec.cfg to load) -persistidents 0 +persistidents 0 // don't save default values checkinit mapstartalways [numAutoSaves = 0; autoSaveCheck] checkinit onNewMap [numAutoSaves = 0; autoSaveCheck] @@ -39,5 +39,3 @@ newmenu [Editing settings] menuitemcheckbox "Enable auto save map: " "$autosavemap" [ autosavemap = $arg1 ] menuitemslider "Time between auto saves (in minutes): " 2 60 "(div $timeBetAutoSaves 60000)" 1 [] [ timeBetAutoSaves = (* $arg1 60000) ] menuitemtextinput "Make a map backup (.BAK) every: " "$numAutoSaveBackups" [ numAutoSaveBackups = $arg1 ] [ if (! $showedBAKinfo) [ echo This setting effects the number of autosavemaps between making a map backup file. "(.BAK)"; showedBAKinfo = 1 ] ] 4 - -persistidents 1 diff --git a/config/opt/compatibility.cfg b/config/opt/compatibility.cfg index 96cffb74..4aa41291 100644 --- a/config/opt/compatibility.cfg +++ b/config/opt/compatibility.cfg @@ -1,8 +1,6 @@ // Makes very old cubescripts compatible with newer versions of the game // (write "load_compatibility" into your autoexec.cfg to load) -persistidents 0 - const alive [ if (&& $numargs (isclient $arg1)) [ result (player $arg1 alive) ] [ result (player1 alive) ] ] const currole [ if (&& $numargs (isclient $arg1)) [ result (player $arg1 role) ] [ result (player1 role) ] ] const curmode [ result $gamemode ] @@ -39,4 +37,3 @@ const orderscorecolumns [ ] ] -persistidents 1 diff --git a/config/opt/convmap.cfg b/config/opt/convmap.cfg index bb30d39c..d9dbce68 100644 --- a/config/opt/convmap.cfg +++ b/config/opt/convmap.cfg @@ -2,8 +2,8 @@ // assisted AC map conversion // - keeps a list of "maps to process" stored as aliases in saved.cfg -// - each run of the script adds the maps listed in "convmaplist", if they are not already on the listallmapmodelattributes -// - script can be run multiple times19 +// - each run of the script adds the maps listed in "convmaplist", if they are not already on the list +// - script can be run multiple times // - amends the main menu (temporarily) with an entry to the batch conversion menu // - to add many maps, add something like convmaplist = [ac_2fort ac_abandoned ac_abyss ac_accomply ac_adventure3 ac_africa] to your autoexec // - this toolset converts maps to map format 10 and helps to fix a lot of errors on maps diff --git a/config/opt/survival.cfg b/config/opt/survival.cfg index 090a45bc..d288b6d2 100644 --- a/config/opt/survival.cfg +++ b/config/opt/survival.cfg @@ -8,7 +8,8 @@ // * The difficulty is "increased" over time, by spawning more and increasing the skill level of bots at "checkpoints". // * If the player dies, or leaves the "zone" for too long of a duration, the game ends. // * Total seconds survived, total number of enemies killed during, average amount of time between kills, and total damage dealt while alive are reported as stats when the game ends. -persistidents 0 + +persistidents 0 // don't save default values // set defaults - may be overwritten by saved.cfg looplist [ @@ -293,5 +294,3 @@ const endSurvival [ tdm (rndmap) ] ] - -persistidents 1 diff --git a/config/prefabs.cfg b/config/prefabs.cfg index 91fd82d0..57f72ca0 100644 --- a/config/prefabs.cfg +++ b/config/prefabs.cfg @@ -2,7 +2,6 @@ // arch of 2xN cubes, i.e. 3 vertices [0..2] // archvertex // vertices not defined have a 0 delta -persistidents 0 const av [ push vn (+ $arg1 1) @@ -45,5 +44,3 @@ const av_measure [ loop i (listlen $ii) [ if $i [ res = (concat $res (- (at $ii $i) $offs)) ] ] result (pop res offs ii) ] - -persistidents 1 diff --git a/config/resetbinds.cfg b/config/resetbinds.cfg index ebaf01f2..cd5fc081 100644 --- a/config/resetbinds.cfg +++ b/config/resetbinds.cfg @@ -3,8 +3,6 @@ // Do not modify. -persistidents 0 - alias key_console_end [ conskip -1000 ] alias key_console_forward [ conskip -5 ] alias key_console_rewind [ conskip 5 ] @@ -274,4 +272,3 @@ _defaultbinds 0 omitunchangeddefaults 1 // switch to a clean saved.cfg when keybinds are reset -persistidents 1 diff --git a/config/scontext.cfg b/config/scontext.cfg index 5080e1da..1cf4bb1c 100644 --- a/config/scontext.cfg +++ b/config/scontext.cfg @@ -1,8 +1,6 @@ // define script security contexts to restrict commands to certain contexts // do NOT modify -persistidents 0 - // supported contexts const context_core 0 // hardcoded scripts const context_cfg 1 // known scripts @@ -25,4 +23,4 @@ isolatecontext $context_mdlcfg // secure this configuration for the rest of the game sealcontexts -persistidents 1 + diff --git a/config/scripts.cfg b/config/scripts.cfg index d6776134..8faf6269 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -1,7 +1,5 @@ // CubeScript placed in this file is automatically executed on each startup. -persistidents 0 - const MODES [tdm coop dm surv tsurv ctf pf btdm bdm lss osok tosok bosok htf tktf ktf tpf tlss bpf blss btsurv btosok] const MODEALIASES [map lms vip sendmap] @@ -573,5 +571,3 @@ tempalias load_parsestring [ run opt/parsestring ; alias load_parsestring [] ] tempalias load_faq [ run opt/faq ; alias load_faq [] ] tempalias load_convmap [ saycommand "/run opt/convmap " ] tempalias load_mapeditscripts [ run opt/mapeditscripts ] - -persistidents 1 diff --git a/source/src/command.cpp b/source/src/command.cpp index 21996432..e99418fd 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -18,11 +18,12 @@ int loop_level = 0; // avoid bad calls of b hashtable *idents = NULL; // contains ALL vars/commands/aliases -VAR(persistidents, 0, 1, 1); +bool persistidents = false; -bool per_idents = true, neverpersist = false; -COMMANDF(per_idents, "i", (int *on) { - per_idents = neverpersist ? false : (*on != 0); +COMMANDF(persistidents, "s", (char *on) +{ + if(on && *on) persistidents = ATOI(on) != 0; + intret(persistidents ? 1 : 0); }); void clearstack(ident &id) @@ -66,7 +67,7 @@ ident *newident(const char *name, int context = execcontext) ident *id = idents->access(name); if(!id) { - ident init(ID_ALIAS, newstring(name), newstring(""), per_idents, context); + ident init(ID_ALIAS, newstring(name), newstring(""), persistidents, context); id = &idents->access(init.name, init); } return id; @@ -1047,6 +1048,7 @@ bool execfile(const char *cfgfile) string s; copystring(s, cfgfile); setcontext("file", cfgfile); + bool oldpersist = persistidents; char *buf = loadfile(path(s), NULL); if(!buf) { @@ -1056,6 +1058,7 @@ bool execfile(const char *cfgfile) execute(buf); delete[] buf; resetcontext(); + persistidents = oldpersist; return true; } diff --git a/source/src/main.cpp b/source/src/main.cpp index 020e7972..de2f6d6f 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -1002,6 +1002,7 @@ int main(int argc, char **argv) entropy_init(time(NULL) + (uint)(size_t)&serverport + (uint)(size_t)entropy_init); pushscontext(IEXC_CFG); + persistidents = false; #define initlog(s) clientlogf("init: " s) @@ -1143,7 +1144,6 @@ int main(int argc, char **argv) if(!notexture) fatal("could not find core textures (hint: run AssaultCube from the parent of the bin directory)"); initlog("console"); - per_idents = false; autostartscripts("_veryfirst_"); // Main font file, all other font files execute from here. if(!execfile("config/font.cfg")) fatal("cannot find default font definitions"); @@ -1190,7 +1190,7 @@ int main(int argc, char **argv) setupautodownload(); int xmn = loadallxmaps(); if(xmn) conoutf("loaded %d xmaps", xmn); - per_idents = true; + persistidents = true; static char resdata[] = { 112, 97, 99, 107, 97, 103, 101, 115, 47, 116, 101, 120, 116, 117, 114, 101, 115, 47, 107, 117, 114, 116, 47, 107, 108, 105, 116, 101, 50, 46, 106, 112, 103, 0 }; stream *f = opengzfile(resdata, "rb"); @@ -1227,9 +1227,9 @@ int main(int argc, char **argv) preload_entmodels(); initlog("docs"); - per_idents = false; + persistidents = false; execfile("config/docs.cfg"); - per_idents = true; + persistidents = true; initlog("localconnect"); extern string clientmap; diff --git a/source/src/md2.h b/source/src/md2.h index 52619301..1f369921 100644 --- a/source/src/md2.h +++ b/source/src/md2.h @@ -259,16 +259,13 @@ struct md2 : vertmodel loopv(mdl.meshes) mdl.meshes[i]->skin = skin; if(skin==notexture) { conoutf("could not load model skin for %s", name1); flagmapconfigerror(LWW_MODELERR); } loadingmd2 = this; + ASSERT(execcontext == IEXC_MDLCFG); defformatstring(name2)("packages/models/%s/md2.cfg", loadname); - per_idents = false; - neverpersist = true; if(!execfile(name2)) { formatstring(name2)("packages/models/%s/md2.cfg", pname); execfile(name2); } - neverpersist = false; - per_idents = true; loadingmd2 = 0; loopv(parts) parts[i]->scaleverts(scale/16.0f, vec(translate.x, -translate.y, translate.z)); radius = calcradius(zradius); diff --git a/source/src/md3.h b/source/src/md3.h index bf5cdcca..067a4be6 100644 --- a/source/src/md3.h +++ b/source/src/md3.h @@ -218,19 +218,15 @@ struct md3 : vertmodel defformatstring(cfgname)("packages/models/%s/md3.cfg", loadname); loadingmd3 = this; - per_idents = false; - neverpersist = true; + ASSERT(execcontext == IEXC_MDLCFG); if(execfile(cfgname) && parts.length()) // configured md3, will call the md3* commands below { - neverpersist = false; - per_idents = true; loadingmd3 = NULL; if(parts.empty()) return false; loopv(parts) if(!parts[i]->filename) return false; } else // md3 without configuration, try default tris and skin { - per_idents = false; loadingmd3 = NULL; md3part &mdl = *new md3part; parts.add(&mdl); diff --git a/source/src/protos.h b/source/src/protos.h index 5327d7a7..140745d0 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -985,7 +985,7 @@ extern bool checkchallenge(const char *answerstr, void *correct); extern void conoutf(const char *s, ...) PRINTFARGS(1, 2); // command -extern bool per_idents, neverpersist; +extern bool persistidents; extern char *exchangestr(char *o, const char *n); extern int variable(const char *name, int min, int cur, int max, int *storage, void (*fun)(), bool persist); extern float fvariable(const char *name, float min, float cur, float max, float *storage, void (*fun)(), bool persist); diff --git a/source/src/serverbrowser.cpp b/source/src/serverbrowser.cpp index f8d0f97f..4eaf7d7a 100644 --- a/source/src/serverbrowser.cpp +++ b/source/src/serverbrowser.cpp @@ -787,8 +787,8 @@ void addfavcategory(const char *refdes) if(!text[0]) { intret(0); return; } loopv(favcats) if(!strcmp(favcats[i], text)) { intret(i + 1); return; } favcats.add(newstring(text)); - bool oldpersist = per_idents; - per_idents = false; // only keep changed values + bool oldpersist = persistidents; + persistidents = false; // only keep changed values loopi(FC_NUM) alx[i] = getalias(favcatargname(text, i)) ? 1 : 0; loopi(3) { @@ -799,7 +799,7 @@ void addfavcategory(const char *refdes) const int defk[] = { FC_WEIGHT, FC_DESC, FC_TAG, FC_KEYS, FC_IGNORE, FC_ALPHA }; const char *defv[] = { "0", val, refdes, "", "", "20" }; loopi(sizeof(defk)/sizeof(defk[0])) { if(!alx[defk[i]]) alias(favcatargname(text, defk[i]), defv[i]); } - per_idents = oldpersist; + persistidents = oldpersist; intret(favcats.length()); } diff --git a/source/src/world.cpp b/source/src/world.cpp index 0fc55ffa..6277fb06 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -728,11 +728,7 @@ bool empty_world(int factor, bool force) // main empty world creation routine if(clearmap) { pushscontext(IEXC_MAPCFG); - per_idents = false; - neverpersist = true; execfile("config/default_map_settings.cfg"); - neverpersist = false; - per_idents = true; popscontext(); setvar("fullbright", 1); fullbrightlight(); diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 131fb64d..a7c0b27b 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -983,8 +983,6 @@ int load_world(char *mname) // still supports all map formats that have e conoutf("%s", hdr.maptitle); mapconfigerror = 0; pushscontext(IEXC_MAPCFG); // untrusted altogether - per_idents = false; - neverpersist = true; if(hdr.flags & MHF_AUTOMAPCONFIG) { // full featured embedded config: no need to read any other map config files copystring(lastloadedconfigfile, ""); @@ -996,8 +994,6 @@ int load_world(char *mname) // still supports all map formats that have e copystring(lastloadedconfigfile, mcfname); } parseheaderextra(); - neverpersist = false; - per_idents = true; popscontext(); c2skeepalive(); @@ -1183,8 +1179,6 @@ struct xmap calclight(); // includes full remip() loopv(headerextras) ::headerextras.add(headerextras[i]->duplicate()); pushscontext(IEXC_MAPCFG); // untrusted altogether - per_idents = false; - neverpersist = true; if(mapconfig.length()) execute(mapconfig.getbuf()); else { @@ -1192,8 +1186,6 @@ struct xmap execfile(lastloadedconfigfile); } parseheaderextra(true, mapconfig.length() ? (1<