function GetItemWZInfo($itemid, $locale)
{
    $db = ConnectCharacterDatabase($locale);
    $key_name = 'data_characterwz_cache' . $itemid;
    if (IsCachedObject($key_name, $locale)) {
        return GetCachedObject($key_name, $locale);
    }
    $q = $db->query("\nSELECT\n\t`key`,\n\t`value`\nFROM\n\t`phpvana_characterwz`\nWHERE\n\t`itemid` = " . intval($itemid));
    if ($q->num_rows == 0) {
        return null;
    }
    $item_info = new TreeNode('main');
    $temp = false;
    //$item_info['grouped'] = array();
    while ($data = $q->fetch_row()) {
        if ($data[0] == 'info_vslot') {
            preg_match_all('/../i', $data[1], $matches);
            $data[1] = $matches[0];
        }
        //$item_info[$data[0]] = $data[1];
        $split = explode('_', $data[0]);
        $tmp2 =& $item_info;
        $elements = count($split);
        foreach ($split as $idx => $name) {
            try {
                if (!isset($tmp2[$name])) {
                    if ($elements - 1 == $idx) {
                        // Is last element
                        if (is_string($data[1]) && strpos($data[1], '{VEC}') !== false) {
                            // Is a vector
                            $vec = explode(';', substr($data[1], 5));
                            $temp = new TreeNode($name, $tmp2);
                            $temp['X'] = $vec[0];
                            $temp['Y'] = $vec[1];
                            $tmp2[$name] = $temp;
                        } else {
                            $tmp2[$name] = $data[1];
                        }
                        break;
                    } else {
                        $tmp2[$name] = new TreeNode($name, $tmp2);
                    }
                }
                if ($tmp2[$name] instanceof TreeNode) {
                    $tmp2 =& $tmp2[$name];
                } else {
                    $tmp2 = $tmp2[$name];
                }
            } catch (Exception $ex) {
                return null;
            }
        }
    }
    $item_info['ITEMID'] = $itemid;
    $q->free();
    SetCachedObject($key_name, $item_info, $locale);
    return $item_info;
}
Пример #2
0
function GetMaplerServerInfo()
{
    global $maplerme_servers;
    $result = array();
    if (IsCachedObject('server_info', 'all')) {
        return GetCachedObject('server_info', 'all');
    }
    foreach ($maplerme_servers as $servername => $data) {
        $socket = @fsockopen($data[0], $data[1], $errno, $errstr, 5);
        $data = array('state' => 'offline', 'locale' => '?', 'version' => '?', 'players' => 0);
        if ($socket) {
            $size = fread($socket, 1);
            for ($i = 0; strlen($size) < 1 && $i < 10; $i++) {
                $size = fread($socket, 1);
            }
            if (strlen($size) == 1) {
                $size = ord($size[0]);
                $data = fread($socket, $size);
                for ($i = 0; strlen($data) < $size && $i < 10; $i++) {
                    $data .= fread($socket, $size - strlen($data));
                }
                if (strlen($data) == $size) {
                    $data = unpack('vversion/clocale/Vplayers', $data);
                    $data['state'] = 'online';
                    $cutversion = substr($data['version'], 0, -2) . '.' . substr($data['version'], -2);
                    switch ($data['locale']) {
                        case 2:
                            $data['locale'] = 'Korea';
                            $data['version'] = '1.' . $cutversion;
                            break;
                        case 7:
                            $data['locale'] = 'SEA';
                            $data['version'] = $cutversion;
                            break;
                        case 8:
                            $data['locale'] = 'Global';
                            $data['version'] = $cutversion;
                            break;
                        case 9:
                            $data['locale'] = 'Europe';
                            $data['version'] = $cutversion;
                            break;
                    }
                }
            }
            fclose($socket);
        }
        $result[$servername] = $data;
    }
    SetCachedObject('server_info', $result, 'all', 3);
    return $result;
}