Vous êtes sur la page 1sur 4

<?

php
/**
* ManuAdminMod
*
* This is a powerful and platform independent software for administrating game
servers of various kinds.
* If you need help with installing or using this software, please visit our web
site at: www.ManuAdminMod.de
* If you want to obtain additional permissions extending the license, contact u
s at: Webmaster@ManuAdminMod.de
*
* @copyright www.ManuAdminMod.de
* @license http://www.creativecommons.org/licenses/by-nc-nd/4.0/ Creative Commo
ns BY-NC-ND 4.0
* @version 1.0.0-Beta+7
* */
namespace MAM;
use
use
use
use
use
use
use
use
use
use
use
use
use
use

MAM\Daemon\Api\Api;
MAM\Daemon\Libraries\GeoIP\GeoIP;
MAM\Daemon\Libraries\GeoIP\GeoIpException;
MAM\Daemon\Libraries\Helper\Helper;
MAM\Daemon\Core\Registry;
MAM\Daemon\Libraries\Logging\LogHandler;
MAM\Daemon\Autoloader;
MAM\Daemon\Libraries\ErrorHandler\ErrorHandler;
MAM\Daemon\Libraries\Database\Database;
MAM\Daemon\Libraries\TeamSpeak3\TeamSpeak3;
MAM\Daemon\Libraries\Jobs\Jobs;
MAM\Daemon\Libraries\Permissions\Permissions;
MAM\Daemon\Libraries\Plugins\PluginLoader;
MAM\Daemon\Core\HeartBeat;

error_reporting(E_ALL);
date_default_timezone_set('Europe/Berlin');
if (version_compare(phpversion(), '5.4.0', '<')) {
exit('This software needs PHP 5.4 or newer!' . PHP_EOL);
}
$extensions = array('json', 'mbstring', 'pdo_sqlite', 'pdo_mysql', 'sockets');
foreach ($extensions as $extension) {
if (!extension_loaded($extension)) {
exit('This software needs the \'' . $extension . '\' extension, please i
nstall it!' . PHP_EOL);
}
}
if (PHP_SAPI != 'cli') {
exit('<h1>This software cannot be run on a webspace!</h1>');
}
/**
* Loads the Autoloader Class
*/
require_once 'daemon/autoloader.php';
Autoloader::register();
$registry = Registry::getInstance();
$registry->define('startuptime', time());
$registry->define('version', '1.0.0-Beta+7');

/**
* Loads basic functions
* @todo Move Functions to HelperClass
*/
try {
$args = Helper::parseArgv(
array(
'game' => array('count' => 1, 'multiple' => false),
'cfgdir' => array('count' => 1, 'multiple' => false),
'logdir' => array('count' => 1, 'multiple' => false),
'debug' => array('count' => 1, 'multiple' => false),
'logrotate' => array('count' => 1, 'multiple' => false)
)
);
} catch (\Exception $e) {
exit('Error in command line parameters: ' . $e->getMessage() . PHP_EOL);
}
//Log and Config Dir
if (!isset($args['cfgdir'])) {
$configdir = 'configs' . '/';
} else {
$configdir = rtrim($args['cfgdir'], '/') . '/';
}
if (!isset($args['logdir'])) {
$logdir = 'logfiles' . '/';
} else {
$logdir = rtrim($args['logdir'], '/') . '/';
}
$registry->define('startargs', $args);
define('DEBUG', (isset($args['debug']) && $args['debug']) ? true : false);
//Define Logging
$registry->define('logdir', $logdir);
$registry->logging = $logging = new LogHandler('Daemon/', 'mod');
if (isset($args['logrotate'])) {
$registry->logging->setLogrotate($args['logrotate']);
}
if (!array_key_exists('game', $args)) {
$logging->error('Please add the -game Parameter');
}
//Set error handler
ini_set('log_errors', 0);
ini_set('display_errors', 1);
ini_set('error_log', $registry->logging->getLogPath());
$error_handler = new ErrorHandler();
set_error_handler(array($error_handler, 'errorHandler'), E_ALL);
register_shutdown_function(array($error_handler, 'checkForFatal'));
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
declare(ticks = 100);
pcntl_signal(SIGTERM, array($error_handler, 'signalHandler'));
pcntl_signal(SIGINT, array($error_handler, 'signalHandler'));
}

//Define Players
$registry->players = array();
//Define Mod
$game = $args['game'];
$engine = Helper::getGameEngine($game);
if (is_null($engine)) {
$logging->error('Game ' . $game . ' isn\'t supported by MAM');
}
$path = __NAMESPACE__ . '\\Daemon\\Engine\\' . ucfirst($engine) . '\\Mod';
/* @var $mod Daemon\Core\Mod */
$mod = new $path;
$registry->mod = $mod;
$mod->setGame($game);
if ($engine == NULL) {
$logging->error('Game "' . $game . '" is not supported');
}
$mod->setEngine($engine);
if (!$mod->setConfigDir($configdir)) {
$logging->error('Couldn\'t find config dir: ' . $configdir);
}
$logging->info('==============================================');
$logging->info('ManuAdminMod | Version ' . $registry->version . ' | CC BY-NC-ND
4.0');
$logging->info('==============================================');
//Read config
$mod->readConfig();
if ($mod->getCV('database', 'databasetype') == 'mysql') {
$dsn = 'mysql:host=' . $mod->getCV('database', 'mysqlhost') . ';port=3306;db
name=' . $mod->getCV('database', 'mysqldatabase') . ';';
$database = new Database($dsn, $mod->getCV('database', 'mysqluser'), $mod->g
etCV('database', 'mysqlpassword'));
} else {
$dsn = 'sqlite:' . $mod->getConfigDir() . 'storage/database.sqlite3';
$database = new Database($dsn);
}
$database->setPrefix($mod->getCV('database', 'prefix'));
$registry->database = $database;
Helper::createTables();
try {
$registry->geoip = new GeoIP();
} catch (GeoIpException $e) {
$logging->warning('GeoIP initialization failed');
}
$registry->jobs = new Jobs();
$mod->registerEvent('everyTime', 'executeJobs', $registry->jobs);
if ($mod->getCV('teamspeak3', 'enabled')) {
try {
$registry->teamspeak3 = new TeamSpeak3($mod->getCV('teamspeak3', 'userna
me'), $mod->getCV('teamspeak3', 'password'), $mod->getCV('teamspeak3', 'ip'), $m
od->getCV('teamspeak3', 'serverqueryport'), $mod->getCV('teamspeak3', 'voiceport
'));

} catch (\Exception $e) {


$logging->warning('TeamSpeak3 initialization failed');
}
}
$registry->permissions = new Permissions();
$registry->api = [];
if ($mod->getCV('api', 'http')['enabled'] === true) {
$registry->api['http'] = new Api('http', $mod->getCV('api', 'http')['port'])
;
}
$game = __NAMESPACE__ . '\\Daemon\\Engine\\' . ucfirst($mod->getEngine()) . '\\L
oop';
$game::init();
//Get playerlist and map from status
$mod->syncPlayerlist(true);
//Get gametype
$mod->updateGametype();
$registry->pluginLoader = new PluginLoader();
new HeartBeat();
$logging->info('== Loading plugins and commands ==');
new Daemon\Libraries\GeoIP\Commands();
new Daemon\Libraries\Permissions\Commands();
new Daemon\Core\Commands();
new Daemon\Libraries\TwoFactorAuth\TwoFactorAuth();
$i = $registry->pluginloader->loadPluginDir('plugins');
$registry->pluginloader->checkDependencies();
$registry->pluginloader->runPlugins();
$logging->info('== Finished loading plugins (' . $i . ' plugins) ==');
//initialisation finished
$logging->info(' !! Finished initialisation');
$logging->info('=== Start processing loglines... ===');
//Stats the Loop
$game::loop();

Vous aimerez peut-être aussi