X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fmain.qc;h=8a2da54aa4a721c2312017b0bd30ae52bd72e561;hb=e9a12973bad78d9c87dab26cdd2e6fd23c0578b0;hp=3859ffa6f7e0b750452b5098db1fcf1232fa4bc2;hpb=dc02e4d78fb0e67b47a0c1e150b4c18c0711b8bf;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/main.qc b/qcsrc/server/main.qc index 3859ffa6f..8a2da54aa 100644 --- a/qcsrc/server/main.qc +++ b/qcsrc/server/main.qc @@ -1,35 +1,64 @@ #include "main.qh" -#include "anticheat.qh" -#include "hook.qh" -#include "damage.qh" -#include "world.qh" -#include "spawnpoints.qh" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include - -#include "bot/api.qh" - -#include "command/common.qh" - +#include +#include #include -#include "weapons/csqcprojectile.qh" +#include #include -#include - -#include "../common/constants.qh" -#include "../common/deathtypes/all.qh" -#include "../common/debug.qh" -#include "../common/mapinfo.qh" -#include "../common/util.qh" +#include +#include -#include "../common/vehicles/all.qh" -#include -#include - -#include "../lib/csqcmodel/sv_model.qh" - -#include "../lib/warpzone/common.qh" -#include "../lib/warpzone/server.qh" +void dropclient_do(entity this) +{ + if (this.owner) + dropclient(this.owner); + delete(this); +} +/** + * Schedules dropclient for a player and returns true; + * if dropclient is already scheduled (for that player) it does nothing and returns false. + * + * NOTE: this function exists only to allow sending a message to the kicked player with + * Send_Notification, which doesn't work if called together with dropclient + */ +bool dropclient_schedule(entity this) +{ + bool scheduled = false; + FOREACH_ENTITY_CLASS("dropclient_handler", true, + { + if(it.owner == this) + { + scheduled = true; + break; // can't use return here, compiler shows a warning + } + }); + if (scheduled) + return false; + + entity e = new_pure(dropclient_handler); + setthink(e, dropclient_do); + e.owner = this; + e.nextthink = time + 0.1; + return true; +} void CreatureFrame_hotliquids(entity this) { @@ -157,20 +186,35 @@ void CreatureFrame_All() }); } -void Pause_TryPause(bool ispaused) +void Pause_TryPause_Dedicated(entity this) { - int n = 0; - FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { - if (PHYS_INPUT_BUTTON_CHAT(it) != ispaused) return; + if (player_count == 0) + setpause(1); +} + +void Pause_TryPause() +{ + int n = 0, p = 0; + FOREACH_CLIENT(IS_REAL_CLIENT(it), { + if (PHYS_INPUT_BUTTON_CHAT(it)) ++p; ++n; }); if (!n) return; - setpause(ispaused); + if (n == p) + setpause(1); + else + setpause(0); } void SV_PausedTic(float elapsedtime) { - if (!server_is_dedicated) Pause_TryPause(false); + if (!server_is_dedicated) + { + if (autocvar_sv_autopause) + Pause_TryPause(); + else + setpause(0); + } } void dedicated_print(string input) @@ -239,7 +283,6 @@ Called before each frame by the server bool game_delay_last; -bool autocvar_sv_autopause = false; void systems_update(); void sys_phys_update(entity this, float dt); void StartFrame() @@ -249,7 +292,7 @@ void StartFrame() IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPreThink(it)); execute_next_frame(); - if (autocvar_sv_autopause && !server_is_dedicated) Pause_TryPause(true); + if (autocvar_sv_autopause && !server_is_dedicated) Pause_TryPause(); delete_fn = remove_unsafely; // not during spawning! serverprevtime = servertime; @@ -302,8 +345,8 @@ void StartFrame() CreatureFrame_All(); CheckRules_World(); - if (warmup_stage && !game_stopped && warmup_limit > 0 && time >= warmup_limit) { - ReadyRestart(); + if (warmup_stage && !game_stopped && warmup_limit > 0 && time - game_starttime >= warmup_limit) { + ReadyRestart(true); return; } @@ -368,6 +411,62 @@ void SV_OnEntityPreSpawnFunction(entity this) } } +string GetField_fullspawndata(entity e, string f, ...) +/* Retrieves the value of a map entity field from fullspawndata + * This bypasses field value changes made by the engine, + * eg string-to-float and escape sequence substitution. + * + * Avoids the need to declare fields just to read them once :) + * + * Returns the last instance of the field to match DarkPlaces behaviour. + * Path support: converts \ to / and tests the file if a third (bool, true) arg is passed. + * Returns string_null if the entity does not have the field, or the file is not in the VFS. + * + * FIXME: entities with //comments are not supported. + */ +{ + string v = string_null; + + if (!e.fullspawndata) + { + //LOG_WARNF("^1EDICT %s (classname %s) has no fullspawndata, engine lacks support?", ftos(num_for_edict(e)), e.classname); + return v; + } + + if (strstrofs(e.fullspawndata, "//", 0) >= 0) + { + // tokenize and tokenize_console return early if "//" is reached, + // which can leave an odd number of tokens and break key:value pairing. + LOG_WARNF("^1EDICT %s fullspawndata contains unsupported //comment^7%s", ftos(num_for_edict(e)), e.fullspawndata); + return v; + } + + //print(sprintf("%s(EDICT %s, FIELD %s)\n", __FUNC__, ftos(num_for_edict(e)), f)); + //print(strcat("FULLSPAWNDATA:", e.fullspawndata, "\n")); + + // tokenize treats \ as an escape, but tokenize_console returns the required literal + for (int t = tokenize_console(e.fullspawndata) - 3; t > 0; t -= 2) + { + //print(sprintf("\tTOKEN %s:%s\t%s:%s\n", ftos(t), ftos(t + 1), argv(t), argv(t + 1))); + if (argv(t) == f) + { + v = argv(t + 1); + break; + } + } + + //print(strcat("RESULT: ", v, "\n\n")); + + if (v && ...(0, bool) == true) + { + v = strreplace("\\", "/", v); + if (whichpack(v) == "") + return string_null; + } + + return v; +} + void WarpZone_PostInitialize_Callback() { // create waypoint links for warpzones @@ -380,6 +479,37 @@ void WarpZone_PostInitialize_Callback() delete(tracetest_ent); } +/** engine callback */ +void URI_Get_Callback(float id, float status, string data) +{ + if(url_URI_Get_Callback(id, status, data)) + { + // handled + } + else if (id == URI_GET_DISCARD) + { + // discard + } + else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END) + { + // sv_cmd curl + Curl_URI_Get_Callback(id, status, data); + } + else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END) + { + // online ban list + OnlineBanList_URI_Get_Callback(id, status, data); + } + else if (MUTATOR_CALLHOOK(URI_GetCallback, id, status, data)) + { + // handled by a mutator + } + else + { + LOG_INFO("Received HTTP request data for an invalid id ", ftos(id), "."); + } +} + /* ================== main