3 #include <common/command/generic.qh>
4 #include <common/constants.qh>
5 #include <common/deathtypes/all.qh>
6 #include <common/debug.qh>
7 #include <common/mapinfo.qh>
8 #include <common/monsters/sv_monsters.qh>
9 #include <common/util.qh>
10 #include <common/vehicles/all.qh>
11 #include <common/weapons/_all.qh>
12 #include <lib/csqcmodel/sv_model.qh>
13 #include <lib/warpzone/common.qh>
14 #include <lib/warpzone/server.qh>
15 #include <server/anticheat.qh>
16 #include <server/bot/api.qh>
17 #include <server/command/common.qh>
18 #include <server/compat/quake3.qh>
19 #include <server/damage.qh>
20 #include <server/gamelog.qh>
21 #include <server/hook.qh>
22 #include <server/ipban.qh>
23 #include <server/mutators/_mod.qh>
24 #include <server/spawnpoints.qh>
25 #include <server/weapons/common.qh>
26 #include <server/weapons/csqcprojectile.qh>
27 #include <server/world.qh>
29 void CreatureFrame_hotliquids(entity this)
31 if (this.contents_damagetime >= time)
36 this.contents_damagetime = time + autocvar_g_balance_contents_damagerate;
38 if (this.flags & FL_PROJECTILE)
40 if (this.watertype == CONTENT_LAVA)
41 Damage (this, NULL, NULL, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_LAVA.m_id, DMG_NOWEP, this.origin, '0 0 0');
42 else if (this.watertype == CONTENT_SLIME)
43 Damage (this, NULL, NULL, autocvar_g_balance_contents_projectiledamage * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_SLIME.m_id, DMG_NOWEP, this.origin, '0 0 0');
47 if (STAT(FROZEN, this))
49 if (this.watertype == CONTENT_LAVA)
50 Damage(this, NULL, NULL, 10000, DEATH_LAVA.m_id, DMG_NOWEP, this.origin, '0 0 0');
51 else if (this.watertype == CONTENT_SLIME)
52 Damage(this, NULL, NULL, 10000, DEATH_SLIME.m_id, DMG_NOWEP, this.origin, '0 0 0');
54 else if (this.watertype == CONTENT_LAVA)
56 if (this.watersound_finished < time)
58 this.watersound_finished = time + 0.5;
59 sound (this, CH_PLAYER_SINGLE, SND_LAVA, VOL_BASE, ATTEN_NORM);
61 Damage (this, NULL, NULL, autocvar_g_balance_contents_playerdamage_lava * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_LAVA.m_id, DMG_NOWEP, this.origin, '0 0 0');
62 if(autocvar_g_balance_contents_playerdamage_lava_burn)
63 Fire_AddDamage(this, NULL, autocvar_g_balance_contents_playerdamage_lava_burn * this.waterlevel, autocvar_g_balance_contents_playerdamage_lava_burn_time * this.waterlevel, DEATH_LAVA.m_id);
65 else if (this.watertype == CONTENT_SLIME)
67 if (this.watersound_finished < time)
69 this.watersound_finished = time + 0.5;
70 sound (this, CH_PLAYER_SINGLE, SND_SLIME, VOL_BASE, ATTEN_NORM);
72 Damage (this, NULL, NULL, autocvar_g_balance_contents_playerdamage_slime * autocvar_g_balance_contents_damagerate * this.waterlevel, DEATH_SLIME.m_id, DMG_NOWEP, this.origin, '0 0 0');
77 void CreatureFrame_Liquids(entity this)
79 if (this.watertype <= CONTENT_WATER && this.waterlevel > 0) // workaround a retarded bug made by id software :P (yes, it's that old of a bug)
81 if (!(this.flags & FL_INWATER))
83 this.flags |= FL_INWATER;
84 this.contents_damagetime = 0;
87 CreatureFrame_hotliquids(this);
91 if (this.flags & FL_INWATER)
93 // play leave water sound
94 this.flags &= ~FL_INWATER;
95 this.contents_damagetime = 0;
100 void CreatureFrame_FallDamage(entity this)
102 if(IS_VEHICLE(this) || (this.flags & FL_PROJECTILE))
103 return; // vehicles and projectiles don't receive fall damage
104 if(!(this.velocity || this.oldvelocity))
105 return; // if the entity hasn't moved and isn't moving, then don't do anything
107 // check for falling damage
108 bool have_hook = false;
109 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
111 .entity weaponentity = weaponentities[slot];
112 if(this.(weaponentity).hook && this.(weaponentity).hook.state)
120 float dm; // dm is the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
121 if(autocvar_g_balance_falldamage_onlyvertical)
122 dm = fabs(this.oldvelocity.z) - vlen(this.velocity);
124 dm = vlen(this.oldvelocity) - vlen(this.velocity);
126 dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
128 dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
131 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
132 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODAMAGE))
133 Damage (this, NULL, NULL, dm, DEATH_FALL.m_id, DMG_NOWEP, this.origin, '0 0 0');
137 if(autocvar_g_maxspeed > 0 && vdist(this.velocity, >, autocvar_g_maxspeed))
138 Damage (this, NULL, NULL, 100000, DEATH_SHOOTING_STAR.m_id, DMG_NOWEP, this.origin, '0 0 0');
141 void CreatureFrame_All()
143 if(game_stopped || time < game_starttime)
146 IL_EACH(g_damagedbycontents, it.damagedbycontents,
148 if (it.move_movetype == MOVETYPE_NOCLIP) continue;
149 CreatureFrame_Liquids(it);
150 CreatureFrame_FallDamage(it);
151 it.oldvelocity = it.velocity;
155 void Pause_TryPause(bool ispaused)
158 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
159 if (PHYS_INPUT_BUTTON_CHAT(it) != ispaused) return;
166 void SV_PausedTic(float elapsedtime)
168 if (!server_is_dedicated) Pause_TryPause(false);
171 void dedicated_print(string input)
173 if (server_is_dedicated) print(input);
176 void make_safe_for_remove(entity e)
178 if (e.initialize_entity)
180 entity ent, prev = NULL;
181 for (ent = initialize_entity_first; ent; )
183 if ((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
185 //print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
186 // skip it in linked list
189 prev.initialize_entity_next = ent.initialize_entity_next;
190 ent = prev.initialize_entity_next;
194 initialize_entity_first = ent.initialize_entity_next;
195 ent = initialize_entity_first;
201 ent = ent.initialize_entity_next;
207 void remove_except_protected(entity e)
209 if(e.remove_except_protected_forbidden)
210 error("not allowed to remove this at this point");
214 void remove_unsafely(entity e)
216 if(e.classname == "spike")
217 error("Removing spikes is forbidden (crylink bug), please report");
221 void remove_safely(entity e)
223 make_safe_for_remove(e);
231 Called before each frame by the server
235 bool game_delay_last;
237 bool autocvar_sv_autopause = false;
238 void systems_update();
239 void sys_phys_update(entity this, float dt);
242 // TODO: if move is more than 50ms, split it into two moves (this matches QWSV behavior and the client prediction)
243 IL_EACH(g_players, IS_FAKE_CLIENT(it), sys_phys_update(it, frametime));
244 IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPreThink(it));
246 execute_next_frame();
247 if (autocvar_sv_autopause && !server_is_dedicated) Pause_TryPause(true);
249 delete_fn = remove_unsafely; // not during spawning!
250 serverprevtime = servertime;
252 serverframetime = frametime;
255 if(time > client_cefc_accumulatortime + 1)
257 float t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
260 FOREACH_CLIENT(true, {
261 if(IS_REAL_CLIENT(it))
267 "CEFC time: ", ftos(t * 1000), "ms; ",
268 "CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ",
269 "CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0')
271 client_cefc_accumulatortime = time;
272 client_cefc_accumulator = 0;
276 IL_EACH(g_projectiles, it.csqcprojectile_clientanimate, CSQCProjectile_Check(it));
278 if (RedirectionThink()) return;
280 UncustomizeEntitiesRun();
281 InitializeEntitiesRun();
283 WarpZone_StartFrame();
285 sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
286 if (sys_frametime <= 0) sys_frametime = 1.0 / 60.0; // somewhat safe fallback
288 if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
289 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
291 // detect when the pre-game countdown (if any) has ended and the game has started
292 bool game_delay = (time < game_starttime);
293 if (autocvar_sv_eventlog && game_delay_last && !game_delay)
294 GameLogEcho(":startdelay_ended");
295 game_delay_last = game_delay;
300 if (warmup_stage && !game_stopped && warmup_limit > 0 && time >= warmup_limit) {
306 anticheat_startframe();
307 MUTATOR_CALLHOOK(SV_StartFrame);
309 GlobalStats_updateglobal();
310 FOREACH_CLIENT(true, GlobalStats_update(it));
311 IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPostThink(it));
314 .vector originjitter;
315 .vector anglesjitter;
317 .string gametypefilter;
320 void SV_OnEntityPreSpawnFunction(entity this)
323 if (this.gametypefilter != "")
324 if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, this.gametypefilter))
329 if (this.cvarfilter != "" && !expr_evaluate(this.cvarfilter)) {
334 if (q3compat && DoesQ3ARemoveThisEntity(this)) {
339 set_movetype(this, this.movetype);
341 if (this.monster_attack) {
342 IL_PUSH(g_monster_targets, this);
345 // support special -1 and -2 angle from radiant
346 if (this.angles == '0 -1 0') {
347 this.angles = '-90 0 0';
348 } else if (this.angles == '0 -2 0') {
349 this.angles = '+90 0 0';
352 #define X(out, in) MACRO_BEGIN \
353 if (in != 0) { out = out + (random() * 2 - 1) * in; } \
355 X(this.origin.x, this.originjitter.x); X(this.origin.y, this.originjitter.y); X(this.origin.z, this.originjitter.z);
356 X(this.angles.x, this.anglesjitter.x); X(this.angles.y, this.anglesjitter.y); X(this.angles.z, this.anglesjitter.z);
357 X(this.angles.y, this.anglejitter);
360 if (MUTATOR_CALLHOOK(OnEntityPreSpawn, this)) {
366 string GetField_fullspawndata(entity e, string f, ...)
367 /* Retrieves the value of a map entity field from fullspawndata
368 * This bypasses field value changes made by the engine,
369 * eg string-to-float and escape sequence substitution.
371 * Avoids the need to declare fields just to read them once :)
373 * Returns the last instance of the field to match DarkPlaces behaviour.
374 * Path support: converts \ to / and tests the file if a third (bool, true) arg is passed.
375 * Returns string_null if the entity does not have the field, or the file is not in the VFS.
377 * FIXME: entities with //comments are not supported.
380 string v = string_null;
382 if (!e.fullspawndata)
384 LOG_WARNF("^1EDICT %s (classname %s) has no fullspawndata, engine lacks support?", ftos(num_for_edict(e)), e.classname);
388 if (strstrofs(e.fullspawndata, "//", 0) >= 0)
390 // tokenize and tokenize_console return early if "//" is reached,
391 // which can leave an odd number of tokens and break key:value pairing.
392 LOG_WARNF("^1EDICT %s fullspawndata contains unsupported //comment^7%s", ftos(num_for_edict(e)), e.fullspawndata);
396 //print(sprintf("%s(EDICT %s, FIELD %s)\n", __FUNC__, ftos(num_for_edict(e)), f));
397 //print(strcat("FULLSPAWNDATA:", e.fullspawndata, "\n"));
399 // tokenize treats \ as an escape, but tokenize_console returns the required literal
400 for (int t = tokenize_console(e.fullspawndata) - 3; t > 0; t -= 2)
402 //print(sprintf("\tTOKEN %s:%s\t%s:%s\n", ftos(t), ftos(t + 1), argv(t), argv(t + 1)));
410 //print(strcat("RESULT: ", v, "\n\n"));
412 if (v && ...(0, bool) == true)
414 v = strreplace("\\", "/", v);
415 if (whichpack(v) == "")
422 void WarpZone_PostInitialize_Callback()
424 // create waypoint links for warpzones
425 entity tracetest_ent = spawn();
426 setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
427 tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
428 //for(entity e = warpzone_first; e; e = e.warpzone_next)
429 for(entity e = NULL; (e = find(e, classname, "trigger_warpzone")); )
430 waypoint_spawnforteleporter_wz(e, tracetest_ent);
431 delete(tracetest_ent);
434 /** engine callback */
435 void URI_Get_Callback(float id, float status, string data)
437 if(url_URI_Get_Callback(id, status, data))
441 else if (id == URI_GET_DISCARD)
445 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
448 Curl_URI_Get_Callback(id, status, data);
450 else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
453 OnlineBanList_URI_Get_Callback(id, status, data);
455 else if (MUTATOR_CALLHOOK(URI_GetCallback, id, status, data))
457 // handled by a mutator
461 LOG_INFO("Received HTTP request data for an invalid id ", ftos(id), ".");
469 unused but required by the engine