Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.47 KB | None | 0 0
  1. <?php
  2.  
  3. Aseco::addChatCommand('xrestart', 'Restarts XASECO interface (and server, when \"all\" parameter is given)');
  4.  
  5. function chat_xrestart($aseco, $command) {
  6.  
  7. /**
  8. * CHANGE THE SETTINGS BELOW IF YOU WISH
  9. */
  10.  
  11. //MUST CHANGE BELOW
  12.  
  13. //absolute path to XAseco2.sh
  14. $xr_xaseco_path = '/home/Fullspeed/Aseco.sh';
  15.  
  16. //absolute path to RunSrv.sh
  17. //$xr_dedi_path = '/home/Fullspeed/';
  18.  
  19.  
  20. //MUST CHANGE ABOVE
  21.  
  22. //Change whether MasterAdmins can restart anything.
  23. $xr_ma_x = true; //Restart XASECO
  24. //$xr_ma_all = true; //Restart server and XASECO
  25.  
  26. //Change whether Admins can restart anything.
  27. $xr_a_x = false; //Restart XASECO
  28. //$xr_a_all = false; //Restart server and XASECO
  29.  
  30. //Change whether Operators can restart anything.
  31. $xr_op_x = false; //Restart XASECO
  32. //$xr_op_all = false; //Restart server and XASECO
  33.  
  34. //Change the return line when no parameter is given (restart only XASECO).
  35. // {1} = Requester name.
  36. // {2} = Server name.
  37. $xr_res_x_msg = "{#server}{#highlite}{1}{#error} restarts XASECO!";
  38.  
  39. //Change the return line when "all" parameter is given (restart both server and XASECO).
  40. // {1} = Requester name.
  41. // {2} = Server name.
  42. //$xr_res_all_msg = "{#server}{#highlite}{1}{#error} restarts the Server!";
  43.  
  44. //Change the return line when wrong parameter is given (error).
  45. // {1} = Requester name.
  46. $xr_error = "{#server}{#error}Wrong parameter! Use \"{#highlite}/xrestart{#error}\"!";
  47.  
  48. //Change the return line when user has no right to execute the command (error).
  49. //Note: Comment out to disable error to user (return nothing)
  50. // {1} = Requester name.
  51. $xr_user_error = "{#server}{#error}You do not have the permission to use this command!";
  52.  
  53. //Show permissions error to normal users (if set to false, only Operators, Admins and MasterAdmins will see error message)
  54. $xr_user_show = false;
  55.  
  56. /**
  57. * CHANGE THE SETTINGS ABOVE IF YOU WISH
  58. * DO NOT CHANGE ANYTHING BELOW THIS
  59. */
  60.  
  61. $player = $command['author'];
  62. $login = $player->login;
  63.  
  64. //Nickname of requester.
  65. $xr_requester = stripColors($player->nickname);
  66.  
  67. //Servername
  68. $xr_servername = stripColors($aseco->server->name);
  69.  
  70. //Determine whether player has rights to restart anything.
  71. if ($aseco->isMasterAdmin($player)) {
  72. $xr_res_x = $xr_ma_x;
  73. //$xr_res_all = $xr_ma_all;
  74. $xr_user = false;
  75. } else if ($aseco->isAdmin($player)) {
  76. $xr_res_x = $xr_a_x;
  77. //$xr_res_all = $xr_a_all;
  78. $xr_user = false;
  79. } else if ($aseco->isOperator($player)) {
  80. $xr_res_x = $xr_op_x;
  81. //$xr_res_all = $xr_op_all;
  82. $xr_user = false;
  83. } else {
  84. //Disable right for user;
  85. $xr_res_x = false;
  86. //$xr_res_all = false;
  87. $xr_user = true;
  88. }
  89.  
  90. // split params into array
  91. $arglist = explode(' ', strtolower(preg_replace('/ +/', ' ', $command['params'])));
  92.  
  93. //Restart XASECO
  94. if ($arglist[0] == null) {
  95.  
  96. //Requester has permission
  97. if ($xr_res_x) {
  98.  
  99. //Split XASECO filenames and directories from paths
  100. if (isset($xr_xaseco_path)) {
  101. $xr_xaseco_path_dir = dirname($xr_xaseco_path);
  102. $xr_xaseco_path_file = basename($xr_xaseco_path);
  103. } else {
  104. $xr_xaseco_path_dir = substr(__DIR__,0,strrpos(__DIR__,'\\'));
  105. //$xr_xaseco_path_file = "Aseco.bat";
  106. $xr_xaseco_path_file = "Aseco.sh";
  107. }
  108.  
  109. //Display message to clients
  110. $message = formatText($xr_res_x_msg,
  111. $xr_requester,
  112. $xr_servername);
  113. $message = $aseco->formatColors($message);
  114. $aseco->client->query('ChatSendServerMessage', $message);
  115.  
  116. //Display message in console
  117. $aseco->console('{2} restarted XASECO!', $logtitle, $login);
  118.  
  119. //execution code for shell
  120. $xr_exec_code = 'cd '.$xr_xaseco_path_dir.' ; ./'.$xr_xaseco_path_file;
  121.  
  122.  
  123. //Start new instance of XASECO
  124. exec($xr_exec_code);
  125. //Shuts down old instance of XASECO
  126. die();
  127.  
  128.  
  129. //Requester has no permission to restart XASECO.
  130. } else if (!$xr_user || ($xr_user && $xr_user_show)) {
  131. //Send error message
  132. $message = formatText($xr_user_error,
  133. $xr_requester);
  134. $message = $aseco->formatColors($message);
  135. $aseco->client->query('ChatSendServerMessageToLogin', $message, $login);
  136. }
  137.  
  138. }
  139. /*
  140. //Restart server
  141. else if ($arglist[0] == "all") {
  142.  
  143. //Requester has permission
  144. if ($xr_res_all) {
  145.  
  146. //Check wether $xr_dedi_path is set
  147. if (!isset($xr_dedi_path)) {
  148. $aseco->console('{2} tried to restart both XASECO and server, but $xr_dedi_path has not been set!', $logtitle, $login);
  149. return;
  150. }
  151. //Split XASECO filenames and directories from paths
  152. if (isset($xr_xaseco_path)) {
  153. $xr_xaseco_path_dir = dirname($xr_xaseco_path);
  154. $xr_xaseco_path_file = basename($xr_xaseco_path);
  155. } else {
  156. $xr_xaseco_path_dir = substr(__DIR__,0,strrpos(__DIR__,'\\'));
  157. //$xr_xaseco_path_file = "Aseco.bat";
  158. $xr_xaseco_path_file = "Server";
  159. }
  160. //Split dedicated server filenames and directories from paths
  161. $xr_dedi_path_dir = dirname($xr_dedi_path);
  162. $xr_dedi_path_file = basename($xr_dedi_path);
  163.  
  164. //Display message to clients
  165. $message = formatText($xr_res_all_msg,
  166. $xr_requester,
  167. $xr_servername);
  168. $message = $aseco->formatColors($message);
  169. $aseco->client->query('ChatSendServerMessage', $message);
  170.  
  171. //Display message in console
  172. $aseco->console('{2} restarted XASECO and server!', $logtitle, $login);
  173.  
  174.  
  175. //execution code for shell
  176.  
  177. $xr_exec_code = 'cd '.$xr_dedi_path_dir.' ; ./'.$xr_dedi_path_file.' restart';
  178.  
  179. //Shuts down old instance of SERVER
  180. $rtn = $aseco->client->query('StopServer');
  181.  
  182. //Start new instances
  183. exec($xr_exec_code);
  184.  
  185.  
  186. if (!$rtn) {
  187. trigger_error('[' . $aseco->client->getErrorCode() . '] ' . $aseco->client->getErrorMessage(), E_USER_WARNING);
  188. die();
  189. } else {
  190. // test for /noautoquit
  191. sleep(2);
  192. $autoquit = new IXR_ClientMulticall_Gbx();
  193. if ($autoquit->InitWithIp($aseco->server->ip, $aseco->server->port))
  194. $aseco->client->query('QuitGame');
  195.  
  196. trigger_error('Restart ' . $aseco->server->getGame() . ' server & XASECO!', E_USER_ERROR);
  197. die();
  198. }
  199.  
  200. //Requester has no permission to restart server.
  201. } else if (!$xr_user || ($xr_user && $xr_user_show)) {
  202. //Send error message
  203. $message = formatText($xr_user_error,
  204. $xr_requester);
  205. $message = $aseco->formatColors($message);
  206. $aseco->client->query('ChatSendServerMessageToLogin', $message, $login);
  207. }
  208.  
  209. //Wrong parameter
  210. } else if (!$xr_user || ($xr_user && $xr_user_show)) {
  211. //Send error message
  212. $message = formatText($xr_error,
  213. $xr_requester);
  214. $message = $aseco->formatColors($message);
  215. $aseco->client->query('ChatSendServerMessageToLogin', $message, $login);
  216. }*/
  217.  
  218. } // chat_xrestart
  219. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement