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 testpassedyay() {
\r
28 void CSQC_Init(void)
\r
32 __engine_check = checkextension("DP_SV_WRITEPICTURE");
\r
35 print("^3Your engine build is outdated\n^3This Server uses a newer QC VM. Please update!\n");
\r
36 localcmd("\ndisconnect\n");
\r
41 __engine_check = true;
\r
47 menu_visible = FALSE;
\r
48 menu_show = menu_show_error;
\r
49 menu_action = menu_sub_null;
\r
52 localcmd("alias order \"cmd order $*\"");
\r
53 //registercmd("ctf_menu");
\r
54 registercmd("ons_map");
\r
55 //registercmd("menu_action");
\r
56 registercmd("sbar_columns_set");
\r
57 registercmd("sbar_columns_help");
\r
59 registercvar("sbar_usecsqc", "1");
\r
60 registercvar("sbar_columns", "ping name | caps returns frags deaths", CVAR_SAVE);
\r
66 // sbar_fields uses strunzone on the titles!
\r
67 for(i = 0; i < MAX_SBAR_FIELDS; ++i)
\r
68 sbar_title[i] = strzone("(null)");
\r
75 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
\r
76 void CSQC_Shutdown(void)
\r
79 IF __engine_check 2;
\r
89 print(strcat("PostInit\n maxclients = ", ftos(maxclients), "\n"));
\r
90 databuf = buf_create();
\r
91 for(i = 0; i < maxclients; ++i)
\r
93 bufstr_set(databuf, DATABUF_PING + i, "N/A");
\r
94 bufstr_set(databuf, DATABUF_DEATHS + i, "0");
\r
95 bufstr_set(databuf, DATABUF_CAPTURES + i, "0");
\r
96 bufstr_set(databuf, DATABUF_RETURNS + i, "0");
\r
99 localcmd(strcat("\nsbar_columns_set ", cvar_string("sbar_columns"), ";\n"));
\r
104 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function
\r
105 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
\r
106 void Cmd_Sbar_SetFields(float);
\r
107 void Cmd_Sbar_Help(float);
\r
108 float CSQC_ConsoleCommand(string strMessage)
\r
112 argc = tokenize(strMessage);
\r
115 local string strCmd;
\r
118 /*if(strCmd == "ctf_menu") {
\r
122 if(strCmd == "ons_map") {
\r
125 } else if(strCmd == "sbar_columns_set") {
\r
126 Cmd_Sbar_SetFields(argc);
\r
128 } else if(strCmd == "sbar_columns_help") {
\r
129 Cmd_Sbar_Help(argc);
\r
136 float GameCommand(string msg)
\r
139 argc = tokenize(msg);
\r
142 if(cmd == "mv_download") {
\r
143 Cmd_MapVote_MapDownload(argc);
\r
150 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
\r
151 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
\r
152 // All keys are in ascii.
\r
153 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
\r
154 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
\r
155 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
\r
156 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
\r
158 local float bSkipKey;
\r
161 if(menu_action(bInputType, nPrimary, nSecondary))
\r
166 // END REQUIRED CSQC FUNCTIONS
\r
167 // --------------------------------------------------------------------------
\r
169 // --------------------------------------------------------------------------
\r
170 // BEGIN OPTIONAL CSQC FUNCTIONS
\r
176 self.origin_x = ReadCoord();
\r
177 self.origin_y = ReadCoord();
\r
178 self.angles_y = ReadCoord();
\r
179 self.origin_z = self.angles_x = self.angles_z = 0;
\r
181 for(gps = gps_start; gps; gps = gps.chain)
\r
188 self.chain = gps_start;
\r
195 if(gps_start == self)
\r
196 gps_start = self.chain;
\r
202 while(ent.chain != self && ent.chain != world)
\r
204 if(ent.chain == self)
\r
205 ent.chain = self.chain;
\r
209 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
\r
210 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
\r
211 void(float bIsNewEntity) CSQC_Ent_Update =
\r
214 self.enttype = ReadByte();
\r
215 if(self.enttype == ENT_CLIENT_ENTCS)
\r
217 self.sv_entnum = ReadByte()-1;
\r
219 for(msg = ReadByte(); msg != ENTCS_MSG_END; msg = ReadByte())
\r
223 case ENTCS_MSG_ONS_GPS: ReadONS(); break;
\r
224 case ENTCS_MSG_ONS_REMOVE: RemoveONS(); break;
\r
226 error("unknown ENTCS_MSG type\n");
\r
231 error("unknown entity type in CSQC_Ent_Update\n");
\r
234 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
\r
235 void CSQC_Ent_Remove()
\r
237 if(self.enttype == ENT_CLIENT_ENTCS)
\r
239 if(using_gps) //gametype == GAME_ONSLAUGHT)
\r
241 if(gps_start == self)
\r
242 gps_start = self.chain;
\r
248 while(ent.chain != self && ent.chain != world)
\r
250 if(ent.chain == self)
\r
251 ent.chain = self.chain;
\r
258 void Gamemode_Init()
\r
260 local string mapinfo, infoline;
\r
263 local vector mi_min, mi_max;
\r
265 gametype = cvar("gametype");
\r
266 if(gametype == GAME_ONSLAUGHT) {
\r
267 if(!strcasecmp(substring(mapname, 0, 5), "maps/"))
\r
268 minimapname = substring(mapname, 5, 999);
\r
270 minimapname = mapname;
\r
271 len = strlen(minimapname);
\r
272 if(!strcasecmp(substring(minimapname, len-4, 4), ".bsp"))
\r
273 minimapname = substring(minimapname, 0, len-4);
\r
275 mapinfo = strcat("maps/", minimapname, ".info");
\r
276 minimapname = strzone(strcat("gfx/", minimapname, "_mini.tga"));
\r
278 mi_min = world.mins;
\r
279 mi_max = world.maxs;
\r
281 file = fopen(mapinfo, FILE_READ);
\r
283 while((infoline = fgets(file))) {
\r
284 if(!strncasecmp(infoline, "mins", 4)) {
\r
285 mi_min = stov(substring(infoline, 5, 999));
\r
286 } else if(!strncasecmp(infoline, "maxs", 4)) {
\r
287 mi_max = stov(substring(infoline, 5, 999));
\r
288 } else if(strncasecmp(infoline, "//", 2)) { // don't print comment-style lines
\r
289 print(strcat("mapinfo: ", infoline, "\n"));
\r
293 print(strcat("Map has no .info file (", mapinfo, ").\n"));
\r
297 print(strcat("Mins: ", vtos(mi_min), " Maxs: ", vtos(mi_max), "\n"));
\r
299 mi_center = (mi_min + mi_max) * 0.5;
\r
300 mi_scale = mi_max - mi_min;
\r
303 print(strcat("Using ", minimapname, " as minimap.\n"));
\r
304 precache_pic(minimapname);
\r
305 precache_pic("gfx/ons-cp-neutral.tga");
\r
306 precache_pic("gfx/ons-cp-red.tga");
\r
307 precache_pic("gfx/ons-cp-blue.tga");
\r
308 precache_pic("gfx/ons-frame.tga");
\r
309 precache_pic("gfx/ons-frame-team.tga");
\r
310 } else if(gametype == GAME_KEYHUNT) {
\r
311 precache_pic("gfx/sb_key_carrying");
\r
312 precache_pic("gfx/sb_key_carrying_outline");
\r
315 // 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
316 void CSQC_Parse_StuffCmd(string strMessage)
\r
318 localcmd(strMessage);
\r
319 // watch for gametype changes!
\r
320 if(gametype != cvar("gametype"))
\r
325 // 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
326 void CSQC_Parse_Print(string strMessage)
\r
330 // 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
331 void CSQC_Parse_CenterPrint(string strMessage)
\r
333 cprint(strMessage);
\r
336 void CSQC_CheckRevision();
\r
338 void Net_ReadInit()
\r
340 csqc_revision = ReadShort();
\r
341 maxclients = ReadByte();
\r
343 CSQC_CheckRevision();
\r
346 void Net_ReadPings()
\r
349 for(plnum = ReadByte(); plnum != 0; plnum = ReadByte())
\r
351 ping = ReadShort();
\r
352 bufstr_set(databuf, DATABUF_PING + plnum-1, ftos(ping));
\r
356 void Net_ReadCaptures()
\r
358 float plnum, caps, mode;
\r
360 caps_team1 = ReadByte();
\r
361 caps_team2 = ReadByte();
\r
362 for(plnum = ReadByte(); plnum != 0; plnum = ReadByte())
\r
365 bufstr_set(databuf, DATABUF_CAPTURES + plnum-1, ftos(caps));
\r
369 void Net_ReadDatabuf(float ofs)
\r
372 for(plnum = ReadByte(); plnum != 0; plnum = ReadByte())
\r
375 bufstr_set(databuf, ofs + plnum-1, ftos(data));
\r
379 void Net_ReadPicture()
\r
382 if(csqc_flags & CSQC_FLAG_READPICTURE)
\r
384 img = ReadPicture();
\r
385 print(strcat("Got Picture: ", img, "\n"));
\r
387 img = ReadString();
\r
388 print(strcat("^3Warning: ^7Couldn't download ", img, ". This is probably because your engine build is outdated.\n"));
\r
390 psize = ReadShort();
\r
391 // Can I be sure that ReadShort is 2 bytes and ReadLong is 4 bytes?
\r
392 // Because then this could be optimized to first get all 4-byte-groups,
\r
393 // then the remaining 2, then the remaining 1
\r
394 for(i = 0; i < psize; ++i)
\r
399 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
\r
400 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
\r
401 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
\r
402 float CSQC_Parse_TempEntity()
\r
404 local float bHandled;
\r
408 nTEID = ReadByte();
\r
410 // NOTE: Could just do return instead of break...
\r
421 case TE_CSQC_CAPTURES:
\r
422 Net_ReadCaptures();
\r
425 case TE_CSQC_RETURNS:
\r
426 Net_ReadDatabuf(DATABUF_RETURNS);
\r
429 case TE_CSQC_DEATHS:
\r
430 Net_ReadDatabuf(DATABUF_DEATHS);
\r
433 case TE_CSQC_PICTURE:
\r
437 case TE_CSQC_MAPVOTE:
\r
443 // No special logic for this temporary entity; return 0 so the engine can handle it
\r
454 // COMMIT-TODO: Update if necessare, before committing
\r
455 float csqc_svn_map[CSQC_REVISION] =
\r
461 // COMMIT-TODO: Update if necessare, before committing
\r
462 void CSQC_CheckRevision()
\r
464 if(csqc_revision == CSQC_REVISION)
\r
466 print("^2SVQC and CSQC revisions are compatible.\n");
\r
467 } else if(csqc_revision < CSQC_REVISION) {
\r
468 print("^1Your csprogs.dat (CSQC) version is newer than the one on the server.\n");
\r
469 print("^1The last known svn revision for the server's CSQC is: ^7");
\r
470 print(ftos(csqc_svn_map[csqc_revision])); // don't use strcat, fteqcc loves screwing up arrays...
\r
472 } else if(csqc_revision > CSQC_REVISION) {
\r
473 print("^1Your csprogs.dat (CSQC) is too old for this server.\n");
\r
474 print("^1Please update to a newer version.\n");
\r