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
220 // return false, because the message shall be sent to the server anyway (for demos/speccing)
\r
223 } else if(strCmd == "-button4") { // zoom
\r
226 } else if(strCmd == "+button3") { // secondary
\r
227 button_attack2 = 1;
\r
229 } else if(strCmd == "-button3") { // secondary
\r
230 button_attack2 = 0;
\r
232 } else if(strCmd == "ons_map") {
\r
235 } else if(strCmd == "sbar_columns_set") {
\r
236 Cmd_Sbar_SetFields(argc);
\r
238 } else if(strCmd == "sbar_columns_help") {
\r
239 Cmd_Sbar_Help(argc);
\r
241 } else if(strCmd == "+showscores") {
\r
242 sb_showscores = true;
\r
244 } else if(strCmd == "-showscores") {
\r
245 sb_showscores = false;
\r
252 float GameCommand(string msg)
\r
255 argc = tokenize(msg);
\r
258 if(cmd == "mv_download") {
\r
259 Cmd_MapVote_MapDownload(argc);
\r
262 else if(cmd == "settemp") {
\r
264 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
\r
265 if(e.netname == argv(1))
\r
268 e.classname = "saved_cvar_value";
\r
269 e.netname = strzone(argv(1));
\r
270 e.message = strzone(cvar_string(argv(1)));
\r
272 cvar_set(argv(1), argv(2));
\r
278 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
\r
279 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
\r
280 // All keys are in ascii.
\r
281 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
\r
282 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
\r
283 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
\r
284 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
\r
286 local float bSkipKey;
\r
290 if(menu_action(bInputType, nPrimary, nSecondary))
\r
295 // END REQUIRED CSQC FUNCTIONS
\r
296 // --------------------------------------------------------------------------
\r
298 // --------------------------------------------------------------------------
\r
299 // BEGIN OPTIONAL CSQC FUNCTIONS
\r
305 self.origin_x = ReadCoord();
\r
306 self.origin_y = ReadCoord();
\r
307 self.angles_y = ReadCoord();
\r
308 self.origin_z = self.angles_x = self.angles_z = 0;
\r
310 for(gps = gps_start; gps; gps = gps.chain)
\r
317 self.chain = gps_start;
\r
322 void Ent_RemoveONS()
\r
324 if(gps_start == self)
\r
325 gps_start = self.chain;
\r
331 while(ent.chain != self && ent.chain != world)
\r
333 if(ent.chain == self)
\r
334 ent.chain = self.chain;
\r
339 void Ent_ReadPlayerScore()
\r
345 // damnit -.- don't want to go change every single .sv_entnum in sbar.qc AGAIN
\r
346 // (no I've never heard of M-x replace-string, sed, or anything like that)
\r
347 isNew = !self.owner; // workaround for DP bug
\r
350 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
351 if(!isNew && n != self.sv_entnum)
\r
353 print("A CSQC entity changed its owner!\n");
\r
356 self.enttype = ENT_CLIENT_SCORES;
\r
360 self.sv_entnum = n;
\r
361 Team = GetPlayerColor(self.sv_entnum);
\r
363 if not(playerslots[self.sv_entnum])
\r
364 playerslots[self.sv_entnum] = spawn();
\r
365 o = self.owner = playerslots[self.sv_entnum];
\r
366 o.sv_entnum = self.sv_entnum;
\r
368 if not(o.sort_prev)
\r
374 for(i = 0; i < MAX_SCORE; ++i)
\r
375 o.(scores[i]) = ReadShort();
\r
384 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
\r
386 o.(scores[i]) = ReadShort();
\r
389 Sbar_UpdatePlayerPos(o);
\r
392 void Ent_ReadTeamScore()
\r
397 self.team = ReadByte();
\r
398 o = self.owner = GetTeam(self.team, true);
\r
400 #if MAX_TEAMSCORE <= 3
\r
401 for(i = 0; i < MAX_TEAMSCORE; ++i)
\r
402 o.(teamscores[i]) = ReadShort();
\r
405 #if MAX_TEAMSCORE <= 8
\r
411 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
\r
413 o.(teamscores[i]) = ReadShort();
\r
416 Sbar_UpdateTeamPos(o);
\r
419 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
\r
420 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
\r
421 void(float bIsNewEntity) CSQC_Ent_Update =
\r
425 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
427 if(t != self.enttype)
\r
429 print("A CSQC entity changed its type!\n");
\r
434 if(self.enttype == ENT_CLIENT_ENTCS)
\r
436 self.sv_entnum = ReadByte()-1;
\r
438 for(msg = ReadByte(); msg != ENTCS_MSG_END; msg = ReadByte())
\r
442 case ENTCS_MSG_ONS_GPS: Ent_ReadONS(); break;
\r
443 case ENTCS_MSG_ONS_REMOVE: Ent_RemoveONS(); break;
\r
445 error("unknown ENTCS_MSG type\n");
\r
449 else if(self.enttype == ENT_CLIENT_SCORES)
\r
450 Ent_ReadPlayerScore();
\r
451 else if(self.enttype == ENT_CLIENT_TEAMSCORES)
\r
452 Ent_ReadTeamScore();
\r
453 else if(self.enttype == ENT_CLIENT_POINTPARTICLES)
\r
454 Ent_PointParticles();
\r
455 else if(self.enttype == ENT_CLIENT_RAINSNOW)
\r
457 else if(self.enttype == ENT_CLIENT_LASER)
\r
460 error("unknown entity type in CSQC_Ent_Update\n");
\r
463 // Destructor, but does NOT deallocate the entity by calling remove(). Also
\r
464 // used when an entity changes its type. For an entity that someone interacts
\r
465 // with others, make sure it can no longer do so.
\r
468 if(self.enttype == ENT_CLIENT_ENTCS)
\r
470 if(using_gps) //gametype == GAME_ONSLAUGHT)
\r
472 if(gps_start == self)
\r
473 gps_start = self.chain;
\r
479 while(ent.chain != self && ent.chain != world)
\r
481 if(ent.chain == self)
\r
482 ent.chain = self.chain;
\r
485 } else if(self.enttype == ENT_CLIENT_SCORES)
\r
489 SetTeam(self.owner, -1);
\r
490 if(self.owner.sort_prev)
\r
491 RemovePlayer(self.owner);
\r
492 self.owner.sort_prev = NULL;
\r
494 } else if(self.enttype == ENT_CLIENT_TEAMSCORES)
\r
498 RemoveTeam(self.owner);
\r
500 // we don't NEED to remove them... they won't display anyway
\r
501 // plus, svqc never does this anyway
\r
502 } else if(self.enttype == ENT_CLIENT_POINTPARTICLES)
\r
504 Ent_PointParticles_Remove();
\r
508 self.classname = "";
\r
509 self.draw = menu_sub_null;
\r
510 // TODO possibly set more stuff to defaults
\r
512 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
\r
513 void CSQC_Ent_Remove()
\r
520 void Gamemode_Init()
\r
522 local string mapinfo, infoline;
\r
525 local vector mi_min, mi_max;
\r
527 if(!strcasecmp(substring(mapname, 0, 5), "maps/"))
\r
528 shortmapname = substring(mapname, 5, 999);
\r
530 shortmapname = mapname;
\r
531 len = strlen(shortmapname);
\r
532 if(!strcasecmp(substring(shortmapname, len-4, 4), ".bsp"))
\r
533 shortmapname = substring(shortmapname, 0, len-4);
\r
534 shortmapname = strzone(shortmapname);
\r
536 if(gametype == GAME_ONSLAUGHT) {
\r
537 mapinfo = strcat("maps/", minimapname, ".info");
\r
538 minimapname = strzone(strcat("gfx/", shortmapname, "_mini.tga"));
\r
540 mi_min = world.mins;
\r
541 mi_max = world.maxs;
\r
543 file = fopen(mapinfo, FILE_READ);
\r
545 while((infoline = fgets(file))) {
\r
546 if(!strncasecmp(infoline, "mins", 4)) {
\r
547 mi_min = stov(substring(infoline, 5, 999));
\r
548 } else if(!strncasecmp(infoline, "maxs", 4)) {
\r
549 mi_max = stov(substring(infoline, 5, 999));
\r
550 } else if(strncasecmp(infoline, "//", 2)) { // don't print comment-style lines
\r
551 print(strcat("mapinfo: ", infoline, "\n"));
\r
555 print(strcat("Map has no .info file (", mapinfo, ").\n"));
\r
559 print(strcat("Mins: ", vtos(mi_min), " Maxs: ", vtos(mi_max), "\n"));
\r
561 mi_center = (mi_min + mi_max) * 0.5;
\r
562 mi_scale = mi_max - mi_min;
\r
565 print(strcat("Using ", minimapname, " as minimap.\n"));
\r
566 precache_pic(minimapname);
\r
567 precache_pic("gfx/ons-cp-neutral.tga");
\r
568 precache_pic("gfx/ons-cp-red.tga");
\r
569 precache_pic("gfx/ons-cp-blue.tga");
\r
570 precache_pic("gfx/ons-frame.tga");
\r
571 precache_pic("gfx/ons-frame-team.tga");
\r
572 } else if(gametype == GAME_KEYHUNT) {
\r
573 precache_pic("gfx/sb_key_carrying");
\r
574 precache_pic("gfx/sb_key_carrying_outline");
\r
577 // 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
578 void CSQC_Parse_StuffCmd(string strMessage)
\r
580 localcmd(strMessage);
\r
582 // 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
583 void CSQC_Parse_Print(string strMessage)
\r
587 // 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
588 void CSQC_Parse_CenterPrint(string strMessage)
\r
590 cprint(strMessage);
\r
593 void CSQC_CheckRevision();
\r
595 void Gamemode_Init();
\r
596 void Net_ReadScoresInfo()
\r
599 gametype = ReadByte();
\r
600 for(i = 0; i < MAX_SCORE; ++i)
\r
602 scores_label[i] = strzone(ReadString());
\r
603 scores_flags[i] = ReadByte();
\r
605 for(i = 0; i < MAX_TEAMSCORE; ++i)
\r
607 teamscores_label[i] = strzone(ReadString());
\r
608 teamscores_flags[i] = ReadByte();
\r
614 void Net_ReadInit()
\r
616 csqc_revision = ReadShort();
\r
617 maxclients = ReadByte();
\r
618 minstagib = ReadByte();
\r
620 CSQC_CheckRevision();
\r
623 string Net_ReadPicture()
\r
626 if(csqc_flags & CSQC_FLAG_READPICTURE)
\r
628 img = ReadPicture();
\r
629 print(strcat("Got Picture: ", img, "\n"));
\r
631 img = ReadString();
\r
632 print(strcat("^3Warning: ^7Couldn't download ", img, ". This is probably because your engine build is outdated.\n"));
\r
634 psize = ReadShort();
\r
635 // Can I be sure that ReadShort is 2 bytes and ReadLong is 4 bytes?
\r
636 // Because then this could be optimized to first get all 4-byte-groups,
\r
637 // then the remaining 2, then the remaining 1
\r
638 for(i = 0; i < psize; ++i)
\r
647 key = ReadString();
\r
648 value = ReadString();
\r
649 db_put(configdb, strcat("/v/", key), value);
\r
650 db_put(configdb, strcat("/s/", key), "1");
\r
653 void Net_ReadRace()
\r
661 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
\r
662 race_checkpoint = ReadByte();
\r
663 race_time = ReadShort();
\r
664 race_previousbesttime = ReadShort();
\r
665 if(race_previousbestname)
\r
666 strunzone(race_previousbestname);
\r
667 race_previousbestname = strzone(ReadString());
\r
669 race_checkpointtime = time;
\r
671 if(race_checkpoint == 0)
\r
672 race_laptime = time; // valid
\r
676 case RACE_NET_CHECKPOINT_CLEAR:
\r
678 race_checkpointtime = 0;
\r
681 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
\r
682 race_laptime = ReadCoord();
\r
683 race_checkpointtime = -99999;
\r
685 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
\r
686 race_nextcheckpoint = ReadByte();
\r
688 race_nextbesttime = ReadShort();
\r
689 if(race_nextbestname)
\r
690 strunzone(race_nextbestname);
\r
691 race_nextbestname = strzone(ReadString());
\r
694 case RACE_NET_CHECKPOINT_HIT_RACE:
\r
695 race_mycheckpoint = ReadByte();
\r
696 race_mycheckpointtime = time;
\r
697 race_mycheckpointdelta = ReadShort();
\r
698 race_mycheckpointlapsdelta = ReadByte();
\r
699 if(race_mycheckpointlapsdelta >= 128)
\r
700 race_mycheckpointlapsdelta -= 256;
\r
701 if(race_mycheckpointenemy)
\r
702 strunzone(race_mycheckpointenemy);
\r
703 race_mycheckpointenemy = strzone(ReadString());
\r
706 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
\r
707 race_othercheckpoint = ReadByte();
\r
708 race_othercheckpointtime = time;
\r
709 race_othercheckpointdelta = ReadShort();
\r
710 race_othercheckpointlapsdelta = ReadByte();
\r
711 if(race_othercheckpointlapsdelta >= 128)
\r
712 race_othercheckpointlapsdelta -= 256;
\r
713 if(race_othercheckpointenemy)
\r
714 strunzone(race_othercheckpointenemy);
\r
715 race_othercheckpointenemy = strzone(ReadString());
\r
720 void Net_ReadForceScoreboard()
\r
722 sb_showscores_force = ReadByte();
\r
728 race_checkpointtime = 0;
\r
731 void Net_ReadSpectating()
\r
733 float newspectatee_status;
\r
734 newspectatee_status = ReadByte();
\r
735 if(newspectatee_status == player_localentnum)
\r
736 newspectatee_status = -1; // observing
\r
737 if(newspectatee_status != spectatee_status)
\r
739 spectatee_status = newspectatee_status;
\r
742 void Net_ReadZoomNotify()
\r
744 spectatorbutton_zoom = ReadByte();
\r
747 void Net_ReadSpawn()
\r
750 current_viewzoom = 0.6;
\r
753 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
\r
754 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
\r
755 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
\r
756 float CSQC_Parse_TempEntity()
\r
758 local float bHandled;
\r
762 nTEID = ReadByte();
\r
764 // NOTE: Could just do return instead of break...
\r
771 case TE_CSQC_MAPVOTE:
\r
775 case TE_CSQC_CONFIG:
\r
779 case TE_CSQC_SCORESINFO:
\r
780 Net_ReadScoresInfo();
\r
787 case TE_CSQC_FORCESCOREBOARD:
\r
788 Net_ReadForceScoreboard();
\r
791 case TE_CSQC_SPECTATING:
\r
792 Net_ReadSpectating();
\r
795 case 13: // TE_BEAM
\r
796 Net_GrapplingHook();
\r
799 case TE_CSQC_SPAWN:
\r
803 case TE_CSQC_ZOOMNOTIFY:
\r
804 Net_ReadZoomNotify();
\r
808 // No special logic for this temporary entity; return 0 so the engine can handle it
\r
819 // COMMIT-TODO: Update if necessare, before committing
\r
820 void CSQC_CheckRevision()
\r
822 if(csqc_revision == CSQC_REVISION)
\r
824 print("^2SVQC and CSQC revisions are compatible.\n");
\r
825 } else if(csqc_revision < CSQC_REVISION) {
\r
826 print("^1Your csprogs.dat (CSQC) version is newer than the one on the server.\n");
\r
827 } else if(csqc_revision > CSQC_REVISION) {
\r
828 print("^1Your csprogs.dat (CSQC) is too old for this server.\n");
\r
829 print("^1Please update to a newer version.\n");
\r