1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace ManiaLive\Application;
13:
14: abstract class CommandLineInterpreter
15: {
16: static function preConfigLoad()
17: {
18: $options = getopt(null,array(
19: 'help::',
20: 'manialive_cfg::',
21: ));
22:
23: $help = 'ManiaLive v2.1.14 (2012 Jul 13)'."\n"
24: .'Authors : '."\n"
25: .' Philippe "farfa" Melot, Maxime "Gouxim" Raoust, Florian "aseco" Schnell, Gwendal "Newbo.O" Martin'."\n"
26: .'Usage: php bootstrapper.php [args]'."\n"
27: .'Arguments:'."\n"
28: .' --help - displays the present help'."\n"
29: .' --rpcport=xxx - xxx represents the xmlrpc to use for the connection to the server'."\n"
30: .' --address=xxx - xxx represents the address of the server, it should be an IP address or localhost'."\n"
31: .' --user=xxx - xxx represents the name of the user to use for the communication. It should be User, Admin or SuperAdmin'."\n"
32: .' --password=xxx - xxx represents the password relative to --user Argument'."\n"
33: .' --dedicated_cfg=xxx - xxx represents the name of the Dedicated configuration file to use to get the connection data. This file should be present in the Dedicated\'s config file.'."\n"
34: .' --manialive_cfg=xxx - xxx represents the name of the ManiaLive\'s configuration file. This file should be present in the ManiaLive\'s config file.'."\n";
35:
36: if(isset($options['help']))
37: {
38: echo $help;
39: exit;
40: }
41:
42: if(isset($options['manialive_cfg']))
43: return $options['manialive_cfg'];
44: else
45: return 'config.ini';
46: }
47:
48: static function postConfigLoad()
49: {
50: $options = getopt(null,array(
51: 'rpcport::',
52: 'address::',
53: 'password::',
54: 'dedicated_cfg::',
55: 'user::'
56: ));
57:
58: $serverConfig = \ManiaLive\DedicatedApi\Config::getInstance();
59:
60: if(isset($options['user']))
61: {
62: if($options['user'] != 'SuperAdmin' && $options['user'] != 'Admin' && $options['user'] != 'User')
63: {
64: echo 'Invalid Username'.PHP_EOL.$help;
65: exit;
66: }
67:
68: $serverConfig->user = $options['user'];
69: }
70:
71: if(isset($options['dedicated_cfg']))
72: {
73: $filename = \ManiaLive\Config\Config::getInstance()->dedicatedPath.'/UserData/Config/'.$options['dedicated_cfg'];
74: if(file_exists($filename))
75: {
76:
77: $config = simplexml_load_file($filename);
78: $serverConfig->port = (int)$config->system_config->xmlrpc_port;
79: foreach ($config->authorization_levels->children() as $level)
80: {
81: if($serverConfig->user == (string)$level->name)
82: {
83: $serverConfig->password = (string)$level->password;
84: break;
85: }
86: }
87: }
88: else
89: throw new Exception('Configuration file not found...'.PHP_EOL.'stopping software...');
90: }
91: else
92: {
93: if(isset($options['rpcport']))
94: $serverConfig->port = $options['rpcport'];
95: if(isset($options['password']))
96: $serverConfig->password = $options['password'];
97: }
98:
99: if(isset($options['address']))
100: $serverConfig->host = $options['address'];
101: }
102: }
103: