2019-08-31 19:18:15 -07:00
|
|
|
/*
|
2020-04-07 05:46:23 -07:00
|
|
|
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
|
2019-08-31 19:18:15 -07:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
2019-01-18 20:50:25 -08:00
|
|
|
|
2019-08-31 19:18:15 -07:00
|
|
|
/* main is a qcc leftover */
|
2019-01-18 20:50:25 -08:00
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartFrame(void)
|
|
|
|
{
|
2020-10-22 07:30:37 -07:00
|
|
|
for (entity a = world; (a = findfloat(a, ::identity, 1));) {
|
2020-01-15 20:43:12 -08:00
|
|
|
CBaseEntity ent = (CBaseEntity)a;
|
|
|
|
ent.ParentUpdate();
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:12:09 -07:00
|
|
|
g_grMode.FrameStart();
|
2020-03-25 05:58:19 -07:00
|
|
|
Vote_Frame();
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
2019-08-31 19:18:15 -07:00
|
|
|
void ClientConnect(float csqc_active)
|
2019-01-18 20:50:25 -08:00
|
|
|
{
|
2020-11-23 12:39:40 -08:00
|
|
|
int playercount = 0;
|
|
|
|
|
2020-10-30 03:28:59 -07:00
|
|
|
/* make sure you never change the classname. ever. */
|
|
|
|
if (self.classname != "player") {
|
|
|
|
spawnfunc_player();
|
|
|
|
}
|
|
|
|
|
|
|
|
g_grMode.PlayerConnect((base_player)self);
|
2020-11-23 12:39:40 -08:00
|
|
|
for (entity a = world; (a = find(a, ::classname, "player"));)
|
|
|
|
playercount++;
|
|
|
|
|
|
|
|
/* we're the only one. respawn all entities */
|
|
|
|
if (playercount == 1) {
|
|
|
|
for (entity a = world; (a = findfloat(a, ::identity, 1));) {
|
|
|
|
CBaseEntity caw = (CBaseEntity)a;
|
|
|
|
caw.Respawn();
|
|
|
|
}
|
|
|
|
Nodes_Init();
|
|
|
|
}
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientDisconnect(void)
|
|
|
|
{
|
2020-10-30 03:28:59 -07:00
|
|
|
g_grMode.PlayerDisconnect((base_player)self);
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientKill(void)
|
|
|
|
{
|
2020-10-30 03:28:59 -07:00
|
|
|
g_grMode.PlayerKill((base_player)self);
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpectatorThink(void)
|
|
|
|
{
|
2019-01-20 18:00:14 -08:00
|
|
|
Game_SpectatorThink();
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
void SpectatorConnect(void)
|
|
|
|
{
|
2019-01-20 18:00:14 -08:00
|
|
|
Game_SpectatorConnect();
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
void SpectatorDisconnect(void)
|
|
|
|
{
|
2019-01-20 18:00:14 -08:00
|
|
|
Game_SpectatorDisconnect();
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PutClientInServer(void)
|
|
|
|
{
|
2020-10-30 03:28:59 -07:00
|
|
|
g_grMode.PlayerSpawn((base_player)self);
|
2020-09-07 18:29:10 -07:00
|
|
|
|
2020-12-22 22:53:43 -08:00
|
|
|
#ifdef BOT_INCLUDED
|
|
|
|
if (clienttype(self) == CLIENTTYPE_BOT) {
|
|
|
|
spawnfunc_bot();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-09-07 18:29:10 -07:00
|
|
|
/* activate all game_playerspawn entities */
|
2020-09-08 13:49:35 -07:00
|
|
|
for (entity a = world; (a = find(a, ::targetname, "game_playerspawn"));) {
|
|
|
|
CBaseTrigger t = (CBaseTrigger)a;
|
2020-09-07 18:29:10 -07:00
|
|
|
|
2020-09-08 13:49:35 -07:00
|
|
|
if (t.Trigger)
|
2020-09-07 18:29:10 -07:00
|
|
|
t.Trigger(self, TRIG_TOGGLE);
|
|
|
|
}
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerPreThink(void)
|
|
|
|
{
|
2020-12-25 22:27:34 -08:00
|
|
|
#ifdef BOT_INCLUDED
|
|
|
|
if (clienttype(self) == CLIENTTYPE_BOT) {
|
|
|
|
((bot)self).PreFrame();
|
|
|
|
}
|
|
|
|
#endif
|
2020-10-30 03:28:59 -07:00
|
|
|
g_grMode.PlayerPreFrame((base_player)self);
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerPostThink(void)
|
|
|
|
{
|
2020-12-25 22:27:34 -08:00
|
|
|
#ifdef BOT_INCLUDED
|
|
|
|
if (clienttype(self) == CLIENTTYPE_BOT) {
|
|
|
|
((bot)self).PostFrame();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-10-30 03:28:59 -07:00
|
|
|
g_grMode.PlayerPostFrame((base_player)self);
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetNewParms(void)
|
|
|
|
{
|
2020-04-19 03:02:05 -07:00
|
|
|
iprint("Setting New Level Parameters");
|
2020-04-13 18:12:09 -07:00
|
|
|
g_grMode.LevelNewParms();
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetChangeParms(void)
|
|
|
|
{
|
2020-04-19 03:02:05 -07:00
|
|
|
iprint("Setting Level-Change Parameters");
|
2020-10-30 03:28:59 -07:00
|
|
|
g_grMode.LevelChangeParms((base_player)self);
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
2019-03-01 14:35:28 -08:00
|
|
|
void SV_RunClientCommand(void)
|
2019-01-18 20:50:25 -08:00
|
|
|
{
|
2020-12-22 22:53:43 -08:00
|
|
|
#ifdef BOT_INCLUDED
|
|
|
|
if (time > 5.0)
|
|
|
|
if (clienttype(self) == CLIENTTYPE_BOT) {
|
|
|
|
((bot)self).RunAI();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-14 02:43:43 -07:00
|
|
|
if (!Plugin_RunClientCommand()) {
|
|
|
|
Game_RunClientCommand();
|
|
|
|
}
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SV_ParseClientCommand(string cmd)
|
|
|
|
{
|
2020-11-06 04:04:22 -08:00
|
|
|
string newcmd = Plugin_ParseClientCommand(cmd);
|
|
|
|
|
|
|
|
if (newcmd == __NULL__)
|
2019-08-14 02:43:43 -07:00
|
|
|
Game_ParseClientCommand(cmd);
|
2020-11-06 04:04:22 -08:00
|
|
|
else
|
|
|
|
Game_ParseClientCommand(newcmd);
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
|
2019-03-06 05:11:23 -08:00
|
|
|
void init(float prevprogs)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
2020-04-19 03:02:05 -07:00
|
|
|
iprint("Initializing Server-Module");
|
2020-04-13 18:12:09 -07:00
|
|
|
Plugin_Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_respawn(void)
|
|
|
|
{
|
2020-04-19 03:02:05 -07:00
|
|
|
iprint("Respawning Entities");
|
2020-04-14 07:19:25 -07:00
|
|
|
g_grMode.InitPostEnts();
|
|
|
|
|
2020-10-22 07:30:37 -07:00
|
|
|
for (entity a = world; (a = findfloat(a, ::identity, 1));) {
|
2020-04-13 18:12:09 -07:00
|
|
|
CBaseEntity ent = (CBaseEntity)a;
|
|
|
|
ent.Respawn();
|
|
|
|
}
|
|
|
|
remove(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
void initents(void)
|
2019-01-18 20:50:25 -08:00
|
|
|
{
|
2020-04-19 03:02:05 -07:00
|
|
|
iprint("Initializing Entities");
|
|
|
|
|
2020-07-09 01:42:34 -07:00
|
|
|
/* sound shader init */
|
2020-04-12 10:40:09 -07:00
|
|
|
Sound_Init();
|
2019-01-18 20:50:25 -08:00
|
|
|
|
2020-12-12 15:56:11 -08:00
|
|
|
if (serverkeyfloat("*bspversion") == BSPVER_HL) {
|
2020-07-09 01:42:34 -07:00
|
|
|
/* load materials.txt because someone thought this was the best idea */
|
2020-05-07 22:44:40 -07:00
|
|
|
filestream fileMaterial = fopen("sound/materials.txt", FILE_READ);
|
|
|
|
hashMaterials = __NULL__;
|
|
|
|
hashMaterials = hash_createtab(2, HASH_ADD);
|
|
|
|
|
|
|
|
if (fileMaterial >= 0) {
|
|
|
|
string sTemp;
|
|
|
|
while ((sTemp = fgets(fileMaterial))) {
|
2020-07-09 01:42:34 -07:00
|
|
|
/* tokenize and just parse this stuff in */
|
2020-05-07 22:44:40 -07:00
|
|
|
if (tokenize_console(sTemp) == 2) {
|
|
|
|
hash_add(hashMaterials, strtolower(argv(1)), str2chr(argv(0), 0));
|
|
|
|
}
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
2020-05-07 22:44:40 -07:00
|
|
|
fclose(fileMaterial);
|
|
|
|
} else {
|
|
|
|
print("Failed to load sound/materials.txt!\n");
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 18:00:14 -08:00
|
|
|
PMove_Init();
|
2019-03-06 05:11:23 -08:00
|
|
|
|
2020-07-09 01:42:34 -07:00
|
|
|
/* TODO: turn these effects into sound shaders */
|
2019-03-01 14:35:28 -08:00
|
|
|
precache_sound("weapons/explode3.wav");
|
|
|
|
precache_sound("weapons/explode4.wav");
|
|
|
|
precache_sound("weapons/explode5.wav");
|
|
|
|
precache_sound("debris/glass1.wav");
|
|
|
|
precache_sound("debris/glass2.wav");
|
|
|
|
precache_sound("debris/glass3.wav");
|
|
|
|
precache_sound("debris/wood1.wav");
|
|
|
|
precache_sound("debris/wood2.wav");
|
|
|
|
precache_sound("debris/wood3.wav");
|
|
|
|
precache_sound("debris/metal1.wav");
|
|
|
|
precache_sound("debris/metal2.wav");
|
|
|
|
precache_sound("debris/metal3.wav");
|
|
|
|
precache_sound("debris/flesh1.wav");
|
|
|
|
precache_sound("debris/flesh2.wav");
|
|
|
|
precache_sound("debris/flesh3.wav");
|
|
|
|
precache_sound("debris/flesh5.wav");
|
|
|
|
precache_sound("debris/flesh6.wav");
|
|
|
|
precache_sound("debris/flesh7.wav");
|
|
|
|
precache_sound("debris/concrete1.wav");
|
|
|
|
precache_sound("debris/concrete2.wav");
|
|
|
|
precache_sound("debris/concrete3.wav");
|
|
|
|
|
2020-10-30 05:29:37 -07:00
|
|
|
Footsteps_Init();
|
2020-04-03 03:12:11 -07:00
|
|
|
|
2019-08-20 08:53:57 -07:00
|
|
|
precache_sound("player/pl_fallpain3.wav");
|
2019-03-01 14:35:28 -08:00
|
|
|
precache_sound("items/9mmclip1.wav");
|
|
|
|
precache_sound("items/gunpickup2.wav");
|
|
|
|
precache_sound("common/wpn_select.wav");
|
|
|
|
precache_sound("common/wpn_denyselect.wav");
|
|
|
|
precache_sound("player/sprayer.wav");
|
|
|
|
precache_sound("items/flashlight1.wav");
|
2019-09-06 23:39:28 -07:00
|
|
|
precache_sound("common/null.wav");
|
|
|
|
|
2020-04-13 18:12:09 -07:00
|
|
|
Game_InitRules();
|
2019-03-06 05:11:23 -08:00
|
|
|
Game_Worldspawn();
|
|
|
|
Decals_Init();
|
2020-03-26 03:24:33 -07:00
|
|
|
Sentences_Init();
|
|
|
|
|
2020-07-09 01:42:34 -07:00
|
|
|
/* TODO: Make sure every entity calls Respawn inside the constructor, then
|
|
|
|
* remove this */
|
2020-03-08 01:59:46 -08:00
|
|
|
entity respawntimer = spawn();
|
|
|
|
respawntimer.think = init_respawn;
|
|
|
|
respawntimer.nextthink = time + 0.1f;
|
2020-09-27 05:25:10 -07:00
|
|
|
|
|
|
|
/* menu background lock */
|
|
|
|
if (cvar("sv_background") == 1) {
|
|
|
|
forceinfokey(world, "background", "1");
|
|
|
|
localcmd("sv_background 0\n");
|
|
|
|
} else {
|
|
|
|
forceinfokey(world, "background", "0");
|
|
|
|
}
|
2019-03-06 05:11:23 -08:00
|
|
|
}
|
2019-03-01 14:35:28 -08:00
|
|
|
|
2020-10-28 00:16:50 -07:00
|
|
|
var int autocvar_sv_levelexec = 1;
|
2019-03-06 05:11:23 -08:00
|
|
|
void worldspawn(void)
|
|
|
|
{
|
2020-04-19 03:02:05 -07:00
|
|
|
iprint("Initializing World");
|
2019-03-01 14:35:28 -08:00
|
|
|
lightstyle(0, "m");
|
|
|
|
lightstyle(1, "mmnmmommommnonmmonqnmmo");
|
|
|
|
lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
|
|
|
|
lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
|
|
|
|
lightstyle(4, "mamamamamama");
|
2020-10-18 06:19:56 -07:00
|
|
|
lightstyle(5, "jklmnopqrstuvwxyzyxwvutsrqponmlkj");
|
2019-03-01 14:35:28 -08:00
|
|
|
lightstyle(6, "nmonqnmomnmomomno");
|
|
|
|
lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
|
|
|
|
lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
|
|
|
|
lightstyle(9, "aaaaaaaazzzzzzzz");
|
|
|
|
lightstyle(10, "mmamammmmammamamaaamammma");
|
|
|
|
lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
|
2020-07-24 16:58:12 -07:00
|
|
|
Skill_Init();
|
2020-10-28 00:16:50 -07:00
|
|
|
|
|
|
|
if (autocvar_sv_levelexec)
|
|
|
|
readcmd(sprintf("exec maps/%s.cfg\n", mapname));
|
2019-01-18 20:50:25 -08:00
|
|
|
}
|
2019-01-20 18:00:14 -08:00
|
|
|
|
|
|
|
float ConsoleCmd(string cmd)
|
|
|
|
{
|
2020-12-22 22:53:43 -08:00
|
|
|
player pl;
|
|
|
|
|
|
|
|
/* some sv commands can only be executed by a player in-world */
|
|
|
|
if ( !self ) {
|
|
|
|
for ( other = world; ( other = find( other, classname, "player" ) ); ) {
|
|
|
|
if ( clienttype( other ) == CLIENTTYPE_REAL ) {
|
|
|
|
self = other;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pl = (player)self;
|
2020-10-06 05:42:46 -07:00
|
|
|
|
|
|
|
/* give the game-mode a chance to override us */
|
|
|
|
if (g_grMode.ConsoleCommand(pl, cmd) == TRUE)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* time to handle commands that apply to all games */
|
|
|
|
tokenize(cmd);
|
|
|
|
switch (argv(0)) {
|
|
|
|
case "trigger_ent":
|
|
|
|
string targ;
|
|
|
|
targ = argv(1);
|
|
|
|
|
|
|
|
if (targ)
|
|
|
|
for (entity a = world; (a = find(a, ::targetname, argv(1)));) {
|
|
|
|
CBaseTrigger t = (CBaseTrigger)a;
|
|
|
|
|
|
|
|
if (t.Trigger)
|
|
|
|
t.Trigger(self, TRIG_TOGGLE);
|
|
|
|
}
|
|
|
|
break;
|
2020-12-22 22:53:43 -08:00
|
|
|
#ifdef BOT_INCLUDED
|
2020-12-25 22:27:34 -08:00
|
|
|
case "way":
|
|
|
|
Way_Cmd();
|
2020-12-22 22:53:43 -08:00
|
|
|
break;
|
|
|
|
#endif
|
2020-10-06 05:42:46 -07:00
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2019-01-20 18:00:14 -08:00
|
|
|
}
|
2020-09-27 05:25:10 -07:00
|
|
|
|
|
|
|
float SV_ShouldPause(float newstatus)
|
|
|
|
{
|
2021-01-06 03:38:35 -08:00
|
|
|
if (serverkeyfloat("background") == 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (cvar("sv_playerslots") > 1)
|
2020-09-27 05:25:10 -07:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return newstatus;
|
|
|
|
}
|