Пример #1
0
function PetStats($house, $species)
{
    global $db;
    $key = 'battlepet_stats_l_' . $species;
    if (($tr = MCGetHouse($house, $key)) !== false) {
        return $tr;
    }
    DBConnect();
    $names = LocaleColumns('i.name');
    $sql = <<<EOF
select i.id, {$names}, i.icon, i.type, i.npc,
s.price, s.quantity, s.lastseen, s.breed
from tblDBCPet i
left join tblPetSummary s on s.house = ? and s.species = i.id
where i.id = ?
EOF;
    $stmt = $db->prepare($sql);
    $stmt->bind_param('ii', $house, $species);
    $stmt->execute();
    $result = $stmt->get_result();
    $tr = DBMapArray($result, array('breed', null));
    foreach ($tr as &$breedRow) {
        $breedRow = array_pop($breedRow);
    }
    unset($breedRow);
    $stmt->close();
    MCSetHouse($house, $key, $tr);
    return $tr;
}
Пример #2
0
function ItemStats($house, $item)
{
    global $db;
    $cacheKey = 'item_stats_b4_' . $item;
    if (($tr = MCGetHouse($house, $cacheKey)) !== false) {
        return $tr;
    }
    DBConnect();
    $localeCols = LocaleColumns('i.name');
    $bonusTags = LocaleColumns('ifnull(group_concat(distinct ind.`desc%1$s` separator \' \'),\'\') bonustag%1$s', true);
    $sql = <<<EOF
select i.id, {$localeCols}, i.icon, i.display, i.class as classid, i.subclass, i.quality, 
i.level, i.stacksize, i.binds, i.buyfromvendor, i.selltovendor, i.auctionable,
s.price, s.quantity, s.lastseen,
ifnull((select group_concat(ils.`level` order by 1 separator ',') from tblItemLevelsSeen ils where ils.item = i.id and ils.bonusset = ifnull(s.bonusset, 0)),'') levels, 
ifnull(s.bonusset,0) bonusset, ifnull(GROUP_CONCAT(distinct bs.tagid ORDER BY 1 SEPARATOR '.'), '') tagurl,
ifnull((select concat_ws(':', nullif(bonus1,0), nullif(bonus2,0), nullif(bonus3,0), nullif(bonus4,0)) 
 FROM `tblItemBonusesSeen` ibs WHERE ibs.item=i.id and ibs.bonusset=s.bonusset order by ibs.observed desc limit 1),'') bonusurl,
{$bonusTags},
ivc.copper vendorprice, ivc.npc vendornpc, ivc.npccount vendornpccount
from tblDBCItem i
left join tblItemSummary s on s.house = %d and s.item = i.id
left join tblBonusSet bs on s.bonusset = bs.`set`
left join tblDBCItemNameDescription ind on ind.id = bs.tagid
left join tblDBCItemVendorCost ivc on ivc.item = i.id
where i.id = %d
group by s.bonusset
EOF;
    $result = $db->query(sprintf($sql, $house, $item), MYSQLI_USE_RESULT);
    $tr = DBMapArray($result, array('bonusset', null));
    foreach ($tr as &$bonusRow) {
        $bonusRow = array_pop($bonusRow);
        $bonusRow['levels'] = explode(',', $bonusRow['levels']);
    }
    unset($bonusRow);
    MCSetHouse($house, $cacheKey, $tr);
    return $tr;
}
Пример #3
0
function GetPetNames($speciesIds, $renamedTo = false)
{
    global $VALID_LOCALES;
    $cacheKeyPrefix = 'petnames_';
    $cacheKeyPrefixLen = strlen($cacheKeyPrefix);
    // assemble memcache keys, and fetch into $names
    $keys = [];
    foreach ($speciesIds as $species) {
        // assumes $speciesIds are unique
        $keys[] = $cacheKeyPrefix . intval($species, 10);
    }
    $names = MCGet($keys);
    // find which keys didn't come back, and fix $names so its keys are bare item IDs
    $keyNames = array_keys($names);
    $missingKeys = array_diff($keys, $keyNames);
    foreach ($keyNames as $keyName) {
        $names[substr($keyName, $cacheKeyPrefixLen)] = $names[$keyName];
        unset($names[$keyName]);
    }
    unset($keyNames);
    if (count($missingKeys)) {
        // split up missing keys into chunks of bare species IDs
        $missingIds = [];
        $chunk = 0;
        $chunkCount = 0;
        foreach ($missingKeys as $missingKey) {
            $missingIds[$chunk][] = substr($missingKey, $cacheKeyPrefixLen);
            if (++$chunkCount >= 100) {
                $chunk++;
                $chunkCount = 0;
            }
        }
        unset($missingKeys, $chunk, $chunkCount);
        // fetch missing IDs, and store them into memcache
        $db = DBConnect();
        $sql = 'select id, ' . LocaleColumns('name') . ' from tblDBCPet where id in (%s)';
        foreach ($missingIds as $missingChunk) {
            $stmt = $db->prepare(sprintf($sql, implode(',', $missingChunk)));
            $stmt->execute();
            $result = $stmt->get_result();
            while ($row = $result->fetch_assoc()) {
                $id = array_shift($row);
                $names[$id] = $row;
                MCSet($cacheKeyPrefix . $id, $names[$id], 86400);
            }
            $result->close();
            $stmt->close();
            foreach ($missingChunk as $id) {
                if (!isset($names[$id])) {
                    // if this id didn't come back from the db
                    foreach ($VALID_LOCALES as $locId) {
                        $names[$id]['name_' . $locId] = 'Species #' . $id;
                    }
                    MCSet($cacheKeyPrefix . $id, $names[$id], 1800);
                }
            }
        }
    }
    if ($renamedTo && $renamedTo != 'name') {
        $keys = array_keys($names);
        foreach ($keys as $key) {
            $names[str_replace('name', $renamedTo, $key)] = $names[$key];
            unset($names[$key]);
        }
    }
    return $names;
}