3 #include "anticheat.qh"
7 #include "spawnpoints.qh"
8 #include <server/ipban.qh>
9 #include <server/gamelog.qh>
13 #include "command/common.qh"
15 #include <server/mutators/_mod.qh>
16 #include "weapons/csqcprojectile.qh"
17 #include <server/weapons/common.qh>
18 #include <server/compat/quake3.qh>
20 #include <common/constants.qh>
21 #include <common/command/generic.qh>
22 #include <common/deathtypes/all.qh>
23 #include <common/debug.qh>
24 #include <common/mapinfo.qh>
25 #include <common/util.qh>
27 #include <common/vehicles/all.qh>
28 #include <common/monsters/sv_monsters.qh>
29 #include <common/weapons/_all.qh>
31 #include <lib/csqcmodel/sv_model.qh>
33 #include <lib/warpzone/common.qh>
34 #include <lib/warpzone/server.qh>
36 void CreatureFrame_hotliquids(entity this)
38 if (this.contents_damagetime >= time)
43 this.contents_damagetime = time + autocvar_g_balance_contents_damagerate;
45 if (this.flags & FL_PROJECTILE)
47 if (this.watertype == CONTENT_LAVA)
48 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');
49 else if (this.watertype == CONTENT_SLIME)
50 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');
54 if (STAT(FROZEN, this))
56 if (this.watertype == CONTENT_LAVA)
57 Damage(this, NULL, NULL, 10000, DEATH_LAVA.m_id, DMG_NOWEP, this.origin, '0 0 0');
58 else if (this.watertype == CONTENT_SLIME)
59 Damage(this, NULL, NULL, 10000, DEATH_SLIME.m_id, DMG_NOWEP, this.origin, '0 0 0');
61 else if (this.watertype == CONTENT_LAVA)
63 if (this.watersound_finished < time)
65 this.watersound_finished = time + 0.5;
66 sound (this, CH_PLAYER_SINGLE, SND_LAVA, VOL_BASE, ATTEN_NORM);
68 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');
69 if(autocvar_g_balance_contents_playerdamage_lava_burn)
70 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);
72 else if (this.watertype == CONTENT_SLIME)
74 if (this.watersound_finished < time)
76 this.watersound_finished = time + 0.5;
77 sound (this, CH_PLAYER_SINGLE, SND_SLIME, VOL_BASE, ATTEN_NORM);
79 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');
84 void CreatureFrame_Liquids(entity this)
86 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)
88 if (!(this.flags & FL_INWATER))
90 this.flags |= FL_INWATER;
91 this.contents_damagetime = 0;
94 CreatureFrame_hotliquids(this);
98 if (this.flags & FL_INWATER)
100 // play leave water sound
101 this.flags &= ~FL_INWATER;
102 this.contents_damagetime = 0;
107 void CreatureFrame_FallDamage(entity this)
109 if(IS_VEHICLE(this) || (this.flags & FL_PROJECTILE))
110 return; // vehicles and projectiles don't receive fall damage
111 if(!(this.velocity || this.oldvelocity))
112 return; // if the entity hasn't moved and isn't moving, then don't do anything
114 // check for falling damage
115 bool have_hook = false;
116 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
118 .entity weaponentity = weaponentities[slot];
119 if(this.(weaponentity).hook && this.(weaponentity).hook.state)
127 float dm; // dm is the velocity DECREASE. Velocity INCREASE should never cause a sound or any damage.
128 if(autocvar_g_balance_falldamage_onlyvertical)
129 dm = fabs(this.oldvelocity.z) - vlen(this.velocity);
131 dm = vlen(this.oldvelocity) - vlen(this.velocity);
133 dm = (dm - autocvar_g_balance_falldamage_deadminspeed) * autocvar_g_balance_falldamage_factor;
135 dm = min((dm - autocvar_g_balance_falldamage_minspeed) * autocvar_g_balance_falldamage_factor, autocvar_g_balance_falldamage_maxdamage);
138 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
139 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODAMAGE))
140 Damage (this, NULL, NULL, dm, DEATH_FALL.m_id, DMG_NOWEP, this.origin, '0 0 0');
144 if(autocvar_g_maxspeed > 0 && vdist(this.velocity, >, autocvar_g_maxspeed))
145 Damage (this, NULL, NULL, 100000, DEATH_SHOOTING_STAR.m_id, DMG_NOWEP, this.origin, '0 0 0');
148 void CreatureFrame_All()
150 if(game_stopped || time < game_starttime)
153 IL_EACH(g_damagedbycontents, it.damagedbycontents,
155 if (it.move_movetype == MOVETYPE_NOCLIP) continue;
156 CreatureFrame_Liquids(it);
157 CreatureFrame_FallDamage(it);
158 it.oldvelocity = it.velocity;
162 void Pause_TryPause(bool ispaused)
165 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
166 if (PHYS_INPUT_BUTTON_CHAT(it) != ispaused) return;
173 void SV_PausedTic(float elapsedtime)
175 if (!server_is_dedicated) Pause_TryPause(false);
178 void dedicated_print(string input)
180 if (server_is_dedicated) print(input);
183 void make_safe_for_remove(entity e)
185 if (e.initialize_entity)
187 entity ent, prev = NULL;
188 for (ent = initialize_entity_first; ent; )
190 if ((ent == e) || ((ent.classname == "initialize_entity") && (ent.enemy == e)))
192 //print("make_safe_for_remove: getting rid of initializer ", etos(ent), "\n");
193 // skip it in linked list
196 prev.initialize_entity_next = ent.initialize_entity_next;
197 ent = prev.initialize_entity_next;
201 initialize_entity_first = ent.initialize_entity_next;
202 ent = initialize_entity_first;
208 ent = ent.initialize_entity_next;
214 void remove_except_protected(entity e)
216 if(e.remove_except_protected_forbidden)
217 error("not allowed to remove this at this point");
221 void remove_unsafely(entity e)
223 if(e.classname == "spike")
224 error("Removing spikes is forbidden (crylink bug), please report");
228 void remove_safely(entity e)
230 make_safe_for_remove(e);
238 Called before each frame by the server
242 bool game_delay_last;
244 bool autocvar_sv_autopause = false;
245 void systems_update();
246 void sys_phys_update(entity this, float dt);
249 // TODO: if move is more than 50ms, split it into two moves (this matches QWSV behavior and the client prediction)
250 IL_EACH(g_players, IS_FAKE_CLIENT(it), sys_phys_update(it, frametime));
251 IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPreThink(it));
253 execute_next_frame();
254 if (autocvar_sv_autopause && !server_is_dedicated) Pause_TryPause(true);
256 delete_fn = remove_unsafely; // not during spawning!
257 serverprevtime = servertime;
259 serverframetime = frametime;
262 if(time > client_cefc_accumulatortime + 1)
264 float t = client_cefc_accumulator / (time - client_cefc_accumulatortime);
267 FOREACH_CLIENT(true, {
268 if(IS_REAL_CLIENT(it))
274 "CEFC time: ", ftos(t * 1000), "ms; ",
275 "CEFC calls per second: ", ftos(c_seeing * (c_seen - 1) / t), "; ",
276 "CEFC 100% load at: ", ftos(solve_quadratic(t, -t, -1) * '0 1 0')
278 client_cefc_accumulatortime = time;
279 client_cefc_accumulator = 0;
283 IL_EACH(g_projectiles, it.csqcprojectile_clientanimate, CSQCProjectile_Check(it));
285 if (RedirectionThink()) return;
287 UncustomizeEntitiesRun();
288 InitializeEntitiesRun();
290 WarpZone_StartFrame();
292 sys_frametime = autocvar_sys_ticrate * autocvar_slowmo;
293 if (sys_frametime <= 0) sys_frametime = 1.0 / 60.0; // somewhat safe fallback
295 if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
296 orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
298 // detect when the pre-game countdown (if any) has ended and the game has started
299 bool game_delay = (time < game_starttime);
300 if (autocvar_sv_eventlog && game_delay_last && !game_delay)
301 GameLogEcho(":startdelay_ended");
302 game_delay_last = game_delay;
307 if (warmup_stage && !game_stopped && warmup_limit > 0 && time >= warmup_limit) {
313 anticheat_startframe();
314 MUTATOR_CALLHOOK(SV_StartFrame);
316 GlobalStats_updateglobal();
317 FOREACH_CLIENT(true, GlobalStats_update(it));
318 IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPostThink(it));
321 .vector originjitter;
322 .vector anglesjitter;
324 .string gametypefilter;
327 void SV_OnEntityPreSpawnFunction(entity this)
330 if (this.gametypefilter != "")
331 if (!isGametypeInFilter(MapInfo_LoadedGametype, teamplay, have_team_spawns, this.gametypefilter))
336 if (this.cvarfilter != "" && !expr_evaluate(this.cvarfilter)) {
341 if (DoesQ3ARemoveThisEntity(this)) {
346 set_movetype(this, this.movetype);
348 if (this.monster_attack) {
349 IL_PUSH(g_monster_targets, this);
352 // support special -1 and -2 angle from radiant
353 if (this.angles == '0 -1 0') {
354 this.angles = '-90 0 0';
355 } else if (this.angles == '0 -2 0') {
356 this.angles = '+90 0 0';
359 #define X(out, in) MACRO_BEGIN \
360 if (in != 0) { out = out + (random() * 2 - 1) * in; } \
362 X(this.origin.x, this.originjitter.x); X(this.origin.y, this.originjitter.y); X(this.origin.z, this.originjitter.z);
363 X(this.angles.x, this.anglesjitter.x); X(this.angles.y, this.anglesjitter.y); X(this.angles.z, this.anglesjitter.z);
364 X(this.angles.y, this.anglejitter);
367 if (MUTATOR_CALLHOOK(OnEntityPreSpawn, this)) {
373 void WarpZone_PostInitialize_Callback()
375 // create waypoint links for warpzones
376 entity tracetest_ent = spawn();
377 setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
378 tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
379 //for(entity e = warpzone_first; e; e = e.warpzone_next)
380 for(entity e = NULL; (e = find(e, classname, "trigger_warpzone")); )
381 waypoint_spawnforteleporter_wz(e, tracetest_ent);
382 delete(tracetest_ent);
385 /** engine callback */
386 void URI_Get_Callback(float id, float status, string data)
388 if(url_URI_Get_Callback(id, status, data))
392 else if (id == URI_GET_DISCARD)
396 else if (id >= URI_GET_CURL && id <= URI_GET_CURL_END)
399 Curl_URI_Get_Callback(id, status, data);
401 else if (id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
404 OnlineBanList_URI_Get_Callback(id, status, data);
406 else if (MUTATOR_CALLHOOK(URI_GetCallback, id, status, data))
408 // handled by a mutator
412 LOG_INFO("Received HTTP request data for an invalid id ", ftos(id), ".");
420 unused but required by the engine