function garenaStop($service_id, $force = false, $restart = false) { global $config; //get the identifier $id = stripAlphaNumeric(getServiceParam($service_id, "id")); if ($id === false) { return "Error: failed to find identifier. Perhaps this isn't a Garena service?"; } if ($force) { //get the pid $pid = stripAlphaNumeric(getServiceParam($service_id, "pid")); if ($pid === false || $pid == 0) { if ($restart) { return true; } else { return "Error: the bot is already offline."; } } //stop the bot $jail = jailEnabled($service_id); if ($jail) { jailExecute($service_id, "kill {$pid}"); } else { //make sure PID is still of garena $result = exec("cat /proc/{$pid}/cmdline"); if (stripos($result, 'java') !== false) { exec("kill {$pid}"); } } } else { //try to send an rcon stop command $config = garenaGetConfiguration($service_id, false); $fail = true; if (isset($config['gcb_rcon']) && isset($config['rcon_password']) && isset($config['rcon_port']) && ($config['gcb_rcon'] == "true" || $config['gcb_rcon'] == "1")) { $socket = @fsockopen("localhost", $config['rcon_port'], $errno, $errstr, 5); if ($socket) { $status = @fwrite($socket, $config['rcon_password'] . "\n"); if ($status !== false) { fwrite($socket, "exit nicely\n"); sleep(1); socket_close($socket); $fail = false; } } } //if we failed to send, then force stop it if ($fail) { garenaStop($service_id, true, $restart); } } //reset the pid setServiceParam($service_id, "pid", 0); return true; }
function minecraftStop($service_id, $restart = false) { global $config; //get the identifier $id = stripAlphaNumeric(getServiceParam($service_id, "id")); if ($id === false) { return "Error: failed to find identifier. Perhaps this isn't a minecraft service?"; } //make sure we are allowed to stop the bot if (!$restart) { $nostop = getServiceParam($service_id, "nostop"); if ($nostop) { return "Error: you are not allowed to stop this server. Use restart instead."; } } //get the pid $pid = stripAlphaNumeric(getServiceParam($service_id, "pid")); if ($pid === false || $pid == 0) { if ($restart) { return true; } else { return "Error: the server is already offline."; } } //stop the bot $jail = jailEnabled($service_id); if ($jail) { jailExecute($service_id, "kill {$pid}"); } else { //make sure PID is still of pychop $result = exec("cat /proc/{$pid}/cmdline"); if (stripos($result, 'minecraft') !== false) { exec("kill {$pid}"); } } //reset the pid setServiceParam($service_id, "pid", 0); return true; }
function ghostSetDatabase($service_id, $db_settings) { global $config; //get the identifier $id = stripAlphaNumeric(getServiceParam($service_id, "id")); if ($id === false) { return false; } //read/write the configuration file $jail = jailEnabled($service_id); if ($jail) { jailFileOpen($service_id, "ghost", "default.cfg"); } $fin = fopen($config['ghost_path'] . $id . "/default.cfg", 'r'); $fout = fopen($config['ghost_path'] . $id . "/default.cfg_", 'w'); while (($buffer = fgets($fin, 4096)) !== false) { $buffer = trim($buffer); if (strpos($buffer, "db_mysql_database") !== false) { fwrite($fout, "db_mysql_database = {$db_settings['name']}\n"); } else { if (strpos($buffer, "db_mysql_server") !== false) { fwrite($fout, "db_mysql_server = {$db_settings['server']}\n"); } else { if (strpos($buffer, "db_mysql_user") !== false) { fwrite($fout, "db_mysql_user = {$db_settings['username']}\n"); } else { if (strpos($buffer, "db_mysql_password") !== false) { fwrite($fout, "db_mysql_password = {$db_settings['password']}\n"); } else { fwrite($fout, $buffer . "\n"); } } } } } fclose($fin); fclose($fout); rename($config['ghost_path'] . $id . "/default.cfg_", $config['ghost_path'] . $id . "/default.cfg"); if ($jail) { jailFileOpen($service_id, "ghost", "default.cfg", true); } }