コード例 #1
0
/**
 * @param announcement  Server announcement string. UTF-8 assumed.
 * @param addr          Remote server address.
 */
function update_server($announcement, $addr)
{
    mb_regex_encoding('UTF-8');
    mb_internal_encoding('UTF-8');
    // First we must determine if the announcement is valid.
    $lines = mb_split("\r\n|\n|\r", $announcement);
    $info = new ServerInfo();
    while (list($line_number, $line) = each($lines)) {
        // Separate the label from the value.
        $colon = strpos($line, ":");
        // It must exist near the beginning.
        if ($colon === false || $colon >= 16) {
            continue;
        }
        $label = substr($line, 0, $colon);
        $value = substr($line, $colon + 1, strlen($line) - $colon - 1);
        if (strlen($value) >= 128) {
            continue;
        }
        // Ensure the label identifies a known property.
        if (isset($info[$label])) {
            // This will be included in the datafile.
            $info[$label] = $value;
        }
    }
    // Also include the remote address.
    $info['at'] = $addr;
    $info['time'] = time();
    // Let's write this info into the datafile.
    write_server($info);
}
コード例 #2
0
function update_server($announcement, $addr)
{
    $info = array();
    // First we must determine if the announcement is valid.
    $lines = split("\n", $announcement);
    while (list($line_number, $line) = each($lines)) {
        // Separate the label from the value.
        $colon = strpos($line, ":");
        // It must exist near the beginning.
        if ($colon === false || $colon >= 16) {
            continue;
        }
        $label = substr($line, 0, $colon);
        $value = substr($line, $colon + 1, strlen($line) - $colon - 1);
        // Let's make sure we know the label.
        if (in_array($label, array("port", "ver", "map", "game", "name", "info", "nump", "maxp", "open", "mode", "setup", "iwad", "pwads", "wcrc", "plrn", "data0", "data1", "data2")) && strlen($value) < 128) {
            // This will be included in the datafile.
            $info[$label] = $value;
        }
    }
    // Also include the remote address.
    $info['at'] = $addr;
    $info['time'] = time();
    // Let's write this info into the datafile.
    write_server($info);
}