-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.php
1645 lines (1450 loc) · 52.3 KB
/
common.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* mta tracker
* 2009 blackmore
*
* "little main"
**/
if(php_sapi_name()!="cli"){
ob_start();
}
/* // send all clients except you to info page
$userIp=(isset($_SERVER['HTTP_CF_CONNECTING_IP'])?$_SERVER['HTTP_CF_CONNECTING_IP']:$_SERVER['REMOTE_ADDR']);
if($userIp != "YOUR.IP.ADDRESS") {
require_once __DIR__ . "/offline.php";
die;
}
*/
//require_once "N14Inc/ErrorHandler.php";
require_once __DIR__."/graphcommon.php";
require_once __DIR__."/config.php";
require_once __DIR__."/N14Inc/Locale.php";
require_once __DIR__."/N14Inc/Pagi.php";
require_once N14CORE_LOCATION."/ModularApp.php";
//require_once "includes/dummylog.php";
use \N14\GetText as GetText;
list($phpMajor, $phpMinor) = explode(".", phpversion());
// BROKEN!! REWRITE USING NCORE SESS
/*if(php_sapi_name()!="cli"){
session_name("N14GTLang");
session_start();
setcookie(session_name(),session_id(),time()+86400*365*2,"/");
}
if(!isset($_SESSION['ngt_userlang']) || isset($_GET['resetlang'])){
$browserLocale=GetText\find_locale_by_httprequest();
if($browserLocale){
$_SESSION['ngt_userlang']=$browserLocale;
}else{
$_SESSION['ngt_userlang']=$defaultLocale;
}
//$firstVisit=true;
}else if(isset($_SESSION['ngt_userlang']) && $_SESSION['ngt_userlang']!=$defaultLocale && !isset($_GET['lang'])){
//echo "REDIR2LOC";
}
if(isset($_GET['lang']) && (
!(isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'],$site_host)===false)
)){
if(GetText\locale_exists($_GET['lang'])){
$_SESSION['ngt_userlang']=$_GET['lang'];
}
}
GetText\setlocale($_SESSION['ngt_userlang']);*/
GetText\setlocale("en");
$_SESSION['nutt_lastreq']=time();
//$log = new DummyLog();
//$modMaster = new N14\ModuleMaster($log);
//$abspath="/uttracker";
$abspath=$sub_site_url;
$dateformat="d-m-Y H:i";
//$rewriteParams=array();
/*
$loc="en_EN";
putenv("LANG=$loc" );
setlocale(LC_ALL, "$loc");
bindtextdomain("messages", "./Locale");
bind_textdomain_codeset("messages", 'UTF-8');
textdomain("messages");
*/
const LPLAYER=0;
const LSERVER=1;
const LGAME=2;
const LFILE=3;
const LSTATICFILE=4;
const LMAP=5;
const LSEARCHPLAYER=6;
const LSEARCHSERVER=7;
const LMAPLAYOUT=8;
//FirePHP::getInstance(true)->log("Commom.php!");
/**
*
* @param string $paramname Request parameter to be removed from URL when doing relative request
*/
function addRewriteParam($paramname){
if(!isset($GLOBALS['rewriteParams'])){
$GLOBALS['rewriteParams']=array();
}
$GLOBALS['rewriteParams'][$paramname]=true;
}
function requestFilterRewriteParams(&$req){
if(isset($GLOBALS['rewriteParams'])){
foreach($GLOBALS['rewriteParams'] as $pn=>$tru){
if(isset($req[$pn])) unset($req[$pn]);
}
}
}
function getSkinImage($mesh,$skin,$face,$floatleft=false){
global $assetsPath,$assetsPathLocal;
$skinn=arrLast(explode(".",$skin));
$facen=arrLast(explode(".",$face));
$gfxf=strtolower("$skinn"."_$facen");
$addcl=($floatleft?" imgleft":"");
if($skinFile=checkForAssetRemote("skins/$gfxf.jpg")) {
return "<img src='$skinFile' alt='$mesh / $skin / $face' class='uttr_skin$addcl'/>\n";
}else if(strtolower($mesh)=="nali cow") {
$skinFile = checkForAssetRemote("skins/cow-face.jpg");
return "<img src='$skinFile' alt='Nali Cow' class='uttr_skin$addcl'/>\n";
}else if(strtolower($mesh)=="boss") {
$skinFile = checkForAssetRemote("skins/boss_xan.jpg");
return "<img src='$skinFile' alt='Boss' class='uttr_skin$addcl'/>\n";
}else if(strtolower($mesh)=="spectator") {
$skinFile = checkForAssetRemote("skins/s_camera.jpg");
return "<img src='$skinFile' alt='Spectator' class='uttr_skin$addcl'/>\n";
}else{
return "<div class='uttr_skin unknown$addcl'><br><br><br>$mesh</div>\n";
}
}
function getflag($c){
global $assetsPath,$assetsPathLocal;
if(isset($GLOBALS['isAF15']) && $GLOBALS['isAF15']) return $flag="<img src='$assetsPath/uttfavRemixed.png' class='cflag' title='".countryName($c)."' alt='{$c}'/>";
if($c!="" && $flagPath=checkForAssetRemote("flags/{$c}.gif"))
$flag="<img src='$flagPath' class='cflag' title='".countryName($c)."' alt='{$c}'/>";
else
$flag="";
return $flag;
}
/**
* Generates URL referring to supplied object for N14 app
* @param int $type Type of link to create
* @param mixed $id (string/int)Object ID or (array)object data
* @param string $name Optional, object name
* @param mixed $params Optional, (array)additional query parameters or (string)contents of "s" parameter
* @param bool $noLang Optional, don't add "lang" parameter to the URL
* @return string
*/
function maklink($type,$id,$name=null,$params=null,$noLang=false){
global $abspath,$assetsPath,$site_host;
$reqParams=array();
if($params!==null) {
if(is_array($params)){
$reqParams = $reqParams + $params;
}else{
//$reqParams['s']=$params; // 16-04-02 NODEVEL, removing some stats features
}
}
/*if(!$noLang){
$reqParams['lang']=GetText\getlocale();
}*/
$q=http_build_query($reqParams);
if($q!="") $q="?".$q;
switch($type){
case LPLAYER:
if(is_array($id)){
$playerData = $id;
$name = $playerData['name'];
$id = $playerData['id'];
}
return "$abspath/player/$id-".name2id($name)."$q";
case LSERVER:
if(is_array($id)){
$addy="";
$serverData = $id;
$name = $serverData['name'];
/*$id = $serverData['serverid'];*/
$ip = getServerIpWithHostPort($serverData['address']);
if(isset($reqParams['page'])){
$addy=";{$reqParams['page']}";
unset($reqParams['page']);
$q=http_build_query($reqParams);
if($q!="") $q="?".$q;
}
return "$abspath/server/$ip%5E".name2id($name)."$addy$q";
}
return "$abspath/server/$id-".name2id($name)."$q";
case LGAME:
return "$abspath/server/$name/game$id.htm$q";
case LFILE:
$file=ltrim(strtok(" ".$id,"?"),"/ ");
$query=strtok("\r");
$queryArr=null;
parse_str($query,$queryArr);
$reqParams=$reqParams+$queryArr;
$q=http_build_query($reqParams);
if($q!="") $q="?".$q;
if(strlen($id) && $id[0]=="/")
return "//$site_host$id$q";
return "$abspath/$file$q";
case LSTATICFILE:
$file = ltrim($id,"/ ");
$filePath=checkForAssetRemote($file);
if($filePath)
return $filePath;
else
return "$assetsPath/$file";
case LMAP:
return "$abspath/map/".urlencode($name)."$q";
case LSEARCHPLAYER:
/*$reqParams['playerSearch']=$name;
$q=http_build_query($reqParams);
return "$abspath/search.php?$q&$id";*/
$q=http_build_query($reqParams);
return "$abspath/search/player/".urlencode($name)."$q";
case LSEARCHSERVER:
$reqParams['serverName']=$name;
$q=http_build_query($reqParams);
case LMAPLAYOUT:
$reqParams=$reqParams+array("map"=>$name, "projmode"=>$id);
$q=http_build_query($reqParams);
return "$abspath/WireframeRenderer/renderpolywithsprites.php?$q";
return "$abspath/?$q&$id";
}
}
function maklinkHtml($type,$id,$name=null,$params=null,$noLang=false){
return htmlspecialchars(maklink($type,$id,$name,$params,$noLang));
}
function checkForAsset($file){
global $assetsGenericPathLocal,$assetsPathLocal;
if($file[0]!="/") $file = "/".$file;
if(file_exists($assetsGenericPathLocal.$file)) return $assetsGenericPathLocal.$file;
else if(file_exists($assetsPathLocal.$file)) return $assetsPathLocal.$file;
else return false;
}
function checkForAssetRemote($file){
global $assetsGenericPathLocal,$assetsPathLocal,$assetsGenericPath,$assetsPath;
if($file[0]!="/") $file = "/".$file;
if(file_exists($assetsGenericPathLocal.$file)) return $assetsGenericPath.$file;
else if(file_exists($assetsPathLocal.$file)) return $assetsPath.$file;
else return false;
}
function getServerIpWithHostPort($addr){
list($ip,$port) = explode(":",$addr);
return $ip . ":" . ($port-1);
}
// ??? no idea what was the point of this
function serializename($nm){
$news="";
for ($i = 0; $i < strlen($nm); $i++):
$cx = ord($nm[$i]);
if (($cx >= 48 && $cx <= 57) || ($cx >= 65 && $cx <= 90) || ($cx >= 97 && $cx <= 122) || $cx == 61 || $cx == 91 || $cx == 93 || $cx == 95 || $cx == 123 || $cx == 125 || $cx == 40 || $cx == 41 || ($cx >= 43 && $cx <= 46) || $cx == 32 || $cx == 33 || $cx == 36 || $cx == 38 || $cx == 39 ):
$news .= chr($cx);
else:
$news .= "%" . strtoupper(dechex($cx));
endif;
endfor;
return $news;
}
/**
* Issue a 301 Moved Permanently redirect and finish the execution of script.
* @param string $url Destination URL
*/
function permredir($url){
ob_end_clean();
header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
exit;
}
/**
* Display an error page when user tries to access nonexistent resource.
* @param type $req Optional, name of requested resource
*/
function triggerNotFoundError($req=null){
global $requestPage,$req,$n14app;
ob_end_clean();
if($req!==null)
$requestPage=$req;
else if(!isset($requestPage))
$requestPage=$_SERVER['REQUEST_URI'];
if(file_exists("404.php")){
include "404.php";
}else{
echo "<h1>404 Not Found</h1><p>The requested resource: $requestPage could not be found. Also, the error landing page was not created for \"".$n14app['id']."\".</p>";
}
exit;
}
/**
* Alias for triggerNotFoundError
* @deprecated since version 58
* @param type $req Optional, name of requested resource
*/
function error404($req=null){
triggerNotFoundError($req);
}
function colAsKey(&$ar,$col){
$newar=array();
foreach($ar as $kn=>$xd){
//echo "AAAAAAAAAAAAAAAA";
$newar[$xd[$col]]=&$xd;
unset($xd);
unset($ar[$kn]);
}
$ar=$newar;
}
/* date & timestamp formatting, LAME!! */
/**
* Formats the timestamp relatively to the present date.
* If the referred date was more than two days before, formats it using the global $dateformat configured of N14APP
* @param int $d Unix timestamp of date to be formatted
* @param boolean $relative Use relative adverbs (Today, Yesterday, X time ago)
* @global string $c
* @return string The formatted date
*/
function uttdateFmt($d,$relative=true){
global $dateformat;
if($relative && $d > time() - dssm()-86400*7)
return niceDate($d);
else if($d==0)
return "???";
else
return date($dateformat,$d);
}
/**
* Formats the timestamp relatively to the present date, using relative adverbs (Today, Yesterday, X time ago)
* @param int $d Unix timestamp of date to be formatted
* @return string The formatted date
*/
function niceDate($d){
if($d > time() - 3600) return sprintf(__("%1\$d min. ago"),floor((time()-$d)/60));
else if($d > time() - dssm()) return sprintf(__("Today, %1\$s"),date("G:i",$d));
else if($d > time() - dssm()-86400) return sprintf(__("Yesterday, %1\$s"),date("G:i",$d));
else if($d == 0) return "??";
else return sprintf(__("%1\$s ago"),formattime((time()-$d)/3600));
}
/**
* Creates friendly timespan string from short intervals (with seconds-precision)
* @param float $seconds Number of seconds
* @return string The formatted time interval
*/
function formattimesmall($seconds){
//return ($hours<1 ? "< 1 h":((floor($hours)>=24)?floor($hours/24)." d ":"").(floor($hours)%24)." h");
return ((floor($seconds)>=3600)?floor($seconds/3600)." h ":"").($seconds>=60?floor(($seconds%3600)/60) ." min ":"") . (floor($seconds)%60) ." s";
}
/**
* Creates friendly timespan string from big timespans (above minute)
* @param float $hours Number of hours
* @return string The formatted time interval
*/
function formattime($hours){
//return ($hours<1 ? "< 1 h":((floor($hours)>=24)?floor($hours/24)." d ":"").(floor($hours)%24)." h");
//return ((floor($hours)>=24)?floor($hours/24)." d ":"").($hours>=1?(floor($hours)%24)." h ":"") . (floor($hours*60)%60) ." min";
return ((floor($hours)>=720) ? floor($hours/720)." mo " : "").
((floor($hours)>=24) ? (($hours/24)%30)." d " : "").
($hours>=1&&$hours<24*5 ? (floor($hours)%24)." h " : "") .
($hours < 2 && $hours>=0 ? (floor($hours*60)%60) ." min" : "").
($hours < 0 ? "[UTT_ACHTUNG!Corrupted timespan]" : ""); // < 2016-03-20
}
/**
* Creates readable time interval using formats:
* MM:SS for intervals below 1 hour
* HH:MM:SS more than 1 hour
* @param int $seconds Time interval in seconds
* @return string The formatted time interval
*/
function shortTimeInterval($seconds){
$sign = $seconds<0 ? "-" : "";
$secondsAbsolute = abs($seconds);
$fullSeconds = $secondsAbsolute%60;
$fullMinutes = floor($secondsAbsolute/60) % 60;
$fullHours = floor($secondsAbsolute/3600);
$result = "";
$result .= $sign;
if($fullHours) $result.=$fullHours . ":";
$result.= str_pad($fullMinutes,2,"0",STR_PAD_LEFT) . ":";
$result.= str_pad($fullSeconds,2,"0",STR_PAD_LEFT);
return $result;
}
/* converts VB-style date to Unix timestamp */
function strtotimeX($str){
return date_create_from_format ("m-d-Y H:i:s",$str)->getTimestamp ();
}
/**
* Gets number of seconds since midnight
* @return int Seconds since midnight
*/
function dssm(){
return date("G")*3600 + date("i") * 60 + date("s");
}
if(!function_exists("name2id")){
function name2id($sx){
$s=strtolower($sx);
$s=str_replace(
array('$', /*"!",*/"@","{}v{}","(.)(.)", "(.y.)", ")-(",")v(","|<","()","'//","'/","|_|","|_","/-]","|-|"),
array("s" , /*"i",*/"a","m", " boobs "," boobs ","h" ,"m" ,"k" ,"o" ,"w", "y" ,"u" ,"l" ,"a" ,"h"),
$s);
$res=substr(str_replace(" ","-",trim(preg_replace("/[^a-z0-9]+/"," ",$s))),0,30);
if(strlen($res)<2){
$res=name2idLITERAL($sx);
}
return $res;
}
function name2idLITERAL($s){
$s=str_replace(
array('$', '#', '!','.....', '.', '+', '~', '}:', '|', '"', "&", "%", "*"),
array(' dollar ',' hash ','a',' lots of dots ','dot',' plus ',' tilde ',' cow ',' vertical bar ',"quote"," and "," percent "," star "),
$s);
return substr(str_replace(" ","-",trim(preg_replace("/[^a-z0-9]+/"," ",$s))),0,30);
}
}
/* detect server type ("tags") from fused serverinfo & serverrules
TODO prettier configurable way
*/
const SERVERTAGS_GAMEMODE=1;
const SERVERTAGS_MUTATOR=2;
function getServerTags($s,$type=255){
$gtypes=array();
$gtx=strtok($s['mapname'],"-");
$mn=strtok("-");
$lcMutators = isset($s['mutators']) ? strtolower($s['mutators']) : ""; // to avoid using stripos
$lcName = isset($s['hostname']) ? strtolower($s['hostname']) : "";
$typeGM = $type & SERVERTAGS_GAMEMODE;
$typeMUT = $type & SERVERTAGS_MUTATOR;
if($typeGM){
if(($gtx=="CTF" && $mn=="BT") || $gtx=="BT"){
$gtypes[]="BT";
}else{
switch(strtolower($s['gametype'])){
case "deathmatchplus": $gtypes[]="DM"; break;
case "teamgameplus": $gtypes[]="TDM"; break;
case "ctfgame": $gtypes[]="CTF"; break;
case "domination": $gtypes[]="DOM"; break;
case "lastmanstanding": $gtypes[]="LMS"; break;
case "thieverydeathmatchplus": $gtypes[]="TH"; break;
case "monsterhunt": $gtypes[]="MH"; break;
case "idm": $gtypes[]="DM"; $gtypes[]="Insta"; break;
case "ictf": $gtypes[]="CTF"; $gtypes[]="Insta"; break;
case "idom": $gtypes[]="DOM"; $gtypes[]="Insta"; break;
case "sactf": $gtypes[]="CTF"; $gtypes[]="Sniper"; break;
case "itdm": $gtypes[]="TDM"; $gtypes[]="Insta"; break;
case "jailbreak": $gtypes[]="JB"; break;
case "soccermatch": $gtypes[]="SCR"; break;
case "shgame": $gtypes[]="SH"; break;
case "coop game":
case "coopgame2":
case "tvcoop":
case "infcoopunrealgame":
$gtypes[]="Coop"; break;
case "siegegi": $gtypes[]="SGI"; break;
default:
if($mn!=""){
$gtypes[]=$gtx;
}else{
$gtypes[]=$s['gametype'];
}
break;
}
}
if(strpos($lcName,"funnel")!==false){
$gtypes[]="FN";
}
}
if($typeGM && (
strpos($lcMutators,"combogib")!==false ||
strpos($lcName,"combogib")!==false ||
strpos($lcName,"comboinstagib")!==false)){
$gtypes[]="Combo";
}elseif($typeGM && (
strpos($lcMutators,"zeroping accugib")!==false ||
strpos($lcName,"insta")!==false) &&
!isset($gtypes['BT'])){
$gtypes[]="Insta";
}elseif($typeMUT && strpos($lcName,"sniper")!==false){
$gtypes[]="Sniper";
}elseif(strpos($lcMutators,"nali weapons 3")!==false ||
strpos($lcName,"nw3")!==false ||
strpos($lcName,"nali weapons 3")!==false ||
strpos($lcName,"naliweaponsiii")!==false){
$gtypes[]="NW3";
}elseif($typeMUT && (
strpos($lcName,"all weapons")!==false ||
strpos($lcName,"allweapons")!==false ||
strpos($lcMutators,"all weapons")!==false ||
strpos($lcMutators,"allweapons")!==false)){
$gtypes[]="ALLWP";
}
if($typeMUT && (
strpos($lcMutators,"grapple")!==false ||
strpos($lcMutators,"grapplinghook")!==false ||
strpos($lcName,"grapple")!==false)){
$gtypes[]="Grapple";
}
if($typeMUT && (strpos($lcMutators,"map-vote")!==false)){
$gtypes[]="MutMV";
}
if($typeMUT && (strpos($lcMutators,"smartctf")!==false)){
$gtypes[]="MutSCTF";
}
if($typeMUT && (
strpos($lcMutators,"doublejumput")!==false ||
strpos($lcMutators,"[r]^sdj")!==false)){
$gtypes[]="MutDJ";
}
if($typeMUT && (strpos($lcMutators,"relic: ")!==false)){
$gtypes[]="MutRL";
}
if($typeMUT && (strpos($lcMutators,"btcheckpoints")!==false)){
$gtypes[]="MutCP";
}
if($typeMUT && strpos($lcName,"pug")!==false){
$gtypes[]="PUG";
}
if(isset($s['gamever']) && $s['gamever']>250 && $s['gamever']<=348){
$gtypes[]="DEMO";
}
return array_unique ($gtypes);
}
/* like print_r, but outputs PHP code */
function print_php($obj){
$bt = debug_backtrace();
$frame=array_shift($bt);
$lines = file($frame['file']);
$code = implode('', array_slice($lines, $frame['line'] - 1));
preg_match('/print_php\s*\(\s*(.*)\s*\)\s*;/i', $code, $matches);
$varname=$matches[1];
echo sprint_php($obj,0,$varname);
}
function sprint_php($obj,$depth=0,$varname=null){
$res="";
if($depth==0) $res.="$varname=";
if(is_string($obj)){
$res.="\"".addcslashes ($obj,"\"")."\"";
}else if(is_numeric($obj)){
$res.="$obj";
}else if(is_bool($obj)){
$res.=$obj?"true":"false";
}else if(is_array($obj)){
$res.="array(";
$is_first=true;
if(count($obj)>0){
foreach($obj as $k=>$v){
if($is_first) $is_first=false; else $res.=",";
$res.="\n";
$res.=padtab($depth+1)."\"".addcslashes ($k,"\"")."\" => " . sprint_php($v,$depth+1)."";
}
$res.="\n";
}
$res.=padtab($depth).")";
} else if(is_object($obj)){
$props=get_object_vars($obj);
$res.="new ".get_class($obj)."();";
if(count($props)>0){
foreach($props as $k=>$v){
$res.="\n";
$res.=padtab($depth+1)."$varname->{".addcslashes ($k,'{}')."} = " . sprint_php($v,$depth+1)."";
}
$res.="\n";
}
$res.=padtab($depth).")";
}else{
$res.="null";
}
if($depth==0) $res.=";";
return $res;
}
/* https://groups.google.com/d/msg/comp.lang.php/UFUAP0SubuQ/sgRLw7T_5icJ
function bobo_the_clown($b) {
$bt = debug_backtrace();
extract(array_pop($bt));
$lines = file($file);
$code = implode('', array_slice($lines, $line - 1));
preg_match('/\bbobo_the_clown\s*\(\s*(\S*?)\s*\)/i', $code, $matches);
return @$matches[1];
}
*/
function padtab($num){
return str_pad ("",$num,"\t");
}
// ???
function xunserialize($str){
$xd=explode("|",$str);
$r=array();
if(count($xd)>0){
foreach($xd as $x){
$w=explode("=",$x,2);
if(!isset($w[1])){
$r[]=$w[0];
}else{
$r[$w[0]]=$w[1];
}
}
}
return $r;
}
function bound($x, $min, $max){
return min(max($x, $min), $max);
}
function http_file_exists($url){
stream_context_set_default(array('http' => array('method' => 'HEAD')));
$headers = get_headers($url);
return (substr($headers[0], 9, 3)=="200");
}
/* SERVER RANKING ALGOS */
/* RF Score
* Server popularity based on number of records from current week
* "RF" has no meaning, it's just a bunch of random letters.
* But if you want, you can call it "Run Forrest"
* Below are tons of different variations, pick one you like the most
*/
/*function rf($a) {
global $cd,$proccd;
//return log(1+$a['pwuplayers']*(pow($a['records']-$a['pwrecords'],2)))/($a['pwrecords']/200+1500)*0.003;
return log(1+$a['pwuplayers']*(pow($a['records']-$a['pwrecords'],2))/250)*0.0003;
//return log(1+($a['records']-$a['pwrecords'])/($a['pwuplayers']+700))*0.0018;
}*/
function rfVersionSome($a) {
global $cd,$proccd;
//return log(1+$a['pwuplayers']*(pow($a['records']-$a['pwrecords'],2)))/($a['pwrecords']/200+1500)*0.003;
return log(1+$a['pwuplayers']*(pow($a['records'],2))/250)*0.0003;
//return log(1+($a['records']-$a['pwrecords'])/($a['pwuplayers']+700))*0.0018;
}
/* Displays equation of RF for the server;
* use when debugging
*/
function rfloud($a) {
global $cd,$proccd;
return "";
//return "\$RF=log(1+(pow({$a['records']}-{$a['pwrecords']},2)))/({$a['pwrecords']}/200+1500)*130";
}
/* old version of RF, used to calculate CSR */
function oldrf($a) {global $cd;return round($a['uplayers']*(($a['records']-$a['pwrecords'])/($a['pwrecords']+2000))*10);}
// Calculates average value of RF.
function rf_avg(&$a){
if(!is_array($a)){
return false;
}else{
$avg=0;
foreach($a as &$s){
$rf=rf($s);
$avg+=$rf;
$s['rf']=$rf;
}
return $avg/count($a);
}
}
/* DEPRECATED AS OF REV52 */
/* SQ Score
* How much players like the server
* Based on the average number of hour spent by players
* formula:
* SQ = A / (P + 1) * ln(P+1.1) * 10
* Just like in RF, let's call it the "Stoned Queen" score.
*/
function sq($a) {global $has; return round(($a['records'])/($a['uplayers']+1)*log($a['uplayers']+1.1)*10);}
/* DEPRECATED AS OF REV14 */
/* CSR Factor
* Used to detect servers messing with their players list.
* score above 5 might suggest that server is cheating.
* formula: (OLD_RF / (P + 1) - 2)^2 - 8
* "Cheating Seems Retarded"
*/
function csr($a) {return round(pow(oldrf($a)/($a['uplayers']+1)-2,2)-8);}
//function oldrf($a) {return ($a['a']-$a['pd'])/($a['pd']+500);}
if(!function_exists("striposa")){
function striposa($haystack, &$needles, $offset=0) { //http://www.php.net/manual/en/function.strpos.php#107351
$chr = array();
foreach($needles as $needle) {
$res = stripos($haystack, $needle, $offset);
//echo "CMP: $haystack || $needle :: $res<br>\n";
if ($res !== false) $chr[$needle] = $res;
}
if(empty($chr)) return false;
return min($chr);
}
}
/* generate data url from gd image */
function image2url($h){
ob_start();
imagepng($h);
$imgd=base64_encode(ob_get_clean ());
//if(isset($_GET['verbose'])) echo "Rendering DC[$name]:<br>";
return "data:image/png;base64,$imgd";
}
/* something to do with graphs drawing */
function uttimagetxt($im,$size,$rot,$x,$y,$c,$t,$shadow=true,$defaultengine=false){
global $shadowcolor,$font;
if($size==1) {
//$font="PixelEx.ttf";
$fsize=5;
}else if($size==2){
//$font="PixelEx.ttf";
$fsize=10;
}else {
$fsize=$size*5;
}
if($shadow) imagettftext($im,$fsize,$rot,$x+$size,$y+$size,0x60000000 | $shadowcolor,"$font",$t);
if($defaultengine)
imagettftext($im,$fsize,$rot,$x,$y,$c,"$font",$t);
else
imagettftextlcd($im,$fsize,$rot,$x,$y,$c,"$font",$t);
}
function cssColToPHP($col){
//FirePHP::getInstance(true)->log($col, "cssColToPHP");
$xv=explode(" ",$col);
if(count($xv)>1){
foreach($xv as $x){
//FirePHP::getInstance(true)->log($x, "foreach");
if($x[0]=="#") {
$col=$x;
break;
}
}
}
$ncol=0;
if($col[0]!="#") {
switch(strtolower($col)){
case "white": return 0xFFFFFF;
case "silver": return 0xC0C0C0;
case "gray": return 0x808080;
case "black": return 0x000000;
case "red": return 0xFF0000;
case "maroon": return 0x800000;
case "yellow": return 0xFFFF00;
case "olive": return 0x808000;
case "lime": return 0x00FF80;
case "green": return 0x008000;
case "aqua": return 0x00FFFF;
case "teal": return 0x008080;
case "blue": return 0x0000FF;
case "navy": return 0x000080;
case "fuchsia": return 0xFF00FF;
case "purple": return 0x800080;
default: return 0;
}
}
if(strlen($col)==7){
list($ncol)=sscanf($col, "#%6x");
}else if(strlen($col)==4){
list($r,$g,$b)=sscanf($col, "#%1x%1x%1x");
$ncol=hexdec("$r$r$g$g$b$b");
}
//FirePHP::getInstance(true)->log($ncol, "COL FROM $col");
return $ncol;
}
/* http://www.codingourweb.com/parsing-css-files-and-strings-using-php/ */
/* Based on a class by Michael Ettl(michael@ettl.com) */
class CSS {
protected $css;
protected $cssprops;
protected $cssstr;
protected $firephp;
/**
* Constructor function for PHP5
*
*/
public function __construct() {
$this->css = array();
$this->cssprops = array();
$this->cssstr = "";
//$this->firephp = FirePHP::getInstance(true);
}
/**
* Parses an entire CSS file
*
* @param mixed $filename CSS File to parse
*/
public function parse_file($file_name)
{
//$fh = fopen($file_name, "r") or die("Error opening file $file_name");
//$css_str = fread($fh, filesize($file_name));
//fclose($fh);
$css_str=file_get_contents($file_name);
return($this->parse_css($css_str));
}
/**
* Parses a CSS string
*
* @param string $css_str CSS to parse
*/
public function parse_css($css_str)
{
$this->cssstr = $css_str;
$this->css = "";
$this->cssprops = "";
//$this->firephp->log($css_str,"CSSFILE");
// Strip all line endings and both single and multiline comments
$css_str = preg_replace("/\/\*[^\*\/]*\*\//", "", $css_str);
$css_class = explode("}", $css_str);
//$this->firephp->log($css_class,"CSS CLASS");
//$this->firephp->log($css_str,"CSS STR");
while(list($key, $val) = each($css_class)){
//$this->firephp->log("K:".$key,"V:".$val);
$aCSSObj = explode("{", $val);
$cSel = strtolower(trim($aCSSObj[0]));
if($cSel){
$this->cssprops[] = $cSel;
$a = explode(";", $aCSSObj[1]);
while(list($key, $val0) = each($a)){
if(trim($val0)){
$aCSSSub = explode(":", $val0);
$cAtt = strtolower(trim($aCSSSub[0]));
if(isset($aCSSSub[1])){
$aCSSItem[$cAtt] = trim($aCSSSub[1]);
}
}
}
if((isset($this->css[$cSel])) && ($this->css[$cSel])){
$aCSSItem = array_merge($this->css[$cSel], $aCSSItem);
}
$this->css[$cSel] = $aCSSItem;
unset($aCSSItem);
}
if(strstr($cSel, ",")){
$aTags = explode(",", $cSel);
foreach($aTags as $key0 => $value0){
$this->css[$value0] = $this->css[$cSel];
}
unset($this->css[$cSel]);
}
}
unset($css_str, $css_class, $aCSSSub, $aCSSItem, $aCSSObj);
return $this->css;
}
/**
* Builds a CSS string out of an existing object
*
* @param boolean $sorted Sort the attributes alphabetically
* @return string Resulting CSS string
*/
public function build_css($sorted = false)
{
$this->cssstr = "";
foreach($this->css as $key0 => $value0) {
$trimmed = trim($key0);
$this->cssstr .= "$trimmed {n";
if($sorted) ksort($this->css[$key0], SORT_STRING);
foreach($this->css[$key0] as $key1 => $value1) {
$this->cssstr .= "t$key1: $value1;n";
}
$this->cssstr .= "}n";
}
return ($this->cssstr);
}
/**
* Writes an existing CSS string to file
*
* @param string $file_name File to save to
* @param boolean $sorted Sort the attributes alphabetically
*/
public function write_file($file_name, $sorted = false)
{
if($this->css == "") die("There is no CSS to write!");
if($this->cssstr == "") $this->build_css($sorted);
$fh = fopen($file_name, "w") or die("Error opening file $file_name");
fwrite($fh, $this->cssstr);
fclose($fh);
}
/**
* Returns the entire CSS object
*
* @return object or false
*/
public function get_css()
{
if (isset($this->css)) return ($this->css);
return false;
}
/**
* Returns all CSS properties
*
* @return array
*/
public function get_properties()
{
if (isset($this->cssprops)) return ($this->cssprops);
return array();
}
/**
* Returns a specified CSS property and all its attributes
*
* @param string $property
* @return array
*/
public function get_property($prop)
{
if (isset($this->css[$prop])) return ($this->css[$prop]);
return array();
}
/**
* Gets attribute value of a specified CSS property
*
* @param string $prop CSS property
* @param string $attr CSS attribute
* @return string
*/
public function get_value($prop, $attr)
{
if (isset($this->css[$prop][$attr])) return ($this->css[$prop][$attr]);
return "";
}
/**
* Sets attribute value of a specified CSS property
*
* @param string $prop CSS property
* @param string $attr CSS attribute
* @param string $value CSS attribute value
* @return boolean Returns true when succeeded
*/
public function set_value($prop, $attr, $value)
{