-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaseco.php
More file actions
2573 lines (2195 loc) · 88 KB
/
aseco.php
File metadata and controls
2573 lines (2195 loc) · 88 KB
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
/* vim: set noexpandtab tabstop=2 softtabstop=2 shiftwidth=2: */
/**
* Projectname: XASECO (formerly ASECO/RASP)
*
* Requires: PHP version 5, MySQL version 4/5
*
* LICENSE: This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
*
* Authored & copyright 2006 by Florian Schnell <floschnell@gmail.com>
*
* Re-authored & copyright May 2007 - Jul 2013 by Xymph <tm@gamers.org>
*
* Visit the official site at http://www.xaseco.org/
*/
/**
* Include required classes
*/
require_once('includes/types.inc.php'); // contains classes to store information
require_once('includes/basic.inc.php'); // contains standard functions
require_once('includes/GbxRemote.inc.php'); // needed for dedicated server connections
require_once('includes/xmlparser.inc.php'); // provides an XML parser
require_once('includes/gbxdatafetcher.inc.php'); // provides access to GBX data
require_once('includes/tmndatafetcher.inc.php'); // provides access to TMN world stats
require_once('includes/rasp.settings.php'); // specific to the RASP plugins
/**
* Runtime configuration definitions
*/
// add abbreviations for some chat commands?
// /admin -> /ad, /jukebox -> /jb, /autojuke -> /aj
define('ABBREV_COMMANDS', false);
// disable local & Dedi record relations commands from help lists?
define('INHIBIT_RECCMDS', false);
// separate logs by month in logs/ dir?
define('MONTHLY_LOGSDIR', false);
// keep UTF-8 encoding in config.xml?
define('CONFIG_UTF8ENCODE', false);
/**
* System definitions - no changes below this point
*/
// current project version
define('XASECO_VERSION', '1.16');
define('XASECO_TMN', 'http://www.gamers.org/tmn/');
define('XASECO_TMF', 'http://www.gamers.org/tmf/');
define('XASECO_TM2', 'http://www.gamers.org/tm2/');
define('XASECO_ORG', 'http://www.xaseco.org/');
// required official dedicated server builds
define('TMN_BUILD', '2006-05-30');
define('TMF_BUILD', '2011-02-21');
// check current operating system
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// on Win32/NT use:
define('CRLF', "\r\n");
} else {
// on Unix use:
define('CRLF', "\n");
}
if (!defined('LF')) {
define('LF', "\n");
}
/**
* Error function
* Report errors in a regular way.
*/
set_error_handler('displayError');
function displayError($errno, $errstr, $errfile, $errline) {
global $aseco;
// check for error suppression
if(error_reporting() === (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE)) {
return;
}
switch ($errno) {
case E_USER_ERROR:
$message = "[XASECO Fatal Error] $errstr on line $errline in file $errfile" . CRLF;
echo $message;
doLog($message);
// throw 'shutting down' event
$aseco->releaseEvent('onShutdown', null);
// clear all ManiaLinks
$aseco->client->query('SendHideManialinkPage');
if (function_exists('xdebug_get_function_stack')) {
$fnc = "xdebug_get_function_stack";
doLog(print_r($fnc()), true);
}
die();
break;
case E_USER_WARNING:
$message = "[XASECO Warning] $errstr" . CRLF;
echo $message;
doLog($message);
break;
case E_ERROR:
$message = "[PHP Error] $errstr on line $errline in file $errfile" . CRLF;
echo $message;
doLog($message);
break;
case E_WARNING:
$message = "[PHP Warning] $errstr on line $errline in file $errfile" . CRLF;
echo $message;
doLog($message);
break;
default:
if (strpos($errstr, 'Function call_user_method') !== false) break;
//$message = "[PHP $errno] $errstr on line $errline in file $errfile" . CRLF;
//echo $message;
//doLog($message);
// do nothing, only treat known errors
}
} // displayError
/**
* Here XASECO actually starts.
*/
class Aseco {
/**
* Public fields
*/
var $client;
var $xml_parser;
var $script_timeout;
var $debug;
var $server;
var $command;
var $events;
var $rpc_calls;
var $rpc_responses;
var $chat_commands;
var $chat_colors;
var $chat_messages;
var $plugins;
var $settings;
var $style;
var $panels;
var $statspanel;
var $titles;
var $masteradmin_list;
var $admin_list;
var $adm_abilities;
var $operator_list;
var $op_abilities;
var $bannedips;
var $startup_phase; // XAseco start-up phase
var $warmup_phase; // warm-up phase
var $restarting; // restarting challenge (0 = not, 1 = instant, 2 = chattime)
var $changingmode; // changing game mode
var $currstatus; // server status changes
var $prevstatus;
var $currsecond; // server time changes
var $prevsecond;
var $uptime; // XAseco start-up time
/**
* Initializes the server.
*/
function __construct($debug) {
global $maxrecs; // from rasp.settings.php
echo '# initialize XASECO ###########################################################' . CRLF;
// log php & mysql version info
$this->console_text('[XAseco] PHP Version is ' . phpversion() . ' on ' . PHP_OS);
// initialize
$this->uptime = time();
$this->chat_commands = array();
$this->debug = $debug;
$this->client = new IXR_ClientMulticall_Gbx();
$this->xml_parser = new Examsly();
$this->server = new Server('127.0.0.1', 5000, 'SuperAdmin', 'SuperAdmin');
$this->server->challenge = new Challenge();
$this->server->players = new PlayerList();
$this->server->records = new RecordList($maxrecs);
$this->server->mutelist = array();
$this->plugins = array();
$this->titles = array();
$this->masteradmin_list = array();
$this->admin_list = array();
$this->adm_abilities = array();
$this->operator_list = array();
$this->op_abilities = array();
$this->bannedips = array();
$this->startup_phase = true;
$this->warmup_phase = false;
$this->restarting = 0;
$this->changingmode = false;
$this->currstatus = 0;
} // Aseco
/**
* Load settings and apply them on the current instance.
*/
function loadSettings($config_file) {
if ($settings = $this->xml_parser->parseXml($config_file, true, CONFIG_UTF8ENCODE)) {
// read the XML structure into an array
$aseco = $settings['SETTINGS']['ASECO'][0];
// read settings and apply them
$this->chat_colors = $aseco['COLORS'][0];
$this->chat_messages = $aseco['MESSAGES'][0];
$this->masteradmin_list = $aseco['MASTERADMINS'][0];
if (!isset($this->masteradmin_list) || !is_array($this->masteradmin_list))
trigger_error('No MasterAdmin(s) configured in config.xml!', E_USER_ERROR);
// check masteradmin list consistency
if (empty($this->masteradmin_list['IPADDRESS'])) {
// fill <ipaddress> list to same length as <tmlogin> list
if (($cnt = count($this->masteradmin_list['TMLOGIN'])) > 0)
$this->masteradmin_list['IPADDRESS'] = array_fill(0, $cnt, '');
} else {
if (count($this->masteradmin_list['TMLOGIN']) != count($this->masteradmin_list['IPADDRESS']))
trigger_error("MasterAdmin mismatch between <tmlogin>'s and <ipaddress>'s!", E_USER_WARNING);
}
// set admin lock password
$this->settings['lock_password'] = $aseco['LOCK_PASSWORD'][0];
// set cheater action
$this->settings['cheater_action'] = $aseco['CHEATER_ACTION'][0];
// set script timeout
$this->settings['script_timeout'] = $aseco['SCRIPT_TIMEOUT'][0];
// set minimum number of records to be displayed
$this->settings['show_min_recs'] = $aseco['SHOW_MIN_RECS'][0];
// show records before start of track?
$this->settings['show_recs_before'] = $aseco['SHOW_RECS_BEFORE'][0];
// show records after end of track?
$this->settings['show_recs_after'] = $aseco['SHOW_RECS_AFTER'][0];
// show TMX world record?
$this->settings['show_tmxrec'] = $aseco['SHOW_TMXREC'][0];
// show played time at end of track?
$this->settings['show_playtime'] = $aseco['SHOW_PLAYTIME'][0];
// show current track at start of track?
$this->settings['show_curtrack'] = $aseco['SHOW_CURTRACK'][0];
// set default filename for readtracklist/writetracklist
$this->settings['default_tracklist'] = $aseco['DEFAULT_TRACKLIST'][0];
// set minimum number of ranked players in a clan to be included in /topclans
$this->settings['topclans_minplayers'] = $aseco['TOPCLANS_MINPLAYERS'][0];
// set multiple of win count to show global congrats message
$this->settings['global_win_multiple'] = ($aseco['GLOBAL_WIN_MULTIPLE'][0] > 0 ? $aseco['GLOBAL_WIN_MULTIPLE'][0] : 1);
// timeout of the TMF message window in seconds
$this->settings['window_timeout'] = $aseco['WINDOW_TIMEOUT'][0];
// set filename of admin/operator/ability lists file
$this->settings['adminops_file'] = $aseco['ADMINOPS_FILE'][0];
// set filename of banned IPs list file
$this->settings['bannedips_file'] = $aseco['BANNEDIPS_FILE'][0];
// set filename of blacklist file
$this->settings['blacklist_file'] = $aseco['BLACKLIST_FILE'][0];
// set filename of guestlist file
$this->settings['guestlist_file'] = $aseco['GUESTLIST_FILE'][0];
// set filename of track history file
$this->settings['trackhist_file'] = $aseco['TRACKHIST_FILE'][0];
// set minimum admin client version
$this->settings['admin_client'] = $aseco['ADMIN_CLIENT_VERSION'][0];
// set minimum player client version
$this->settings['player_client'] = $aseco['PLAYER_CLIENT_VERSION'][0];
// set default rounds points system
$this->settings['default_rpoints'] = $aseco['DEFAULT_RPOINTS'][0];
// set windows style (none = old TMN style)
$this->settings['window_style'] = $aseco['WINDOW_STYLE'][0];
// set admin panel (none = no panel)
$this->settings['admin_panel'] = $aseco['ADMIN_PANEL'][0];
// set donate panel (none = no panel)
$this->settings['donate_panel'] = $aseco['DONATE_PANEL'][0];
// set records panel (none = no panel)
$this->settings['records_panel'] = $aseco['RECORDS_PANEL'][0];
// set vote panel (none = no panel)
$this->settings['vote_panel'] = $aseco['VOTE_PANEL'][0];
// display welcome message as window ?
if (strtoupper($aseco['WELCOME_MSG_WINDOW'][0]) == 'TRUE') {
$this->settings['welcome_msg_window'] = true;
} else {
$this->settings['welcome_msg_window'] = false;
}
// log all chat, not just chat commands ?
if (strtoupper($aseco['LOG_ALL_CHAT'][0]) == 'TRUE') {
$this->settings['log_all_chat'] = true;
} else {
$this->settings['log_all_chat'] = false;
}
// show timestamps in /chatlog, /pmlog & /admin pmlog ?
if (strtoupper($aseco['CHATPMLOG_TIMES'][0]) == 'TRUE') {
$this->settings['chatpmlog_times'] = true;
} else {
$this->settings['chatpmlog_times'] = false;
}
// show records range?
if (strtoupper($aseco['SHOW_RECS_RANGE'][0]) == 'TRUE') {
$this->settings['show_recs_range'] = true;
} else {
$this->settings['show_recs_range'] = false;
}
// show records in message window?
if (strtoupper($aseco['RECS_IN_WINDOW'][0]) == 'TRUE') {
$this->settings['recs_in_window'] = true;
} else {
$this->settings['recs_in_window'] = false;
}
// show round reports in message window?
if (strtoupper($aseco['ROUNDS_IN_WINDOW'][0]) == 'TRUE') {
$this->settings['rounds_in_window'] = true;
} else {
$this->settings['rounds_in_window'] = false;
}
// add random filter to /admin writetracklist output
if (strtoupper($aseco['WRITETRACKLIST_RANDOM'][0]) == 'TRUE') {
$this->settings['writetracklist_random'] = true;
} else {
$this->settings['writetracklist_random'] = false;
}
// add explanation to /help output
if (strtoupper($aseco['HELP_EXPLANATION'][0]) == 'TRUE') {
$this->settings['help_explanation'] = true;
} else {
$this->settings['help_explanation'] = false;
}
// color nicknames in the various /top... etc lists?
if (strtoupper($aseco['LISTS_COLORNICKS'][0]) == 'TRUE') {
$this->settings['lists_colornicks'] = true;
} else {
$this->settings['lists_colornicks'] = false;
}
// color tracknames in the various /lists... lists?
if (strtoupper($aseco['LISTS_COLORTRACKS'][0]) == 'TRUE') {
$this->settings['lists_colortracks'] = true;
} else {
$this->settings['lists_colortracks'] = false;
}
// display checkpoints panel (TMF) or pop-up (TMN)?
if (strtoupper($aseco['DISPLAY_CHECKPOINTS'][0]) == 'TRUE') {
$this->settings['display_checkpoints'] = true;
} else {
$this->settings['display_checkpoints'] = false;
}
// enable /cpsspec command (TMF-only)?
if (strtoupper($aseco['ENABLE_CPSSPEC'][0]) == 'TRUE') {
$this->settings['enable_cpsspec'] = true;
} else {
$this->settings['enable_cpsspec'] = false;
}
// automatically enable /cps for new players?
if (strtoupper($aseco['AUTO_ENABLE_CPS'][0]) == 'TRUE') {
$this->settings['auto_enable_cps'] = true;
} else {
$this->settings['auto_enable_cps'] = false;
}
// automatically enable /dedicps for new players?
if (strtoupper($aseco['AUTO_ENABLE_DEDICPS'][0]) == 'TRUE') {
$this->settings['auto_enable_dedicps'] = true;
} else {
$this->settings['auto_enable_dedicps'] = false;
}
// automatically add IP for new admins/operators?
if (strtoupper($aseco['AUTO_ADMIN_ADDIP'][0]) == 'TRUE') {
$this->settings['auto_admin_addip'] = true;
} else {
$this->settings['auto_admin_addip'] = false;
}
// automatically force spectator on player using /afk ?
if (strtoupper($aseco['AFK_FORCE_SPEC'][0]) == 'TRUE') {
$this->settings['afk_force_spec'] = true;
} else {
$this->settings['afk_force_spec'] = false;
}
// provide clickable buttons in TMF lists?
if (strtoupper($aseco['CLICKABLE_LISTS'][0]) == 'TRUE') {
$this->settings['clickable_lists'] = true;
} else {
$this->settings['clickable_lists'] = false;
}
// show logins in /recs on TMF?
if (strtoupper($aseco['SHOW_REC_LOGINS'][0]) == 'TRUE') {
$this->settings['show_rec_logins'] = true;
} else {
$this->settings['show_rec_logins'] = false;
}
// display individual stats panels at TMF scoreboard?
if (strtoupper($aseco['SB_STATS_PANELS'][0]) == 'TRUE') {
$this->settings['sb_stats_panels'] = true;
} else {
$this->settings['sb_stats_panels'] = false;
}
// read the XML structure into an array
$tmserver = $settings['SETTINGS']['TMSERVER'][0];
// read settings and apply them
$this->server->login = $tmserver['LOGIN'][0];
$this->server->pass = $tmserver['PASSWORD'][0];
$this->server->port = $tmserver['PORT'][0];
$this->server->ip = $tmserver['IP'][0];
if (isset($tmserver['TIMEOUT'][0])) {
$this->server->timeout = (int)$tmserver['TIMEOUT'][0];
} else {
$this->server->timeout = null;
trigger_error('Server init timeout not specified in config.xml !', E_USER_WARNING);
}
$this->style = array();
$this->panels = array();
$this->panels['admin'] = '';
$this->panels['donate'] = '';
$this->panels['records'] = '';
$this->panels['vote'] = '';
if ($this->settings['admin_client'] != '' &&
preg_match('/^2\.11\.[12][0-9]$/', $this->settings['admin_client']) != 1 ||
$this->settings['admin_client'] == '2.11.10')
trigger_error('Invalid admin client version : ' . $this->settings['admin_client'] . ' !', E_USER_ERROR);
if ($this->settings['player_client'] != '' &&
preg_match('/^2\.11\.[12][0-9]$/', $this->settings['player_client']) != 1 ||
$this->settings['player_client'] == '2.11.10')
trigger_error('Invalid player client version: ' . $this->settings['player_client'] . ' !', E_USER_ERROR);
} else {
// could not parse XML file
trigger_error('Could not read/parse config file ' . $config_file . ' !', E_USER_ERROR);
}
} // loadSettings
/**
* Read Admin/Operator/Ability lists and apply them on the current instance.
*/
function readLists() {
// get lists file name
$adminops_file = $this->settings['adminops_file'];
if ($lists = $this->xml_parser->parseXml($adminops_file, true, true)) {
// read the XML structure into arrays
$this->titles = $lists['LISTS']['TITLES'][0];
if (is_array($lists['LISTS']['ADMINS'][0])) {
$this->admin_list = $lists['LISTS']['ADMINS'][0];
// check admin list consistency
if (empty($this->admin_list['IPADDRESS'])) {
// fill <ipaddress> list to same length as <tmlogin> list
if (($cnt = count($this->admin_list['TMLOGIN'])) > 0)
$this->admin_list['IPADDRESS'] = array_fill(0, $cnt, '');
} else {
if (count($this->admin_list['TMLOGIN']) != count($this->admin_list['IPADDRESS']))
trigger_error("Admin mismatch between <tmlogin>'s and <ipaddress>'s!", E_USER_WARNING);
}
}
if (is_array($lists['LISTS']['OPERATORS'][0])) {
$this->operator_list = $lists['LISTS']['OPERATORS'][0];
// check operator list consistency
if (empty($this->operator_list['IPADDRESS'])) {
// fill <ipaddress> list to same length as <tmlogin> list
if (($cnt = count($this->operator_list['TMLOGIN'])) > 0)
$this->operator_list['IPADDRESS'] = array_fill(0, $cnt, '');
} else {
if (count($this->operator_list['TMLOGIN']) != count($this->operator_list['IPADDRESS']))
trigger_error("Operators mismatch between <tmlogin>'s and <ipaddress>'s!", E_USER_WARNING);
}
}
$this->adm_abilities = $lists['LISTS']['ADMIN_ABILITIES'][0];
$this->op_abilities = $lists['LISTS']['OPERATOR_ABILITIES'][0];
// convert strings to booleans
foreach ($this->adm_abilities as $ability => $value) {
if (strtoupper($value[0]) == 'TRUE') {
$this->adm_abilities[$ability][0] = true;
} else {
$this->adm_abilities[$ability][0] = false;
}
}
foreach ($this->op_abilities as $ability => $value) {
if (strtoupper($value[0]) == 'TRUE') {
$this->op_abilities[$ability][0] = true;
} else {
$this->op_abilities[$ability][0] = false;
}
}
return true;
} else {
// could not parse XML file
trigger_error('Could not read/parse adminops file ' . $adminops_file . ' !', E_USER_WARNING);
return false;
}
} // readLists
/**
* Write Admin/Operator/Ability lists to save them for future runs.
*/
function writeLists() {
// get lists file name
$adminops_file = $this->settings['adminops_file'];
// compile lists file contents
$lists = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" . CRLF
. "<lists>" . CRLF
. "\t<titles>" . CRLF;
foreach ($this->titles as $title => $value) {
$lists .= "\t\t<" . strtolower($title) . ">" .
$value[0]
. "</" . strtolower($title) . ">" . CRLF;
}
$lists .= "\t</titles>" . CRLF
. CRLF
. "\t<admins>" . CRLF;
$empty = true;
if (isset($this->admin_list['TMLOGIN'])) {
for ($i = 0; $i < count($this->admin_list['TMLOGIN']); $i++) {
if ($this->admin_list['TMLOGIN'][$i] != '') {
$lists .= "\t\t<tmlogin>" . $this->admin_list['TMLOGIN'][$i] . "</tmlogin>"
. " <ipaddress>" . $this->admin_list['IPADDRESS'][$i] . "</ipaddress>" . CRLF;
$empty = false;
}
}
}
if ($empty) {
$lists .= "<!-- format:" . CRLF
. "\t\t<tmlogin>YOUR_ADMIN_LOGIN</tmlogin> <ipaddress></ipaddress>" . CRLF
. "-->" . CRLF;
}
$lists .= "\t</admins>" . CRLF
. CRLF
. "\t<operators>" . CRLF;
$empty = true;
if (isset($this->operator_list['TMLOGIN'])) {
for ($i = 0; $i < count($this->operator_list['TMLOGIN']); $i++) {
if ($this->operator_list['TMLOGIN'][$i] != '') {
$lists .= "\t\t<tmlogin>" . $this->operator_list['TMLOGIN'][$i] . "</tmlogin>"
. " <ipaddress>" . $this->operator_list['IPADDRESS'][$i] . "</ipaddress>" . CRLF;
$empty = false;
}
}
}
if ($empty) {
$lists .= "<!-- format:" . CRLF
. "\t\t<tmlogin>YOUR_OPERATOR_LOGIN</tmlogin> <ipaddress></ipaddress>" . CRLF
. "-->" . CRLF;
}
$lists .= "\t</operators>" . CRLF
. CRLF
. "\t<admin_abilities>" . CRLF;
foreach ($this->adm_abilities as $ability => $value) {
$lists .= "\t\t<" . strtolower($ability) . ">" .
($value[0] ? "true" : "false")
. "</" . strtolower($ability) . ">" . CRLF;
}
$lists .= "\t</admin_abilities>" . CRLF
. CRLF
. "\t<operator_abilities>" . CRLF;
foreach ($this->op_abilities as $ability => $value) {
$lists .= "\t\t<" . strtolower($ability) . ">" .
($value[0] ? "true" : "false")
. "</" . strtolower($ability) . ">" . CRLF;
}
$lists .= "\t</operator_abilities>" . CRLF
. "</lists>" . CRLF;
// write out the lists file
if (!@file_put_contents($adminops_file, $lists)) {
trigger_error('Could not write adminops file ' . $adminops_file . ' !', E_USER_WARNING);
return false;
} else {
return true;
}
} // writeLists
/**
* Read Banned IPs list and apply it on the current instance.
*/
function readIPs() {
// get banned IPs file name
$bannedips_file = $this->settings['bannedips_file'];
if ($list = $this->xml_parser->parseXml($bannedips_file)) {
// read the XML structure into variable
if (isset($list['BAN_LIST']['IPADDRESS']))
$this->bannedips = $list['BAN_LIST']['IPADDRESS'];
else
$this->bannedips = array();
return true;
} else {
// could not parse XML file
trigger_error('Could not read/parse banned IPs file ' . $bannedips_file . ' !', E_USER_WARNING);
return false;
}
} // readIPs
/**
* Write Banned IPs list to save it for future runs.
*/
function writeIPs() {
// get banned IPs file name
$bannedips_file = $this->settings['bannedips_file'];
$empty = true;
// compile banned IPs file contents
$list = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" . CRLF
. "<ban_list>" . CRLF;
for ($i = 0; $i < count($this->bannedips); $i++) {
if ($this->bannedips[$i] != '') {
$list .= "\t\t<ipaddress>" . $this->bannedips[$i] . "</ipaddress>" . CRLF;
$empty = false;
}
}
if ($empty) {
$list .= "<!-- format:" . CRLF
. "\t\t<ipaddress>xx.xx.xx.xx</ipaddress>" . CRLF
. "-->" . CRLF;
}
$list .= "</ban_list>" . CRLF;
// write out the list file
if (!@file_put_contents($bannedips_file, $list)) {
trigger_error('Could not write banned IPs file ' . $bannedips_file . ' !', E_USER_WARNING);
return false;
} else {
return true;
}
} // writeIPs
/**
* Loads files in the plugins directory.
*/
function loadPlugins() {
// load and parse the plugins file
if ($plugins = $this->xml_parser->parseXml('plugins.xml')) {
if (!empty($plugins['ASECO_PLUGINS']['PLUGIN'])) {
// take each plugin tag
foreach ($plugins['ASECO_PLUGINS']['PLUGIN'] as $plugin) {
// log plugin message
$this->console_text('[XAseco] Load plugin [' . $plugin . ']');
// include the plugin
require_once('plugins/' . $plugin);
$this->plugins[] = $plugin;
}
}
} else {
trigger_error('Could not read/parse plugins list plugins.xml !', E_USER_ERROR);
}
} // loadPlugins
/**
* Runs the server.
*/
function run($config_file) {
// load new settings, if available
$this->console_text('[XAseco] Load settings [{1}]', $config_file);
$this->loadSettings($config_file);
// load admin/operator/ability lists, if available
$this->console_text('[XAseco] Load admin/ops lists [{1}]', $this->settings['adminops_file']);
$this->readLists();
// load banned IPs list, if available
$this->console_text('[XAseco] Load banned IPs list [{1}]', $this->settings['bannedips_file']);
$this->readIPs();
// load plugins and register chat commands
$this->console_text('[XAseco] Load plugins list [plugins.xml]');
$this->loadPlugins();
// connect to Trackmania Dedicated Server
if (!$this->connect()) {
// kill program with an error
trigger_error('Connection could not be established !', E_USER_ERROR);
}
// log status message
$this->console('Connection established successfully !');
// log admin lock message
if ($this->settings['lock_password'] != '')
$this->console_text("[XAseco] Locked admin commands & features with password '{1}'", $this->settings['lock_password']);
// get basic server info
$this->client->query('GetVersion');
$response['version'] = $this->client->getResponse();
$this->server->game = $response['version']['Name'];
$this->server->version = $response['version']['Version'];
$this->server->build = $response['version']['Build'];
register_manialink_events($this);
// throw 'starting up' event
$this->releaseEvent('onStartup', null);
// synchronize information with server
$this->serverSync();
// register all chat commands
if ($this->server->getGame() != 'TMF') {
$this->registerChatCommands();
// set spectator not available outside TMF
if ($this->settings['cheater_action'] == 1)
$this->settings['cheater_action'] = 0;
}
// make a visual header
$this->sendHeader();
// get current game infos if server loaded a track yet
if ($this->currstatus == 100) {
$this->console_text('[XAseco] Waiting for the server to start a challenge');
} else {
$this->beginRace(false);
}
// main loop
$this->startup_phase = false;
while (true) {
$starttime = microtime(true);
// get callbacks from the server
$this->executeCallbacks();
// sends calls to the server
$this->executeCalls();
// throw timing events
$this->releaseEvent('onMainLoop', null);
$this->currsecond = time();
if ($this->prevsecond != $this->currsecond) {
$this->prevsecond = $this->currsecond;
$this->releaseEvent('onEverySecond', null);
}
// reduce CPU usage if main loop has time left
$endtime = microtime(true);
$delay = 200000 - ($endtime - $starttime) * 1000000;
if ($delay > 0)
usleep($delay);
// make sure the script does not timeout
@set_time_limit($this->settings['script_timeout']);
}
// close the client connection
$this->client->Terminate();
} // run
/**
* Authenticates XASECO at the server.
*/
function connect() {
// only if logins are set
if ($this->server->ip && $this->server->port && $this->server->login && $this->server->pass) {
// log console message
$this->console('Try to connect to TM dedicated server on {1}:{2} timeout {3}s',
$this->server->ip, $this->server->port,
($this->server->timeout !== null ? $this->server->timeout : 0));
// connect to the server
if (!$this->client->InitWithIp($this->server->ip, $this->server->port, $this->server->timeout)) {
trigger_error('[' . $this->client->getErrorCode() . '] InitWithIp - ' . $this->client->getErrorMessage(), E_USER_WARNING);
return false;
}
// log console message
$this->console("Try to authenticate with login '{1}' and password '{2}'",
$this->server->login, $this->server->pass);
// check login
if ($this->server->login != 'SuperAdmin') {
trigger_error("Invalid login '" . $this->server->login . "' - must be 'SuperAdmin' in config.xml !", E_USER_WARNING);
return false;
}
// check password
if ($this->server->pass == 'SuperAdmin') {
trigger_error("Insecure password '" . $this->server->pass . "' - should be changed in dedicated config and config.xml !", E_USER_WARNING);
}
// log into the server
if (!$this->client->query('Authenticate', $this->server->login, $this->server->pass)) {
trigger_error('[' . $this->client->getErrorCode() . '] Authenticate - ' . $this->client->getErrorMessage(), E_USER_WARNING);
return false;
}
// enable callback system
$this->client->query('EnableCallbacks', true);
// wait for server to be ready
$this->waitServerReady();
// connection established
return true;
} else {
// connection failed
return false;
}
} // connect
/**
* Waits for the server to be ready (status 4, 'Running - Play')
*/
function waitServerReady() {
$this->client->query('GetStatus');
$status = $this->client->getResponse();
if ($status['Code'] != 4) {
$this->console("Waiting for dedicated server to reach status 'Running - Play'...");
$this->console('Status: ' . $status['Name']);
$timeout = 0;
$laststatus = $status['Name'];
while ($status['Code'] != 4) {
sleep(1);
$this->client->query('GetStatus');
$status = $this->client->getResponse();
if ($laststatus != $status['Name']) {
$this->console('Status: ' . $status['Name']);
$laststatus = $status['Name'];
}
if (isset($this->server->timeout) && $timeout++ > $this->server->timeout)
trigger_error('Timed out while waiting for dedicated server!', E_USER_ERROR);
}
}
} // waitServerReady
/**
* Initializes the server and the player list.
* Reads a list of the players who are on the server already,
* and loads all server variables.
*/
function serverSync() {
// check server build
if (strlen($this->server->build) == 0 ||
($this->server->getGame() != 'TMF' && strcmp($this->server->build, TMN_BUILD) < 0) ||
($this->server->getGame() == 'TMF' && strcmp($this->server->build, TMF_BUILD) < 0)) {
trigger_error("Obsolete server build '" . $this->server->build . "' - must be " .
($this->server->getGame() == 'TMF' ? "at least '" . TMF_BUILD . "' !" : "'" . TMN_BUILD . "' !"), E_USER_ERROR);
}
// get server id, login, nickname, zone & packmask
$this->server->id = 0; // on TMN/TMO/TMS
$this->server->rights = false;
$this->server->isrelay = false;
$this->server->relaymaster = null;
$this->server->relayslist = array();
$this->server->gamestate = Server::RACE;
$this->server->packmask = '';
if ($this->server->getGame() == 'TMF') {
$this->client->query('GetSystemInfo');
$response['system'] = $this->client->getResponse();
$this->server->serverlogin = $response['system']['ServerLogin'];
$this->client->query('GetDetailedPlayerInfo', $this->server->serverlogin);
$response['info'] = $this->client->getResponse();
$this->server->id = $response['info']['PlayerId'];
$this->server->nickname = $response['info']['NickName'];
$this->server->zone = substr($response['info']['Path'], 6); // strip 'World|'
$this->server->rights = ($response['info']['OnlineRights'] == 3); // United = true
$this->client->query('GetLadderServerLimits');
$response['ladder'] = $this->client->getResponse();
$this->server->laddermin = $response['ladder']['LadderServerLimitMin'];
$this->server->laddermax = $response['ladder']['LadderServerLimitMax'];
$this->client->query('IsRelayServer');
$this->server->isrelay = ($this->client->getResponse() > 0);
if ($this->server->isrelay) {
$this->client->query('GetMainServerPlayerInfo', 1);
$this->server->relaymaster = $this->client->getResponse();
}
// TMNF packmask = 'Stadium' for 'nations' or 'stadium'
$this->client->query('GetServerPackMask');
$this->server->packmask = $this->client->getResponse();
// clear possible leftover ManiaLinks
$this->client->query('SendHideManialinkPage');
}
// get mode & limits
$this->client->query('GetCurrentGameInfo', ($this->server->getGame() == 'TMF' ? 1 : 0));
$response['gameinfo'] = $this->client->getResponse();
$this->server->gameinfo = new Gameinfo($response['gameinfo']);
// get status
$this->client->query('GetStatus');
$response['status'] = $this->client->getResponse();
$this->currstatus = $response['status']['Code'];
// get game & trackdir
$this->client->query('GameDataDirectory');
$this->server->gamedir = $this->client->getResponse();
$this->client->query('GetTracksDirectory');
$this->server->trackdir = $this->client->getResponse();
// get server name & options
$this->getServerOptions();
// throw 'synchronisation' event
$this->releaseEvent('onSync', null);
// get current players/servers on the server (hardlimited to 300)
if ($this->server->getGame() == 'TMF')
$this->client->query('GetPlayerList', 300, 0, 2);
else
$this->client->query('GetPlayerList', 300, 0);
$response['playerlist'] = $this->client->getResponse();
// update players/relays lists
if (!empty($response['playerlist'])) {
foreach ($response['playerlist'] as $player) {
// fake it into thinking it's a connecting player:
// it gets team & ladder info this way & will also throw an
// onPlayerConnect event for players (not relays) to all plugins
$this->playerConnect(array($player['Login'], ''));
}
}
} // serverSync
/**
* Sends program header to console and ingame chat.
*/
function sendHeader() {
$this->console_text('###############################################################################');
$this->console_text(' XASECO v' . XASECO_VERSION . ' running on {1}:{2}', $this->server->ip, $this->server->port);
if ($this->server->getGame() == 'TMF') {
$this->console_text(' Name : {1} - {2}', stripColors($this->server->name, false), $this->server->serverlogin);
if ($this->server->isrelay)
$this->console_text(' Relays : {1} - {2}', stripColors($this->server->relaymaster['NickName'], false), $this->server->relaymaster['Login']);
$this->console_text(' Game : {1} {2} - {3} - {4}', $this->server->game,
($this->server->rights ? 'United' : 'Nations'),
$this->server->packmask, $this->server->gameinfo->getMode());
} else {
$this->console_text(' Name : {1}', stripColors($this->server->name, false));
$this->console_text(' Game : {1} - {2}', $this->server->game, $this->server->gameinfo->getMode());
}
$this->console_text(' Version: {1} / {2}', $this->server->version, $this->server->build);
$this->console_text(' Authors: Florian Schnell & Assembler Maniac');
$this->console_text(' Re-Authored: Xymph');
$this->console_text('###############################################################################');
// format the text of the message
$startup_msg = formatText($this->getChatMessage('STARTUP'),
XASECO_VERSION,
$this->server->ip, $this->server->port);
// show startup message
$this->client->query('ChatSendServerMessage', $this->formatColors($startup_msg));
} // sendHeader
/**