diff --git a/config/serverparameters.cfg b/config/serverparameters.cfg index 0fd8a85e..49c50f05 100644 --- a/config/serverparameters.cfg +++ b/config/serverparameters.cfg @@ -19,9 +19,10 @@ auth_verify_ip:0 // integer [0..1], default 1, 0:disabled, 1:enabled mandatory_auth:1 +// DEPRECATED: // vitaautosave Vita file autosave interval in minutes (0: only when server is empty) -// integer [0..1440], default 10 -vitaautosave:10 +// integer [0..1440], default 0 +//vitaautosave:0 // vitamaxage Omit vitas from autosave, if the last login has been more than the specified number of months ago // integer [3..120], default 12 diff --git a/source/src/server.cpp b/source/src/server.cpp index 61d4d119..b90542da 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -119,15 +119,47 @@ int cn2boot; const char *endis[] = { "disabled", "enabled", "" }; SERVPARLIST(dumpmaprot, 0, 1, 0, endis, "ddump maprot parameters for all maps (once, to logs/debug/maprot_debug_verbose.txt)"); SERVPARLIST(dumpparameters, 0, 0, 0, endis, "ddump server parameters when updated"); -SERVPAR(vitaautosave, 0, 10, 24 * 60, "sVita file autosave interval in minutes (0: only when server is empty)"); +//SERVPAR(vitaautosave, 0, 10, 24 * 60, "sVita file autosave interval in minutes (0: only when server is empty)"); // deprecated SERVPAR(vitamaxage, 3, 12, 120, "sOmit vitas from autosave, if the last login has been more than the specified number of months ago"); +//int lastvitasave = 0; // deprecated +bool pushvitasforsaving(bool forceupdate = false) +{ + if(vitastosave) // only if the last push has been processed + { + return false; + } + else + { + //lastvitasave = servmillis; + vitastosave = new vector; + vitakey_s vk; + int too_old = 0; + enumeratekt(vitas, uchar32, k, vita_s, v, + { + if((servclock - v.vs[VS_LASTLOGIN]) / (60 * 24 * 31) <= vitamaxage // Vita is within the max age (months) + || (v.vs[VS_BAN] == 1 || (servclock - v.vs[VS_BAN]) < 0) // Do not remove if vita has the ban, whitelist, or admin flag set + || (v.vs[VS_WHITELISTED] == 1 || (servclock - v.vs[VS_WHITELISTED]) < 0) + || (v.vs[VS_ADMIN] == 1 || (servclock - v.vs[VS_ADMIN]) < 0)) + { + vk.k = &k; + vk.v = &v; + vitastosave->add(vk); + } + else too_old++; + }); + if(too_old) mlog(ACLOG_VERBOSE, "omitted %d vitas from autosave (exceeding maxage of %d months)", too_old, vitamaxage); + if(forceupdate) readserverconfigsthread_sem->post(); + } + return true; +} + bool triggerpollrestart = false; void poll_serverthreads() // called once per mainloop-timeslice { static vector servermapstodelete; - static int stage = 0, lastworkerthreadstart = 0, nextserverconfig = 0, lastvitasave = 0; + static int stage = 0, lastworkerthreadstart = 0, nextserverconfig = 0; static bool debugmaprot = true, serverwasnotempty = false; switch(stage) // cycle through some tasks once per minute (mostly file polling) @@ -236,27 +268,9 @@ void poll_serverthreads() // called once per mainloop-timeslice delete f; } } - else if(!vitastosave && serverwasnotempty && (numclients() == 0 || (vitaautosave && (servmillis - lastvitasave) > 1000 * 60 * vitaautosave))) + else if(!vitastosave && serverwasnotempty && numclients() == 0) { - serverwasnotempty = false; - lastvitasave = servmillis; - vitastosave = new vector; - vitakey_s vk; - int too_old = 0; - enumeratekt(vitas, uchar32, k, vita_s, v, - { - if((servclock - v.vs[VS_LASTLOGIN]) / (60 * 24 * 31) <= vitamaxage // Vita is within the max age (months) - || (v.vs[VS_BAN] == 1 || (servclock - v.vs[VS_BAN]) < 0) // Do not remove if vita has the ban, whitelist, or admin flag set - || (v.vs[VS_WHITELISTED] == 1 || (servclock - v.vs[VS_WHITELISTED]) < 0) - || (v.vs[VS_ADMIN] == 1 || (servclock - v.vs[VS_ADMIN]) < 0)) - { - vk.k = &k; - vk.v = &v; - vitastosave->add(vk); - } - else too_old++; - }); - if(too_old) mlog(ACLOG_VERBOSE, "omitted %d vitas from autosave (exceeding maxage of %d months)", too_old, vitamaxage); + serverwasnotempty = !pushvitasforsaving(false); } else stage++; break; @@ -4027,6 +4041,7 @@ void process(ENetPacket *packet, int sender, int chan) vi->action = new autoteamaction((vi->num1 = getint(p)) > 0); break; case SA_SHUFFLETEAMS: + pushvitasforsaving(true); vi->action = new shuffleteamaction(); break; case SA_FORCETEAM: @@ -4306,6 +4321,7 @@ void checkintermission() { // intermission starting here sg->interm = sg->gamemillis + 10000; demorecord_beginintermission(); + pushvitasforsaving(true); } sg->forceintermission = false; } diff --git a/source/src/serverfiles.h b/source/src/serverfiles.h index 29510494..f4cb5ad8 100644 --- a/source/src/serverfiles.h +++ b/source/src/serverfiles.h @@ -656,7 +656,7 @@ bool serverwritemap(const char *mapname, int mapsize, int cfgsize, int cfgsizegz } } else - { + { written = true; } } @@ -762,9 +762,9 @@ int readserverconfigsthread(void *data) { while(1) { - while(!recheckallserverconfigs) readserverconfigsthread_sem->wait(); // wait without using the cpu + while(!recheckallserverconfigs&&!vitastosave) readserverconfigsthread_sem->wait(); // wait without using the cpu - loopv(serverconfigs) serverconfigs[i]->trypreload(); + if(recheckallserverconfigs) loopv(serverconfigs) serverconfigs[i]->trypreload(); // special treatment for vita updates: read once and move out of the way if(!vitaupdatebuf && getfilesize(vitafilename_update) > 0)