Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Aseco::addChatCommand('xrestart', 'Restarts XASECO interface (and server, when \"all\" parameter is given)');
- function chat_xrestart($aseco, $command) {
- /**
- * CHANGE THE SETTINGS BELOW IF YOU WISH
- */
- //MUST CHANGE BELOW
- //absolute path to XAseco2.sh
- $xr_xaseco_path = '/home/Fullspeed/Aseco.sh';
- //absolute path to RunSrv.sh
- //$xr_dedi_path = '/home/Fullspeed/';
- //MUST CHANGE ABOVE
- //Change whether MasterAdmins can restart anything.
- $xr_ma_x = true; //Restart XASECO
- //$xr_ma_all = true; //Restart server and XASECO
- //Change whether Admins can restart anything.
- $xr_a_x = false; //Restart XASECO
- //$xr_a_all = false; //Restart server and XASECO
- //Change whether Operators can restart anything.
- $xr_op_x = false; //Restart XASECO
- //$xr_op_all = false; //Restart server and XASECO
- //Change the return line when no parameter is given (restart only XASECO).
- // {1} = Requester name.
- // {2} = Server name.
- $xr_res_x_msg = "{#server}{#highlite}{1}{#error} restarts XASECO!";
- //Change the return line when "all" parameter is given (restart both server and XASECO).
- // {1} = Requester name.
- // {2} = Server name.
- //$xr_res_all_msg = "{#server}{#highlite}{1}{#error} restarts the Server!";
- //Change the return line when wrong parameter is given (error).
- // {1} = Requester name.
- $xr_error = "{#server}{#error}Wrong parameter! Use \"{#highlite}/xrestart{#error}\"!";
- //Change the return line when user has no right to execute the command (error).
- //Note: Comment out to disable error to user (return nothing)
- // {1} = Requester name.
- $xr_user_error = "{#server}{#error}You do not have the permission to use this command!";
- //Show permissions error to normal users (if set to false, only Operators, Admins and MasterAdmins will see error message)
- $xr_user_show = false;
- /**
- * CHANGE THE SETTINGS ABOVE IF YOU WISH
- * DO NOT CHANGE ANYTHING BELOW THIS
- */
- $player = $command['author'];
- $login = $player->login;
- //Nickname of requester.
- $xr_requester = stripColors($player->nickname);
- //Servername
- $xr_servername = stripColors($aseco->server->name);
- //Determine whether player has rights to restart anything.
- if ($aseco->isMasterAdmin($player)) {
- $xr_res_x = $xr_ma_x;
- //$xr_res_all = $xr_ma_all;
- $xr_user = false;
- } else if ($aseco->isAdmin($player)) {
- $xr_res_x = $xr_a_x;
- //$xr_res_all = $xr_a_all;
- $xr_user = false;
- } else if ($aseco->isOperator($player)) {
- $xr_res_x = $xr_op_x;
- //$xr_res_all = $xr_op_all;
- $xr_user = false;
- } else {
- //Disable right for user;
- $xr_res_x = false;
- //$xr_res_all = false;
- $xr_user = true;
- }
- // split params into array
- $arglist = explode(' ', strtolower(preg_replace('/ +/', ' ', $command['params'])));
- //Restart XASECO
- if ($arglist[0] == null) {
- //Requester has permission
- if ($xr_res_x) {
- //Split XASECO filenames and directories from paths
- if (isset($xr_xaseco_path)) {
- $xr_xaseco_path_dir = dirname($xr_xaseco_path);
- $xr_xaseco_path_file = basename($xr_xaseco_path);
- } else {
- $xr_xaseco_path_dir = substr(__DIR__,0,strrpos(__DIR__,'\\'));
- //$xr_xaseco_path_file = "Aseco.bat";
- $xr_xaseco_path_file = "Aseco.sh";
- }
- //Display message to clients
- $message = formatText($xr_res_x_msg,
- $xr_requester,
- $xr_servername);
- $message = $aseco->formatColors($message);
- $aseco->client->query('ChatSendServerMessage', $message);
- //Display message in console
- $aseco->console('{2} restarted XASECO!', $logtitle, $login);
- //execution code for shell
- $xr_exec_code = 'cd '.$xr_xaseco_path_dir.' ; ./'.$xr_xaseco_path_file;
- //Start new instance of XASECO
- exec($xr_exec_code);
- //Shuts down old instance of XASECO
- die();
- //Requester has no permission to restart XASECO.
- } else if (!$xr_user || ($xr_user && $xr_user_show)) {
- //Send error message
- $message = formatText($xr_user_error,
- $xr_requester);
- $message = $aseco->formatColors($message);
- $aseco->client->query('ChatSendServerMessageToLogin', $message, $login);
- }
- }
- /*
- //Restart server
- else if ($arglist[0] == "all") {
- //Requester has permission
- if ($xr_res_all) {
- //Check wether $xr_dedi_path is set
- if (!isset($xr_dedi_path)) {
- $aseco->console('{2} tried to restart both XASECO and server, but $xr_dedi_path has not been set!', $logtitle, $login);
- return;
- }
- //Split XASECO filenames and directories from paths
- if (isset($xr_xaseco_path)) {
- $xr_xaseco_path_dir = dirname($xr_xaseco_path);
- $xr_xaseco_path_file = basename($xr_xaseco_path);
- } else {
- $xr_xaseco_path_dir = substr(__DIR__,0,strrpos(__DIR__,'\\'));
- //$xr_xaseco_path_file = "Aseco.bat";
- $xr_xaseco_path_file = "Server";
- }
- //Split dedicated server filenames and directories from paths
- $xr_dedi_path_dir = dirname($xr_dedi_path);
- $xr_dedi_path_file = basename($xr_dedi_path);
- //Display message to clients
- $message = formatText($xr_res_all_msg,
- $xr_requester,
- $xr_servername);
- $message = $aseco->formatColors($message);
- $aseco->client->query('ChatSendServerMessage', $message);
- //Display message in console
- $aseco->console('{2} restarted XASECO and server!', $logtitle, $login);
- //execution code for shell
- $xr_exec_code = 'cd '.$xr_dedi_path_dir.' ; ./'.$xr_dedi_path_file.' restart';
- //Shuts down old instance of SERVER
- $rtn = $aseco->client->query('StopServer');
- //Start new instances
- exec($xr_exec_code);
- if (!$rtn) {
- trigger_error('[' . $aseco->client->getErrorCode() . '] ' . $aseco->client->getErrorMessage(), E_USER_WARNING);
- die();
- } else {
- // test for /noautoquit
- sleep(2);
- $autoquit = new IXR_ClientMulticall_Gbx();
- if ($autoquit->InitWithIp($aseco->server->ip, $aseco->server->port))
- $aseco->client->query('QuitGame');
- trigger_error('Restart ' . $aseco->server->getGame() . ' server & XASECO!', E_USER_ERROR);
- die();
- }
- //Requester has no permission to restart server.
- } else if (!$xr_user || ($xr_user && $xr_user_show)) {
- //Send error message
- $message = formatText($xr_user_error,
- $xr_requester);
- $message = $aseco->formatColors($message);
- $aseco->client->query('ChatSendServerMessageToLogin', $message, $login);
- }
- //Wrong parameter
- } else if (!$xr_user || ($xr_user && $xr_user_show)) {
- //Send error message
- $message = formatText($xr_error,
- $xr_requester);
- $message = $aseco->formatColors($message);
- $aseco->client->query('ChatSendServerMessageToLogin', $message, $login);
- }*/
- } // chat_xrestart
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement