1 // --------------------------------------------------------------------------
\r
2 // BEGIN REQUIRED CSQC FUNCTIONS
\r
5 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
7 void cvar_settemp(string cv, string val)
\r
10 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
\r
14 e.classname = "saved_cvar_value";
\r
15 e.netname = strzone(cv);
\r
16 e.message = strzone(cvar_string(cv));
\r
21 void cvar_settemp_restore()
\r
24 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
\r
25 cvar_set(e.netname, e.message);
\r
28 void() menu_show_error =
\r
30 drawstring('0 200 0', "ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!", '8 8 0', '1 0 0', 1, 0);
\r
33 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
\r
34 // Useful for precaching things
\r
36 void() menu_sub_null =
\r
40 // let's make this a general data buffer...
\r
44 float __engine_check;
\r
47 string config_get(string key, string defaultvalue)
\r
50 s = db_get(configdb, strcat("/s/", key));
\r
52 return defaultvalue;
\r
54 return db_get(configdb, strcat("/v/", key));
\r
57 void CSQC_Init(void)
\r
61 __engine_check = checkextension("DP_SV_WRITEPICTURE");
\r
64 print("^3Your engine build is outdated\n^3This Server uses a newer QC VM. Please update!\n");
\r
65 localcmd("\ndisconnect\n");
\r
74 configdb = db_create();
\r
75 binddb = db_create();
\r
76 compressShortVector_init();
\r
79 menu_visible = FALSE;
\r
80 menu_show = menu_show_error;
\r
81 menu_action = menu_sub_null;
\r
83 maxclients = 255; // we later get the real maxclients to speed up stuff
\r
85 // localcmd("alias order \"cmd order $*\""); enable if ctf-command thingy is used
\r
86 //registercmd("ctf_menu");
\r
87 registercmd("ons_map");
\r
88 //registercmd("menu_action");
\r
89 registercmd("sbar_columns_set");
\r
90 registercmd("sbar_columns_help");
\r
92 registercmd("+button3");
\r
93 registercmd("-button3");
\r
94 registercmd("+button4");
\r
95 registercmd("-button4");
\r
97 registercvar("sbar_usecsqc", "1");
\r
98 registercvar("sbar_columns", "default", CVAR_SAVE);
\r
104 // sbar_fields uses strunzone on the titles!
\r
105 for(i = 0; i < MAX_SBAR_FIELDS; ++i)
\r
106 sbar_title[i] = strzone("(null)");
\r
110 teams = Sort_Spawn();
\r
111 players = Sort_Spawn();
\r
113 GetTeam(COLOR_SPECTATOR, true); // add specs first
\r
115 cvar_settemp("_supports_weaponpriority", "1");
\r
118 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
\r
119 void CSQC_Shutdown(void)
\r
123 if(!__engine_check)
\r
130 db_close(configdb);
\r
133 cvar_settemp_restore();
\r
137 float SetTeam(entity o, float Team)
\r
140 if(Team == -1) // leave
\r
144 //print("(DISCONNECT) leave team ", ftos(o.team), "\n");
\r
145 tm = GetTeam(o.team, false);
\r
155 //print("(CONNECT) enter team ", ftos(o.team), "\n");
\r
157 tm = GetTeam(Team, true);
\r
162 else if(Team != o.team)
\r
164 //print("(CHANGE) leave team ", ftos(o.team), "\n");
\r
165 tm = GetTeam(o.team, false);
\r
168 //print("(CHANGE) enter team ", ftos(o.team), "\n");
\r
169 tm = GetTeam(Team, true);
\r
177 void Playerchecker_Think()
\r
180 for(i = 0; i < maxclients; ++i)
\r
182 if(getplayerkey(i, "name") == "")
\r
184 if(playerslots[i].sort_prev)
\r
186 //print("playerchecker: KILL KILL KILL\n");
\r
187 // player disconnected
\r
188 SetTeam(playerslots[i], -1);
\r
189 RemovePlayer(playerslots[i]);
\r
190 playerslots[i].sort_prev = world;
\r
191 playerslots[i].gotscores = 0;
\r
196 if not(playerslots[i].sort_prev)
\r
198 //print("playerchecker: SPAWN SPAWN SPAWN\n");
\r
199 // player connected
\r
200 if not(playerslots[i])
\r
201 playerslots[i] = spawn();
\r
202 playerslots[i].sv_entnum = i;
\r
203 playerslots[i].gotscores = 0;
\r
204 SetTeam(playerslots[i], COLOR_SPECTATOR);
\r
205 RegisterPlayer(playerslots[i]);
\r
206 Sbar_UpdatePlayerPos(playerslots[i]);
\r
210 self.nextthink = time + 0.2;
\r
214 void PostInit(void)
\r
216 print(strcat("PostInit\n maxclients = ", ftos(maxclients), "\n"));
\r
217 localcmd(strcat("\nsbar_columns_set ", cvar_string("sbar_columns"), ";\n"));
\r
219 entity playerchecker;
\r
220 playerchecker = spawn();
\r
221 playerchecker.think = Playerchecker_Think;
\r
222 playerchecker.nextthink = time + 0.2;
\r
229 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function
\r
230 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
\r
232 void Cmd_Sbar_SetFields(float);
\r
233 void Cmd_Sbar_Help(float);
\r
234 float CSQC_ConsoleCommand(string strMessage)
\r
238 //argc = tokenize(strMessage);
\r
239 argc = tokenizebyseparator(strMessage, " ");
\r
242 local string strCmd;
\r
245 if(strCmd == "+button4") { // zoom
\r
246 // return false, because the message shall be sent to the server anyway (for demos/speccing)
\r
247 if(ignore_plus_zoom)
\r
249 --ignore_plus_zoom;
\r
254 } else if(strCmd == "-button4") { // zoom
\r
255 if(ignore_minus_zoom)
\r
257 --ignore_minus_zoom;
\r
262 } else if(strCmd == "+button3") { // secondary
\r
263 button_attack2 = 1;
\r
265 } else if(strCmd == "-button3") { // secondary
\r
266 button_attack2 = 0;
\r
268 } else if(strCmd == "ons_map") {
\r
271 } else if(strCmd == "sbar_columns_set") {
\r
272 Cmd_Sbar_SetFields(argc);
\r
274 } else if(strCmd == "sbar_columns_help") {
\r
275 Cmd_Sbar_Help(argc);
\r
277 } else if(strCmd == "+showscores") {
\r
278 sb_showscores = true;
\r
280 } else if(strCmd == "-showscores") {
\r
281 sb_showscores = false;
\r
288 float GameCommand(string msg)
\r
291 argc = tokenize(msg);
\r
294 if(cmd == "mv_download") {
\r
295 Cmd_MapVote_MapDownload(argc);
\r
298 else if(cmd == "settemp") {
\r
299 cvar_settemp(argv(1), argv(2));
\r
305 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
\r
306 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
\r
307 // All keys are in ascii.
\r
308 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
\r
309 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
\r
310 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
\r
311 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
\r
313 local float bSkipKey;
\r
317 if(menu_action(bInputType, nPrimary, nSecondary))
\r
322 // END REQUIRED CSQC FUNCTIONS
\r
323 // --------------------------------------------------------------------------
\r
325 // --------------------------------------------------------------------------
\r
326 // BEGIN OPTIONAL CSQC FUNCTIONS
\r
332 self.origin_x = ReadCoord();
\r
333 self.origin_y = ReadCoord();
\r
334 self.angles_y = ReadCoord();
\r
335 self.origin_z = self.angles_x = self.angles_z = 0;
\r
337 for(gps = gps_start; gps; gps = gps.chain)
\r
344 self.chain = gps_start;
\r
349 void Ent_RemoveONS()
\r
351 if(gps_start == self)
\r
352 gps_start = self.chain;
\r
358 while(ent.chain != self && ent.chain != world)
\r
360 if(ent.chain == self)
\r
361 ent.chain = self.chain;
\r
366 void Ent_ReadPlayerScore()
\r
372 // damnit -.- don't want to go change every single .sv_entnum in sbar.qc AGAIN
\r
373 // (no I've never heard of M-x replace-string, sed, or anything like that)
\r
374 isNew = !self.owner; // workaround for DP bug
\r
377 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
378 if(!isNew && n != self.sv_entnum)
\r
380 print("A CSQC entity changed its owner!\n");
\r
383 self.enttype = ENT_CLIENT_SCORES;
\r
387 self.sv_entnum = n;
\r
388 Team = GetPlayerColor(self.sv_entnum);
\r
390 if not(playerslots[self.sv_entnum])
\r
391 playerslots[self.sv_entnum] = spawn();
\r
392 o = self.owner = playerslots[self.sv_entnum];
\r
393 o.sv_entnum = self.sv_entnum;
\r
395 if not(o.sort_prev)
\r
401 for(i = 0; i < MAX_SCORE; ++i)
\r
402 o.(scores[i]) = ReadShort();
\r
411 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
\r
413 o.(scores[i]) = ReadShort();
\r
416 Sbar_UpdatePlayerPos(o);
\r
419 void Ent_ReadTeamScore()
\r
424 self.team = ReadByte();
\r
425 o = self.owner = GetTeam(self.team, true);
\r
427 #if MAX_TEAMSCORE <= 3
\r
428 for(i = 0; i < MAX_TEAMSCORE; ++i)
\r
429 o.(teamscores[i]) = ReadShort();
\r
432 #if MAX_TEAMSCORE <= 8
\r
438 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
\r
440 o.(teamscores[i]) = ReadShort();
\r
443 Sbar_UpdateTeamPos(o);
\r
446 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
\r
447 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
\r
448 void(float bIsNewEntity) CSQC_Ent_Update =
\r
452 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
454 if(t != self.enttype)
\r
456 print("A CSQC entity changed its type!\n");
\r
461 if(self.enttype == ENT_CLIENT_ENTCS)
\r
463 self.sv_entnum = ReadByte()-1;
\r
465 for(msg = ReadByte(); msg != ENTCS_MSG_END; msg = ReadByte())
\r
469 case ENTCS_MSG_ONS_GPS: Ent_ReadONS(); break;
\r
470 case ENTCS_MSG_ONS_REMOVE: Ent_RemoveONS(); break;
\r
472 error("unknown ENTCS_MSG type\n");
\r
476 else if(self.enttype == ENT_CLIENT_SCORES)
\r
477 Ent_ReadPlayerScore();
\r
478 else if(self.enttype == ENT_CLIENT_TEAMSCORES)
\r
479 Ent_ReadTeamScore();
\r
480 else if(self.enttype == ENT_CLIENT_POINTPARTICLES)
\r
481 Ent_PointParticles();
\r
482 else if(self.enttype == ENT_CLIENT_RAINSNOW)
\r
484 else if(self.enttype == ENT_CLIENT_LASER)
\r
487 error("unknown entity type in CSQC_Ent_Update\n");
\r
490 // Destructor, but does NOT deallocate the entity by calling remove(). Also
\r
491 // used when an entity changes its type. For an entity that someone interacts
\r
492 // with others, make sure it can no longer do so.
\r
495 if(self.enttype == ENT_CLIENT_ENTCS)
\r
497 if(using_gps) //gametype == GAME_ONSLAUGHT)
\r
499 if(gps_start == self)
\r
500 gps_start = self.chain;
\r
506 while(ent.chain != self && ent.chain != world)
\r
508 if(ent.chain == self)
\r
509 ent.chain = self.chain;
\r
512 } else if(self.enttype == ENT_CLIENT_SCORES)
\r
516 SetTeam(self.owner, -1);
\r
517 if(self.owner.sort_prev)
\r
518 RemovePlayer(self.owner);
\r
519 self.owner.sort_prev = NULL;
\r
521 } else if(self.enttype == ENT_CLIENT_TEAMSCORES)
\r
525 RemoveTeam(self.owner);
\r
527 // we don't NEED to remove them... they won't display anyway
\r
528 // plus, svqc never does this anyway
\r
529 } else if(self.enttype == ENT_CLIENT_POINTPARTICLES)
\r
531 Ent_PointParticles_Remove();
\r
535 self.classname = "";
\r
536 self.draw = menu_sub_null;
\r
537 // TODO possibly set more stuff to defaults
\r
539 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
\r
540 void CSQC_Ent_Remove()
\r
547 void Gamemode_Init()
\r
549 local string mapinfo, infoline;
\r
552 local vector mi_min, mi_max;
\r
554 if(!strcasecmp(substring(mapname, 0, 5), "maps/"))
\r
555 shortmapname = substring(mapname, 5, 999);
\r
557 shortmapname = mapname;
\r
558 len = strlen(shortmapname);
\r
559 if(!strcasecmp(substring(shortmapname, len-4, 4), ".bsp"))
\r
560 shortmapname = substring(shortmapname, 0, len-4);
\r
561 shortmapname = strzone(shortmapname);
\r
563 if(gametype == GAME_ONSLAUGHT) {
\r
564 mapinfo = strcat("maps/", minimapname, ".info");
\r
565 minimapname = strzone(strcat("gfx/", shortmapname, "_mini.tga"));
\r
567 mi_min = world.mins;
\r
568 mi_max = world.maxs;
\r
570 file = fopen(mapinfo, FILE_READ);
\r
572 while((infoline = fgets(file))) {
\r
573 if(!strncasecmp(infoline, "mins", 4)) {
\r
574 mi_min = stov(substring(infoline, 5, 999));
\r
575 } else if(!strncasecmp(infoline, "maxs", 4)) {
\r
576 mi_max = stov(substring(infoline, 5, 999));
\r
577 } else if(strncasecmp(infoline, "//", 2)) { // don't print comment-style lines
\r
578 print(strcat("mapinfo: ", infoline, "\n"));
\r
582 print(strcat("Map has no .info file (", mapinfo, ").\n"));
\r
586 print(strcat("Mins: ", vtos(mi_min), " Maxs: ", vtos(mi_max), "\n"));
\r
588 mi_center = (mi_min + mi_max) * 0.5;
\r
589 mi_scale = mi_max - mi_min;
\r
592 print(strcat("Using ", minimapname, " as minimap.\n"));
\r
593 precache_pic(minimapname);
\r
594 precache_pic("gfx/ons-cp-neutral.tga");
\r
595 precache_pic("gfx/ons-cp-red.tga");
\r
596 precache_pic("gfx/ons-cp-blue.tga");
\r
597 precache_pic("gfx/ons-frame.tga");
\r
598 precache_pic("gfx/ons-frame-team.tga");
\r
599 } else if(gametype == GAME_KEYHUNT) {
\r
600 precache_pic("gfx/sb_key_carrying");
\r
601 precache_pic("gfx/sb_key_carrying_outline");
\r
604 // 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
605 void CSQC_Parse_StuffCmd(string strMessage)
\r
607 localcmd(strMessage);
\r
609 // 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
610 void CSQC_Parse_Print(string strMessage)
\r
614 // 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
615 void CSQC_Parse_CenterPrint(string strMessage)
\r
617 cprint(strMessage);
\r
620 void CSQC_CheckRevision();
\r
622 void Gamemode_Init();
\r
623 void Net_ReadScoresInfo()
\r
626 gametype = ReadByte();
\r
627 for(i = 0; i < MAX_SCORE; ++i)
\r
629 scores_label[i] = strzone(ReadString());
\r
630 scores_flags[i] = ReadByte();
\r
632 for(i = 0; i < MAX_TEAMSCORE; ++i)
\r
634 teamscores_label[i] = strzone(ReadString());
\r
635 teamscores_flags[i] = ReadByte();
\r
641 void Net_ReadInit()
\r
644 csqc_revision = ReadShort();
\r
645 maxclients = ReadByte();
\r
646 for(i = 0; i < 24; ++i)
\r
647 weaponimpulse[i] = ReadByte() - 1;
\r
648 CSQC_CheckRevision();
\r
651 string Net_ReadPicture()
\r
654 if(csqc_flags & CSQC_FLAG_READPICTURE)
\r
656 img = ReadPicture();
\r
657 print(strcat("Got Picture: ", img, "\n"));
\r
659 img = ReadString();
\r
660 print(strcat("^3Warning: ^7Couldn't download ", img, ". This is probably because your engine build is outdated.\n"));
\r
662 psize = ReadShort();
\r
663 // Can I be sure that ReadShort is 2 bytes and ReadLong is 4 bytes?
\r
664 // Because then this could be optimized to first get all 4-byte-groups,
\r
665 // then the remaining 2, then the remaining 1
\r
666 for(i = 0; i < psize; ++i)
\r
675 key = ReadString();
\r
676 value = ReadString();
\r
677 db_put(configdb, strcat("/v/", key), value);
\r
678 db_put(configdb, strcat("/s/", key), "1");
\r
681 void Net_ReadRace()
\r
689 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
\r
690 race_checkpoint = ReadByte();
\r
691 race_time = ReadShort();
\r
692 race_previousbesttime = ReadShort();
\r
693 if(race_previousbestname)
\r
694 strunzone(race_previousbestname);
\r
695 race_previousbestname = strzone(ReadString());
\r
697 race_checkpointtime = time;
\r
699 if(race_checkpoint == 0)
\r
700 race_laptime = time; // valid
\r
704 case RACE_NET_CHECKPOINT_CLEAR:
\r
706 race_checkpointtime = 0;
\r
709 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
\r
710 race_laptime = ReadCoord();
\r
711 race_checkpointtime = -99999;
\r
713 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
\r
714 race_nextcheckpoint = ReadByte();
\r
716 race_nextbesttime = ReadShort();
\r
717 if(race_nextbestname)
\r
718 strunzone(race_nextbestname);
\r
719 race_nextbestname = strzone(ReadString());
\r
722 case RACE_NET_CHECKPOINT_HIT_RACE:
\r
723 race_mycheckpoint = ReadByte();
\r
724 race_mycheckpointtime = time;
\r
725 race_mycheckpointdelta = ReadShort();
\r
726 race_mycheckpointlapsdelta = ReadByte();
\r
727 if(race_mycheckpointlapsdelta >= 128)
\r
728 race_mycheckpointlapsdelta -= 256;
\r
729 if(race_mycheckpointenemy)
\r
730 strunzone(race_mycheckpointenemy);
\r
731 race_mycheckpointenemy = strzone(ReadString());
\r
734 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
\r
735 race_othercheckpoint = ReadByte();
\r
736 race_othercheckpointtime = time;
\r
737 race_othercheckpointdelta = ReadShort();
\r
738 race_othercheckpointlapsdelta = ReadByte();
\r
739 if(race_othercheckpointlapsdelta >= 128)
\r
740 race_othercheckpointlapsdelta -= 256;
\r
741 if(race_othercheckpointenemy)
\r
742 strunzone(race_othercheckpointenemy);
\r
743 race_othercheckpointenemy = strzone(ReadString());
\r
748 void Net_ReadForceScoreboard()
\r
750 sb_showscores_force = ReadByte();
\r
757 race_checkpointtime = 0;
\r
758 for(i = 0; i < 24; ++i)
\r
759 angles_held_status[i] = 0;
\r
762 void Net_ReadSpectating()
\r
764 float newspectatee_status;
\r
765 newspectatee_status = ReadByte();
\r
766 if(newspectatee_status == player_localentnum)
\r
767 newspectatee_status = -1; // observing
\r
768 if(newspectatee_status != spectatee_status)
\r
770 spectatee_status = newspectatee_status;
\r
773 void Net_ReadZoomNotify()
\r
775 spectatorbutton_zoom = ReadByte();
\r
778 void Net_ReadSpawn()
\r
781 current_viewzoom = 0.6;
\r
784 void Net_ReadWarmupStage()
\r
786 warmup_stage = ReadByte();
\r
789 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
\r
790 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
\r
791 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
\r
792 void Net_ReadHoldAngles();
\r
793 float CSQC_Parse_TempEntity()
\r
795 local float bHandled;
\r
799 nTEID = ReadByte();
\r
801 // NOTE: Could just do return instead of break...
\r
808 case TE_CSQC_MAPVOTE:
\r
812 case TE_CSQC_CONFIG:
\r
816 case TE_CSQC_SCORESINFO:
\r
817 Net_ReadScoresInfo();
\r
824 case TE_CSQC_FORCESCOREBOARD:
\r
825 Net_ReadForceScoreboard();
\r
828 case TE_CSQC_SPECTATING:
\r
829 Net_ReadSpectating();
\r
832 case 13: // TE_BEAM
\r
833 Net_GrapplingHook();
\r
836 case TE_CSQC_SPAWN:
\r
840 case TE_CSQC_ZOOMNOTIFY:
\r
841 Net_ReadZoomNotify();
\r
844 case TE_CSQC_HOLDANGLES:
\r
845 Net_ReadHoldAngles();
\r
848 case TE_CSQC_WARMUP:
\r
849 Net_ReadWarmupStage();
\r
853 // No special logic for this temporary entity; return 0 so the engine can handle it
\r
864 // COMMIT-TODO: Update if necessare, before committing
\r
865 void CSQC_CheckRevision()
\r
867 if(csqc_revision == CSQC_REVISION)
\r
869 print("^2SVQC and CSQC revisions are compatible.\n");
\r
870 } else if(csqc_revision < CSQC_REVISION) {
\r
871 print("^1Your csprogs.dat (CSQC) version is newer than the one on the server.\n");
\r
872 } else if(csqc_revision > CSQC_REVISION) {
\r
873 print("^1Your csprogs.dat (CSQC) is too old for this server.\n");
\r
874 print("^1Please update to a newer version.\n");
\r
878 string getcommandkey(string text, string command)
\r
883 if (!sbar_showbinds)
\r
886 keys = db_get(binddb, command);
\r
889 n = tokenize(findkeysforcommand(command));
\r
890 for(j = 0; j < n; ++j)
\r
896 keys = keynumtostring(k);
\r
898 keys = strcat(keys, ", ", keynumtostring(k));
\r
901 if (sbar_showbinds_limit > 0 && sbar_showbinds_limit >= l) break;
\r
905 db_put(binddb, command, keys);
\r
909 if (sbar_showbinds > 1)
\r
910 return strcat(text, " (not bound)");
\r
914 else if (sbar_showbinds > 1)
\r
915 return strcat(text, " (", keys, ")");
\r