Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
function jailFileExists($service_id, $filename)
{
    global $config;
    //get the identifier
    $id = stripAlphaNumeric(getServiceParam($service_id, "id"));
    if ($id === false) {
        return;
    }
    $jail_path = getServiceParam($service_id, "jail_path");
    $jail_file = $jail_path . $filename;
    $array = array();
    return jailExecute($service_id, "[ -f " . escapeshellarg($jail_file) . " ] && echo \"1\" || echo \"0\"", $array, "bash") == "1";
}