<?php

include_once "../includes/config.php";
if (isset($_SESSION['connected']) && $_SESSION['connected']) {
    //find some status information
    $rcon = new RCon($_SESSION['server'], $_SESSION['port'], $_SESSION['password']);
    $rcon->authenticate();
    $status = $rcon->getStatus();
    echo '({
			"ip": ' . json_encode($status['ip']) . ',
			"hostname": ' . json_encode($status['hostname']) . ',
			"map": ' . json_encode($status['map']) . ',
			"difficulty": ' . json_encode($status['difficulty']) . ',
			"players": ' . json_encode($status['players']) . ',
			"playercount": ' . $status['playercount'] . ',
			"playerinfo": [';
    for ($i = 1; $i <= $status['playercount']; $i++) {
        echo '{
						"id": ' . json_encode($status['player' . $i]['id']) . ',
						"name": ' . json_encode($status['player' . $i]["name"]) . ',
						"uniqid": ' . json_encode($status['player' . $i]["uniqid"]) . ',
						"connected": ' . json_encode($status['player' . $i]["connected"]) . ',
						"ping": ' . json_encode($status['player' . $i]["ping"]) . ',
						"state": ' . json_encode($status['player' . $i]["state"]) . ',
						"ip": ' . json_encode($status['player' . $i]["ip"]) . '
					}';
        if ($i != $status['playercount']) {
            echo ',';
        }
    }
    echo '
Beispiel #2
0
while (list($var, $param) = @each($post_var_list)) {
    if (!empty($_POST[$param]) && strlen(trim($_POST[$param]))) {
        $_POST[$param] = strtolower(trim(addslashes($_POST[$param])));
    } else {
        setError("Connection failed: invalid server/authentication details", "../index.php");
    }
}
//find port from server post var
$serverInfo = explode(":", $_POST['server']);
if (count($serverInfo) < 2 || strlen($serverInfo[1]) < 1) {
    $port = 27015;
} else {
    $port = $serverInfo[1];
}
$_SESSION['server'] = $_POST['server'];
$_SESSION['port'] = $port;
$_SESSION['password'] = $_POST['password'];
$rcon = new RCon($_SESSION['server'], $_SESSION['port'], $_SESSION['password']);
//abort if no connection is possible at all
if ($rcon->_Sock == null) {
    setError("Connection failed: cannot connect to that server", "../index.php");
}
//attempt to authenticate with rcon password
$success = $rcon->authenticate();
if ($success) {
    $_SESSION['connected'] = true;
    setNotice("Connection made", "../index.php");
} else {
    $_SESSION['connected'] = false;
    setError("Connection failed: incorrect rcon password", "../index.php");
}