1 // --------------------------------------------------------------------------
\r
2 // BEGIN REQUIRED CSQC FUNCTIONS
\r
5 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
7 void() menu_show_error =
\r
9 drawstring('0 200 0', "ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!", '8 8 0', '1 0 0', 1, 0);
\r
12 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
\r
13 // Useful for precaching things
\r
15 void() menu_sub_null =
\r
19 // let's make this a general data buffer...
\r
23 float __engine_check;
\r
26 string config_get(string key, string defaultvalue)
\r
29 s = db_get(configdb, strcat("/s/", key));
\r
31 return defaultvalue;
\r
33 return db_get(configdb, strcat("/v/", key));
\r
36 void CSQC_Init(void)
\r
40 __engine_check = checkextension("DP_SV_WRITEPICTURE");
\r
43 print("^3Your engine build is outdated\n^3This Server uses a newer QC VM. Please update!\n");
\r
44 localcmd("\ndisconnect\n");
\r
53 configdb = db_create();
\r
54 compressShortVector_init();
\r
57 menu_visible = FALSE;
\r
58 menu_show = menu_show_error;
\r
59 menu_action = menu_sub_null;
\r
61 maxclients = 255; // we later get the real maxclients to speed up stuff
\r
63 // localcmd("alias order \"cmd order $*\""); enable if ctf-command thingy is used
\r
64 //registercmd("ctf_menu");
\r
65 registercmd("ons_map");
\r
66 //registercmd("menu_action");
\r
67 registercmd("sbar_columns_set");
\r
68 registercmd("sbar_columns_help");
\r
70 registercmd("+button3");
\r
71 registercmd("-button3");
\r
72 registercmd("+button4");
\r
73 registercmd("-button4");
\r
75 registercvar("sbar_usecsqc", "1");
\r
76 registercvar("sbar_columns", "default", CVAR_SAVE);
\r
82 // sbar_fields uses strunzone on the titles!
\r
83 for(i = 0; i < MAX_SBAR_FIELDS; ++i)
\r
84 sbar_title[i] = strzone("(null)");
\r
88 teams = Sort_Spawn();
\r
89 players = Sort_Spawn();
\r
91 GetTeam(COLOR_SPECTATOR, true); // add specs first
\r
94 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
\r
95 void CSQC_Shutdown(void)
\r
106 db_close(configdb);
\r
109 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
\r
110 cvar_set(e.netname, e.message);
\r
114 float SetTeam(entity o, float Team)
\r
117 if(Team == -1) // leave
\r
121 //print("(DISCONNECT) leave team ", ftos(o.team), "\n");
\r
122 tm = GetTeam(o.team, false);
\r
132 //print("(CONNECT) enter team ", ftos(o.team), "\n");
\r
134 tm = GetTeam(Team, true);
\r
139 else if(Team != o.team)
\r
141 //print("(CHANGE) leave team ", ftos(o.team), "\n");
\r
142 tm = GetTeam(o.team, false);
\r
145 //print("(CHANGE) enter team ", ftos(o.team), "\n");
\r
146 tm = GetTeam(Team, true);
\r
154 void Playerchecker_Think()
\r
157 for(i = 0; i < maxclients; ++i)
\r
159 if(getplayerkey(i, "name") == "")
\r
161 if(playerslots[i].sort_prev)
\r
163 //print("playerchecker: KILL KILL KILL\n");
\r
164 // player disconnected
\r
165 SetTeam(playerslots[i], -1);
\r
166 RemovePlayer(playerslots[i]);
\r
167 playerslots[i].sort_prev = world;
\r
168 playerslots[i].gotscores = 0;
\r
173 if not(playerslots[i].sort_prev)
\r
175 //print("playerchecker: SPAWN SPAWN SPAWN\n");
\r
176 // player connected
\r
177 if not(playerslots[i])
\r
178 playerslots[i] = spawn();
\r
179 playerslots[i].sv_entnum = i;
\r
180 playerslots[i].gotscores = 0;
\r
181 SetTeam(playerslots[i], COLOR_SPECTATOR);
\r
182 RegisterPlayer(playerslots[i]);
\r
183 Sbar_UpdatePlayerPos(playerslots[i]);
\r
187 self.nextthink = time + 0.2;
\r
190 void PostInit(void)
\r
192 print(strcat("PostInit\n maxclients = ", ftos(maxclients), "\n"));
\r
193 localcmd(strcat("\nsbar_columns_set ", cvar_string("sbar_columns"), ";\n"));
\r
195 entity playerchecker;
\r
196 playerchecker = spawn();
\r
197 playerchecker.think = Playerchecker_Think;
\r
198 playerchecker.nextthink = time + 0.2;
\r
203 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function
\r
204 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
\r
206 void Cmd_Sbar_SetFields(float);
\r
207 void Cmd_Sbar_Help(float);
\r
208 float CSQC_ConsoleCommand(string strMessage)
\r
212 //argc = tokenize(strMessage);
\r
213 argc = tokenizebyseparator(strMessage, " ");
\r
216 local string strCmd;
\r
219 if(strCmd == "+button4") { // zoom
\r
222 } else if(strCmd == "-button4") { // zoom
\r
225 } else if(strCmd == "+button3") { // secondary
\r
226 button_attack2 = 1;
\r
228 } else if(strCmd == "-button3") { // secondary
\r
229 button_attack2 = 0;
\r
231 } else if(strCmd == "ons_map") {
\r
234 } else if(strCmd == "sbar_columns_set") {
\r
235 Cmd_Sbar_SetFields(argc);
\r
237 } else if(strCmd == "sbar_columns_help") {
\r
238 Cmd_Sbar_Help(argc);
\r
240 } else if(strCmd == "+showscores") {
\r
241 sb_showscores = true;
\r
243 } else if(strCmd == "-showscores") {
\r
244 sb_showscores = false;
\r
251 float GameCommand(string msg)
\r
254 argc = tokenize(msg);
\r
257 if(cmd == "mv_download") {
\r
258 Cmd_MapVote_MapDownload(argc);
\r
261 else if(cmd == "settemp") {
\r
263 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
\r
264 if(e.netname == argv(1))
\r
267 e.classname = "saved_cvar_value";
\r
268 e.netname = strzone(argv(1));
\r
269 e.message = strzone(cvar_string(argv(1)));
\r
271 cvar_set(argv(1), argv(2));
\r
277 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
\r
278 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
\r
279 // All keys are in ascii.
\r
280 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
\r
281 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
\r
282 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
\r
283 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
\r
285 local float bSkipKey;
\r
289 if(menu_action(bInputType, nPrimary, nSecondary))
\r
294 // END REQUIRED CSQC FUNCTIONS
\r
295 // --------------------------------------------------------------------------
\r
297 // --------------------------------------------------------------------------
\r
298 // BEGIN OPTIONAL CSQC FUNCTIONS
\r
304 self.origin_x = ReadCoord();
\r
305 self.origin_y = ReadCoord();
\r
306 self.angles_y = ReadCoord();
\r
307 self.origin_z = self.angles_x = self.angles_z = 0;
\r
309 for(gps = gps_start; gps; gps = gps.chain)
\r
316 self.chain = gps_start;
\r
321 void Ent_RemoveONS()
\r
323 if(gps_start == self)
\r
324 gps_start = self.chain;
\r
330 while(ent.chain != self && ent.chain != world)
\r
332 if(ent.chain == self)
\r
333 ent.chain = self.chain;
\r
338 void Ent_ReadPlayerScore()
\r
344 // damnit -.- don't want to go change every single .sv_entnum in sbar.qc AGAIN
\r
345 // (no I've never heard of M-x replace-string, sed, or anything like that)
\r
346 isNew = !self.owner; // workaround for DP bug
\r
349 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
350 if(!isNew && n != self.sv_entnum)
\r
352 print("A CSQC entity changed its owner!\n");
\r
355 self.enttype = ENT_CLIENT_SCORES;
\r
359 self.sv_entnum = n;
\r
360 Team = GetPlayerColor(self.sv_entnum);
\r
362 if not(playerslots[self.sv_entnum])
\r
363 playerslots[self.sv_entnum] = spawn();
\r
364 o = self.owner = playerslots[self.sv_entnum];
\r
365 o.sv_entnum = self.sv_entnum;
\r
367 if not(o.sort_prev)
\r
373 for(i = 0; i < MAX_SCORE; ++i)
\r
374 o.(scores[i]) = ReadShort();
\r
383 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
\r
385 o.(scores[i]) = ReadShort();
\r
388 Sbar_UpdatePlayerPos(o);
\r
391 void Ent_ReadTeamScore()
\r
396 self.team = ReadByte();
\r
397 o = self.owner = GetTeam(self.team, true);
\r
399 #if MAX_TEAMSCORE <= 3
\r
400 for(i = 0; i < MAX_TEAMSCORE; ++i)
\r
401 o.(teamscores[i]) = ReadShort();
\r
404 #if MAX_TEAMSCORE <= 8
\r
410 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
\r
412 o.(teamscores[i]) = ReadShort();
\r
415 Sbar_UpdateTeamPos(o);
\r
418 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
\r
419 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
\r
420 void(float bIsNewEntity) CSQC_Ent_Update =
\r
424 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
426 if(t != self.enttype)
\r
428 print("A CSQC entity changed its type!\n");
\r
433 if(self.enttype == ENT_CLIENT_ENTCS)
\r
435 self.sv_entnum = ReadByte()-1;
\r
437 for(msg = ReadByte(); msg != ENTCS_MSG_END; msg = ReadByte())
\r
441 case ENTCS_MSG_ONS_GPS: Ent_ReadONS(); break;
\r
442 case ENTCS_MSG_ONS_REMOVE: Ent_RemoveONS(); break;
\r
444 error("unknown ENTCS_MSG type\n");
\r
448 else if(self.enttype == ENT_CLIENT_SCORES)
\r
449 Ent_ReadPlayerScore();
\r
450 else if(self.enttype == ENT_CLIENT_TEAMSCORES)
\r
451 Ent_ReadTeamScore();
\r
452 else if(self.enttype == ENT_CLIENT_POINTPARTICLES)
\r
453 Ent_PointParticles();
\r
454 else if(self.enttype == ENT_CLIENT_RAINSNOW)
\r
456 else if(self.enttype == ENT_CLIENT_LASER)
\r
459 error("unknown entity type in CSQC_Ent_Update\n");
\r
462 // Destructor, but does NOT deallocate the entity by calling remove(). Also
\r
463 // used when an entity changes its type. For an entity that someone interacts
\r
464 // with others, make sure it can no longer do so.
\r
467 if(self.enttype == ENT_CLIENT_ENTCS)
\r
469 if(using_gps) //gametype == GAME_ONSLAUGHT)
\r
471 if(gps_start == self)
\r
472 gps_start = self.chain;
\r
478 while(ent.chain != self && ent.chain != world)
\r
480 if(ent.chain == self)
\r
481 ent.chain = self.chain;
\r
484 } else if(self.enttype == ENT_CLIENT_SCORES)
\r
488 SetTeam(self.owner, -1);
\r
489 if(self.owner.sort_prev)
\r
490 RemovePlayer(self.owner);
\r
491 self.owner.sort_prev = NULL;
\r
493 } else if(self.enttype == ENT_CLIENT_TEAMSCORES)
\r
497 RemoveTeam(self.owner);
\r
499 // we don't NEED to remove them... they won't display anyway
\r
500 // plus, svqc never does this anyway
\r
501 } else if(self.enttype == ENT_CLIENT_POINTPARTICLES)
\r
503 Ent_PointParticles_Remove();
\r
507 self.classname = "";
\r
508 self.draw = menu_sub_null;
\r
509 // TODO possibly set more stuff to defaults
\r
511 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
\r
512 void CSQC_Ent_Remove()
\r
519 void Gamemode_Init()
\r
521 local string mapinfo, infoline;
\r
524 local vector mi_min, mi_max;
\r
526 if(!strcasecmp(substring(mapname, 0, 5), "maps/"))
\r
527 shortmapname = substring(mapname, 5, 999);
\r
529 shortmapname = mapname;
\r
530 len = strlen(shortmapname);
\r
531 if(!strcasecmp(substring(shortmapname, len-4, 4), ".bsp"))
\r
532 shortmapname = substring(shortmapname, 0, len-4);
\r
533 shortmapname = strzone(shortmapname);
\r
535 if(gametype == GAME_ONSLAUGHT) {
\r
536 mapinfo = strcat("maps/", minimapname, ".info");
\r
537 minimapname = strzone(strcat("gfx/", shortmapname, "_mini.tga"));
\r
539 mi_min = world.mins;
\r
540 mi_max = world.maxs;
\r
542 file = fopen(mapinfo, FILE_READ);
\r
544 while((infoline = fgets(file))) {
\r
545 if(!strncasecmp(infoline, "mins", 4)) {
\r
546 mi_min = stov(substring(infoline, 5, 999));
\r
547 } else if(!strncasecmp(infoline, "maxs", 4)) {
\r
548 mi_max = stov(substring(infoline, 5, 999));
\r
549 } else if(strncasecmp(infoline, "//", 2)) { // don't print comment-style lines
\r
550 print(strcat("mapinfo: ", infoline, "\n"));
\r
554 print(strcat("Map has no .info file (", mapinfo, ").\n"));
\r
558 print(strcat("Mins: ", vtos(mi_min), " Maxs: ", vtos(mi_max), "\n"));
\r
560 mi_center = (mi_min + mi_max) * 0.5;
\r
561 mi_scale = mi_max - mi_min;
\r
564 print(strcat("Using ", minimapname, " as minimap.\n"));
\r
565 precache_pic(minimapname);
\r
566 precache_pic("gfx/ons-cp-neutral.tga");
\r
567 precache_pic("gfx/ons-cp-red.tga");
\r
568 precache_pic("gfx/ons-cp-blue.tga");
\r
569 precache_pic("gfx/ons-frame.tga");
\r
570 precache_pic("gfx/ons-frame-team.tga");
\r
571 } else if(gametype == GAME_KEYHUNT) {
\r
572 precache_pic("gfx/sb_key_carrying");
\r
573 precache_pic("gfx/sb_key_carrying_outline");
\r
576 // CSQC_Parse_StuffCmd : Provides the stuffcmd string in the first parameter that the server provided. To execute standard behavior, simply execute localcmd with the string.
\r
577 void CSQC_Parse_StuffCmd(string strMessage)
\r
579 localcmd(strMessage);
\r
581 // CSQC_Parse_Print : Provides the print string in the first parameter that the server provided. To execute standard behavior, simply execute print with the string.
\r
582 void CSQC_Parse_Print(string strMessage)
\r
586 // CSQC_Parse_CenterPrint : Provides the centerprint string in the first parameter that the server provided. To execute standard behavior, simply execute cprint with the string.
\r
587 void CSQC_Parse_CenterPrint(string strMessage)
\r
589 cprint(strMessage);
\r
592 void CSQC_CheckRevision();
\r
594 void Gamemode_Init();
\r
595 void Net_ReadScoresInfo()
\r
598 gametype = ReadByte();
\r
599 for(i = 0; i < MAX_SCORE; ++i)
\r
601 scores_label[i] = strzone(ReadString());
\r
602 scores_flags[i] = ReadByte();
\r
604 for(i = 0; i < MAX_TEAMSCORE; ++i)
\r
606 teamscores_label[i] = strzone(ReadString());
\r
607 teamscores_flags[i] = ReadByte();
\r
613 void Net_ReadInit()
\r
615 csqc_revision = ReadShort();
\r
616 maxclients = ReadByte();
\r
617 minstagib = ReadByte();
\r
619 CSQC_CheckRevision();
\r
622 string Net_ReadPicture()
\r
625 if(csqc_flags & CSQC_FLAG_READPICTURE)
\r
627 img = ReadPicture();
\r
628 print(strcat("Got Picture: ", img, "\n"));
\r
630 img = ReadString();
\r
631 print(strcat("^3Warning: ^7Couldn't download ", img, ". This is probably because your engine build is outdated.\n"));
\r
633 psize = ReadShort();
\r
634 // Can I be sure that ReadShort is 2 bytes and ReadLong is 4 bytes?
\r
635 // Because then this could be optimized to first get all 4-byte-groups,
\r
636 // then the remaining 2, then the remaining 1
\r
637 for(i = 0; i < psize; ++i)
\r
646 key = ReadString();
\r
647 value = ReadString();
\r
648 db_put(configdb, strcat("/v/", key), value);
\r
649 db_put(configdb, strcat("/s/", key), "1");
\r
652 void Net_ReadRace()
\r
660 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
\r
661 race_checkpoint = ReadByte();
\r
662 race_time = ReadShort();
\r
663 race_previousbesttime = ReadShort();
\r
664 if(race_previousbestname)
\r
665 strunzone(race_previousbestname);
\r
666 race_previousbestname = strzone(ReadString());
\r
668 race_checkpointtime = time;
\r
670 if(race_checkpoint == 0)
\r
671 race_laptime = time; // valid
\r
675 case RACE_NET_CHECKPOINT_CLEAR:
\r
677 race_checkpointtime = 0;
\r
680 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
\r
681 race_laptime = ReadCoord();
\r
682 race_checkpointtime = -99999;
\r
684 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
\r
685 race_nextcheckpoint = ReadByte();
\r
687 race_nextbesttime = ReadShort();
\r
688 if(race_nextbestname)
\r
689 strunzone(race_nextbestname);
\r
690 race_nextbestname = strzone(ReadString());
\r
693 case RACE_NET_CHECKPOINT_HIT_RACE:
\r
694 race_mycheckpoint = ReadByte();
\r
695 race_mycheckpointtime = time;
\r
696 race_mycheckpointdelta = ReadShort();
\r
697 race_mycheckpointlapsdelta = ReadByte();
\r
698 if(race_mycheckpointlapsdelta >= 128)
\r
699 race_mycheckpointlapsdelta -= 256;
\r
700 if(race_mycheckpointenemy)
\r
701 strunzone(race_mycheckpointenemy);
\r
702 race_mycheckpointenemy = strzone(ReadString());
\r
705 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
\r
706 race_othercheckpoint = ReadByte();
\r
707 race_othercheckpointtime = time;
\r
708 race_othercheckpointdelta = ReadShort();
\r
709 race_othercheckpointlapsdelta = ReadByte();
\r
710 if(race_othercheckpointlapsdelta >= 128)
\r
711 race_othercheckpointlapsdelta -= 256;
\r
712 if(race_othercheckpointenemy)
\r
713 strunzone(race_othercheckpointenemy);
\r
714 race_othercheckpointenemy = strzone(ReadString());
\r
719 void Net_ReadForceScoreboard()
\r
721 sb_showscores_force = ReadByte();
\r
727 race_checkpointtime = 0;
\r
730 void Net_ReadSpectating()
\r
732 float newspectatee_status;
\r
733 newspectatee_status = ReadByte();
\r
734 if(newspectatee_status == player_localentnum)
\r
735 newspectatee_status = -1; // observing
\r
736 if(newspectatee_status != spectatee_status)
\r
738 spectatee_status = newspectatee_status;
\r
741 void Net_ReadSpawn()
\r
744 current_viewzoom = 0.6;
\r
747 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
\r
748 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
\r
749 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
\r
750 float CSQC_Parse_TempEntity()
\r
752 local float bHandled;
\r
756 nTEID = ReadByte();
\r
758 // NOTE: Could just do return instead of break...
\r
765 case TE_CSQC_MAPVOTE:
\r
769 case TE_CSQC_CONFIG:
\r
773 case TE_CSQC_SCORESINFO:
\r
774 Net_ReadScoresInfo();
\r
781 case TE_CSQC_FORCESCOREBOARD:
\r
782 Net_ReadForceScoreboard();
\r
785 case TE_CSQC_SPECTATING:
\r
786 Net_ReadSpectating();
\r
789 case 13: // TE_BEAM
\r
790 Net_GrapplingHook();
\r
793 case TE_CSQC_SPAWN: // TE_BEAM
\r
798 // No special logic for this temporary entity; return 0 so the engine can handle it
\r
809 // COMMIT-TODO: Update if necessare, before committing
\r
810 void CSQC_CheckRevision()
\r
812 if(csqc_revision == CSQC_REVISION)
\r
814 print("^2SVQC and CSQC revisions are compatible.\n");
\r
815 } else if(csqc_revision < CSQC_REVISION) {
\r
816 print("^1Your csprogs.dat (CSQC) version is newer than the one on the server.\n");
\r
817 } else if(csqc_revision > CSQC_REVISION) {
\r
818 print("^1Your csprogs.dat (CSQC) is too old for this server.\n");
\r
819 print("^1Please update to a newer version.\n");
\r