]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_world.qc
made cvars like g_ctf only be queried once on startup
[divverent/nexuiz.git] / data / qcsrc / server / g_world.qc
1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
3
4 string GetMapname();
5 void GotoNextMap();
6 void ShuffleMaplist()
7 float() DoNextMapOverride;
8
9 void SetDefaultAlpha()
10 {
11         if(cvar("g_running_guns"))
12         {
13                 default_player_alpha = -1;
14                 default_weapon_alpha = +1;
15         }
16         else if(cvar("g_cloaked"))
17         {
18                 default_player_alpha = cvar("g_balance_cloaked_alpha");
19                 default_weapon_alpha = default_player_alpha;
20         }
21         else
22         {
23                 default_player_alpha = cvar("g_player_alpha");
24                 if(default_player_alpha <= 0)
25                         default_player_alpha = 1;
26                 default_weapon_alpha = default_player_alpha;
27         }
28 }
29
30 void fteqcc_testbugs()
31 {
32         float a, b;
33
34         if(!cvar("developer_fteqccbugs"))
35                 return;
36
37         dprint("*** fteqcc test: checking for bugs...\n");
38
39         a = 1;
40         b = 5;
41         if(sqrt(a) - sqrt(b - a) == 0)
42                 dprint("*** fteqcc test: found same-function-twice bug\n");
43         else
44                 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
45
46         world.frags = -10;
47         world.enemy = world;
48         world.enemy.frags += 10;
49         if(world.frags > 0.2 || world.frags < -0.2) // don't error out if it's just roundoff errors
50                 dprint("*** fteqcc test: found += bug\n");
51         else
52                 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
53         world.frags = 0;
54 }
55
56 void GotoFirstMap()
57 {
58         if(cvar("_sv_init"))
59         {
60                 cvar_set("_sv_init", "0");
61                 if(cvar("g_maplist_shuffle"))
62                         ShuffleMaplist();
63                 tokenize(cvar_string("g_maplist"));
64                 if(argv(0) != GetMapname())
65                 {
66                         cvar_set("nextmap", argv(0));
67                         if(!DoNextMapOverride())
68                                 GotoNextMap();
69                 }
70         }
71 }
72
73 float world_already_spawned;
74 void worldspawn (void)
75 {
76         float globhandle, i, n;
77
78         dprint_load(); // load dprint status from cvar
79
80         if(world_already_spawned)
81                 error("world already spawned - you may have EXACTLY ONE worldspawn!");
82         world_already_spawned = TRUE;
83
84         sv_cheats = cvar("sv_cheats");
85
86         /*
87         TODO sound pack system
88         // initialize sound pack system
89         soundpack = cvar_string("g_soundpack");
90         if(soundpack != "")
91                 soundpack = strcat(soundpack, "/");
92         soundpack = strzone(soundpack);
93         */
94
95         // gamemode related things
96         precache_model ("models/misc/chatbubble.spr");
97         precache_model ("models/misc/teambubble.spr");
98         if (cvar("g_runematch"))
99         {
100                 precache_model ("models/runematch/curse.mdl");
101                 precache_model ("models/runematch/rune.mdl");
102         }
103
104         // Precache all player models if desired
105         if (cvar("sv_precacheplayermodels"))
106         {
107                 globhandle = search_begin("models/player/*.zym", TRUE, FALSE);
108                 n = search_getsize(globhandle);
109                 for(i = 0; i < n; ++i)
110                 {
111                         //print(search_getfilename(globhandle, i), "\n");
112                         precache_model(search_getfilename(globhandle, i));
113                 }
114                 search_end(globhandle);
115                 //precache_model("models/player/carni.zym");
116                 //precache_model("models/player/crash.zym");
117                 //precache_model("models/player/grunt.zym");
118                 //precache_model("models/player/headhunter.zym");
119                 //precache_model("models/player/insurrectionist.zym");
120                 //precache_model("models/player/jeandarc.zym");
121                 //precache_model("models/player/lurk.zym");
122                 //precache_model("models/player/lycanthrope.zym");
123                 //precache_model("models/player/marine.zym");
124                 //precache_model("models/player/nexus.zym");
125                 //precache_model("models/player/pyria.zym");
126                 //precache_model("models/player/shock.zym");
127                 //precache_model("models/player/skadi.zym");
128                 //precache_model("models/player/specop.zym");
129                 //precache_model("models/player/visitant.zym");
130         }
131
132         if (cvar("g_footsteps"))
133         {
134                 precache_sound ("misc/footstep01.wav");
135                 precache_sound ("misc/footstep02.wav");
136                 precache_sound ("misc/footstep03.wav");
137                 precache_sound ("misc/footstep04.wav");
138                 precache_sound ("misc/footstep05.wav");
139                 precache_sound ("misc/footstep06.wav");
140         }
141
142         // gore and miscellaneous sounds
143         //precache_sound ("misc/h2ohit.wav");
144         precache_model ("models/gibs/bloodyskull.md3");
145         precache_model ("models/gibs/chunk.mdl");
146         precache_model ("models/gibs/eye.md3");
147         precache_model ("models/gibs/gib1.md3");
148         precache_model ("models/gibs/gib1.mdl");
149         precache_model ("models/gibs/gib2.mdl");
150         precache_model ("models/gibs/gib3.mdl");
151         precache_model ("models/gibs/gib5.md3");
152         precache_model ("models/hook.md3");
153         precache_sound ("misc/armorimpact.wav");
154         precache_sound ("misc/bodyimpact1.wav");
155         precache_sound ("misc/bodyimpact2.wav");
156         precache_sound ("misc/gib.wav");
157         precache_sound ("misc/gib_splat01.wav");
158         precache_sound ("misc/gib_splat02.wav");
159         precache_sound ("misc/gib_splat03.wav");
160         precache_sound ("misc/gib_splat04.wav");
161         precache_sound ("misc/hit.wav");
162         precache_sound ("misc/hitground1.wav");
163         precache_sound ("misc/hitground2.wav");
164         precache_sound ("misc/hitground3.wav");
165         precache_sound ("misc/hitground4.wav");
166         precache_sound ("misc/null.wav");
167         precache_sound ("misc/spawn.wav");
168         precache_sound ("misc/talk.wav");
169         precache_sound ("misc/teleport.wav");
170         precache_sound ("player/lava.wav");
171         precache_sound ("player/slime.wav");
172
173         // announcer sounds - male
174         //precache_sound ("announcer/male/electrobitch.wav");
175         precache_sound ("announcer/male/03kills.wav");
176         precache_sound ("announcer/male/05kills.wav");
177         precache_sound ("announcer/male/10kills.wav");
178         precache_sound ("announcer/male/15kills.wav");
179         precache_sound ("announcer/male/20kills.wav");
180         precache_sound ("announcer/male/25kills.wav");
181         precache_sound ("announcer/male/30kills.wav");
182         precache_sound ("announcer/male/botlike.wav");
183         precache_sound ("announcer/male/yoda.wav");
184
185         // announcer sounds - robotic
186         precache_sound ("announcer/robotic/1fragleft.wav");
187         precache_sound ("announcer/robotic/1minuteremains.wav");
188         precache_sound ("announcer/robotic/2fragsleft.wav");
189         precache_sound ("announcer/robotic/3fragsleft.wav");
190         if (cvar("g_minstagib"))
191         {
192                 precache_sound ("announcer/robotic/lastsecond.wav");
193                 precache_sound ("announcer/robotic/narrowly.wav");
194                 precache_sound ("announcer/robotic/1.wav");
195                 precache_sound ("announcer/robotic/2.wav");
196                 precache_sound ("announcer/robotic/3.wav");
197                 precache_sound ("announcer/robotic/4.wav");
198                 precache_sound ("announcer/robotic/5.wav");
199                 precache_sound ("announcer/robotic/6.wav");
200                 precache_sound ("announcer/robotic/7.wav");
201                 precache_sound ("announcer/robotic/8.wav");
202                 precache_sound ("announcer/robotic/9.wav");
203                 precache_sound ("announcer/robotic/10.wav");
204         }
205
206         // common weapon precaches
207         precache_sound ("weapons/weapon_switch.wav");
208         precache_sound ("weapons/weaponpickup.wav");
209         if (cvar("g_grappling_hook"))
210         {
211                 precache_sound ("weapons/hook_fire.wav"); // hook
212                 precache_sound ("weapons/hook_impact.wav"); // hook
213         }
214
215         if (cvar("sv_precacheweapons") || cvar("g_nixnex"))
216         {
217                 //precache weapon models/sounds
218                 local float wep;
219                 wep = WEP_FIRST;
220                 while (wep <= WEP_LAST)
221                 {
222                         weapon_action(wep, WR_PRECACHE);
223                         wep = wep + 1;
224                 }
225         }
226
227         // plays music for the level if there is any
228         if (self.noise)
229         {
230                 precache_sound (self.noise);
231                 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
232         }
233
234         // 0 normal
235         lightstyle(0, "m");
236
237         // 1 FLICKER (first variety)
238         lightstyle(1, "mmnmmommommnonmmonqnmmo");
239
240         // 2 SLOW STRONG PULSE
241         lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
242
243         // 3 CANDLE (first variety)
244         lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
245
246         // 4 FAST STROBE
247         lightstyle(4, "mamamamamama");
248
249         // 5 GENTLE PULSE 1
250         lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
251
252         // 6 FLICKER (second variety)
253         lightstyle(6, "nmonqnmomnmomomno");
254
255         // 7 CANDLE (second variety)
256         lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
257
258         // 8 CANDLE (third variety)
259         lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
260
261         // 9 SLOW STROBE (fourth variety)
262         lightstyle(9, "aaaaaaaazzzzzzzz");
263
264         // 10 FLUORESCENT FLICKER
265         lightstyle(10, "mmamammmmammamamaaamammma");
266
267         // 11 SLOW PULSE NOT FADE TO BLACK
268         lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
269
270         // styles 32-62 are assigned by the light program for switchable lights
271
272         // 63 testing
273         lightstyle(63, "a");
274
275         player_count = 0;
276         lms_lowest_lives = 0;
277         lms_next_place = 0;
278
279         GotoFirstMap();
280
281         bot_waypoints_for_items = cvar("g_waypoints_for_items");
282         if(bot_waypoints_for_items == 1)
283                 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
284                         bot_waypoints_for_items = 0;
285
286         if(cvar("g_campaign"))
287                 CampaignPreInit();
288
289         InitGameplayMode();
290
291         WaypointSprite_Init();
292
293         //if (cvar("g_domination"))
294         //      dom_init();
295
296         local entity head;
297         head = nextent(world);
298         maxclients = 0;
299         while(head)
300         {
301                 maxclients++;
302                 head = nextent(head);
303         }
304
305         GameLogInit(); // prepare everything
306         if(cvar("sv_eventlog"))
307         {
308                 local string s;
309                 GameLogEcho(":logversion:2", FALSE);
310                 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
311                 s = strcat(s, ftos(random()));
312                 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
313                 s = ":gameinfo:mutators:LIST";
314                 if(cvar("g_grappling_hook"))
315                         s = strcat(s, ":grappling_hook");
316                 if(!cvar("g_use_ammunition"))
317                         s = strcat(s, ":no_use_ammunition");
318                 if(!cvar("g_pickup_items"))
319                         s = strcat(s, ":no_pickup_items");
320                 if(cvar("g_instagib"))
321                         s = strcat(s, ":instagib");
322                 if(cvar("g_rocketarena"))
323                         s = strcat(s, ":rockerarena");
324                 if(cvar("g_nixnex"))
325                         s = strcat(s, ":nixnex");
326                 if(cvar("g_vampire"))
327                         s = strcat(s, ":vampire");
328                 if(cvar("g_laserguided_missile"))
329                         s = strcat(s, ":laserguided_missile");
330                 if(cvar("g_norecoil"))
331                         s = strcat(s, ":norecoil");
332                 if(cvar("g_midair"))
333                         s = strcat(s, ":midair");
334                 if(cvar("g_minstagib"))
335                         s = strcat(s, ":minstagib");
336                 GameLogEcho(s, FALSE);
337                 GameLogEcho(":gameinfo:end", FALSE);
338         }
339
340         cvar_set("nextmap", "");
341
342         SetDefaultAlpha();
343
344         if(cvar("g_campaign"))
345                 CampaignPostInit();
346
347         fteqcc_testbugs();
348
349         readlevelcvars();
350
351         Ban_LoadBans();
352 }
353
354 void light (void)
355 {
356         //makestatic (self); // Who the f___ did that?
357         remove(self);
358 }
359
360 float( string pFilename ) TryFile =
361 {
362         local float lHandle;
363         dprint("TryFile(\"", pFilename, "\")\n");
364         lHandle = fopen( pFilename, FILE_READ );
365         if( lHandle != -1 ) {
366                 fclose( lHandle );
367                 return TRUE;
368         } else {
369                 return FALSE;
370         }
371 };
372
373 string GetGametype()
374 {
375         if (game == GAME_DEATHMATCH)
376                 return "dm";
377         else if (game == GAME_TEAM_DEATHMATCH)
378                 return "tdm";
379         else if (game == GAME_DOMINATION)
380                 return "dom";
381         else if (game == GAME_CTF)
382                 return "ctf";
383         else if (game == GAME_RUNEMATCH)
384                 return "rune";
385         else if (game == GAME_LMS)
386                 return "lms";
387         else if (game == GAME_KEYHUNT)
388                 return "kh";
389         else if (game == GAME_ONSLAUGHT)
390                 return "ons";
391         else if (game == GAME_ASSAULT)
392                 return "as";
393         return "dm";
394 }
395
396 float IsSameGametype(string mapcfgname)
397 {
398         string gt;
399         gt = GetGametype();
400 #ifdef MAPINFO
401 #else
402         if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
403                 return TRUE;
404         return FALSE;
405 #endif
406 }
407
408 string getmapname_stored;
409 string GetMapname()
410 {
411 #ifdef MAPINFO
412 #else
413         if(getmapname_stored == "")
414                 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
415         return getmapname_stored;
416 #endif
417 }
418
419 float Map_Count, Map_Current;
420 string Map_Current_Name;
421
422 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
423 float GetMaplistPosition()
424 {
425         float pos, idx;
426         string map;
427
428         map = GetMapname();
429         idx = cvar("g_maplist_index");
430
431         if(idx >= 0)
432                 if(idx < Map_Count)
433                         if(map == argv(idx))
434                                 return idx;
435
436         for(pos = 0; pos < Map_Count; ++pos)
437                 if(map == argv(pos))
438                         return pos;
439
440         // resume normal maplist rotation if current map is not in g_maplist
441         return idx;
442 }
443
444 float MapHasRightSize(string map)
445 {
446         // open map size restriction file
447         float fh;
448         dprint("opensize "); dprint(map);
449         fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
450         if(fh >= 0)
451         {
452                 float mapmin, mapmax;
453                 dprint(": ok, ");
454                 mapmin = stof(fgets(fh));
455                 mapmax = stof(fgets(fh));
456                 fclose(fh);
457                 if(player_count < mapmin)
458                 {
459                         dprint("not enough\n");
460                         return FALSE;
461                 }
462                 if(player_count > mapmax)
463                 {
464                         dprint("too many\n");
465                         return FALSE;
466                 }
467                 dprint("right size\n");
468                 return TRUE;
469         }
470         dprint(": not found\n");
471         return TRUE;
472 }
473
474 #ifdef MAPINFO
475 #else
476 string Map_Filename(float position)
477 {
478         // FIXME unused
479         return strcat("maps/", argv(position), ".mapcfg");
480 }
481 #endif
482
483 string strwords(string s, float w)
484 {
485         float endpos;
486         for(endpos = 0; w && endpos >= 0; --w)
487                 endpos = strstrofs(s, " ", endpos + 1);
488         if(endpos < 0)
489                 return s;
490         else
491                 return substring(s, 0, endpos);
492 }
493
494 float strhasword(string s, string w)
495 {
496         return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
497 }
498
499 void Map_MarkAsRecent(string m)
500 {
501         cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
502 }
503
504 float Map_IsRecent(string m)
505 {
506         return strhasword(cvar_string("g_maplist_mostrecent"), m);
507 }
508
509 float(float position, float pass) Map_Check =
510 {
511         string filename;
512         string map_next;
513         map_next = argv(position);
514         if(pass <= 1)
515         {
516                 if(map_next == Map_Current_Name) // same map again in first pass?
517                         return 0;
518                 if(Map_IsRecent(map_next))
519                         return 0;
520         }
521 #ifdef MAPINFO
522 #else
523         filename = Map_Filename(position);
524         if(TryFile(filename))
525 #endif
526         {
527                 if(pass == 2)
528                         return 1;
529                 if(MapHasRightSize(argv(position)))
530                         return 1;
531                 return 0;
532         }
533         else
534                 dprint( "Couldn't find '", filename, "'..\n" );
535
536         return 0;
537 }
538
539 void(string nextmapname) Map_Goto_SetStr =
540 {
541         if(getmapname_stored != "")
542                 strunzone(getmapname_stored);
543         if(nextmapname == "")
544                 getmapname_stored = "";
545         else
546                 getmapname_stored = strzone(nextmapname);
547 }
548
549 void(float position) Map_Goto_SetFloat =
550 {
551         cvar_set("g_maplist_index", ftos(position));
552         Map_Goto_SetStr(argv(position));
553 }
554
555 void() GameResetCfg =
556 {
557         // if an exit cfg is defined by exiting map, exec it.
558         string exit_cfg;
559         exit_cfg = cvar_string("exit_cfg");
560         if(exit_cfg != "")
561                 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
562
563         localcmd("exec game_reset.cfg\n");
564
565         Ban_SaveBans();
566 };
567
568 void() Map_Goto =
569 {
570         Map_MarkAsRecent(getmapname_stored);
571         GameResetCfg();
572 #ifdef MAPINFO
573 #else
574         localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
575 #endif
576 }
577
578 // return codes of map selectors:
579 //   -1 = temporary failure (that is, try some method that is guaranteed to succeed)
580 //   -2 = permanent failure
581 float() MaplistMethod_Iterate = // usual method
582 {
583         float pass, i;
584
585         for(pass = 1; pass <= 2; ++pass)
586         {
587                 for(i = 1; i < Map_Count; ++i)
588                 {
589                         float mapindex;
590                         mapindex = math_mod(i + Map_Current, Map_Count);
591                         if(Map_Check(mapindex, pass))
592                                 return mapindex;
593                 }
594         }
595         return -1;
596 }
597
598 float() MaplistMethod_Repeat = // fallback method
599 {
600         if(Map_Check(Map_Current, 2))
601                 return Map_Current;
602         return -2;
603 }
604
605 float() MaplistMethod_Random = // random map selection
606 {
607         float i, imax;
608
609         imax = 42;
610
611         for(i = 0; i <= imax; ++i)
612         {
613                 float mapindex;
614                 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
615                 if(Map_Check(mapindex, 1))
616                         return mapindex;
617         }
618         return -1;
619 }
620
621 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
622 // the exponent sets a bias on the map selection:
623 // the higher the exponent, the less likely "shortly repeated" same maps are
624 {
625         float i, j, imax, insertpos;
626
627         imax = 42;
628
629         if(Map_Count <= 1)
630                 return 0; // only one map, then always play this one
631
632         for(i = 0; i <= imax; ++i)
633         {
634                 string newlist;
635
636                 // now reinsert this at another position
637                 insertpos = pow(random(), 1 / exponent);       // ]0, 1]
638                 insertpos = insertpos * (Map_Count - 1);       // ]0, Map_Count - 1]
639                 insertpos = ceil(insertpos) + 1;               // {2, 3, 4, ..., Map_Count}
640                 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
641
642                 // insert the current map there
643                 newlist = "";
644                 for(j = 1; j < insertpos; ++j)                 // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
645                         newlist = strcat(newlist, "'", argv(j), "'");
646                 newlist = strcat(newlist, "'", argv(0), "'");  // now insert the just selected map
647                 for(j = insertpos; j < Map_Count; ++j)         // i == Map_Count: no loop, has just been inserted as last
648                         newlist = strcat(newlist, "'", argv(j), "'");
649                 cvar_set("g_maplist", newlist);
650                 Map_Count = tokenize(newlist);
651
652                 // NOTE: the selected map has just been inserted at (insertpos-1)th position
653                 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
654                 if(Map_Check(Map_Current, 1))
655                         return Map_Current;
656         }
657         return -1;
658 }
659
660 void() Maplist_Init =
661 {
662         string temp;
663         temp = cvar_string("g_maplist");
664         Map_Count = tokenize(temp);
665         if(Map_Count == 0)
666         {
667                 bprint( "Maplist is empty!  Resetting it to default map list.\n" );
668 #ifdef MAPINFO
669 #else
670                 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
671 #endif
672                 Map_Count = tokenize(temp);
673         }
674         if(Map_Count == 0)
675                 error("empty maplist, cannot select a new map");
676         Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
677
678         Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
679         // this may or may not be correct, but who cares, in the worst case a map
680         // isn't chosen in the first pass that should have been
681 }
682
683 string() GetNextMap =
684 {
685         float nextMap;
686
687         Maplist_Init();
688         nextMap = -1;
689
690         if(nextMap == -1)
691                 if(cvar("g_maplist_shuffle") > 0)
692                         nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
693
694         if(nextMap == -1)
695                 if(cvar("g_maplist_selectrandom"))
696                         nextMap = MaplistMethod_Random();
697
698         if(nextMap == -1)
699                 nextMap = MaplistMethod_Iterate();
700
701         if(nextMap == -1)
702                 nextMap = MaplistMethod_Repeat();
703
704         if(nextMap >= 0)
705         {
706                 Map_Goto_SetFloat(nextMap);
707                 return getmapname_stored;
708         }
709
710         return "";
711 };
712
713 float() DoNextMapOverride =
714 {
715         Ban_SaveBans();
716
717         if(cvar("g_campaign"))
718         {
719                 CampaignPostIntermission();
720                 alreadychangedlevel = TRUE;
721                 return TRUE;
722         }
723         if(cvar("quit_when_empty"))
724         {
725                 if(player_count <= currentbots)
726                 {
727                         localcmd("quit\n");
728                         alreadychangedlevel = TRUE;
729                         return TRUE;
730                 }
731         }
732         if(cvar_string("quit_and_redirect") != "")
733         {
734                 redirection_target = strzone(cvar_string("quit_and_redirect"));
735                 alreadychangedlevel = TRUE;
736                 return TRUE;
737         }
738         if (cvar("samelevel")) // if samelevel is set, stay on same level
739         {
740                 // this does not work because it tries to exec maps/nexdm01.mapcfg (which doesn't exist, it should be trying maps/dm_nexdm01.mapcfg for example)
741                 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
742                 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
743                 localcmd("restart\n");
744                 //changelevel (mapname);
745                 alreadychangedlevel = TRUE;
746                 return TRUE;
747         }
748         if(cvar_string("nextmap") != "")
749 #ifdef MAPINFO
750 #else
751                 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
752 #endif
753                 {
754                         Map_Goto_SetStr(cvar_string("nextmap"));
755                         Map_Goto();
756                         alreadychangedlevel = TRUE;
757                         return TRUE;
758                 }
759         if(cvar("lastlevel"))
760         {
761                 GameResetCfg();
762                 localcmd("set lastlevel 0\ntogglemenu\n");
763                 alreadychangedlevel = TRUE;
764                 return TRUE;
765         }
766         return FALSE;
767 };
768
769 void() GotoNextMap =
770 {
771         //local string nextmap;
772         //local float n, nummaps;
773         //local string s;
774         if (alreadychangedlevel)
775                 return;
776         alreadychangedlevel = TRUE;
777
778         {
779                 string nextMap;
780                 float allowReset;
781
782                 for(allowReset = 1; allowReset >= 0; --allowReset)
783                 {
784                         nextMap = GetNextMap();
785                         if(nextMap != "")
786                                 break;
787
788                         if(allowReset)
789                         {
790                                 bprint( "Maplist contains no single playable map!  Resetting it to default map list.\n" );
791 #ifdef MAPINFO
792 #else
793                                 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
794 #endif
795                         }
796                         else
797                         {
798                                 error("Everything is broken - not even the default map list works. Please report this to the developers.");
799                         }
800                 }
801                 Map_Goto();
802         }
803 };
804
805
806 /*
807 ============
808 IntermissionThink
809
810 When the player presses attack or jump, change to the next level
811 ============
812 */
813 .float autoscreenshot;
814 void() MapVote_Start;
815 void() MapVote_Think;
816 float mapvote_initialized;
817 void() IntermissionThink =
818 {
819         FixIntermissionClient(self);
820
821         if(cvar("sv_autoscreenshot"))
822         if(self.autoscreenshot > 0)
823         if(time > self.autoscreenshot)
824         {
825                 self.autoscreenshot = -1;
826                 if(clienttype(self) == CLIENTTYPE_REAL)
827                         stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
828                 return;
829         }
830
831         if (time < intermission_exittime)
832                 return;
833
834         if(!mapvote_initialized)
835                 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
836                         return;
837
838         MapVote_Start();
839 };
840
841 /*
842 ============
843 FindIntermission
844
845 Returns the entity to view from
846 ============
847 */
848 /*
849 entity() FindIntermission =
850 {
851         local   entity spot;
852         local   float cyc;
853
854 // look for info_intermission first
855         spot = find (world, classname, "info_intermission");
856         if (spot)
857         {       // pick a random one
858                 cyc = random() * 4;
859                 while (cyc > 1)
860                 {
861                         spot = find (spot, classname, "info_intermission");
862                         if (!spot)
863                                 spot = find (spot, classname, "info_intermission");
864                         cyc = cyc - 1;
865                 }
866                 return spot;
867         }
868
869 // then look for the start position
870         spot = find (world, classname, "info_player_start");
871         if (spot)
872                 return spot;
873
874 // testinfo_player_start is only found in regioned levels
875         spot = find (world, classname, "testplayerstart");
876         if (spot)
877                 return spot;
878
879 // then look for the start position
880         spot = find (world, classname, "info_player_deathmatch");
881         if (spot)
882                 return spot;
883
884         //objerror ("FindIntermission: no spot");
885         return world;
886 };
887 */
888
889 /*
890 ===============================================================================
891
892 RULES
893
894 ===============================================================================
895 */
896
897 void(float final) DumpStats =
898 {
899         local float file;
900         local string s;
901         local float to_console;
902         local float to_eventlog;
903         local float to_file;
904
905         to_console = cvar("sv_logscores_console");
906         to_eventlog = cvar("sv_eventlog");
907         to_file = cvar("sv_logscores_file");
908
909         if(!final)
910         {
911                 to_console = TRUE; // always print printstats replies
912                 to_eventlog = FALSE; // but never print them to the event log
913         }
914
915         if(to_eventlog)
916                 if(cvar("sv_eventlog_console"))
917                         to_console = FALSE; // otherwise we get the output twice
918
919         if(final)
920                 s = ":scores:";
921         else
922                 s = ":status:";
923         s = strcat(s, GetMapname(), ":", ftos(rint(time)));
924
925         if(to_console)
926                 ServerConsoleEcho(s, FALSE);
927         if(to_eventlog)
928                 GameLogEcho(s, FALSE);
929         if(to_file)
930         {
931                 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
932                 if(file == -1)
933                         to_file = FALSE;
934                 else
935                         fputs(file, strcat(s, "\n"));
936         }
937
938         FOR_EACH_CLIENT(other)
939         {
940                 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
941                 {
942                         s = strcat(":player:", ftos(other.frags), ":");
943                         s = strcat(s, ftos(other.deaths), ":");
944                         s = strcat(s, ftos(rint(time - other.jointime)), ":");
945                         s = strcat(s, ftos(other.team), ":");
946
947                         if(to_console)
948                                 ServerConsoleEcho(strcat(s, other.netname), TRUE);
949                         if(to_eventlog)
950                                 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
951                         if(to_file)
952                                 fputs(file, strcat(s, other.netname, "\n"));
953                 }
954         }
955
956         if(to_console)
957                 ServerConsoleEcho(":end", FALSE);
958         if(to_eventlog)
959                 GameLogEcho(":end", FALSE);
960         if(to_file)
961         {
962                 fputs(file, ":end\n");
963                 fclose(file);
964         }
965 }
966
967 void FixIntermissionClient(entity e)
968 {
969         if(!e.autoscreenshot) // initial call
970         {
971                 e.angles = e.v_angle;
972                 e.angles_x = -e.angles_x;
973                 e.autoscreenshot = time + 0.8;  // used for autoscreenshot
974                 e.health = -2342;
975                 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
976                 e.solid = SOLID_NOT;
977                 e.movetype = MOVETYPE_NONE;
978                 e.takedamage = DAMAGE_NO;
979                 if(e.weaponentity)
980                         e.weaponentity.effects = EF_NODRAW;
981                 stuffcmd(e, "\nscr_printspeed 1000000\n");
982                 if(clienttype(e) == CLIENTTYPE_REAL)
983                 {
984                         msg_entity = e;
985                         WriteByte(MSG_ONE, SVC_INTERMISSION);
986                 }
987         }
988
989         //e.velocity = '0 0 0';
990         //e.fixangle = TRUE;
991
992         // TODO halt weapon animation
993 }
994
995
996 /*
997 go to the next level for deathmatch
998 only called if a time or frag limit has expired
999 */
1000 void() NextLevel =
1001 {
1002         float minTotalFrags;
1003         float maxTotalFrags;
1004         float score;
1005         float f;
1006
1007         gameover = TRUE;
1008
1009         intermission_running = 1;
1010
1011 // enforce a wait time before allowing changelevel
1012         if(player_count > 0)
1013                 intermission_exittime = time + cvar("sv_mapchange_delay");
1014         else
1015                 intermission_exittime = -1;
1016
1017         WriteByte (MSG_ALL, SVC_CDTRACK);
1018         WriteByte (MSG_ALL, 3);
1019         WriteByte (MSG_ALL, 3);
1020
1021         //pos = FindIntermission ();
1022
1023         VoteReset();
1024
1025         DumpStats(TRUE);
1026
1027         if(cvar("sv_eventlog"))
1028                 GameLogEcho(":gameover", FALSE);
1029
1030         GameLogClose();
1031
1032         FOR_EACH_CLIENT(other)
1033         {
1034                 FixIntermissionClient(other);
1035
1036                 if(other.winning)
1037                         bprint(other.netname, " ^7wins.\n");
1038         }
1039
1040         minTotalFrags = 0;
1041         maxTotalFrags = 0;
1042         FOR_EACH_PLAYER(other)
1043         {
1044                 if(maxTotalFrags < other.totalfrags)
1045                         maxTotalFrags = other.totalfrags;
1046                 if(minTotalFrags > other.totalfrags)
1047                         minTotalFrags = other.totalfrags;
1048         }
1049
1050         if(!currentbots)
1051         {
1052                 FOR_EACH_PLAYER(other)
1053                 {
1054                         score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1055                         f = bound(0, other.play_time / max(time, 1), 1);
1056                         // store some statistics?
1057                 }
1058         }
1059
1060         if(cvar("g_campaign"))
1061                 CampaignPreIntermission();
1062
1063         // WriteByte (MSG_ALL, SVC_INTERMISSION);
1064 };
1065
1066 /*
1067 ============
1068 CheckRules_Player
1069
1070 Exit deathmatch games upon conditions
1071 ============
1072 */
1073 void() CheckRules_Player =
1074 {
1075         if (gameover)   // someone else quit the game already
1076                 return;
1077
1078         if(self.deadflag == DEAD_NO)
1079                 self.play_time += frametime;
1080
1081         // fixme: don't check players; instead check dom_team and ctf_team entities
1082         //   (div0: and that in CheckRules_World please)
1083 };
1084
1085 float checkrules_oneminutewarning;
1086 float checkrules_leaderfrags;
1087 float tdm_max_score, tdm_old_score;
1088
1089 float checkrules_equality;
1090 float checkrules_overtimewarning;
1091 float checkrules_overtimeend;
1092
1093 void() InitiateOvertime =
1094 {
1095         if(!checkrules_overtimeend)
1096                 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1097 }
1098
1099 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1100 float WINNING_YES = 1; // winner found
1101 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1102 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1103
1104 float(float fraglimitreached, float equality) GetWinningCode =
1105 {
1106         if(equality)
1107                 if(fraglimitreached)
1108                         return WINNING_STARTOVERTIME;
1109                 else
1110                         return WINNING_NEVER;
1111         else
1112                 if(fraglimitreached)
1113                         return WINNING_YES;
1114                 else
1115                         return WINNING_NO;
1116 }
1117
1118 // set the .winning flag for exactly those players with a given field value
1119 void(.float field, float value) SetWinners =
1120 {
1121         entity head;
1122         FOR_EACH_PLAYER(head)
1123                 head.winning = (head.field == value);
1124 }
1125
1126 // set the .winning flag for those players with a given field value
1127 void(.float field, float value) AddWinners =
1128 {
1129         entity head;
1130         FOR_EACH_PLAYER(head)
1131                 if(head.field == value)
1132                         head.winning = 1;
1133 }
1134
1135 // clear the .winning flags
1136 void(void) ClearWinners =
1137 {
1138         entity head;
1139         FOR_EACH_PLAYER(head)
1140                 head.winning = 0;
1141 }
1142
1143 // Onslaught winning condition:
1144 // game terminates if only one team has a working generator (or none)
1145 float() WinningCondition_Onslaught =
1146 {
1147         entity head;
1148         local float t1, t2, t3, t4;
1149         // first check if the game has ended
1150         t1 = t2 = t3 = t4 = 0;
1151         head = find(world, classname, "onslaught_generator");
1152         while (head)
1153         {
1154                 if (head.health > 0)
1155                 {
1156                         if (head.team == COLOR_TEAM1) t1 = 1;
1157                         if (head.team == COLOR_TEAM2) t2 = 1;
1158                         if (head.team == COLOR_TEAM3) t3 = 1;
1159                         if (head.team == COLOR_TEAM4) t4 = 1;
1160                 }
1161                 head = find(head, classname, "onslaught_generator");
1162         }
1163         if (t1 + t2 + t3 + t4 < 2)
1164         {
1165                 // game over, only one team remains (or none)
1166                 ClearWinners();
1167                 if (t1) SetWinners(team, COLOR_TEAM1);
1168                 if (t2) SetWinners(team, COLOR_TEAM2);
1169                 if (t3) SetWinners(team, COLOR_TEAM3);
1170                 if (t4) SetWinners(team, COLOR_TEAM4);
1171                 dprint("Have a winner, ending game.\n");
1172                 return WINNING_YES;
1173         }
1174
1175         // Two or more teams remain
1176         return WINNING_NO;
1177 }
1178
1179 float() LMS_NewPlayerLives =
1180 {
1181         float fl;
1182         fl = cvar("fraglimit");
1183         if(fl == 0)
1184                 fl = 999;
1185
1186         // first player has left the game for dying too much? Nobody else can get in.
1187         if(lms_lowest_lives < 1)
1188                 return FALSE;
1189
1190         if(!cvar("g_lms_join_anytime"))
1191                 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1192                         return FALSE;
1193
1194         return bound(1, lms_lowest_lives, fl);
1195 }
1196
1197 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1198 // they win. Otherwise the defending team wins once the timelimit passes.
1199 void assault_new_round();
1200 float() WinningCondition_Assault =
1201 {
1202         local float status;
1203         status = WINNING_NO;
1204
1205         // as the timelimit has not yet passed just assume the defending team will win
1206         if(assault_attacker_team == COLOR_TEAM1)
1207         {
1208                 SetWinners(team, COLOR_TEAM2);
1209         }
1210         else
1211         {
1212                 SetWinners(team, COLOR_TEAM1);
1213         }       
1214                 
1215         local entity ent;
1216         ent = find(world, classname, "target_assault_roundend");
1217         if(ent)
1218         {
1219                 if(ent.winning) // round end has been triggered by attacking team
1220                 {
1221                         SetWinners(team, assault_attacker_team);
1222                         if(assault_attacker_team == COLOR_TEAM1)
1223                         {
1224                                 team1_score = team1_score + 50;
1225                         }
1226                         else
1227                         {
1228                                 team2_score = team2_score + 50;
1229                         }
1230
1231                         if(ent.cnt == 1) // this was the second round
1232                         {
1233                                 status = WINNING_YES;
1234                         }
1235                         else
1236                         {
1237                                 cvar_set("timelimit", ftos((2*time)/60));
1238                                 assault_new_round();
1239                         }
1240                 }               
1241         }
1242
1243         return status;
1244
1245 }
1246
1247
1248 // LMS winning condition: game terminates if and only if there's at most one
1249 // one player who's living lives. Top two scores being equal cancels the time
1250 // limit.
1251 float() WinningCondition_LMS =
1252 {
1253         entity head;
1254         float have_player;
1255         float have_players;
1256         float l;
1257
1258         have_player = FALSE;
1259         have_players = FALSE;
1260         l = LMS_NewPlayerLives();
1261
1262         head = find(world, classname, "player");
1263         if(head)
1264                 have_player = TRUE;
1265         head = find(head, classname, "player");
1266         if(head)
1267                 have_players = TRUE;
1268
1269         if(have_player)
1270         {
1271                 // we have at least one player
1272                 if(have_players)
1273                 {
1274                         // two or more active players - continue with the game
1275                 }
1276                 else
1277                 {
1278                         // exactly one player?
1279                         if(l)
1280                         {
1281                                 // but no game has taken place yet
1282                         }
1283                         else
1284                         {
1285                                 // a winner!
1286                                 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1287                                 dprint("Have a winner, ending game.\n");
1288                                 return WINNING_YES;
1289                         }
1290                 }
1291         }
1292         else
1293         {
1294                 // nobody is playing at all...
1295                 if(l)
1296                 {
1297                         // wait for players...
1298                 }
1299                 else
1300                 {
1301                         // SNAFU (maybe a draw game?)
1302                         ClearWinners();
1303                         dprint("No players, ending game.\n");
1304                         return WINNING_YES;
1305                 }
1306         }
1307
1308         // When we get here, we have at least two players who are actually LIVING,
1309         // or one player who is still waiting for a victim to join the server. Now
1310         // check if the top two players have equal score.
1311
1312         checkrules_leaderfrags = 0;
1313         checkrules_equality = FALSE;
1314         FOR_EACH_PLAYER(head)
1315         {
1316                 if(head.frags > checkrules_leaderfrags)
1317                 {
1318                         checkrules_leaderfrags = head.frags;
1319                         checkrules_equality = FALSE;
1320                 }
1321                 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1322                         checkrules_equality = TRUE;
1323         }
1324
1325         SetWinners(frags, checkrules_leaderfrags);
1326
1327         // The top two players have the same amount of lives? No timelimit then,
1328         // enter overtime...
1329
1330         if(checkrules_equality)
1331                 return WINNING_NEVER;
1332
1333         // Top two have different scores? Way to go for our beloved TIMELIMIT!
1334         return WINNING_NO;
1335 }
1336
1337 // DM winning condition: game terminates if a player reached the fraglimit,
1338 // unless the first two players have the same score. The latter case also
1339 // breaks the time limit.
1340 float(float fraglimit) WinningCondition_MaxIndividualScore =
1341 {
1342         float checkrules_oldleaderfrags;
1343         entity head;
1344
1345         checkrules_oldleaderfrags = checkrules_leaderfrags;
1346         checkrules_leaderfrags = 0;
1347         checkrules_equality = FALSE;
1348         FOR_EACH_PLAYER(head)
1349         {
1350                 if(head.frags > checkrules_leaderfrags)
1351                 {
1352                         checkrules_leaderfrags = head.frags;
1353                         checkrules_equality = FALSE;
1354                 }
1355                 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1356                         checkrules_equality = TRUE;
1357         }
1358
1359         if(checkrules_leaderfrags > 0)
1360                 SetWinners(frags, checkrules_leaderfrags);
1361         else
1362                 ClearWinners();
1363
1364         if (!cvar("g_runematch"))
1365                 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1366                 {
1367                         if (checkrules_leaderfrags == fraglimit - 1)
1368                                 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1369                         else if (checkrules_leaderfrags == fraglimit - 2)
1370                                 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1371                         else if (checkrules_leaderfrags == fraglimit - 3)
1372                                 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1373                 }
1374
1375         return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1376 }
1377
1378 float(float fraglimit) WinningConditionBase_Teamplay =
1379 {
1380         tdm_old_score = tdm_max_score;
1381         tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1382
1383         checkrules_equality =
1384         (
1385                 (tdm_max_score > 0)
1386                 &&
1387                 (
1388                           (team1_score == tdm_max_score)
1389                         + (team2_score == tdm_max_score)
1390                         + (team3_score == tdm_max_score)
1391                         + (team4_score == tdm_max_score)
1392                         >= 2));
1393
1394         ClearWinners();
1395         if(tdm_max_score > 0)
1396         {
1397                 if(team1_score == tdm_max_score)
1398                         AddWinners(team, COLOR_TEAM1);
1399                 if(team2_score == tdm_max_score)
1400                         AddWinners(team, COLOR_TEAM2);
1401                 if(team3_score == tdm_max_score)
1402                         AddWinners(team, COLOR_TEAM3);
1403                 if(team4_score == tdm_max_score)
1404                         AddWinners(team, COLOR_TEAM4);
1405         }
1406
1407         if(!cvar("g_runematch") && !cvar("g_domination"))
1408                 if(tdm_max_score != tdm_old_score)
1409                 {
1410                         if(tdm_max_score == fraglimit - 1)
1411                                 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1412                         else if(tdm_max_score == fraglimit - 2)
1413                                 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1414                         else if(tdm_max_score == fraglimit - 3)
1415                                 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1416                 }
1417
1418         return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1419 }
1420
1421 // TDM winning condition: game terminates if a team's score sum reached the
1422 // fraglimit, unless the first two teams have the same total score. The latter
1423 // case also breaks the time limit.
1424 float(float fraglimit) WinningCondition_MaxTeamSum =
1425 {
1426         entity head;
1427
1428         team1_score = team2_score = team3_score = team4_score = 0;
1429
1430         FOR_EACH_PLAYER(head)
1431         {
1432                 if(head.team == COLOR_TEAM1)
1433                         team1_score += head.frags;
1434                 else if(head.team == COLOR_TEAM2)
1435                         team2_score += head.frags;
1436                 else if(head.team == COLOR_TEAM3)
1437                         team3_score += head.frags;
1438                 else if(head.team == COLOR_TEAM4)
1439                         team4_score += head.frags;
1440         }
1441
1442         return WinningConditionBase_Teamplay(fraglimit);
1443 }
1444
1445 // DOM/CTF winning condition: game terminates if the max of a team's players'
1446 // score reached the fraglimit, unless the first two teams have the same
1447 // maximum score. The latter case also breaks the time limit.
1448 float(float fraglimit) WinningCondition_MaxTeamMax =
1449 {
1450         entity head;
1451
1452         team1_score = team2_score = team3_score = team4_score = 0;
1453
1454         FOR_EACH_PLAYER(head)
1455         {
1456                 if(head.team == COLOR_TEAM1)
1457                 {
1458                         if(head.frags > team1_score)
1459                                 team1_score = head.frags;
1460                 }
1461                 else if(head.team == COLOR_TEAM2)
1462                 {
1463                         if(head.frags > team2_score)
1464                                 team2_score = head.frags;
1465                 }
1466                 else if(head.team == COLOR_TEAM3)
1467                 {
1468                         if(head.frags > team3_score)
1469                                 team3_score = head.frags;
1470                 }
1471                 else if(head.team == COLOR_TEAM4)
1472                 {
1473                         if(head.frags > team4_score)
1474                                 team4_score = head.frags;
1475                 }
1476         }
1477
1478         return WinningConditionBase_Teamplay(fraglimit);
1479 }
1480
1481 void print_to(entity e, string s)
1482 {
1483         if(e)
1484                 sprint(e, strcat(s, "\n"));
1485         else
1486                 ServerConsoleEcho(s, TRUE);
1487 }
1488
1489 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1490 {
1491         entity head;
1492         float v;
1493         float teamvalue;
1494         float fragtotal;
1495         string s;
1496         float found;
1497         found = FALSE;
1498         teamvalue = 0;
1499         FOR_EACH_PLAYER(head)
1500         {
1501                 if(!whichteam || head.team == whichteam)
1502                 {
1503                         if(name != "")
1504                                 if(!found)
1505                                         print_to(e, strcat(" ", colorcode, name, ":"));
1506                         found = TRUE;
1507                         fragtotal = fragtotal + head.frags;
1508                         s = ftos(head.frags);
1509                         s = strcat(s, "/", ftos(head.deaths));
1510                         s = strcat(s, " @ ", ftos(head.ping));
1511                         if(clienttype(head) == CLIENTTYPE_BOT)
1512                                 s = strcat(s, "botms");
1513                         else
1514                                 s = strcat(s, "ms");
1515                         v = PlayerValue(head);
1516                         teamvalue += v;
1517                         s = strcat(s, " / ", ftos(v));
1518                         print_to(e, strcat("  ", colorcode, head.netname, colorcode, " (", s, ")"));
1519                 }
1520         }
1521         if(whichteam && found)
1522         {
1523                 s = ftos(fragtotal);
1524                 s = strcat(s, " / ", ftos(teamvalue));
1525                 print_to(e, strcat(colorcode, "  (total: ", s, ")"));
1526         }
1527 }
1528
1529 void PrintScoreboard(entity e)
1530 {
1531         print_to(e, strcat("Time:      ", ftos(time / 60)));
1532         print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1533         print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1534         print_to(e, "Scoreboard:");
1535         if(teams_matter)
1536         {
1537                 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1538                 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1539                 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1540                 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1541         }
1542         else
1543         {
1544                 PrintScoreboardFor(e, "", "^7", 0);
1545         }
1546         print_to(e, ".");
1547 }
1548
1549 void ShuffleMaplist()
1550 {
1551         string result;
1552         float start;
1553         float litems;
1554         float selected;
1555         float i;
1556
1557         result = cvar_string("g_maplist");
1558         litems = tokenize(result);
1559
1560         for(start = 0; start < litems - 1; ++start)
1561         {
1562                 result = "";
1563
1564                 // select a random item
1565                 selected = ceil(random() * (litems - start) + start) - 1;
1566
1567                 // shift this item to the place start
1568                 for(i = 0; i < start; ++i)
1569                         result = strcat(result, "'", argv(i), "'");
1570                 result = strcat(result, "'", argv(selected), "'");
1571                 for(i = start; i < litems; ++i)
1572                         if(i != selected)
1573                                 result = strcat(result, "'", argv(i), "'");
1574
1575                 litems = tokenize(result);
1576
1577                 //dprint(result, "\n");
1578         }
1579
1580         cvar_set("g_maplist", result);
1581 }
1582
1583 /*
1584 ============
1585 CheckRules_World
1586
1587 Exit deathmatch games upon conditions
1588 ============
1589 */
1590 void() CheckRules_World =
1591 {
1592         local float status;
1593         local float timelimit;
1594         local float fraglimit;
1595
1596         VoteThink();
1597         MapVote_Think();
1598
1599         SetDefaultAlpha();
1600
1601         /*
1602         MapVote_Think should now do that part
1603         if (intermission_running)
1604                 if (time >= intermission_exittime + 60)
1605                 {
1606                         if(!DoNextMapOverride())
1607                                 GotoNextMap();
1608                         return;
1609                 }
1610         */
1611
1612         if (gameover)   // someone else quit the game already
1613         {
1614                 if(player_count == 0) // Nobody there? Then let's go to the next map
1615                         MapVote_Start();
1616                         // this will actually check the player count in the next frame
1617                         // again, but this shouldn't hurt
1618                 return;
1619         }
1620
1621         timelimit = cvar("timelimit") * 60;
1622         fraglimit = cvar("fraglimit");
1623
1624         if(checkrules_overtimeend)
1625         {
1626                 if(!checkrules_overtimewarning)
1627                 {
1628                         checkrules_overtimewarning = TRUE;
1629                         //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1630                         bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1631                 }
1632         }
1633         else
1634         {
1635                 if (timelimit && time >= timelimit)
1636                         InitiateOvertime();
1637         }
1638
1639         if (checkrules_overtimeend && time >= checkrules_overtimeend)
1640         {
1641                 NextLevel();
1642                 return;
1643         }
1644
1645         if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1646         {
1647                 checkrules_oneminutewarning = TRUE;
1648                 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1649         }
1650
1651         status = WINNING_NO;
1652         if(g_assault)
1653         {
1654                 status = WinningCondition_Assault();
1655         }
1656         else if(g_lms)
1657         {
1658                 status = WinningCondition_LMS();
1659         }
1660         else if (g_onslaught)
1661         {
1662                 status = WinningCondition_Onslaught();
1663         }
1664         else
1665         {
1666                 if(teams_matter)
1667                 {
1668                         if(g_tdm || cvar("g_runematch") || g_ctf || cvar("g_domination") || g_keyhunt)
1669                                 status = WinningCondition_MaxTeamSum(fraglimit);
1670                         //else if()
1671                         //      status = WinningCondition_MaxTeamMax(fraglimit);
1672                         else
1673                         {
1674                                 dprint("div0: How can this happen?\n");
1675                                 status = WinningCondition_MaxTeamMax(fraglimit);
1676                         }
1677                 }
1678                 else
1679                         status = WinningCondition_MaxIndividualScore(fraglimit);
1680         }
1681
1682         if(status == WINNING_STARTOVERTIME)
1683         {
1684                 status = WINNING_NEVER;
1685                 InitiateOvertime();
1686         }
1687
1688         if(status == WINNING_NEVER)
1689                 // equality cases! Nobody wins if the overtime ends in a draw.
1690                 ClearWinners();
1691
1692         if(checkrules_overtimeend)
1693                 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1694                         status = WINNING_YES;
1695
1696         if(status == WINNING_YES)
1697                 NextLevel();
1698 };
1699
1700 float randsel_value;
1701 float randsel_priority;
1702 float randsel_count;
1703 void RandSel_Init()
1704 {
1705         randsel_value = -1;
1706         randsel_priority = -1;
1707         randsel_count = -1;
1708 }
1709 void RandSel_Add(float priority, float value)
1710 {
1711         if(priority > randsel_priority)
1712         {
1713                 randsel_priority = priority;
1714                 randsel_value = value;
1715                 randsel_count = 1;
1716         }
1717         else if(priority == randsel_priority)
1718         {
1719                 randsel_count += 1;
1720                 if(ceil(random() * randsel_count) == 1)
1721                         randsel_value = value;
1722         }
1723 }
1724
1725 float mapvote_nextthink;
1726 float mapvote_initialized;
1727 float mapvote_keeptwotime;
1728 float mapvote_timeout;
1729 string mapvote_message;
1730
1731 #define MAPVOTE_COUNT 10
1732 float mapvote_count;
1733 string mapvote_maps[MAPVOTE_COUNT];
1734 float mapvote_maps_suggested[MAPVOTE_COUNT];
1735 string mapvote_suggestions[MAPVOTE_COUNT];
1736 float mapvote_suggestion_ptr;
1737 float mapvote_maxlen;
1738 float mapvote_voters;
1739 float mapvote_votes[MAPVOTE_COUNT];
1740 float mapvote_run;
1741 .float mapvote;
1742
1743 void MapVote_ClearAllVotes()
1744 {
1745         FOR_EACH_CLIENT(other)
1746                 other.mapvote = 0;
1747 }
1748
1749 string MapVote_Suggest(string m)
1750 {
1751         float i;
1752         if(m == "")
1753                 return "That's not how to use this command.";
1754         if(!cvar("g_maplist_votable_suggestions"))
1755                 return "Suggestions are not accepted on this server.";
1756         if(mapvote_initialized)
1757                 return "Can't suggest - voting is already in progress!";
1758         if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1759                 if(!IsSameGametype(m))
1760                         return "This server does not allow changing the game type by map suggestions.";
1761         if(!cvar("g_maplist_votable_override_mostrecent"))
1762                 if(Map_IsRecent(m))
1763                         return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1764
1765 #ifdef MAPINFO
1766 #else
1767         if(!TryFile(strcat("maps/", m, ".mapcfg")))
1768 #endif
1769                 return "The map you suggested is not available on this server.";
1770         for(i = 0; i < mapvote_suggestion_ptr; ++i)
1771                 if(mapvote_suggestions[i] == m)
1772                         return "This map was already suggested.";
1773         if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1774         {
1775                 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1776         }
1777         else
1778         {
1779                 i = mapvote_suggestion_ptr;
1780                 mapvote_suggestion_ptr += 1;
1781         }
1782         if(mapvote_suggestions[i] != "")
1783                 strunzone(mapvote_suggestions[i]);
1784         mapvote_suggestions[i] = strzone(m);
1785         GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1786         return "Suggestion accepted.";
1787 }
1788
1789 void MapVote_AddVotable(string nextMap, float isSuggestion)
1790 {
1791         float j;
1792         if(nextMap == "")
1793                 return;
1794         for(j = 0; j < mapvote_count; ++j)
1795                 if(mapvote_maps[j] == nextMap)
1796                         return;
1797         if(strlen(nextMap) > mapvote_maxlen)
1798                 mapvote_maxlen = strlen(nextMap);
1799         mapvote_maps[mapvote_count] = strzone(nextMap);
1800         mapvote_maps_suggested[mapvote_count] = isSuggestion;
1801         mapvote_count += 1;
1802 }
1803
1804 void MapVote_Init()
1805 {
1806         float i;
1807         float nmax, smax;
1808
1809         MapVote_ClearAllVotes();
1810
1811         nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1812         smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1813         mapvote_count = 0;
1814
1815         for(i = 0; i < 100 && mapvote_count < smax; ++i)
1816                 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1817
1818         for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1819                 MapVote_AddVotable(GetNextMap(), FALSE);
1820
1821         if(mapvote_count == 0)
1822         {
1823                 bprint( "Maplist contains no single playable map!  Resetting it to default map list.\n" );
1824 #ifdef MAPINFO
1825 #else
1826                 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1827 #endif
1828                 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1829                         MapVote_AddVotable(GetNextMap(), FALSE);
1830         }
1831
1832         //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1833
1834         mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1835         mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1836         if(mapvote_count < 3 || mapvote_keeptwotime <= time)
1837                 mapvote_keeptwotime = 0;
1838         mapvote_message = "Choose a map and press its key!";
1839 }
1840 float MapVote_Finished(float mappos)
1841 {
1842         string result;
1843         float i;
1844
1845         result = strcat(":vote:finished:", mapvote_maps[mappos]);
1846         result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1847         for(i = 0; i < mapvote_count; ++i)
1848                 if(i != mappos)
1849                         if(mapvote_maps[i] != "")
1850                         {
1851                                 result = strcat(result, ":", mapvote_maps[i]);
1852                                 result = strcat(result, ":", ftos(mapvote_votes[i]));
1853                         }
1854         GameLogEcho(result, FALSE);
1855         if(mapvote_maps_suggested[mappos])
1856                 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1857
1858         FOR_EACH_REALCLIENT(other)
1859                 FixClientCvars(other);
1860
1861         Map_Goto_SetStr(mapvote_maps[mappos]);
1862         Map_Goto();
1863         alreadychangedlevel = TRUE;
1864         return TRUE;
1865 }
1866 void MapVote_CheckRules_1()
1867 {
1868         float i;
1869
1870         for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1871         {
1872                 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1873                 mapvote_votes[i] = 0;
1874         }
1875
1876         mapvote_voters = 0;
1877         FOR_EACH_REALCLIENT(other)
1878         {
1879                 ++mapvote_voters;
1880                 if(other.mapvote)
1881                 {
1882                         i = other.mapvote - 1;
1883                         //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1884                         mapvote_votes[i] = mapvote_votes[i] + 1;
1885                 }
1886         }
1887 }
1888
1889 float MapVote_CheckRules_2()
1890 {
1891         float i;
1892         float firstPlace, secondPlace;
1893         float firstPlaceVotes, secondPlaceVotes;
1894         string result;
1895
1896         RandSel_Init();
1897         for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1898                 RandSel_Add(mapvote_votes[i], i);
1899         firstPlace = randsel_value;
1900         firstPlaceVotes = randsel_priority;
1901         //dprint("First place: ", ftos(firstPlace), "\n");
1902         //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1903
1904         RandSel_Init();
1905         for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1906                 if(i != firstPlace)
1907                         RandSel_Add(mapvote_votes[i], i);
1908         secondPlace = randsel_value;
1909         secondPlaceVotes = randsel_priority;
1910         //dprint("Second place: ", ftos(secondPlace), "\n");
1911         //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1912
1913         if(firstPlace == -1)
1914                 error("No first place in map vote... WTF?");
1915
1916         if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters - firstPlaceVotes) < firstPlaceVotes)
1917                 return MapVote_Finished(firstPlace);
1918
1919         if(mapvote_keeptwotime)
1920                 if(time > mapvote_keeptwotime || (mapvote_voters - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1921                 {
1922                         mapvote_message = "Now decide between the TOP TWO!";
1923                         mapvote_keeptwotime = 0;
1924                         result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1925                         result = strcat(result, ":", ftos(firstPlaceVotes));
1926                         result = strcat(result, ":", mapvote_maps[secondPlace]);
1927                         result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1928                         for(i = 0; i < mapvote_count; ++i)
1929                                 if(i != firstPlace)
1930                                         if(i != secondPlace)
1931                                                 if(mapvote_maps[i] != "")
1932                                                 {
1933                                                         result = strcat(result, ":", mapvote_maps[i]);
1934                                                         result = strcat(result, ":", ftos(mapvote_votes[i]));
1935                                                         strunzone(mapvote_maps[i]);
1936                                                         mapvote_maps[i] = "";
1937                                                 }
1938                         GameLogEcho(result, FALSE);
1939                 }
1940
1941         return FALSE;
1942 }
1943 void MapVote_Tick()
1944 {
1945         string msgstr;
1946         string tmp;
1947         float i;
1948         float keeptwo;
1949
1950         keeptwo = mapvote_keeptwotime;
1951         MapVote_CheckRules_1(); // count
1952         if(MapVote_CheckRules_2()) // decide
1953                 return;
1954
1955         FOR_EACH_REALCLIENT(other)
1956         {
1957                 // hide scoreboard again
1958                 if(other.health != 2342)
1959                 {
1960                         other.health = 2342;
1961                         other.impulse = 0;
1962                         if(clienttype(other) == CLIENTTYPE_REAL)
1963                         {
1964                                 stuffcmd(other, "\nin_bind 7 1 \"impulse 1\"; in_bind 7 2 \"impulse 2\"; in_bind 7 3 \"impulse 3\"; in_bind 7 4 \"impulse 4\"; in_bind 7 5 \"impulse 5\"; in_bind 7 6 \"impulse 6\"; in_bind 7 7 \"impulse 7\"; in_bind 7 8 \"impulse 8\"; in_bind 7 9 \"impulse 9\"; in_bind 7 0 \"impulse 10\"; in_bind 7 KP_1 \"impulse 1\"; in_bind 7 KP_2 \"impulse 2\"; in_bind 7 KP_3 \"impulse 3\"; in_bind 7 KP_4 \"impulse 4\"; in_bind 7 KP_5 \"impulse 5\"; in_bind 7 KP_6 \"impulse 6\"; in_bind 7 KP_7 \"impulse 7\"; in_bind 7 KP_8 \"impulse 8\"; in_bind 7 KP_9 \"impulse 9\"; in_bind 7 KP_0 \"impulse 10\"; in_bindmap 7 0\n");
1965                                 msg_entity = other;
1966                                 WriteByte(MSG_ONE, SVC_FINALE);
1967                                 WriteString(MSG_ONE, "");
1968                                 /*
1969                                 for(i = 0; i < mapvote_count; ++i)
1970                                         if(mapvote_maps[i] != "")
1971                                         {
1972                                                 tmp = mapvote_maps[i];
1973                                                 sprint(other, strcat("map voting: type ^1impulse ", ftos(i+1), "^7 to vote for ", tmp, "\n"));
1974                                         }
1975                                 */
1976                         }
1977                 }
1978
1979                 // notify about keep-two
1980                 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1981                         play2(other, "misc/invshot.wav");
1982
1983                 // clear possibly invalid votes
1984                 if(mapvote_maps[other.mapvote - 1] == "")
1985                         other.mapvote = 0;
1986                 // use impulses as new vote
1987                 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1988                         if(mapvote_maps[other.impulse - 1] != "")
1989                                 other.mapvote = other.impulse;
1990                 other.impulse = 0;
1991         }
1992
1993         MapVote_CheckRules_1(); // just count
1994
1995         FOR_EACH_REALCLIENT(other)
1996         {
1997                 // display voting screen
1998                 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1999                 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2000                 msgstr = strcat(msgstr, mapvote_message);
2001                 msgstr = strcat(msgstr, "\n\n");
2002                 for(i = 0; i < mapvote_count; ++i)
2003                         if(mapvote_maps[i] == "")
2004                                 msgstr = strcat(msgstr, "\n");
2005                         else
2006                         {
2007                                 tmp = mapvote_maps[i];
2008                                 tmp = strpad(mapvote_maxlen, tmp);
2009                                 tmp = strcat(ftos(math_mod(i + 1, 10)), ": ", tmp);
2010                                 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2011                                 if(mapvote_votes[i] != 1)
2012                                         tmp = strcat(tmp, "s");
2013                                 tmp = strcat(tmp, ")");
2014                                 tmp = strpad(mapvote_maxlen + 15, tmp);
2015                                 if(other.mapvote == i + 1)
2016                                         msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2017                                 else
2018                                         msgstr = strcat(msgstr, "^7  ", tmp, "\n");
2019                         }
2020                 i = ceil(mapvote_timeout - time);
2021                 msgstr = strcat(msgstr, "\n\n", ftos(i), " second");
2022                 if(i != 1)
2023                         msgstr = strcat(msgstr, "s");
2024                 msgstr = strcat(msgstr, " left");
2025
2026                 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2027         }
2028 }
2029 void MapVote_Start()
2030 {
2031         mapvote_run = TRUE;
2032 }
2033 void MapVote_Think()
2034 {
2035         if(!mapvote_run)
2036                 return;
2037
2038         if(alreadychangedlevel)
2039                 return;
2040
2041         if(time < mapvote_nextthink)
2042                 return;
2043         //dprint("tick\n");
2044
2045         mapvote_nextthink = time + 0.5;
2046
2047         if(!mapvote_initialized)
2048         {
2049                 mapvote_initialized = TRUE;
2050                 if(DoNextMapOverride())
2051                         return;
2052                 if(!cvar("g_maplist_votable") || player_count <= 0)
2053                 {
2054                         GotoNextMap();
2055                         return;
2056                 }
2057                 MapVote_Init();
2058         }
2059
2060         MapVote_Tick();
2061 };
2062
2063 string GotoMap(string m)
2064 {
2065 #ifdef MAPINFO
2066 #else
2067         if(!TryFile(strcat("maps/", m, ".mapcfg")))
2068 #endif
2069                 return "The map you chose is not available on this server.";
2070         cvar_set("nextmap", m);
2071         cvar_set("timelimit", "-1");
2072         if(mapvote_initialized || alreadychangedlevel)
2073         {
2074                 if(DoNextMapOverride())
2075                         return "Map switch initiated.";
2076                 else
2077                         return "Hm... no. For some reason I like THIS map more.";
2078         }
2079         else
2080                 return "Map switch will happen after scoreboard.";
2081 }
2082
2083
2084 void EndFrame()
2085 {
2086         FOR_EACH_REALCLIENT(self)
2087         {
2088                 if(self.classname == "spectator")
2089                 {
2090                         if(self.enemy.hitsound)
2091                                 play2(self, "misc/hit.wav");
2092                 }
2093                 else
2094                 {
2095                         if(self.hitsound)
2096                                 play2(self, "misc/hit.wav");
2097                 }
2098         }
2099         FOR_EACH_CLIENT(self)
2100                 self.hitsound = FALSE;
2101 }
2102
2103
2104 /*
2105  * RedirectionThink:
2106  * returns TRUE if redirecting
2107  */
2108 float redirection_timeout;
2109 float redirection_nextthink;
2110 float RedirectionThink()
2111 {
2112         float clients_found;
2113
2114         if(redirection_target == "")
2115                 return FALSE;
2116
2117         if(!redirection_timeout)
2118         {
2119                 cvar_set("sv_public", "-2");
2120                 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2121                 if(redirection_target == "self")
2122                         bprint("^3SERVER NOTICE:^7 restarting the server\n");
2123                 else
2124                         bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2125         }
2126
2127         if(time < redirection_nextthink)
2128                 return TRUE;
2129
2130         redirection_nextthink = time + 1;
2131
2132         clients_found = 0;
2133         FOR_EACH_REALCLIENT(self)
2134         {
2135                 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2136                 if(redirection_target == "self")
2137                         stuffcmd(self, "\ndisconnect; reconnect\n");
2138                 else
2139                         stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2140                 ++clients_found;
2141         }
2142
2143         ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2144
2145         if(time > redirection_timeout || clients_found == 0)
2146                 localcmd("\nwait; wait; wait; quit\n");
2147
2148         return TRUE;
2149 }