Beispiel #1
0
function minecraftCommand($service_id, $command)
{
    if (strlen($command > 1000)) {
        return "Error: the entered command is too long!";
    }
    //get the configuration
    $configuration = minecraftGetConfiguration($service_id, false);
    if (isset($configuration['rcon.password']) && isset($configuration['rcon.port'])) {
        $hostname = "localhost";
        if (!empty($configuration['server-ip'])) {
            $hostname = $configuration['server-ip'];
        }
        require_once includePath() . "/rcon.php";
        try {
            $rcon = new RCon($hostname, $configuration['rcon.port'], $configuration['rcon.password']);
        } catch (Exception $e) {
            return "Error: {$e}";
        }
        if ($rcon->Auth()) {
            //allow execution of multiple commands
            if (is_array($command)) {
                foreach ($command as $str) {
                    $rcon->rconCommand($command);
                }
            } else {
                $rcon->rconCommand($command);
            }
            return true;
        } else {
            return "Error: failed to connect and authenticate with Minecraft server (is it online?).";
        }
    } else {
        return "Error: could not find rcon port and password to use.";
    }
}