Esempio n. 1
0
function garenaReconfigure($service_id, $array, $remove = false)
{
    global $config, $garenaConnectionParameters;
    $parameters = garenaGetParameters($service_id);
    //get the identifier
    $id = stripAlphaNumeric(getServiceParam($service_id, "id"));
    if ($id === false) {
        return false;
    }
    //get the existing configuration
    $garenaConfiguration = garenaGetConfiguration($service_id, false);
    //modify the configuration based on input $array settings
    foreach ($array as $k => $v) {
        if (!$remove) {
            if (isset($parameters[$k])) {
                $garenaConfiguration[$k] = garenaEscape($parameters[$k][0], $parameters[$k][1], $parameters[$k][2], $v);
            } else {
                if (($ckey_info = garenaConfigurationConnectionKey($k)) !== false && isset($garenaConnectionParameters[$ckey_info['key']])) {
                    $subkey = $ckey_info['key'];
                    $garenaConfiguration[$k] = garenaEscape($garenaConnectionParameters[$subkey][0], $garenaConnectionParameters[$subkey][1], $garenaConnectionParameters[$subkey][2], $v);
                }
            }
        } else {
            if (isset($garenaConfiguration[$k])) {
                unset($garenaConfiguration[$k]);
            }
        }
    }
    //sort the configuration intelligently
    uksort($garenaConfiguration, 'garenaConfigurationComparator');
    //re-order the configuration so that the connection id's start from 1 and go up incrementally
    $curr_connection_id = 0;
    //the connection id counter
    $seen_connection_id = -1;
    //the last seen connection id from the input
    $reorderedConfiguration = array();
    foreach ($garenaConfiguration as $k => $v) {
        if (($ckey_info = garenaConfigurationConnectionKey($k)) !== false) {
            $connection_id = $ckey_info['id'];
            $subkey = $ckey_info['key'];
            if ($connection_id != $seen_connection_id) {
                $curr_connection_id++;
                $seen_connection_id = $connection_id;
            }
            if ($connection_id != $curr_connection_id) {
                $k = "garena{$curr_connection_id}_{$subkey}";
            }
        }
        $reorderedConfiguration[$k] = $v;
    }
    //sort the configuration intelligently again, just in case?
    uksort($reorderedConfiguration, 'garenaConfigurationComparator');
    //write the configuration out
    $fout = fopen($config['garena_path'] . $id . "/gcb.cfg", 'w');
    foreach ($reorderedConfiguration as $k => $v) {
        fwrite($fout, "{$k} = {$v}\n");
    }
    fclose($fout);
    $jail = jailEnabled($service_id);
    if ($jail) {
        jailFileClose($service_id, "garena", "gcb.cfg", true);
    }
    return true;
}
Esempio n. 2
0
function minecraftDisplayFile($service_id, $filename)
{
    global $config, $minecraftUpdatableFiles;
    //get the identifier
    $id = stripAlphaNumeric(getServiceParam($service_id, "id"));
    if ($id === false) {
        return "Error: failed to load file!";
    }
    if (in_array($filename, $minecraftUpdatableFiles)) {
        $jail = jailEnabled($service_id);
        if ($jail) {
            jailFileOpen($service_id, "minecraft", $filename);
        }
        $str = file_get_contents($config['minecraft_path'] . $id . "/" . $filename);
        if ($jail) {
            jailFileClose($service_id, "minecraft", $filename, false);
        }
        return $str;
    } else {
        return "Error: failed to load file!";
    }
}
Esempio n. 3
0
function ghostDisplayFile($service_id, $filename, $mapcfg = false)
{
    global $config, $updatableFiles;
    //get the identifier
    $id = stripAlphaNumeric(getServiceParam($service_id, "id"));
    if ($id === false) {
        return "Error: failed to load file!";
    }
    if (!$mapcfg && in_array($filename, $updatableFiles)) {
        $jail = jailEnabled($service_id);
        if ($jail) {
            jailFileOpen($service_id, "ghost", $filename);
        }
        $str = file_get_contents($config['ghost_path'] . $id . "/" . $filename);
        if ($jail) {
            jailFileClose($service_id, "ghost", $filename, false);
        }
        return $str;
    } else {
        if ($mapcfg) {
            $filename = escapeFile($filename);
            if (getExtension($filename) != "cfg") {
                return "Error: bad filename. Incident has been reported to administration.";
            }
            $jail = jailEnabled($service_id);
            if ($jail && jailFileExists($service_id, 'mapcfgs/' . $filename) || !$jail && file_exists($config['ghost_path'] . $id . "/mapcfgs/" . $filename)) {
                if ($jail) {
                    jailFileOpen($service_id, "ghost", "mapcfgs/" . $filename);
                }
                $str = file_get_contents($config['ghost_path'] . $id . "/mapcfgs/" . $filename);
                if ($jail) {
                    jailFileClose($service_id, "ghost", "mapcfgs/" . $filename, false);
                }
                return $str;
            } else {
                return "This map configuration file does not exist.";
            }
        } else {
            return "Error: failed to load file!";
        }
    }
}