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
221 if(ignore_plus_zoom)
\r
223 --ignore_plus_zoom;
\r
228 } else if(strCmd == "-button4") { // zoom
\r
229 if(ignore_minus_zoom)
\r
231 --ignore_minus_zoom;
\r
236 } else if(strCmd == "+button3") { // secondary
\r
237 button_attack2 = 1;
\r
239 } else if(strCmd == "-button3") { // secondary
\r
240 button_attack2 = 0;
\r
242 } else if(strCmd == "ons_map") {
\r
245 } else if(strCmd == "sbar_columns_set") {
\r
246 Cmd_Sbar_SetFields(argc);
\r
248 } else if(strCmd == "sbar_columns_help") {
\r
249 Cmd_Sbar_Help(argc);
\r
251 } else if(strCmd == "+showscores") {
\r
252 sb_showscores = true;
\r
254 } else if(strCmd == "-showscores") {
\r
255 sb_showscores = false;
\r
262 float GameCommand(string msg)
\r
265 argc = tokenize(msg);
\r
268 if(cmd == "mv_download") {
\r
269 Cmd_MapVote_MapDownload(argc);
\r
272 else if(cmd == "settemp") {
\r
274 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
\r
275 if(e.netname == argv(1))
\r
278 e.classname = "saved_cvar_value";
\r
279 e.netname = strzone(argv(1));
\r
280 e.message = strzone(cvar_string(argv(1)));
\r
282 cvar_set(argv(1), argv(2));
\r
288 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
\r
289 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
\r
290 // All keys are in ascii.
\r
291 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
\r
292 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
\r
293 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
\r
294 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
\r
296 local float bSkipKey;
\r
300 if(menu_action(bInputType, nPrimary, nSecondary))
\r
305 // END REQUIRED CSQC FUNCTIONS
\r
306 // --------------------------------------------------------------------------
\r
308 // --------------------------------------------------------------------------
\r
309 // BEGIN OPTIONAL CSQC FUNCTIONS
\r
315 self.origin_x = ReadCoord();
\r
316 self.origin_y = ReadCoord();
\r
317 self.angles_y = ReadCoord();
\r
318 self.origin_z = self.angles_x = self.angles_z = 0;
\r
320 for(gps = gps_start; gps; gps = gps.chain)
\r
327 self.chain = gps_start;
\r
332 void Ent_RemoveONS()
\r
334 if(gps_start == self)
\r
335 gps_start = self.chain;
\r
341 while(ent.chain != self && ent.chain != world)
\r
343 if(ent.chain == self)
\r
344 ent.chain = self.chain;
\r
349 void Ent_ReadPlayerScore()
\r
355 // damnit -.- don't want to go change every single .sv_entnum in sbar.qc AGAIN
\r
356 // (no I've never heard of M-x replace-string, sed, or anything like that)
\r
357 isNew = !self.owner; // workaround for DP bug
\r
360 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
361 if(!isNew && n != self.sv_entnum)
\r
363 print("A CSQC entity changed its owner!\n");
\r
366 self.enttype = ENT_CLIENT_SCORES;
\r
370 self.sv_entnum = n;
\r
371 Team = GetPlayerColor(self.sv_entnum);
\r
373 if not(playerslots[self.sv_entnum])
\r
374 playerslots[self.sv_entnum] = spawn();
\r
375 o = self.owner = playerslots[self.sv_entnum];
\r
376 o.sv_entnum = self.sv_entnum;
\r
378 if not(o.sort_prev)
\r
384 for(i = 0; i < MAX_SCORE; ++i)
\r
385 o.(scores[i]) = ReadShort();
\r
394 for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
\r
396 o.(scores[i]) = ReadShort();
\r
399 Sbar_UpdatePlayerPos(o);
\r
402 void Ent_ReadTeamScore()
\r
407 self.team = ReadByte();
\r
408 o = self.owner = GetTeam(self.team, true);
\r
410 #if MAX_TEAMSCORE <= 3
\r
411 for(i = 0; i < MAX_TEAMSCORE; ++i)
\r
412 o.(teamscores[i]) = ReadShort();
\r
415 #if MAX_TEAMSCORE <= 8
\r
421 for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
\r
423 o.(teamscores[i]) = ReadShort();
\r
426 Sbar_UpdateTeamPos(o);
\r
429 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
\r
430 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
\r
431 void(float bIsNewEntity) CSQC_Ent_Update =
\r
435 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
\r
437 if(t != self.enttype)
\r
439 print("A CSQC entity changed its type!\n");
\r
444 if(self.enttype == ENT_CLIENT_ENTCS)
\r
446 self.sv_entnum = ReadByte()-1;
\r
448 for(msg = ReadByte(); msg != ENTCS_MSG_END; msg = ReadByte())
\r
452 case ENTCS_MSG_ONS_GPS: Ent_ReadONS(); break;
\r
453 case ENTCS_MSG_ONS_REMOVE: Ent_RemoveONS(); break;
\r
455 error("unknown ENTCS_MSG type\n");
\r
459 else if(self.enttype == ENT_CLIENT_SCORES)
\r
460 Ent_ReadPlayerScore();
\r
461 else if(self.enttype == ENT_CLIENT_TEAMSCORES)
\r
462 Ent_ReadTeamScore();
\r
463 else if(self.enttype == ENT_CLIENT_POINTPARTICLES)
\r
464 Ent_PointParticles();
\r
465 else if(self.enttype == ENT_CLIENT_RAINSNOW)
\r
467 else if(self.enttype == ENT_CLIENT_LASER)
\r
470 error("unknown entity type in CSQC_Ent_Update\n");
\r
473 // Destructor, but does NOT deallocate the entity by calling remove(). Also
\r
474 // used when an entity changes its type. For an entity that someone interacts
\r
475 // with others, make sure it can no longer do so.
\r
478 if(self.enttype == ENT_CLIENT_ENTCS)
\r
480 if(using_gps) //gametype == GAME_ONSLAUGHT)
\r
482 if(gps_start == self)
\r
483 gps_start = self.chain;
\r
489 while(ent.chain != self && ent.chain != world)
\r
491 if(ent.chain == self)
\r
492 ent.chain = self.chain;
\r
495 } else if(self.enttype == ENT_CLIENT_SCORES)
\r
499 SetTeam(self.owner, -1);
\r
500 if(self.owner.sort_prev)
\r
501 RemovePlayer(self.owner);
\r
502 self.owner.sort_prev = NULL;
\r
504 } else if(self.enttype == ENT_CLIENT_TEAMSCORES)
\r
508 RemoveTeam(self.owner);
\r
510 // we don't NEED to remove them... they won't display anyway
\r
511 // plus, svqc never does this anyway
\r
512 } else if(self.enttype == ENT_CLIENT_POINTPARTICLES)
\r
514 Ent_PointParticles_Remove();
\r
518 self.classname = "";
\r
519 self.draw = menu_sub_null;
\r
520 // TODO possibly set more stuff to defaults
\r
522 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
\r
523 void CSQC_Ent_Remove()
\r
530 void Gamemode_Init()
\r
532 local string mapinfo, infoline;
\r
535 local vector mi_min, mi_max;
\r
537 if(!strcasecmp(substring(mapname, 0, 5), "maps/"))
\r
538 shortmapname = substring(mapname, 5, 999);
\r
540 shortmapname = mapname;
\r
541 len = strlen(shortmapname);
\r
542 if(!strcasecmp(substring(shortmapname, len-4, 4), ".bsp"))
\r
543 shortmapname = substring(shortmapname, 0, len-4);
\r
544 shortmapname = strzone(shortmapname);
\r
546 if(gametype == GAME_ONSLAUGHT) {
\r
547 mapinfo = strcat("maps/", minimapname, ".info");
\r
548 minimapname = strzone(strcat("gfx/", shortmapname, "_mini.tga"));
\r
550 mi_min = world.mins;
\r
551 mi_max = world.maxs;
\r
553 file = fopen(mapinfo, FILE_READ);
\r
555 while((infoline = fgets(file))) {
\r
556 if(!strncasecmp(infoline, "mins", 4)) {
\r
557 mi_min = stov(substring(infoline, 5, 999));
\r
558 } else if(!strncasecmp(infoline, "maxs", 4)) {
\r
559 mi_max = stov(substring(infoline, 5, 999));
\r
560 } else if(strncasecmp(infoline, "//", 2)) { // don't print comment-style lines
\r
561 print(strcat("mapinfo: ", infoline, "\n"));
\r
565 print(strcat("Map has no .info file (", mapinfo, ").\n"));
\r
569 print(strcat("Mins: ", vtos(mi_min), " Maxs: ", vtos(mi_max), "\n"));
\r
571 mi_center = (mi_min + mi_max) * 0.5;
\r
572 mi_scale = mi_max - mi_min;
\r
575 print(strcat("Using ", minimapname, " as minimap.\n"));
\r
576 precache_pic(minimapname);
\r
577 precache_pic("gfx/ons-cp-neutral.tga");
\r
578 precache_pic("gfx/ons-cp-red.tga");
\r
579 precache_pic("gfx/ons-cp-blue.tga");
\r
580 precache_pic("gfx/ons-frame.tga");
\r
581 precache_pic("gfx/ons-frame-team.tga");
\r
582 } else if(gametype == GAME_KEYHUNT) {
\r
583 precache_pic("gfx/sb_key_carrying");
\r
584 precache_pic("gfx/sb_key_carrying_outline");
\r
587 // 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
588 void CSQC_Parse_StuffCmd(string strMessage)
\r
590 localcmd(strMessage);
\r
592 // 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
593 void CSQC_Parse_Print(string strMessage)
\r
597 // 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
598 void CSQC_Parse_CenterPrint(string strMessage)
\r
600 cprint(strMessage);
\r
603 void CSQC_CheckRevision();
\r
605 void Gamemode_Init();
\r
606 void Net_ReadScoresInfo()
\r
609 gametype = ReadByte();
\r
610 for(i = 0; i < MAX_SCORE; ++i)
\r
612 scores_label[i] = strzone(ReadString());
\r
613 scores_flags[i] = ReadByte();
\r
615 for(i = 0; i < MAX_TEAMSCORE; ++i)
\r
617 teamscores_label[i] = strzone(ReadString());
\r
618 teamscores_flags[i] = ReadByte();
\r
624 void Net_ReadInit()
\r
626 csqc_revision = ReadShort();
\r
627 maxclients = ReadByte();
\r
628 minstagib = ReadByte();
\r
630 CSQC_CheckRevision();
\r
633 string Net_ReadPicture()
\r
636 if(csqc_flags & CSQC_FLAG_READPICTURE)
\r
638 img = ReadPicture();
\r
639 print(strcat("Got Picture: ", img, "\n"));
\r
641 img = ReadString();
\r
642 print(strcat("^3Warning: ^7Couldn't download ", img, ". This is probably because your engine build is outdated.\n"));
\r
644 psize = ReadShort();
\r
645 // Can I be sure that ReadShort is 2 bytes and ReadLong is 4 bytes?
\r
646 // Because then this could be optimized to first get all 4-byte-groups,
\r
647 // then the remaining 2, then the remaining 1
\r
648 for(i = 0; i < psize; ++i)
\r
657 key = ReadString();
\r
658 value = ReadString();
\r
659 db_put(configdb, strcat("/v/", key), value);
\r
660 db_put(configdb, strcat("/s/", key), "1");
\r
663 void Net_ReadRace()
\r
671 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
\r
672 race_checkpoint = ReadByte();
\r
673 race_time = ReadShort();
\r
674 race_previousbesttime = ReadShort();
\r
675 if(race_previousbestname)
\r
676 strunzone(race_previousbestname);
\r
677 race_previousbestname = strzone(ReadString());
\r
679 race_checkpointtime = time;
\r
681 if(race_checkpoint == 0)
\r
682 race_laptime = time; // valid
\r
686 case RACE_NET_CHECKPOINT_CLEAR:
\r
688 race_checkpointtime = 0;
\r
691 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:
\r
692 race_laptime = ReadCoord();
\r
693 race_checkpointtime = -99999;
\r
695 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:
\r
696 race_nextcheckpoint = ReadByte();
\r
698 race_nextbesttime = ReadShort();
\r
699 if(race_nextbestname)
\r
700 strunzone(race_nextbestname);
\r
701 race_nextbestname = strzone(ReadString());
\r
704 case RACE_NET_CHECKPOINT_HIT_RACE:
\r
705 race_mycheckpoint = ReadByte();
\r
706 race_mycheckpointtime = time;
\r
707 race_mycheckpointdelta = ReadShort();
\r
708 race_mycheckpointlapsdelta = ReadByte();
\r
709 if(race_mycheckpointlapsdelta >= 128)
\r
710 race_mycheckpointlapsdelta -= 256;
\r
711 if(race_mycheckpointenemy)
\r
712 strunzone(race_mycheckpointenemy);
\r
713 race_mycheckpointenemy = strzone(ReadString());
\r
716 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
\r
717 race_othercheckpoint = ReadByte();
\r
718 race_othercheckpointtime = time;
\r
719 race_othercheckpointdelta = ReadShort();
\r
720 race_othercheckpointlapsdelta = ReadByte();
\r
721 if(race_othercheckpointlapsdelta >= 128)
\r
722 race_othercheckpointlapsdelta -= 256;
\r
723 if(race_othercheckpointenemy)
\r
724 strunzone(race_othercheckpointenemy);
\r
725 race_othercheckpointenemy = strzone(ReadString());
\r
730 void Net_ReadForceScoreboard()
\r
732 sb_showscores_force = ReadByte();
\r
738 race_checkpointtime = 0;
\r
741 void Net_ReadSpectating()
\r
743 float newspectatee_status;
\r
744 newspectatee_status = ReadByte();
\r
745 if(newspectatee_status == player_localentnum)
\r
746 newspectatee_status = -1; // observing
\r
747 if(newspectatee_status != spectatee_status)
\r
749 spectatee_status = newspectatee_status;
\r
752 void Net_ReadZoomNotify()
\r
754 spectatorbutton_zoom = ReadByte();
\r
757 void Net_ReadSpawn()
\r
760 current_viewzoom = 0.6;
\r
763 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
\r
764 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
\r
765 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
\r
766 float CSQC_Parse_TempEntity()
\r
768 local float bHandled;
\r
772 nTEID = ReadByte();
\r
774 // NOTE: Could just do return instead of break...
\r
781 case TE_CSQC_MAPVOTE:
\r
785 case TE_CSQC_CONFIG:
\r
789 case TE_CSQC_SCORESINFO:
\r
790 Net_ReadScoresInfo();
\r
797 case TE_CSQC_FORCESCOREBOARD:
\r
798 Net_ReadForceScoreboard();
\r
801 case TE_CSQC_SPECTATING:
\r
802 Net_ReadSpectating();
\r
805 case 13: // TE_BEAM
\r
806 Net_GrapplingHook();
\r
809 case TE_CSQC_SPAWN:
\r
813 case TE_CSQC_ZOOMNOTIFY:
\r
814 Net_ReadZoomNotify();
\r
818 // No special logic for this temporary entity; return 0 so the engine can handle it
\r
829 // COMMIT-TODO: Update if necessare, before committing
\r
830 void CSQC_CheckRevision()
\r
832 if(csqc_revision == CSQC_REVISION)
\r
834 print("^2SVQC and CSQC revisions are compatible.\n");
\r
835 } else if(csqc_revision < CSQC_REVISION) {
\r
836 print("^1Your csprogs.dat (CSQC) version is newer than the one on the server.\n");
\r
837 } else if(csqc_revision > CSQC_REVISION) {
\r
838 print("^1Your csprogs.dat (CSQC) is too old for this server.\n");
\r
839 print("^1Please update to a newer version.\n");
\r