forked from undeflabs/UASECO-Maniaplanet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uaseco.php
2796 lines (2424 loc) · 116 KB
/
uaseco.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
/*
* Projectname: UASECO
* ~~~~~~~~~~~~~~~~~~~~
* » ASECO is an abbreviation of "Automatic SErver COntrol", the prefix U at UASECO
* stays for "undef", which follows the same naming convention initiated by Xymph
* for XAseco.
*
* This project was forked in May 2014 from XAseco2/1.03 release and was mixed
* with parts/ideas from MPAseco and ASECO/2.2.0c, for supporting the Trackmania²
* Modescript Gamemodes from the Maniaplanet/3+ update.
*
* Many parts has been rewritten in 2017 again because of the ModeScript API
* changes for the Maniaplanet/4 update.
*
* Visit the official site from this fork at http://www.UASECO.org/
*
* » Original project:
* Authored & copyright Aug 2011 - May 2013 by Xymph <[email protected]>
* Derived from XAseco (formerly ASECO/RASP) by Xymph, Flo and others
*
* ----------------------------------------------------------------------------------
* Author: undef.de
* Copyright: May 2014 - July 2020 by undef.de
* ----------------------------------------------------------------------------------
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* ----------------------------------------------------------------------------------
*
*/
// Current project name, version and website
define('UASECO_NAME', 'UASECO');
define('UASECO_VERSION', '0.9.7');
define('UASECO_BUILD', '2020-07-16');
define('UASECO_WEBSITE', 'https://www.UASECO.org');
// Setup required official dedicated server build, Api-Version and PHP-Version
define('MANIAPLANET_BUILD_POSIX', '2019-10-24_16_00');
define('MANIAPLANET_BUILD_WINDOWS', '2019-10-23_20_00');
define('XMLRPC_API_VERSION', '2013-04-16');
define('MODESCRIPT_API_VERSION', '2.5.0'); // https://github.com/maniaplanet/script-xmlrpc/releases
define('MIN_PHP_VERSION', '7.2.0');
define('MIN_MYSQL_VERSION', '5.1.0');
define('MIN_MARIADB_VERSION', '5.5.20');
// Setup misc.
define('CRLF', PHP_EOL);
define('LF', "\n");
if (strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN') {
define('OPERATING_SYSTEM', 'WINDOWS');
define('MANIAPLANET_BUILD', MANIAPLANET_BUILD_WINDOWS);
}
else {
define('OPERATING_SYSTEM', 'POSIX');
define('MANIAPLANET_BUILD', MANIAPLANET_BUILD_POSIX);
}
// Report all
error_reporting(-1);
date_default_timezone_set(@date_default_timezone_get());
setlocale(LC_NUMERIC, 'C');
mb_internal_encoding('UTF-8');
// Init random generator
list($usec, $sec) = explode(' ', microtime());
mt_srand((float) $sec + ((float) $usec * 100000));
// Include required classes
require_once('includes/core/baseclass.class.php'); // Base class
require_once('includes/core/helper.class.php'); // Misc. functions for UASECO, e.g. $aseco->console()... based upon basic.inc.php
require_once('includes/core/XmlRpc/GbxRemote.php'); // https://github.com/maniaplanet/dedicated-server-api
require_once('includes/core/webrequest.class.php');
require_once('includes/core/xmlparser.class.php');
require_once('includes/core/gbxdatafetcher.class.php'); // Provides access to GBX data
require_once('includes/core/mxinfofetcher.class.php'); // Provides access to ManiaExchange info
require_once('includes/core/continent.class.php');
require_once('includes/core/country.class.php');
require_once('includes/core/database.class.php');
require_once('includes/core/locales.class.php'); // Required by includes/core/message.class.php
require_once('includes/core/message.class.php');
require_once('includes/core/gameinfo.class.php'); // Required by includes/core/server.class.php
require_once('includes/core/server.class.php');
require_once('includes/core/dependence.class.php'); // Required by includes/core/plugin.class.php
require_once('includes/core/plugin.class.php');
require_once('includes/core/dialog.class.php');
require_once('includes/core/window.class.php'); // Required by includes/core/windowlist.class.php
require_once('includes/core/windowlist.class.php');
require_once('includes/core/player.class.php');
require_once('includes/core/playerlist.class.php');
require_once('includes/core/playlist.class.php'); // Holds the Playlist (aka Jukebox) for Maps
require_once('includes/core/checkpoint.class.php');
require_once('includes/core/record.class.php');
require_once('includes/core/recordlist.class.php');
require_once('includes/core/ranking.class.php'); // Required by includes/core/rankinglist.class.php
require_once('includes/core/rankinglist.class.php');
require_once('includes/core/map.class.php'); // Required by includes/core/maplist.class.php
require_once('includes/core/maplist.class.php');
require_once('includes/core/maphistory.class.php'); // Holds the Maphistory
/*
#///////////////////////////////////////////////////////////////////////#
# #
#///////////////////////////////////////////////////////////////////////#
*/
class UASECO extends Helper {
public $debug;
public $logfile;
public $client;
public $parser;
public $webrequest;
public $db;
public $locales;
public $continent;
public $country;
public $windows;
public $server;
public $registered_events;
public $registered_chatcmds;
public $chat_colors;
public $chat_messages;
public $plugins;
public $settings;
public $titles;
public $masteradmin_list;
public $admin_list;
public $admin_abilities;
public $operator_list;
public $operator_abilities;
public $banned_ips;
public $uptime; // UASECO start-up time
public $startup_phase; // UASECO start-up phase
public $shutdown_phase; // UASECO shutdown phase
public $warmup_phase; // warm-up phase
public $restarting; // restarting map (true or false)
public $changing_to_gamemode;
public $current_status; // server status changes
public $characters;
public $environments = array(
'Canyon',
'Stadium',
'Valley',
'Lagoon',
);
private $next_second;
private $next_tenth;
private $next_quarter;
private $next_minute;
/*
#///////////////////////////////////////////////////////////////////////#
# #
#///////////////////////////////////////////////////////////////////////#
*/
// Initializes the server.
public function __construct () {
// Error function, report errors in a regular way.
$this->logfile['handle'] = false;
set_error_handler(array($this, 'customErrorHandler'));
register_shutdown_function(array($this, 'customFatalErrorShutdownHandler'));
// Setup logfile
$this->setupLogfile();
$this->console('####[INIT]###########################################################################');
if (version_compare(PHP_VERSION, MIN_PHP_VERSION, '<')) {
$this->console('[UASECO][ERROR] UASECO requires min. PHP/'. MIN_PHP_VERSION .' and can not run with current PHP/'. PHP_VERSION .', please update PHP!');
die();
}
$extensions = array(
array(
'required' => false,
'extension' => 'exif',
'name' => 'Exchangeable Image Information',
'link' => 'http://php.net/manual/en/book.exif.php',
),
array(
'required' => true,
'extension' => 'ftp',
'name' => 'File Transfer Protocol',
'link' => 'http://php.net/manual/en/book.ftp.php',
),
array(
'required' => true,
'extension' => 'iconv',
'name' => 'ICONV character set conversion facility',
'link' => 'http://php.net/manual/en/book.iconv.php',
),
array(
'required' => true,
'extension' => 'gd',
'name' => 'Image Processing and GD',
'link' => 'http://php.net/manual/en/book.image.php',
),
array(
'required' => true,
'extension' => 'json',
'name' => 'JavaScript Object Notation',
'link' => 'http://php.net/manual/en/book.json.php',
),
array(
'required' => true,
'extension' => 'libxml',
'name' => 'LibXML',
'link' => 'http://php.net/manual/en/book.libxml.php',
),
array(
'required' => true,
'extension' => 'mbstring',
'name' => 'Multibyte String',
'link' => 'http://php.net/manual/en/book.mbstring.php',
),
array(
'required' => true,
'extension' => 'mysqli',
'name' => 'MySQL Improved',
'link' => 'http://php.net/manual/en/book.mysqli.php',
),
array(
'required' => true,
'extension' => 'SimpleXML',
'name' => 'SimpleXML',
'link' => 'http://php.net/manual/en/book.simplexml.php',
),
);
$this->console('[PHP] Checking for required PHP extensions...');
$this->console('[PHP] PHP is using "'. php_ini_loaded_file() .'"');
$pass = true;
foreach ($extensions as $item) {
$found = extension_loaded($item['extension']);
$msg = '[PHP] » Checking "'. $item['name'] .'" ('. $item['extension'] .'): ';
if ($found === false && $item['required'] === true) {
$msg .= 'extension not loaded, it is REQUIRED to enable this extension.. See "'. $item['link'] .'" for installation details.';
$pass = false;
}
else if ($found === false && $item['required'] === false) {
$msg .= 'extension not loaded, it is RECOMMENDED to enable this extension. See "'. $item['link'] .'" for installation details.';
}
else if ($found === true) {
$msg .= 'OK!';
}
$this->console($msg);
}
if ($pass === false) {
$this->console('[PHP] » Please enable the required PHP extensions and try again!');
die();
}
// Extended characters list from askuri: https://forum.maniaplanet.com/viewtopic.php?p=266201#p266201
$this->characters = array(
'a' => explode(' ', '@ 4 À Á Â Ã Ä Å ª à á â ã ä å ƛ Ǎ ǎ Ǟ ǟ Ǻ ǻ Ā ā Ă ă Ą ą А Д а д Ѧ ѧ ג Ά Α Δ Λ ά α λ'),
'b' => explode(' ', 'Þ ß þ ƀ Б В Ъ Ь в ь ъ ѣ Ѣ Β β ϐ'),
'c' => explode(' ', '¢ © Ç ç Ć ć Ĉ ĉ Ċ ċ Č č С с Ҁ ҁ Ҫ ҫ ζ ς'),
'd' => explode(' ', 'Ð ð Ď ď Đ đ δ の פ'),
'e' => explode(' ', 'È Ê É Ë è é ê ë Ə Ē ē Ĕ ĕ Ė ė Ę ę Ě ě Ё Є Е е ё є Ҽ ҽ Ҿ ҿ Έ Ε Ξ Σ έ ε ξ ミ ɛ ϵ'),
'f' => explode(' ', 'Ƒ ƒ Ŧ Ғ ғ'),
'g' => explode(' ', 'Ǥ Ǧ ǥ ǧ ǵ Ĝ ĝ Ğ ğ Ġ ġ Ģ ģ'),
'h' => explode(' ', 'Ĥ ĥ Ħ ħ Н Ч н ч ђ ћ Ң ң Ҥ ҥ Һ һ Ӈ ӈ Ή Η'),
'i' => explode(' ', 'Ì Í Î Ï ì í î ï Ǐ ǐ ǰ Ĩ ĩ Ī ī Ĭ ĭ Į į İ ı ĺ ļ ľ ŀ ł І Ї ї і ׀ Ί ΐ Ι Ϊ ί ι ϊ エ エ'),
'j' => explode(' ', 'ǰ ĵ Ĵ Ј ј'),
'k' => explode(' ', 'Ǩ ǩ ĸ ķ Ķ Ќ К к ќ Қ қ Ҝ ҝ Ҟ ҟ Ҡ ҡ Ӄ ӄ Κ κ'),
'l' => explode(' ', 'Ĺ ĺ Ļ ļ Ľ ľ Ŀ ŀ Ł ł І ׀ し じ ム レ'),
'm' => explode(' ', 'М м Μ'),
'n' => explode(' ', 'Ñ ñ Ń ń Ņ ņ Ň ň ʼn Ŋ ŋ Й И Л П и й л п ה ח מ ת Ν ή η ท'),
'o' => explode(' ', 'Ò Ó Ô Õ Ö Ø ð ò ó ô õ ö ø Ɵ Ơ ơ Ǒ ǒ ǫ Ǫ Ǭ ǭ Ǿ ǿ Ō ō Ŏ ŏ Ő ő Ф О о Ѳ ѳ Ѻ ѻ ט ס Ό Ώ Θ Ο Φ Ω θ ο σ φ ό ϕ 〇 °'),
'p' => explode(' ', 'Þ þ Р р ק Ρ ρ ア ァ ヤ ャ'),
'q' => explode(' ', 'Ǫ ǫ Ǭ ǭ'),
'r' => explode(' ', '® Ŕ ŕ Ŗ ŗ Ř ř Ѓ Г Я г я ѓ Γ'),
's' => explode(' ', '§ Ś ś Ŝ ŝ Ş ş Š š Ѕ ѕ ς'),
't' => explode(' ', 'Ɨ ƚ ƫ Ʈ ł Ţ ţ Ť ť ŧ Т т Ҭ ҭ ד Τ τ て 〒 〶 ィ イ'),
'u' => explode(' ', 'Ù Ú Û Ü ù ú û ü ý Ư ư Ǔ ǔ Ǖ ǖ Ǘ ǘ Ǚ ǚ ǜ Ǜ IJ Ũ ũ Ū ū Ŭ ŭ Ů ů Ű ű Ų ų Џ Ц ц ט ΰ μ υ ϋ ύ ひ び ぴ'),
'v' => explode(' ', 'Ѵ ѵ Ѷ ѷ ν'),
'w' => explode(' ', 'Ŵ ŵ Ш Щ ш щ Ѡ ѡ Ѽ ѽ Ѿ ѿ ω ώ ϖ'),
'x' => explode(' ', '× æ ǣ ǽ Ж Х ж х Җ җ Ҳ ҳ Ӂ ӂ Χ χ メ'),
'y' => explode(' ', '¥ Ý ÿ Ŷ ŷ Ÿ Ў У у ў Ү ү Ұ ұ ע ץ Ύ Ϋ γ ϒ ϓ ϔ'),
'z' => explode(' ', 'Ƶ ƶ Ʒ Ǯ ǯ Ź ź Ż ż Ž ž Ζ'),
'0' => explode(' ', 'º ʘ'),
'1' => explode(' ', '¹'),
'2' => explode(' ', '²'),
'3' => explode(' ', '³ Ʒ Ǯ ǯ З Э з Ѯ ѯ Ҙ ҙ ɝ ɜ ヨ ョ ʒ ʓ ϶'),
'4' => explode(' ', 'Ч ч'),
'6' => explode(' ', 'б'),
);
}
/*
#///////////////////////////////////////////////////////////////////////#
# #
#///////////////////////////////////////////////////////////////////////#
*/
// Runs the server.
public function run () {
// Initialize
$this->debug = false;
$this->uptime = time();
$this->registered_events = array();
$this->registered_chatcmds = array();
$this->locales = new Locales();
$this->client = new GbxRemote(); // includes/core/XmlRpc/GbxRemote.php
$this->parser = new XmlParser();
$this->webrequest = new WebRequest();
$this->continent = new Continent();
$this->country = new Country();
$this->server = new Server('127.0.0.1', 5000, 'SuperAdmin', 'SuperAdmin');
$this->windows = new WindowList($this);
$this->plugins = array();
$this->titles = array();
$this->masteradmin_list = array();
$this->admin_list = array();
$this->admin_abilities = array();
$this->operator_list = array();
$this->operator_abilities = array();
$this->banned_ips = array();
$this->startup_phase = true;
$this->shutdown_phase = false;
$this->warmup_phase = false;
$this->restarting = false;
$this->changing_to_gamemode = false;
$this->current_status = 0;
// Setup config file
$config_file = 'config/UASECO.xml';
// Load new settings, if available
$this->console('[Config] Load settings [{1}]', $config_file);
$this->loadSettings($config_file);
// Initialize further
$this->server->maps = new MapList($this->debug, $this->settings['developer']['force_maplist_update']);
$this->server->maps->history = new MapHistory($this->debug, $this->settings['max_history_entries']);
$this->server->maps->playlist = new PlayList($this->debug);
$this->server->players = new PlayerList($this->debug);
$this->server->rankings = new RankingList($this->debug);
$this->server->mutelist = array();
// Load admin/operator/ability lists, if available
$this->console('[Config] Load admin and operator lists [{1}]', $this->settings['adminops_file']);
$this->readLists();
// Load banned IPs list, if available
$this->console('[Config] Load banned IPs list [{1}]', $this->settings['bannedips_file']);
$this->readIPs();
// Setup PHP memory_limit
$limit = $this->shorthand2bytes(ini_get('memory_limit'));
if ($limit !== -1) {
ini_set('memory_limit', $this->settings['memory_limit']);
}
$limit = $this->shorthand2bytes(ini_get('memory_limit'));
if ($limit !== -1 && $limit < 256 * 1048576) {
ini_set('memory_limit', '256M');
}
$limit = $this->shorthand2bytes(ini_get('memory_limit'));
if ($limit === -1) {
$this->console('[PHP] Setup memory limit to unlimited');
}
else {
$this->console('[PHP] Setup memory limit to '. $this->bytes2shorthand($limit, 'M'));
}
// Setup PHP script_timeout
@set_time_limit($this->settings['script_timeout']);
$this->console('[PHP] Setup script timeout to '. $this->settings['script_timeout'] .' second'. ($this->settings['script_timeout'] === 1 ? '' : 's'));
// Connect to Trackmania Dedicated Server
if (!$this->connectDedicated()) {
// kill program with an error
$this->console('[Dedicated] ...connection could not be established!');
die();
}
// Log status message
$this->console('[Dedicated] ...connection established successfully!');
// Clear possible leftover ManiaLinks
$this->client->query('SendHideManialinkPage');
// Connect to the database
$this->displayLoadStatus('Connecting to database...', 0.0);
if ($this->settings['mask_password'] === true) {
$this->console("[Database] Try to connect to database server on [{1}] with database [{2}], login [{3}] and password [{4}] (masked password)",
$this->settings['dbms']['host'],
$this->settings['dbms']['database'],
$this->settings['dbms']['login'],
preg_replace('#.#', '*', $this->settings['dbms']['password'])
);
}
else {
$this->console("[Database] Try to connect to database server on [{1}] with database [{2}], login [{3}] and password [{4}]",
$this->settings['dbms']['host'],
$this->settings['dbms']['database'],
$this->settings['dbms']['login'],
$this->settings['dbms']['password']
);
}
$this->connectDatabase();
$this->displayLoadStatus('Connection established successfully!', 0.1);
// Check database structure
$this->displayLoadStatus('Checking database structure...', 0.15);
$this->checkDatabaseStructure();
$this->displayLoadStatus('Structure successfully checked!', 1.0);
// Load plugins and register chat commands
$this->console('[Plugin] Loading plugins [config/plugins.xml]');
$this->loadPlugins();
// Register own onShutdown() function
$this->registerEvent('onShutdown', array($this, 'onShutdown'));
// Log admin lock message
if ($this->settings['lock_password'] !== '') {
if ($this->settings['mask_password'] === true) {
$this->console('[Config] Locked admin commands and features with password "{1}" (masked password)',
preg_replace('#.#', '*', $this->settings['lock_password'])
);
}
else {
$this->console('[Config] Locked admin commands and features with password "{1}"',
$this->settings['lock_password']
);
}
}
// Throw 'starting up' event
$this->releaseEvent('onStartup', null);
// Synchronize information with server
$this->serverSync();
// Make a visual header
$this->sendHeader();
// Get current players/servers on the server (hardlimited to 300)
$playerlist = $this->client->query('GetPlayerList', 300, 0, 2);
// Update players/relays lists
if (!empty($playerlist)) {
foreach ($playerlist as $player) {
// Fake it into thinking it's a connecting Player:
// It gets team and ladder info this way and will also throw an
// onPlayerConnect event for Players (not relays) to all Plugins
$this->playerConnect($player['Login'], false);
}
}
unset($playerlist);
// Get current game infos if server loaded a map yet
if ($this->current_status === 100) {
$this->console('[UASECO] Waiting for the server to start a map...');
}
else {
$this->loadingMap($this->server->maps->current->uid);
}
// Startup done
$this->startup_phase = false;
$this->displayLoadStatus(false);
// Main loop
while (true) {
$starttime = microtime(true);
if ($this->shutdown_phase === false) {
// Get callbacks from the server
$this->executeCallbacks();
// Sends calls to the server
$this->executeMulticall();
}
// Throw timing events
$this->releaseEvent('onMainLoop', null);
if (time() >= $this->next_second) {
$this->webrequest->update();
$this->next_second = (time() + 1);
$this->releaseEvent('onEverySecond', null);
}
if (time() >= $this->next_tenth) {
// Check for Database connection and reconnect on lost connection
if ($this->db->ping() === false) {
$this->console('[Database] Lost connection, try to reconnect...');
$this->connectDatabase();
}
$this->next_tenth = (time() + 10);
$this->releaseEvent('onEveryTenSeconds', null);
}
if (time() >= $this->next_quarter) {
$this->next_quarter = (time() + 15);
$this->releaseEvent('onEveryFifteenSeconds', null);
}
if (time() >= $this->next_minute) {
$this->next_minute = (time() + 60);
$this->releaseEvent('onEveryMinute', 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();
}
/*
#///////////////////////////////////////////////////////////////////////#
# #
#///////////////////////////////////////////////////////////////////////#
*/
// Initializes the server, loads all server variables
// and reads all Maps from server.
private function serverSync () {
// Get basic server info, server id, login, nickname, zone, name, options, mode, limits...
$this->server->getServerSettings();
if (!file_exists($this->server->mapdir .'MatchSettings/'. $this->settings['default_maplist'])) {
$this->console('[UASECO][ERROR] Can not find the file "'. $this->server->mapdir .'MatchSettings/'. $this->settings['default_maplist'] .'" from setting <default_maplist> from [config/UASECO.xml]!');
die();
}
// Add 'POWERED BY UASECO' to server comment
if (strpos($this->stripStyles($this->server->comment, true), 'POWERED BY UASECO') === false) {
$this->client->query('SetServerComment', $this->server->comment ."\n". '$Z$O$FFFPOWERED BY $0AF$L['. UASECO_WEBSITE .']'. UASECO_NAME .'$L');
}
// Check server build
if (strlen($this->server->build) === 0 || ($this->server->game === 'ManiaPlanet' && strcmp($this->server->build, MANIAPLANET_BUILD) < 0)) {
$this->console('[UASECO][ERROR] Obsolete server build "'. $this->server->build .'" - must be at least "'. MANIAPLANET_BUILD .'"!');
die();
}
// Create a USER_AGENT string
define('USER_AGENT', UASECO_NAME .'/'. UASECO_VERSION .'_'. UASECO_BUILD .' '. $this->server->game .'/'. $this->server->build .' php/'. phpversion() .' '. php_uname());
// Get status
$status = $this->client->query('GetStatus');
$this->current_status = $status['Code'];
unset($status);
// Get all Maps from server
$this->console('[MapList] Reading complete map list from server...');
$this->server->maps->readMapList();
$count = count($this->server->maps->map_list);
$this->console('[MapList] ...successfully done, read '. $count .' map'. ($count === 1 ? '' : 's') .' which matches server settings!');
// Load MapHistory
$this->console('[Playlist] Reading map history...');
$this->server->maps->history->readMapHistory();
$this->console('[Playlist] ...successfully done!');
// Throw 'synchronisation' event
$this->releaseEvent('onSync', null);
}
/*
#///////////////////////////////////////////////////////////////////////#
# #
#///////////////////////////////////////////////////////////////////////#
*/
// Sends program header to console and ingame chat.
private function sendHeader () {
$max_execution_time = (int)ini_get('max_execution_time') .' second'. ((int)ini_get('max_execution_time') === 1 ? '' : 's');
$wrappers = stream_get_wrappers();
sort($wrappers, SORT_STRING);
$gd = gd_info();
$this->console_text('####[ABOUT]##########################################################################');
$this->console_text('» Dedicated: {1}/{2} build {3}, using Method-API {4}, ModeScript-API {5}', $this->server->game, $this->server->version, $this->server->build, $this->server->api_version, MODESCRIPT_API_VERSION);
$this->console_text('» MatchSettings: {1}', $this->settings['default_maplist']);
$this->console_text('» Host: {1}', $this->server->xmlrpc['ip']);
$this->console_text('» Ports: Connections {1}, P2P {2}, XmlRpc {3}', $this->server->port, $this->server->p2pport, $this->server->xmlrpc['port']);
$this->console_text('» Network: Send {1} KB, Receive {2} KB', $this->formatNumber($this->server->networkstats['TotalSendingSize'],0,',','.'), $this->formatNumber($this->server->networkstats['TotalReceivingSize'],0,',','.'));
$this->console_text('» Uptime: {1}', $this->timeString($this->server->networkstats['Uptime']));
$this->console_text('» Name: {1} ({2}), join link: "maniaplanet://#join={3}@{4}"{5}', $this->stripStyles($this->server->name, false), $this->server->login, $this->server->login, $this->server->title, (!empty($this->server->options['Password']) ? ' (server is password protected)' : '') );
if ($this->server->isrelay) {
$this->console_text('=> Relays: {1} - {2}', $this->stripStyles($this->server->relaymaster['NickName'], false), $this->server->relaymaster['Login']);
}
$this->console_text('» Title: {1}', $this->server->title);
$this->console_text('» Ladder: {1} - {2}k', substr(($this->server->ladder_limit_min / 1000), 0, 3), substr(($this->server->ladder_limit_max / 1000), 0, 3));
$this->console_text('» Gamemode: "{1}" with script "{2}" version "{3}"', str_replace('_', '', $this->server->gameinfo->getModeName()), $this->server->gameinfo->getModeScriptName(), $this->server->gameinfo->getModeVersion());
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» PHP: PHP/{1}', phpversion());
$this->console_text('» INI-File: {1}', php_ini_loaded_file());
$this->console_text('» MemoryLimit: {1}', ini_get('memory_limit'));
$this->console_text('» MaxExecutionTime: {1}', $max_execution_time);
$this->console_text('» AllowUrlFopen: {1}', $this->bool2string(((int)ini_get('allow_url_fopen') === 1 ? true : false)));
$this->console_text('» Streams: {1}', implode(', ', $wrappers));
$this->console_text('» GD-Lib: Version: {1}, JPEG: {2}, PNG: {3}, FreeType: {4}', $gd['GD Version'], $this->bool2string($gd['JPEG Support']), $this->bool2string($gd['PNG Support']), $this->bool2string($gd['FreeType Support']));
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» Database: Server: {1}', $this->db->server_version());
$this->console_text('» Client: {1}', $this->db->client_version());
$this->console_text('» Connect: {1}', $this->db->connection_info());
$this->console_text('» Status: {1}', $this->db->host_status());
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» OS: {1}', php_uname());
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» UASECO: Version {1} build {2}', UASECO_VERSION, UASECO_BUILD);
$this->console_text('» Based upon the work of the authors and projects of:');
$this->console_text('» - Xymph (XAseco2),');
$this->console_text('» - Florian Schnell, AssemblerManiac and many others (ASECO),');
$this->console_text('» - Kremsy (MPASECO)');
$this->console_text('» Author: undef.de (UASECO)');
$this->console_text('» Website: {1}', UASECO_WEBSITE);
$this->console_text('####[PLUGINS]########################################################################');
foreach ($this->plugins as $plugin) {
$this->console_text('» {1}{2} ({3})', $plugin->getFilename() . sprintf('%'. (50 - strlen($plugin->getFilename())) .'s', ''), $plugin->getVersion() . sprintf('%'. (8 - strlen($plugin->getVersion())) .'s', ''), $plugin->getBuild());
}
$this->console_text('#####################################################################################');
// Show startup message
$msg = new Message('uaseco', 'startup');
$msg->addPlaceholders(
UASECO_VERSION,
UASECO_BUILD,
$this->server->xmlrpc['ip'],
$this->server->xmlrpc['port']
);
$msg->sendChatMessage();
}
/*
#///////////////////////////////////////////////////////////////////////#
# #
#///////////////////////////////////////////////////////////////////////#
*/
private function logDebugInformations () {
$max_execution_time = (int)ini_get('max_execution_time') .' second'. ((int)ini_get('max_execution_time') === 1 ? '' : 's');
$wrappers = stream_get_wrappers();
sort($wrappers, SORT_STRING);
$gd = gd_info();
$this->console_text('####[DEBUG]##########################################################################');
$this->console_text('» StartupPhase: {1}', $this->bool2string($this->startup_phase));
$this->console_text('» WarmupPhase: {1}', $this->bool2string($this->warmup_phase));
$this->console_text('» Restarting: {1}', $this->bool2string($this->restarting));
$this->console_text('» CurrentStatus: [{1}] {2}', $this->current_status, $this->server->state_names[$this->current_status]);
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» Uptime: {1}', $this->timeString(time() - $this->uptime));
if ( function_exists('sys_getloadavg') ) {
$this->console_text('» System Load: {1}', implode(', ', sys_getloadavg()));
}
$this->console_text('» MEM-Usage: {1} MB, PEAK: {2} MB', round(memory_get_usage() / pow(1024,2), 4), round(memory_get_peak_usage() / pow(1024,2), 4));
if (function_exists('posix_getuid') && function_exists('posix_getgid')) {
$this->console_text('» Process user: {1}:{2} (UID/GID)', posix_getuid(), posix_getgid());
}
$this->console_text('» Script owner: {1}:{2} (UID/GID)', getmyuid(), getmygid());
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» NbPlugins: {1}', sprintf("%5s", count($this->plugins)));
$this->console_text('» RegEvents: {1}', sprintf("%5s", count($this->registered_events)));
$this->console_text('» RegChatCmds: {1}', sprintf("%5s", count($this->registered_chatcmds)));
$this->console_text('» NbMaps: {1} : {2} bytes', sprintf("%5s", $this->server->maps->count()), sprintf("%10s", $this->formatNumber(strlen(serialize($this->server->maps->map_list)),0,'.','.')));
$this->console_text('» NbPlayers: {1} : {2} bytes', sprintf("%5s", $this->server->players->count()), sprintf("%10s", $this->formatNumber(strlen(serialize($this->server->players->player_list)),0,'.','.')));
$this->console_text('» PlayerRanks: {1} : {2} bytes', sprintf("%5s", $this->server->rankings->count()), sprintf("%10s", $this->formatNumber(strlen(serialize($this->server->rankings->ranking_list)),0,'.','.')));
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» Dedicated: {1}/{2} build {3}, using Method-API {4}, ModeScript-API {5}', $this->server->game, $this->server->version, $this->server->build, $this->server->api_version, MODESCRIPT_API_VERSION);
$this->console_text('» MatchSettings: {1}', $this->settings['default_maplist']);
$this->console_text('» Host: {1}', $this->server->xmlrpc['ip']);
$this->console_text('» Ports: Connections {1}, P2P {2}, XmlRpc {3}', $this->server->port, $this->server->p2pport, $this->server->xmlrpc['port']);
$this->console_text('» Network: Send {1} KB, Receive {2} KB', $this->formatNumber($this->server->networkstats['TotalSendingSize'],0,',','.'), $this->formatNumber($this->server->networkstats['TotalReceivingSize'],0,',','.'));
$this->console_text('» Uptime: {1}', $this->timeString($this->server->networkstats['Uptime']));
$this->console_text('» Name: {1} ({2}), join link: "maniaplanet://#join={3}@{4}"{5}', $this->stripStyles($this->server->name, false), $this->server->login, $this->server->login, $this->server->title, (!empty($this->server->options['Password']) ? ' (server is password protected)' : '') );
if ($this->server->isrelay) {
$this->console_text('=> Relays: {1} - {2}', $this->stripStyles($this->server->relaymaster['NickName'], false), $this->server->relaymaster['Login']);
}
$this->console_text('» Title: {1}', $this->server->title);
$this->console_text('» Ladder: {1} - {2}k', substr(($this->server->ladder_limit_min / 1000), 0, 3), substr(($this->server->ladder_limit_max / 1000), 0, 3));
$this->console_text('» Gamemode: "{1}" with script "{2}" version "{3}"', str_replace('_', '', $this->server->gameinfo->getModeName()), $this->server->gameinfo->getModeScriptName(), $this->server->gameinfo->getModeVersion());
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» PHP: PHP/{1}', phpversion());
$this->console_text('» INI-File: {1}', php_ini_loaded_file());
$this->console_text('» MemoryLimit: {1}', ini_get('memory_limit'));
$this->console_text('» MaxExecutionTime: {1}', $max_execution_time);
$this->console_text('» AllowUrlFopen: {1}', $this->bool2string(((int)ini_get('allow_url_fopen') === 1 ? true : false)));
$this->console_text('» Streams: {1}', implode(', ', $wrappers));
$this->console_text('» GD-Lib: Version: {1}, JPEG: {2}, PNG: {3}, FreeType: {4}', $gd['GD Version'], $this->bool2string($gd['JPEG Support']), $this->bool2string($gd['PNG Support']), $this->bool2string($gd['FreeType Support']));
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» Database: Server: {1}', $this->db->server_version());
$this->console_text('» Client: {1}', $this->db->client_version());
$this->console_text('» Connect: {1}', $this->db->connection_info());
$this->console_text('» Status: {1}', $this->db->host_status());
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» OS: {1}', php_uname());
$this->console_text('» -----------------------------------------------------------------------------------');
$this->console_text('» UASECO: Version {1} build {2}', UASECO_VERSION, UASECO_BUILD);
$this->console_text('####[PLUGINS]########################################################################');
foreach ($this->plugins as $plugin) {
$this->console_text('» {1}{2} ({3})', $plugin->getFilename() . sprintf('%'. (50 - strlen($plugin->getFilename())) .'s', ''), $plugin->getVersion() . sprintf('%'. (8 - strlen($plugin->getVersion())) .'s', ''), $plugin->getBuild());
}
$this->console_text('#####################################################################################');
}
/*
#///////////////////////////////////////////////////////////////////////#
# #
#///////////////////////////////////////////////////////////////////////#
*/
private function logDebugPluginUsage ($list) {
$this->console_text('####[DEBUG]##########################################################################');
$this->console_text('» Plugin memory usage on initialization:');
foreach ($list as $plugin => $usage) {
$this->console_text('» {1} {2} bytes', str_pad('['. $plugin .']', 30, ' ', STR_PAD_RIGHT), str_pad($this->formatNumber($usage, 0, '.', '.'), 15, ' ', STR_PAD_LEFT));
}
$this->console_text('#####################################################################################');
}
/*
#///////////////////////////////////////////////////////////////////////#
# #
#///////////////////////////////////////////////////////////////////////#
*/
// Load settings and apply them on the current instance.
private function loadSettings ($config_file) {
if ($settings = $this->parser->xmlToArray($config_file, true, true)) {
// read the XML structure into an array
$settings = $settings['SETTINGS'];
// Read <developer_options> settings and apply them
$this->debug = $this->string2bool($settings['DEVELOPER_OPTIONS'][0]['DEBUG'][0]);
$this->settings['developer']['log_events']['common'] = $this->string2bool($settings['DEVELOPER_OPTIONS'][0]['LOG_EVENTS'][0]['COMMON'][0]);
$this->settings['developer']['log_events']['registered_types'] = $this->string2bool($settings['DEVELOPER_OPTIONS'][0]['LOG_EVENTS'][0]['REGISTERED_TYPES'][0]);
$this->settings['developer']['log_events']['all_types'] = $this->string2bool($settings['DEVELOPER_OPTIONS'][0]['LOG_EVENTS'][0]['ALL_TYPES'][0]);
$this->settings['developer']['force_maplist_update'] = $this->string2bool($settings['DEVELOPER_OPTIONS'][0]['FORCE_MAPLIST_UPDATE'][0]);
$this->settings['developer']['write_documentation'] = $this->string2bool($settings['DEVELOPER_OPTIONS'][0]['WRITE_DOCUMENTATION'][0]);
$this->settings['chat_prefix_replacement'] = $settings['CHAT_PREFIX_REPLACEMENT'][0];
// Read settings and apply them
$this->chat_colors = $settings['COLORS'][0];
$this->masteradmin_list = $settings['MASTERADMINS'][0];
if (!isset($this->masteradmin_list) || !is_array($this->masteradmin_list)) {
$this->console('[UASECO][ERROR] No MasterAdmin(s) configured in [config/UASECO.xml] at <masteradmins>!');
die();
}
// Set admin contact
$this->settings['admin_contact'] = $settings['ADMIN_CONTACT'][0];
if (strtolower($this->settings['admin_contact']) === '[email protected]' || filter_var($this->settings['admin_contact'], FILTER_VALIDATE_EMAIL) === false) {
$this->console('[UASECO][WARNING] ###############################################################################################################');
$this->console('[UASECO][WARNING] You should setup a working mail to be able to contact you, change it in [config/UASECO.xml] at <admin_contact>!');
$this->console('[UASECO][WARNING] ###############################################################################################################');
}
// Set admin lock password
$this->settings['lock_password'] = $settings['LOCK_PASSWORD'][0];
if (empty($this->settings['lock_password'])) {
$this->console('[UASECO][WARNING] To increase security you should setup a lock password at <lock_password> in [config/UASECO.xml]!');
}
// Show played time at end of map?
$this->settings['show_playtime'] = $settings['SHOW_PLAYTIME'][0];
// Show current map at start?
$this->settings['show_curmap'] = $settings['SHOW_CURMAP'][0];
// Set default filename for readmaplist/writemaplist
$this->settings['default_maplist'] = $settings['DEFAULT_MAPLIST'][0];
if ($this->settings['default_maplist'] === '') {
$this->console('[UASECO][ERROR] You have to setup <default_maplist> from [config/UASECO.xml] to run UASECO!');
die();
}
if (strpos($this->settings['default_maplist'], '/') !== false) {
$this->console('[UASECO][ERROR] Found a path separator ("/"), which should only contain a filename in <default_maplist> from [config/UASECO.xml]!');
die();
}
else if (strpos($this->settings['default_maplist'], '\\') !== false) {
$this->console('[UASECO][ERROR] Found a path separator ("\"), which should only contain a filename in <default_maplist> from [config/UASECO.xml]!');
die();
}
// Add random filter to "/admin writemaplist" output
$this->settings['writemaplist_random'] = $this->string2bool($settings['WRITEMAPLIST_RANDOM'][0]);
// Sets automatic saving the maplist
$this->settings['autosave_maplist'] = $this->string2bool($settings['AUTOSAVE_MAPLIST'][0]);
// Automatic refresh of the maplist when the callback "ManiaPlanet.MapListModified" is received
$this->settings['automatic_refresh_maplist'] = $this->string2bool($settings['AUTOMATIC_REFRESH_MAPLIST'][0]);
// Specifies how large the Map(List) history buffer is.
$this->settings['max_history_entries'] = (int)$settings['MAX_HISTORY_ENTRIES'][0];
// Sets the minimum amount of records required for a player to be ranked: Higher = Faster
$this->settings['server_rank_min_records'] = (int)$settings['SERVER_RANK_MIN_RECORDS'][0];
// Setup default storing path for the map images
$this->settings['mapimages_path'] = $settings['MAPIMAGES_PATH'][0];
if ((OPERATING_SYSTEM === 'POSIX' && substr($this->settings['mapimages_path'], -1) !== '/') || (OPERATING_SYSTEM === 'WINDOWS' && substr($this->settings['mapimages_path'], -1) !== '\\')) {
$this->console('[Config] Adding missing trailing "'. DIRECTORY_SEPARATOR .'" <mapimages_path> from [config/UASECO.xml]!');
$this->settings['mapimages_path'] = $this->settings['mapimages_path'] . DIRECTORY_SEPARATOR;
}
// Set multiple of win count to show global congrats message
$this->settings['global_win_multiple'] = ($settings['GLOBAL_WIN_MULTIPLE'][0] > 0 ? $settings['GLOBAL_WIN_MULTIPLE'][0] : 1);
// Timeout of the message window in seconds
$this->settings['window_timeout'] = $settings['WINDOW_TIMEOUT'][0];
// Set filename of admin/operator/ability lists file
$this->settings['adminops_file'] = $settings['ADMINOPS_FILE'][0];
// Set filename of banned IPs list file
$this->settings['bannedips_file'] = $settings['BANNEDIPS_FILE'][0];
// Set filename of blacklist file
$this->settings['blacklist_file'] = $settings['BLACKLIST_FILE'][0];
// Set filename of guestlist file
$this->settings['guestlist_file'] = $settings['GUESTLIST_FILE'][0];
// Set minimum admin client version
$this->settings['admin_client'] = $settings['ADMIN_CLIENT_VERSION'][0];
// Set minimum player client version
$this->settings['player_client'] = $settings['PLAYER_CLIENT_VERSION'][0];
// Log all chat, not just chat commands ?
$this->settings['log_all_chat'] = $this->string2bool($settings['LOG_ALL_CHAT'][0]);
// Show timestamps in /chatlog, /pmlog & /admin pmlog ?
$this->settings['chatpmlog_times'] = $this->string2bool($settings['CHATPMLOG_TIMES'][0]);
// Show round reports in message window?
$this->settings['rounds_in_window'] = $this->string2bool($settings['ROUNDS_IN_WINDOW'][0]);
// Color nicknames in the various /top... etc lists?
$this->settings['lists_colornicks'] = $this->string2bool($settings['LISTS_COLORNICKS'][0]);
// Color mapnames in the various /lists... lists?
$this->settings['lists_colormaps'] = $this->string2bool($settings['LISTS_COLORMAPS'][0]);
// Automatically force spectator on player using /afk ?
$this->settings['afk_force_spec'] = $this->string2bool($settings['AFK_FORCE_SPEC'][0]);
// Provide clickable buttons in lists?
$this->settings['clickable_lists'] = $this->string2bool($settings['CLICKABLE_LISTS'][0]);
// Show logins in /recs?
$this->settings['show_rec_logins'] = $this->string2bool($settings['SHOW_REC_LOGINS'][0]);
// Set status path
$this->settings['status_path'] = $settings['STATUS_PATH'][0];
// Set dedicated Server installation path
$this->settings['dedicated_installation'] = $settings['DEDICATED_INSTALLATION'][0];
if (strtoupper($this->settings['dedicated_installation']) === 'PATH_TO_DEDICATED_SERVER' || empty($this->settings['dedicated_installation'])) {
$this->console('[UASECO][ERROR] Please setup <dedicated_installation> in [config/UASECO.xml]!');
die();
}
if ((OPERATING_SYSTEM === 'POSIX' && substr($this->settings['dedicated_installation'], -1) !== '/') || (OPERATING_SYSTEM === 'WINDOWS' && substr($this->settings['dedicated_installation'], -1) !== '\\')) {
$this->console('[Config] Adding missing trailing "'. DIRECTORY_SEPARATOR .'" <dedicated_installation> from [config/UASECO.xml]!');
$this->settings['dedicated_installation'] = $this->settings['dedicated_installation'] . DIRECTORY_SEPARATOR;
}
// Log passwords in logfile?
$this->settings['mask_password'] = $this->string2bool($settings['MASK_PASSWORD'][0]);
$this->settings['show_load_status'] = $this->string2bool($settings['SHOW_LOAD_STATUS'][0]);
// PHP related stuff
$this->settings['script_timeout'] = $settings['SCRIPT_TIMEOUT'][0];
$this->settings['memory_limit'] = $settings['MEMORY_LIMIT'][0];
// Read <dbms> settings and apply them
$this->settings['dbms']['host'] = $settings['DBMS'][0]['HOST'][0];
$this->settings['dbms']['login'] = $settings['DBMS'][0]['LOGIN'][0];
$this->settings['dbms']['password'] = $settings['DBMS'][0]['PASSWORD'][0];
$this->settings['dbms']['database'] = $settings['DBMS'][0]['DATABASE'][0];
$this->settings['dbms']['table_prefix'] = $settings['DBMS'][0]['TABLE_PREFIX'][0];
if (empty($this->settings['dbms']['table_prefix'])) {
$this->settings['dbms']['table_prefix'] = 'uaseco_';
}
// Read <dedicated_server> settings and apply them
$this->server->xmlrpc['login'] = $settings['DEDICATED_SERVER'][0]['LOGIN'][0];
$this->server->xmlrpc['pass'] = $settings['DEDICATED_SERVER'][0]['PASSWORD'][0];
$this->server->xmlrpc['port'] = $settings['DEDICATED_SERVER'][0]['PORT'][0];
$this->server->xmlrpc['ip'] = $settings['DEDICATED_SERVER'][0]['IP'][0];
if (isset($settings['DEDICATED_SERVER'][0]['TIMEOUT'][0])) {
$this->server->timeout = (int)$settings['DEDICATED_SERVER'][0]['TIMEOUT'][0];
}
else {
$this->server->timeout = null;
$this->console('[WARNING] Server init timeout not specified in [config/UASECO.xml]!');
}
if ($this->settings['admin_client'] !== '' && preg_match('/^2\.11\.[12][0-9]$/', $this->settings['admin_client']) !== 1 || $this->settings['admin_client'] === '2.11.10') {
$this->console('[UASECO][ERROR] Invalid admin client version: '. $this->settings['admin_client'] .'!');
die();
}
if ($this->settings['player_client'] !== '' && preg_match('/^2\.11\.[12][0-9]$/', $this->settings['player_client']) !== 1 || $this->settings['player_client'] === '2.11.10') {
$this->console('[UASECO][ERROR] Invalid player client version: '. $this->settings['player_client'] .'!');
die();
}
}
else {
// Could not parse XML file
$this->console('[UASECO][ERROR] Could not read/parse config file ['. $config_file .']!');
die();
}
}
/*
#///////////////////////////////////////////////////////////////////////#
# #
#///////////////////////////////////////////////////////////////////////#
*/
// Loads files in the plugins directory.
private function loadPlugins () {
// Debug
$plugin_usage = array();
$this->displayLoadStatus('Loading Plugins...', 0.0);
// Load and parse the plugins file
if ($plugins = $this->parser->xmlToArray('config/plugins.xml')) {
if (!empty($plugins['PLUGINS']['PLUGIN'])) {
// Take each plugin tag
$count = 0;
$amount = count($plugins['PLUGINS']['PLUGIN']);
foreach ($plugins['PLUGINS']['PLUGIN'] as $plugin) {
// Reset plugin variables... useless, but removes warning!
$_PLUGIN = null;
unset($_PLUGIN);
// Debug
$usage_before = memory_get_usage();
// Log plugin message
$this->console('[Plugin] » initialize [plugins/'. $plugin .']');
// Include the plugin
require_once('plugins/'. $plugin);
// Load only plugins that were configured right...
if (!isset($_PLUGIN) || get_parent_class($_PLUGIN) !== 'Plugin') {
$this->console('[WARNING] require_once() does not load the file [plugins/'. $plugin .'] from <plugin> position '. ($count + 1) .', which means that this Plugin is probably an old version or it is added twice at [config/plugins.xml]!');
continue;
}
$count ++;
$ratio = (1.0 / $amount) * $count;
$this->displayLoadStatus('Loading Plugin '. $_PLUGIN->getClassname() .'...', $ratio);