1 // --------------------------------------------------------------------------
\r
2 // BEGIN REQUIRED CSQC FUNCTIONS
\r
5 void() menu_show_error =
\r
7 drawstring('0 200', "ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!", '8 8 0', '1 0 0', 1, 0);
\r
10 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
\r
11 // Useful for precaching things
\r
13 void() menu_sub_null =
\r
17 // let's make this a general data buffer...
\r
20 float __engine_check;
\r
22 void CSQC_Init(void)
\r
26 __engine_check = checkextension("DP_SV_WRITEPICTURE");
\r
29 print("^3Your engine build is outdated\n^3This Server uses a newer QC VM. Please update!\n");
\r
30 localcmd("\ndisconnect\n");
\r
35 __engine_check = true;
\r
41 menu_visible = FALSE;
\r
42 menu_show = menu_show_error;
\r
43 menu_action = menu_sub_null;
\r
46 localcmd("alias order \"cmd order $*\"");
\r
47 //registercmd("ctf_menu");
\r
48 registercmd("ons_map");
\r
49 //registercmd("menu_action");
\r
50 registercmd("sbar_columns_set");
\r
51 registercmd("sbar_columns_help");
\r
53 registercvar("sbar_usecsqc", "1");
\r
54 registercvar("sbar_columns", "ping name | caps returns frags deaths", CVAR_SAVE);
\r
60 // sbar_fields uses strunzone on the titles!
\r
61 for(i = 0; i < MAX_SBAR_FIELDS; ++i)
\r
62 sbar_title[i] = strzone("(null)");
\r
69 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
\r
70 void CSQC_Shutdown(void)
\r
73 IF __engine_check 2;
\r
83 print(strcat("PostInit\n maxclients = ", ftos(maxclients), "\n"));
\r
84 databuf = buf_create();
\r
85 for(i = 0; i < maxclients; ++i)
\r
87 bufstr_set(databuf, DATABUF_PING + i, "N/A");
\r
88 bufstr_set(databuf, DATABUF_DEATHS + i, "0");
\r
89 bufstr_set(databuf, DATABUF_CAPTURES + i, "0");
\r
90 bufstr_set(databuf, DATABUF_RETURNS + i, "0");
\r
93 localcmd(strcat("\nsbar_columns_set ", cvar_string("sbar_columns"), ";\n"));
\r
98 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function
\r
99 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
\r
100 void Cmd_Sbar_SetFields(float);
\r
101 void Cmd_Sbar_Help(float);
\r
102 float CSQC_ConsoleCommand(string strMessage)
\r
106 argc = tokenize(strMessage);
\r
109 local string strCmd;
\r
112 /*if(strCmd == "ctf_menu") {
\r
116 if(strCmd == "ons_map") {
\r
119 } else if(strCmd == "sbar_columns_set") {
\r
120 Cmd_Sbar_SetFields(argc);
\r
122 } else if(strCmd == "sbar_columns_help") {
\r
123 Cmd_Sbar_Help(argc);
\r
130 float GameCommand(string msg)
\r
133 argc = tokenize(msg);
\r
136 if(cmd == "mv_download") {
\r
137 Cmd_MapVote_MapDownload(argc);
\r
144 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
\r
145 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
\r
146 // All keys are in ascii.
\r
147 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
\r
148 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
\r
149 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
\r
150 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
\r
152 local float bSkipKey;
\r
155 if(menu_action(bInputType, nPrimary, nSecondary))
\r
160 // END REQUIRED CSQC FUNCTIONS
\r
161 // --------------------------------------------------------------------------
\r
163 // --------------------------------------------------------------------------
\r
164 // BEGIN OPTIONAL CSQC FUNCTIONS
\r
170 self.origin_x = ReadCoord();
\r
171 self.origin_y = ReadCoord();
\r
172 self.angles_y = ReadCoord();
\r
173 self.origin_z = self.angles_x = self.angles_z = 0;
\r
175 for(gps = gps_start; gps; gps = gps.chain)
\r
182 self.chain = gps_start;
\r
189 if(gps_start == self)
\r
190 gps_start = self.chain;
\r
196 while(ent.chain != self && ent.chain != world)
\r
198 if(ent.chain == self)
\r
199 ent.chain = self.chain;
\r
203 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
\r
204 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
\r
205 void(float bIsNewEntity) CSQC_Ent_Update =
\r
208 self.enttype = ReadByte();
\r
209 if(self.enttype == ENT_CLIENT_ENTCS)
\r
211 self.sv_entnum = ReadByte()-1;
\r
213 for(msg = ReadByte(); msg != ENTCS_MSG_END; msg = ReadByte())
\r
217 case ENTCS_MSG_ONS_GPS: ReadONS(); break;
\r
218 case ENTCS_MSG_ONS_REMOVE: RemoveONS(); break;
\r
220 error("unknown ENTCS_MSG type\n");
\r
225 error("unknown entity type in CSQC_Ent_Update\n");
\r
228 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
\r
229 void CSQC_Ent_Remove()
\r
231 if(self.enttype == ENT_CLIENT_ENTCS)
\r
233 if(using_gps) //gametype == GAME_ONSLAUGHT)
\r
235 if(gps_start == self)
\r
236 gps_start = self.chain;
\r
242 while(ent.chain != self && ent.chain != world)
\r
244 if(ent.chain == self)
\r
245 ent.chain = self.chain;
\r
252 void Gamemode_Init()
\r
254 local string mapinfo, infoline;
\r
257 local vector mi_min, mi_max;
\r
259 gametype = cvar("gametype");
\r
260 if(gametype == GAME_ONSLAUGHT) {
\r
261 if(!strcasecmp(substring(mapname, 0, 5), "maps/"))
\r
262 minimapname = substring(mapname, 5, 999);
\r
264 minimapname = mapname;
\r
265 len = strlen(minimapname);
\r
266 if(!strcasecmp(substring(minimapname, len-4, 4), ".bsp"))
\r
267 minimapname = substring(minimapname, 0, len-4);
\r
269 mapinfo = strcat("maps/", minimapname, ".info");
\r
270 minimapname = strzone(strcat("gfx/", minimapname, "_mini.tga"));
\r
272 mi_min = world.mins;
\r
273 mi_max = world.maxs;
\r
275 file = fopen(mapinfo, FILE_READ);
\r
277 while((infoline = fgets(file))) {
\r
278 if(!strncasecmp(infoline, "mins", 4)) {
\r
279 mi_min = stov(substring(infoline, 5, 999));
\r
280 } else if(!strncasecmp(infoline, "maxs", 4)) {
\r
281 mi_max = stov(substring(infoline, 5, 999));
\r
282 } else if(strncasecmp(infoline, "//", 2)) { // don't print comment-style lines
\r
283 print(strcat("mapinfo: ", infoline, "\n"));
\r
287 print(strcat("Map has no .info file (", mapinfo, ").\n"));
\r
291 print(strcat("Mins: ", vtos(mi_min), " Maxs: ", vtos(mi_max), "\n"));
\r
293 mi_center = (mi_min + mi_max) * 0.5;
\r
294 mi_scale = mi_max - mi_min;
\r
297 print(strcat("Using ", minimapname, " as minimap.\n"));
\r
298 precache_pic(minimapname);
\r
299 precache_pic("gfx/ons-cp-neutral.tga");
\r
300 precache_pic("gfx/ons-cp-red.tga");
\r
301 precache_pic("gfx/ons-cp-blue.tga");
\r
302 precache_pic("gfx/ons-frame.tga");
\r
303 precache_pic("gfx/ons-frame-team.tga");
\r
304 } else if(gametype == GAME_KEYHUNT) {
\r
305 precache_pic("gfx/sb_key_carrying");
\r
306 precache_pic("gfx/sb_key_carrying_outline");
\r
309 // 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
310 void CSQC_Parse_StuffCmd(string strMessage)
\r
312 localcmd(strMessage);
\r
313 // watch for gametype changes!
\r
314 if(gametype != cvar("gametype"))
\r
319 // 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
320 void CSQC_Parse_Print(string strMessage)
\r
324 // 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
325 void CSQC_Parse_CenterPrint(string strMessage)
\r
327 cprint(strMessage);
\r
330 void CSQC_CheckRevision();
\r
332 void Net_ReadInit()
\r
334 csqc_revision = ReadShort();
\r
335 maxclients = ReadByte();
\r
337 CSQC_CheckRevision();
\r
340 void Net_ReadPings()
\r
343 for(plnum = ReadByte(); plnum != 0; plnum = ReadByte())
\r
345 ping = ReadShort();
\r
346 bufstr_set(databuf, DATABUF_PING + plnum-1, ftos(ping));
\r
350 void Net_ReadCaptures()
\r
352 float plnum, caps, mode;
\r
354 caps_team1 = ReadByte();
\r
355 caps_team2 = ReadByte();
\r
356 for(plnum = ReadByte(); plnum != 0; plnum = ReadByte())
\r
359 bufstr_set(databuf, DATABUF_CAPTURES + plnum-1, ftos(caps));
\r
363 void Net_ReadDatabuf(float ofs)
\r
366 for(plnum = ReadByte(); plnum != 0; plnum = ReadByte())
\r
369 bufstr_set(databuf, ofs + plnum-1, ftos(data));
\r
373 string Net_ReadPicture()
\r
376 if(csqc_flags & CSQC_FLAG_READPICTURE)
\r
378 img = ReadPicture();
\r
379 print(strcat("Got Picture: ", img, "\n"));
\r
381 img = ReadString();
\r
382 print(strcat("^3Warning: ^7Couldn't download ", img, ". This is probably because your engine build is outdated.\n"));
\r
384 psize = ReadShort();
\r
385 // Can I be sure that ReadShort is 2 bytes and ReadLong is 4 bytes?
\r
386 // Because then this could be optimized to first get all 4-byte-groups,
\r
387 // then the remaining 2, then the remaining 1
\r
388 for(i = 0; i < psize; ++i)
\r
394 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
\r
395 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
\r
396 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
\r
397 float CSQC_Parse_TempEntity()
\r
399 local float bHandled;
\r
403 nTEID = ReadByte();
\r
405 // NOTE: Could just do return instead of break...
\r
416 case TE_CSQC_CAPTURES:
\r
417 Net_ReadCaptures();
\r
420 case TE_CSQC_RETURNS:
\r
421 Net_ReadDatabuf(DATABUF_RETURNS);
\r
424 case TE_CSQC_DEATHS:
\r
425 Net_ReadDatabuf(DATABUF_DEATHS);
\r
428 case TE_CSQC_MAPVOTE:
\r
434 // No special logic for this temporary entity; return 0 so the engine can handle it
\r
445 // COMMIT-TODO: Update if necessare, before committing
\r
446 float csqc_svn_map[CSQC_REVISION] =
\r
449 3820 // mapvote protocol changed from there
\r
452 // COMMIT-TODO: Update if necessare, before committing
\r
453 void CSQC_CheckRevision()
\r
455 if(csqc_revision == CSQC_REVISION)
\r
457 print("^2SVQC and CSQC revisions are compatible.\n");
\r
458 } else if(csqc_revision < CSQC_REVISION) {
\r
459 print("^1Your csprogs.dat (CSQC) version is newer than the one on the server.\n");
\r
460 print("^1The last known svn revision for the server's CSQC is: ^7");
\r
461 print(ftos(csqc_svn_map[csqc_revision])); // don't use strcat, fteqcc loves screwing up arrays...
\r
463 } else if(csqc_revision > CSQC_REVISION) {
\r
464 print("^1Your csprogs.dat (CSQC) is too old for this server.\n");
\r
465 print("^1Please update to a newer version.\n");
\r