oops :P
[divverent/nexuiz.git] / data / qcsrc / client / Main.qc
1 // --------------------------------------------------------------------------\r
2 // BEGIN REQUIRED CSQC FUNCTIONS\r
3 //include "main.qh"\r
4 \r
5 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED\r
6 \r
7 void() menu_show_error =\r
8 {\r
9         drawstring('0 200 0', "ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!", '8 8 0', '1 0 0', 1, 0);\r
10 };\r
11 \r
12 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)\r
13 // Useful for precaching things\r
14 \r
15 void() menu_sub_null =\r
16 {\r
17 };\r
18 \r
19 // let's make this a general data buffer...\r
20 float using_gps;\r
21 \r
22 #ifdef USE_FTE\r
23 float __engine_check;\r
24 #endif\r
25 \r
26 string config_get(string key, string defaultvalue)\r
27 {\r
28         string s;\r
29         s = db_get(configdb, strcat("/s/", key));\r
30         if(s == "")\r
31                 return defaultvalue;\r
32         else\r
33                 return db_get(configdb, strcat("/v/", key));\r
34 }\r
35 \r
36 void CSQC_Init(void)\r
37 {\r
38 #ifdef USE_FTE\r
39 #pragma target ID\r
40         __engine_check = checkextension("DP_SV_WRITEPICTURE");\r
41         if(!__engine_check)\r
42         {\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
45                 return;\r
46         }\r
47 #pragma target FTE\r
48 #endif\r
49         \r
50         float i;\r
51         CSQC_CheckEngine();\r
52 \r
53         configdb = db_create();\r
54         compressShortVector_init();\r
55 \r
56         drawfont = 0;\r
57         menu_visible = FALSE;\r
58         menu_show = menu_show_error;\r
59         menu_action = menu_sub_null;\r
60         using_gps = false;\r
61         maxclients = 255; // we later get the real maxclients to speed up stuff\r
62         //ctf_temp_1 = "";\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
69 \r
70         registercvar("sbar_usecsqc", "1");\r
71         registercvar("sbar_columns", "default", CVAR_SAVE);\r
72 \r
73         gametype = 0;\r
74 \r
75         gps_start = world;\r
76 \r
77         // sbar_fields uses strunzone on the titles!\r
78         for(i = 0; i < MAX_SBAR_FIELDS; ++i)\r
79                 sbar_title[i] = strzone("(null)");\r
80 \r
81         postinit = false;\r
82 \r
83         teams = Sort_Spawn();\r
84         players = Sort_Spawn();\r
85         \r
86         GetTeam(COLOR_SPECTATOR, true); // add specs first\r
87 }\r
88 \r
89 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)\r
90 void CSQC_Shutdown(void)\r
91 {\r
92 #ifdef USE_FTE\r
93 #pragma TARGET id\r
94         if(!__engine_check)\r
95                 return 0;\r
96 #pragma TARGET fte\r
97 #endif\r
98 \r
99         remove(teams);\r
100         remove(players);\r
101         db_close(configdb);\r
102 \r
103         entity e;\r
104         for(e = world; (e = find(e, classname, "saved_cvar_value")); )\r
105                         cvar_set(e.netname, e.message);\r
106 }\r
107 \r
108 .float has_team;\r
109 float SetTeam(entity o, float Team)\r
110 {\r
111         entity tm;\r
112         if(Team == -1) // leave\r
113         {\r
114                 if(o.has_team)\r
115                 {\r
116                         //print("(DISCONNECT) leave team ", ftos(o.team), "\n");\r
117                         tm = GetTeam(o.team, false);\r
118                         tm.team_size -= 1;\r
119                         o.has_team = 0;\r
120                         return TRUE;\r
121                 }\r
122         }\r
123         else\r
124         {\r
125                 if not(o.has_team)\r
126                 {\r
127                         //print("(CONNECT) enter team ", ftos(o.team), "\n");\r
128                         o.team = Team;\r
129                         tm = GetTeam(Team, true);\r
130                         tm.team_size += 1;\r
131                         o.has_team = 1;\r
132                         return TRUE;\r
133                 }\r
134                 else if(Team != o.team)\r
135                 {\r
136                         //print("(CHANGE) leave team ", ftos(o.team), "\n");\r
137                         tm = GetTeam(o.team, false);\r
138                         tm.team_size -= 1;\r
139                         o.team = Team;\r
140                         //print("(CHANGE) enter team ", ftos(o.team), "\n");\r
141                         tm = GetTeam(Team, true);\r
142                         tm.team_size += 1;\r
143                         return TRUE;\r
144                 }\r
145         }\r
146         return FALSE;\r
147 }\r
148 \r
149 void Playerchecker_Think()\r
150 {\r
151         float i;\r
152         for(i = 0; i < maxclients; ++i)\r
153         {\r
154                 if(getplayerkey(i, "name") == "")\r
155                 {\r
156                         if(playerslots[i].sort_prev)\r
157                         {\r
158                                 //print("playerchecker: KILL KILL KILL\n");\r
159                                 // player disconnected\r
160                                 SetTeam(playerslots[i], -1);\r
161                                 RemovePlayer(playerslots[i]);\r
162                                 playerslots[i].sort_prev = world;\r
163                                 playerslots[i].gotscores = 0;\r
164                         }\r
165                 }\r
166                 else\r
167                 {\r
168                         if not(playerslots[i].sort_prev)\r
169                         {\r
170                                 //print("playerchecker: SPAWN SPAWN SPAWN\n");\r
171                                 // player connected\r
172                                 if not(playerslots[i])\r
173                                         playerslots[i] = spawn();\r
174                                 playerslots[i].sv_entnum = i;\r
175                                 playerslots[i].gotscores = 0;\r
176                                 SetTeam(playerslots[i], COLOR_SPECTATOR);\r
177                                 RegisterPlayer(playerslots[i]);\r
178                                 Sbar_UpdatePlayerPos(playerslots[i]);\r
179                         }\r
180                 }\r
181         }\r
182         self.nextthink = time + 0.2;\r
183 }\r
184 \r
185 void PostInit(void)\r
186 {\r
187         print(strcat("PostInit\n    maxclients = ", ftos(maxclients), "\n"));\r
188         localcmd(strcat("\nsbar_columns_set ", cvar_string("sbar_columns"), ";\n"));\r
189 \r
190         entity playerchecker;\r
191         playerchecker = spawn();\r
192         playerchecker.think = Playerchecker_Think;\r
193         playerchecker.nextthink = time + 0.2;\r
194 \r
195         postinit = true;\r
196 }\r
197 \r
198 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function\r
199 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.\r
200 void Cmd_Sbar_SetFields(float);\r
201 void Cmd_Sbar_Help(float);\r
202 float CSQC_ConsoleCommand(string strMessage)\r
203 {\r
204         float argc;\r
205         // Tokenize String\r
206         //argc = tokenize(strMessage);\r
207         argc = tokenizebyseparator(strMessage, " ");\r
208         \r
209         // Acquire Command\r
210         local string strCmd;\r
211         strCmd = argv(0);\r
212 \r
213         /*if(strCmd == "ctf_menu") {\r
214                 ctf_menu_show();\r
215                 nReturn = true;\r
216                 } else*/\r
217         if(strCmd == "ons_map") {\r
218                 Cmd_ons_map();\r
219                 return true;\r
220         } else if(strCmd == "sbar_columns_set") {\r
221                 Cmd_Sbar_SetFields(argc);\r
222                 return true;\r
223         } else if(strCmd == "sbar_columns_help") {\r
224                 Cmd_Sbar_Help(argc);\r
225                 return true;\r
226         } else if(strCmd == "+showscores") {\r
227                 sb_showscores = true;\r
228                 return true;\r
229         } else if(strCmd == "-showscores") {\r
230                 sb_showscores = false;\r
231                 return true;\r
232         }\r
233         \r
234         return false;\r
235 }\r
236 \r
237 float GameCommand(string msg)\r
238 {\r
239         float argc;\r
240         argc = tokenize(msg);\r
241         string cmd;\r
242         cmd = argv(0);\r
243         if(cmd == "mv_download") {\r
244                 Cmd_MapVote_MapDownload(argc);\r
245                 return true;\r
246         }\r
247         else if(cmd == "settemp") {\r
248                 entity e;\r
249                 for(e = world; (e = find(e, classname, "saved_cvar_value")); )\r
250                         if(e.netname == argv(1))\r
251                                 goto saved;\r
252                 e = spawn();\r
253                 e.classname = "saved_cvar_value";\r
254                 e.netname = strzone(argv(1));\r
255                 e.message = strzone(cvar_string(argv(1)));\r
256 :saved\r
257                 cvar_set(argv(1), argv(2));\r
258         }\r
259         \r
260         return false;\r
261 }\r
262 \r
263 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.\r
264 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.\r
265 // All keys are in ascii.\r
266 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.\r
267 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.\r
268 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.\r
269 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)\r
270 {\r
271         local float bSkipKey;\r
272         bSkipKey = false;\r
273         \r
274         if(menu_visible)\r
275                 if(menu_action(bInputType, nPrimary, nSecondary))\r
276                         return TRUE;\r
277         return bSkipKey;\r
278 }\r
279 \r
280 // END REQUIRED CSQC FUNCTIONS\r
281 // --------------------------------------------------------------------------\r
282 \r
283 // --------------------------------------------------------------------------\r
284 // BEGIN OPTIONAL CSQC FUNCTIONS\r
285 void Ent_ReadONS()\r
286 {\r
287         entity gps;\r
288         using_gps = true;\r
289 \r
290         self.origin_x = ReadCoord();\r
291         self.origin_y = ReadCoord();\r
292         self.angles_y = ReadCoord();\r
293         self.origin_z = self.angles_x = self.angles_z = 0;\r
294 \r
295         for(gps = gps_start; gps; gps = gps.chain)\r
296         {\r
297                 if(gps == self)\r
298                         break;\r
299         }\r
300         if(!gps)\r
301         {\r
302                 self.chain = gps_start;\r
303                 gps_start = self;\r
304         }\r
305 }\r
306 \r
307 void Ent_RemoveONS()\r
308 {\r
309         if(gps_start == self)\r
310                 gps_start = self.chain;\r
311         else\r
312         {\r
313                 local entity ent;\r
314                 ent = gps_start;\r
315                         \r
316                 while(ent.chain != self && ent.chain != world)\r
317                         ent = ent.chain;\r
318                 if(ent.chain == self)\r
319                         ent.chain = self.chain;\r
320         }\r
321 }\r
322 \r
323 void Ent_Remove();\r
324 void Ent_ReadPlayerScore()\r
325 {\r
326         float i, Team, n;\r
327         float isNew;\r
328         entity o;\r
329 \r
330         // damnit -.- don't want to go change every single .sv_entnum in sbar.qc AGAIN\r
331         // (no I've never heard of M-x replace-string, sed, or anything like that)\r
332         isNew = !self.owner; // workaround for DP bug\r
333         n = ReadByte()-1;\r
334 \r
335 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED\r
336         if(!isNew && n != self.sv_entnum)\r
337         {\r
338                 print("A CSQC entity changed its owner!\n");\r
339                 isNew = true;\r
340                 Ent_Remove();\r
341                 self.enttype = ENT_CLIENT_SCORES;\r
342         }\r
343 #endif\r
344 \r
345         self.sv_entnum = n;\r
346         Team = GetPlayerColor(self.sv_entnum);\r
347 \r
348         if not(playerslots[self.sv_entnum])\r
349                 playerslots[self.sv_entnum] = spawn();\r
350         o = self.owner = playerslots[self.sv_entnum];\r
351         o.sv_entnum = self.sv_entnum;\r
352         o.gotscores = 1;\r
353         if not(o.sort_prev)\r
354                 RegisterPlayer(o);\r
355 \r
356         SetTeam(o, Team);\r
357 \r
358 #if MAX_SCORE <= 3\r
359         for(i = 0; i < MAX_SCORE; ++i)\r
360                 o.(scores[i]) = ReadShort();\r
361 #else\r
362         float sf;\r
363 #if MAX_SCORE <= 8\r
364         sf = ReadByte();\r
365 #else\r
366         sf = ReadShort();\r
367 #endif\r
368         float p;\r
369         for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)\r
370                 if(sf & p)\r
371                         o.(scores[i]) = ReadShort();\r
372 #endif\r
373 \r
374         Sbar_UpdatePlayerPos(o);\r
375 }\r
376 \r
377 void Ent_ReadTeamScore()\r
378 {\r
379         float i;\r
380         entity o;\r
381         \r
382         self.team = ReadByte();\r
383         o = self.owner = GetTeam(self.team, true);\r
384 \r
385 #if MAX_TEAMSCORE <= 3\r
386         for(i = 0; i < MAX_TEAMSCORE; ++i)\r
387                 o.(teamscores[i]) = ReadShort();\r
388 #else\r
389         float sf;\r
390 #if MAX_TEAMSCORE <= 8\r
391         sf = ReadByte();\r
392 #else\r
393         sf = ReadShort();\r
394 #endif\r
395         float p;\r
396         for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)\r
397                 if(sf & p)\r
398                         o.(teamscores[i]) = ReadShort();\r
399 #endif\r
400 \r
401         Sbar_UpdateTeamPos(o);\r
402 }\r
403 \r
404 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.\r
405 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.\r
406 void(float bIsNewEntity) CSQC_Ent_Update =\r
407 {\r
408         float msg, t;\r
409         t = ReadByte();\r
410 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED\r
411         if(self.enttype)\r
412                 if(t != self.enttype)\r
413                 {\r
414                         print("A CSQC entity changed its type!\n");\r
415                         Ent_Remove();\r
416                 }\r
417 #endif\r
418         self.enttype = t;\r
419         if(self.enttype == ENT_CLIENT_ENTCS)\r
420         {\r
421                 self.sv_entnum = ReadByte()-1;\r
422 \r
423                 for(msg = ReadByte(); msg != ENTCS_MSG_END; msg = ReadByte())\r
424                 {\r
425                         switch(msg)\r
426                         {\r
427                         case ENTCS_MSG_ONS_GPS: Ent_ReadONS(); break;\r
428                         case ENTCS_MSG_ONS_REMOVE: Ent_RemoveONS(); break;\r
429                         default:\r
430                                 error("unknown ENTCS_MSG type\n");\r
431                         }\r
432                 }\r
433         }\r
434         else if(self.enttype == ENT_CLIENT_SCORES)\r
435                 Ent_ReadPlayerScore();\r
436         else if(self.enttype == ENT_CLIENT_TEAMSCORES)\r
437                 Ent_ReadTeamScore();\r
438         else if(self.enttype == ENT_CLIENT_POINTPARTICLES)\r
439                 Ent_PointParticles();\r
440         else if(self.enttype == ENT_CLIENT_RAINSNOW)\r
441                 Ent_RainOrSnow();\r
442         else\r
443                 error("unknown entity type in CSQC_Ent_Update\n");\r
444         \r
445 };\r
446 // Destructor, but does NOT deallocate the entity by calling remove(). Also\r
447 // used when an entity changes its type. For an entity that someone interacts\r
448 // with others, make sure it can no longer do so.\r
449 void Ent_Remove()\r
450 {\r
451         if(self.enttype == ENT_CLIENT_ENTCS)\r
452         {\r
453                 if(using_gps) //gametype == GAME_ONSLAUGHT)\r
454                 {\r
455                         if(gps_start == self)\r
456                                 gps_start = self.chain;\r
457                         else\r
458                         {\r
459                                 local entity ent;\r
460                                 ent = gps_start;\r
461                         \r
462                                 while(ent.chain != self && ent.chain != world)\r
463                                         ent = ent.chain;\r
464                                 if(ent.chain == self)\r
465                                         ent.chain = self.chain;\r
466                         }\r
467                 }\r
468         } else if(self.enttype == ENT_CLIENT_SCORES)\r
469         {\r
470                 if(self.owner)\r
471                 {\r
472                         SetTeam(self.owner, -1);\r
473                         if(self.owner.sort_prev)\r
474                                 RemovePlayer(self.owner);\r
475                         self.owner.sort_prev = NULL;\r
476                 }\r
477         } else if(self.enttype == ENT_CLIENT_TEAMSCORES)\r
478         {\r
479                 /*\r
480                 if(self.owner)\r
481                         RemoveTeam(self.owner);\r
482                 */\r
483                 // we don't NEED to remove them... they won't display anyway\r
484                 // plus, svqc never does this anyway\r
485         }\r
486 \r
487         self.enttype = 0;\r
488         self.classname = "";\r
489         self.draw = menu_sub_null;\r
490         // TODO possibly set more stuff to defaults\r
491 }\r
492 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.\r
493 void CSQC_Ent_Remove()\r
494 {\r
495         if(self.enttype)\r
496                 Ent_Remove();\r
497         remove(self);\r
498 }\r
499 \r
500 void Gamemode_Init()\r
501 {\r
502         local string mapinfo, infoline;\r
503         local float len;\r
504         local float file;\r
505         local vector mi_min, mi_max;\r
506 \r
507         if(!strcasecmp(substring(mapname, 0, 5), "maps/"))\r
508                 shortmapname = substring(mapname, 5, 999);\r
509         else\r
510                 shortmapname = mapname;\r
511         len = strlen(shortmapname);\r
512         if(!strcasecmp(substring(shortmapname, len-4, 4), ".bsp"))\r
513                 shortmapname = substring(shortmapname, 0, len-4);\r
514         shortmapname = strzone(shortmapname);\r
515 \r
516         if(gametype == GAME_ONSLAUGHT) {\r
517                 mapinfo = strcat("maps/", minimapname, ".info");\r
518                 minimapname = strzone(strcat("gfx/", shortmapname, "_mini.tga"));\r
519 \r
520                 mi_min = world.mins;\r
521                 mi_max = world.maxs;\r
522                 \r
523                 file = fopen(mapinfo, FILE_READ);\r
524                 if(file >= 0) {\r
525                         while((infoline = fgets(file))) {\r
526                                 if(!strncasecmp(infoline, "mins", 4)) {\r
527                                         mi_min = stov(substring(infoline, 5, 999));\r
528                                 } else if(!strncasecmp(infoline, "maxs", 4)) {\r
529                                         mi_max = stov(substring(infoline, 5, 999));\r
530                                 } else if(strncasecmp(infoline, "//", 2)) { // don't print comment-style lines\r
531                                         print(strcat("mapinfo: ", infoline, "\n"));\r
532                                 }\r
533                         }\r
534                 } else {\r
535                         print(strcat("Map has no .info file (", mapinfo, ").\n"));\r
536                 }\r
537                 fclose(file);\r
538 \r
539                 print(strcat("Mins: ", vtos(mi_min), "    Maxs: ", vtos(mi_max), "\n"));\r
540                 \r
541                 mi_center = (mi_min + mi_max) * 0.5;\r
542                 mi_scale = mi_max - mi_min;\r
543                 \r
544                 \r
545                 print(strcat("Using ", minimapname, " as minimap.\n"));\r
546                 precache_pic(minimapname);\r
547                 precache_pic("gfx/ons-cp-neutral.tga");\r
548                 precache_pic("gfx/ons-cp-red.tga");\r
549                 precache_pic("gfx/ons-cp-blue.tga");\r
550                 precache_pic("gfx/ons-frame.tga");\r
551                 precache_pic("gfx/ons-frame-team.tga");\r
552         } else if(gametype == GAME_KEYHUNT) {\r
553                 precache_pic("gfx/sb_key_carrying");\r
554                 precache_pic("gfx/sb_key_carrying_outline");\r
555         }\r
556 }\r
557 // 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
558 void CSQC_Parse_StuffCmd(string strMessage)\r
559 {\r
560         localcmd(strMessage);\r
561 }\r
562 // 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
563 void CSQC_Parse_Print(string strMessage)\r
564 {\r
565         print(strMessage);\r
566 }\r
567 // 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
568 void CSQC_Parse_CenterPrint(string strMessage)\r
569 {\r
570         cprint(strMessage);\r
571 }\r
572 \r
573 void CSQC_CheckRevision();\r
574 \r
575 void Gamemode_Init();\r
576 void Net_ReadScoresInfo()\r
577 {\r
578         float i;\r
579         gametype = ReadByte();\r
580         for(i = 0; i < MAX_SCORE; ++i)\r
581         {\r
582                 scores_label[i] = strzone(ReadString());\r
583                 scores_flags[i] = ReadByte();\r
584         }\r
585         for(i = 0; i < MAX_TEAMSCORE; ++i)\r
586         {\r
587                 teamscores_label[i] = strzone(ReadString());\r
588                 teamscores_flags[i] = ReadByte();\r
589         }\r
590         Sbar_InitScores();\r
591         Gamemode_Init();\r
592 }\r
593 \r
594 void Net_ReadInit()\r
595 {\r
596         csqc_revision = ReadShort();\r
597         maxclients = ReadByte();\r
598 \r
599         CSQC_CheckRevision();\r
600 }\r
601 \r
602 string Net_ReadPicture()\r
603 {\r
604         string img;\r
605         if(csqc_flags & CSQC_FLAG_READPICTURE)\r
606         {\r
607                 img = ReadPicture();\r
608                 print(strcat("Got Picture: ", img, "\n"));\r
609         } else {\r
610                 img = ReadString();\r
611                 print(strcat("^3Warning: ^7Couldn't download ", img, ". This is probably because your engine build is outdated.\n"));\r
612                 float psize, i;\r
613                 psize = ReadShort();\r
614                 // Can I be sure that ReadShort is 2 bytes and ReadLong is 4 bytes?\r
615                 // Because then this could be optimized to first get all 4-byte-groups,\r
616                 // then the remaining 2, then the remaining 1\r
617                 for(i = 0; i < psize; ++i)\r
618                         ReadByte();\r
619         }\r
620         return img;\r
621 }\r
622 \r
623 void Net_Config()\r
624 {\r
625         string key, value;\r
626         key = ReadString();\r
627         value = ReadString();\r
628         db_put(configdb, strcat("/v/", key), value);\r
629         db_put(configdb, strcat("/s/", key), "1");\r
630 }\r
631 \r
632 void Net_ReadRace()\r
633 {\r
634         float b;\r
635 \r
636         b = ReadByte();\r
637 \r
638         switch(b)\r
639         {\r
640                 case RACE_NET_CHECKPOINT_HIT_QUALIFYING:\r
641                         race_checkpoint = ReadByte();\r
642                         race_time = ReadShort();\r
643                         race_previousbesttime = ReadShort();\r
644                         if(race_previousbestname)\r
645                                 strunzone(race_previousbestname);\r
646                         race_previousbestname = strzone(ReadString());\r
647 \r
648                         race_checkpointtime = time;\r
649 \r
650                         if(race_checkpoint == 0)\r
651                                 race_laptime = time; // valid\r
652 \r
653                         break;\r
654 \r
655                 case RACE_NET_CHECKPOINT_CLEAR:\r
656                         race_laptime = 0;\r
657                         race_checkpointtime = 0;\r
658                         break;\r
659 \r
660                 case RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING:\r
661                         race_laptime = ReadCoord();\r
662                         race_checkpointtime = -99999;\r
663                         // fall through\r
664                 case RACE_NET_CHECKPOINT_NEXT_QUALIFYING:\r
665                         race_nextcheckpoint = ReadByte();\r
666 \r
667                         race_nextbesttime = ReadShort();\r
668                         if(race_nextbestname)\r
669                                 strunzone(race_nextbestname);\r
670                         race_nextbestname = strzone(ReadString());\r
671                         break;\r
672 \r
673                 case RACE_NET_CHECKPOINT_HIT_RACE:\r
674                         race_mycheckpoint = ReadByte();\r
675                         race_mycheckpointtime = time;\r
676                         race_mycheckpointdelta = ReadShort();\r
677                         race_mycheckpointlapsdelta = ReadByte();\r
678                         if(race_mycheckpointlapsdelta >= 128)\r
679                                 race_mycheckpointlapsdelta -= 256;\r
680                         if(race_mycheckpointenemy)\r
681                                 strunzone(race_mycheckpointenemy);\r
682                         race_mycheckpointenemy = strzone(ReadString());\r
683                         break;\r
684 \r
685                 case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:\r
686                         race_othercheckpoint = ReadByte();\r
687                         race_othercheckpointtime = time;\r
688                         race_othercheckpointdelta = ReadShort();\r
689                         race_othercheckpointlapsdelta = ReadByte();\r
690                         if(race_othercheckpointlapsdelta >= 128)\r
691                                 race_othercheckpointlapsdelta -= 256;\r
692                         if(race_othercheckpointenemy)\r
693                                 strunzone(race_othercheckpointenemy);\r
694                         race_othercheckpointenemy = strzone(ReadString());\r
695                         break;\r
696         }\r
697 }\r
698 \r
699 void Net_ReadForceScoreboard()\r
700 {\r
701         sb_showscores_force = ReadByte();\r
702 }\r
703 \r
704 void Net_Reset()\r
705 {\r
706         race_laptime = 0;\r
707         race_checkpointtime = 0;\r
708 }\r
709 \r
710 void Net_ReadSpectating()\r
711 {\r
712         float newspectatee_status;\r
713         newspectatee_status = ReadByte();\r
714         if(newspectatee_status == player_localentnum)\r
715                 newspectatee_status = -1; // observing\r
716         if(newspectatee_status != spectatee_status)\r
717                 Net_Reset();\r
718         spectatee_status = newspectatee_status;\r
719 }\r
720 \r
721 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.\r
722 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.\r
723 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.\r
724 float CSQC_Parse_TempEntity()\r
725 {\r
726         local float bHandled;\r
727                 bHandled  = true;\r
728         // Acquire TE ID\r
729         local float nTEID;\r
730                 nTEID = ReadByte();\r
731 \r
732                 // NOTE: Could just do return instead of break...\r
733         switch(nTEID)\r
734         {\r
735                 case TE_CSQC_INIT:\r
736                         Net_ReadInit();\r
737                         bHandled = true;\r
738                         break;\r
739                 case TE_CSQC_MAPVOTE:\r
740                         Net_Mapvote();\r
741                         bHandled = true;\r
742                         break;\r
743                 case TE_CSQC_CONFIG:\r
744                         Net_Config();\r
745                         bHandled = true;\r
746                         break;\r
747                 case TE_CSQC_SCORESINFO:\r
748                         Net_ReadScoresInfo();\r
749                         bHandled = true;\r
750                         break;\r
751                 case TE_CSQC_RACE:\r
752                         Net_ReadRace();\r
753                         bHandled = true;\r
754                         break;\r
755                 case TE_CSQC_FORCESCOREBOARD:\r
756                         Net_ReadForceScoreboard();\r
757                         bHandled = true;\r
758                         break;\r
759                 case TE_CSQC_SPECTATING:\r
760                         Net_ReadSpectating();\r
761                         bHandled = true;\r
762                         break;\r
763                 case 13: // TE_BEAM\r
764                         Net_GrapplingHook();\r
765                         bHandled = true;\r
766                         break;\r
767                 default:\r
768                         // No special logic for this temporary entity; return 0 so the engine can handle it\r
769                         bHandled = false;\r
770                         break;\r
771         }\r
772         \r
773         if(!postinit)\r
774                 PostInit();\r
775                 \r
776         return bHandled;\r
777 }\r
778 \r
779 // COMMIT-TODO: Update if necessare, before committing\r
780 void CSQC_CheckRevision()\r
781 {\r
782         if(csqc_revision == CSQC_REVISION)\r
783         {\r
784                 print("^2SVQC and CSQC revisions are compatible.\n");\r
785         } else if(csqc_revision < CSQC_REVISION) {\r
786                 print("^1Your csprogs.dat (CSQC) version is newer than the one on the server.\n");\r
787         } else if(csqc_revision > CSQC_REVISION) {\r
788                 print("^1Your csprogs.dat (CSQC) is too old for this server.\n");\r
789                 print("^1Please update to a newer version.\n");\r
790         }\r
791 }\r