예제 #1
0
function MCSetHouse($house, $key, $val, $expire = 10800)
{
    global $memcache;
    $prefix = '';
    if ($key != 'ts') {
        $prefix = MCGetHouse($house) . '_';
    }
    $fullKey = 'h' . $house . '_' . $prefix . $key;
    return $memcache->set($fullKey, $val, 0, $expire);
}
예제 #2
0
function TransmogGenericItemList($house, $params)
{
    global $db, $canCache;
    $key = 'transmog_gi2_' . md5(json_encode($params));
    if ($canCache && ($tr = MCGetHouse($house, $key)) !== false) {
        return $tr;
    }
    DBConnect();
    if (is_array($params)) {
        $joins = isset($params['joins']) ? $params['joins'] : '';
        $where = isset($params['where']) ? ' and ' . $params['where'] : '';
        $group = isset($params['group']) ? array_merge($params['group'], [false]) : null;
    } else {
        $joins = '';
        $group = null;
        $where = $params == '' ? '' : ' and ' . $params;
    }
    $sql = <<<EOF
select ab.id, ab.display, ab.buy, ab.class, ab.subclass, ifnull(ab.type, -1 & ab.subclass) `type`, ab.subclassname
from (
    select aa.*, if(@previd = aa.display, 0, @previd := aa.display) previd
    from (select @previd := 0) aasetup, (
        SELECT i.id, i.display, a.buy, i.class, i.subclass, i.type, concat_ws('-', i.class, i.subclass) subclassname
        FROM `tblDBCItem` i
        join tblAuction a on a.item=i.id
        {$joins}
        WHERE i.auctionable=1
        and i.quality > 1
        {$where}
        and i.display is not null
        and i.flags & 2 = 0
        and a.house = ?
        and a.buy > 0
        order by i.display, a.buy) aa
    ) ab
where ab.previd > 0
EOF;
    $stmt = $db->prepare($sql);
    if (!$stmt) {
        DebugMessage("Bad SQL: \n" . $sql, E_USER_ERROR);
    }
    $stmt->bind_param('i', $house);
    $stmt->execute();
    $result = $stmt->get_result();
    $tr = DBMapArray($result, $group);
    $stmt->close();
    MCSetHouse($house, $key, $tr);
    return $tr;
}
예제 #3
0
function PetAuctions($house, $species)
{
    global $db;
    $key = 'battlepet_auctions2_' . $species;
    if (($tr = MCGetHouse($house, $key)) !== false) {
        return $tr;
    }
    DBConnect();
    $sql = <<<EOF
SELECT ap.breed, quantity, bid, buy, ap.level, ap.quality, s.realm sellerrealm, ifnull(s.name, '???') sellername
FROM `tblAuction` a
JOIN `tblAuctionPet` ap on a.house = ap.house and a.id = ap.id
left join tblSeller s on a.seller=s.id
WHERE a.house=? and a.item=82800 and ap.species=?
EOF;
    $stmt = $db->prepare($sql);
    $stmt->bind_param('ii', $house, $species);
    $stmt->execute();
    $result = $stmt->get_result();
    $tr = DBMapArray($result, array('breed', null));
    $stmt->close();
    MCSetHouse($house, $key, $tr);
    return $tr;
}
예제 #4
0
파일: house.php 프로젝트: erorus/newsstand
function HouseBotSellers($house)
{
    global $db;
    $cacheKey = 'house_botsellers';
    if (($tr = MCGetHouse($house, $cacheKey)) !== false) {
        return $tr;
    }
    DBConnect();
    $items = '128159, 127736, 127738, 127732, 127731, 127737, 127735, 127730, 127734, 127733, 127718, 128158, 127720, 127714, 127713, 127719, 127717, 127712, 127716, 127715';
    $sql = <<<'EOF'
select s.realm, s.name
from (
    select seller, count(distinct `snapshot`) cnt
    from (
        SELECT sih.seller, sih.item, sih.`snapshot`
        FROM `tblSellerItemHistory` sih
        join tblSeller s on sih.seller = s.id
        join tblRealm r on s.realm = r.id
        where r.house = ?
        and sih.item in (%1$s)
        and s.firstseen > timestampadd(day, -14, now())
    ) z1
    group by seller
    having count(distinct item) >= 4
) z2
join tblSeller s on s.id = z2.seller
left join tblSellerItemHistory h on h.seller = z2.seller and h.item not in (%1$s)
where h.seller is null
and z2.cnt >= 3
and s.lastseen > timestampadd(hour, -48, now())
order by s.lastseen desc
limit 20
EOF;
    $stmt = $db->prepare(sprintf($sql, $items));
    $stmt->bind_param('i', $house);
    $stmt->execute();
    $result = $stmt->get_result();
    $tr = $result->fetch_all(MYSQLI_ASSOC);
    $stmt->close();
    MCSetHouse($house, $cacheKey, $tr);
    return $tr;
}
예제 #5
0
function CategoryDealsItemListCached($house, $iidList, $flags)
{
    if (count($iidList) == 0) {
        return array();
    }
    $auctionIds = [];
    $sortBy = [];
    $sql = '(';
    foreach ($iidList as $row) {
        $sql .= (strlen($sql) == 1 ? '' : ' or ') . '(i.id = ' . $row['item'] . ' and s.bonusset = ' . $row['bonusset'] . ')';
        $itemKey = $row['item'] . ':' . $row['bonusset'];
        $sortBy[] = $itemKey;
        if (isset($row['cheapestid'])) {
            $auctionIds[$itemKey] = $row['cheapestid'];
        }
    }
    $sql .= ')';
    $sortBy = array_flip($sortBy);
    if ($flags & CATEGORY_FLAGS_WITH_BONUSES) {
        $tr = CategoryBonusItemList($house, ['where' => $sql, 'cols' => 'g.median globalmedian', 'outside' => 'r2.globalmedian']);
    } else {
        $tr = CategoryRegularItemList($house, ['where' => $sql, 'cols' => 'g.median globalmedian']);
    }
    usort($tr, function ($a, $b) use($sortBy) {
        return $sortBy[$a['id'] . ':' . $a['bonusset']] - $sortBy[$b['id'] . ':' . $b['bonusset']];
    });
    static $allRecentDates = [];
    if (isset($allRecentDates[$house])) {
        $recentDates = $allRecentDates[$house];
    } else {
        $recentDates = MCGetHouse($house, 'category_disnapshots');
        if ($recentDates === false) {
            $db = DBConnect();
            $stmt = $db->stmt_init();
            $stmt->prepare('SELECT unix_timestamp(updated) upd, maxid FROM `tblSnapshot` WHERE house=? and updated > timestampadd(hour, -60, now()) order by updated');
            $stmt->bind_param('i', $house);
            $stmt->execute();
            $result = $stmt->get_result();
            $recentDates = DBMapArray($result, null);
            $stmt->close();
            MCSetHouse($house, 'category_disnapshots', $recentDates);
        }
        $allRecentDates[$house] = $recentDates;
    }
    if (count($recentDates) < 2) {
        return $tr;
    }
    $rolloverBump = 0;
    if ($recentDates[count($recentDates) - 1]['maxid'] < $recentDates[0]['maxid']) {
        $rolloverBump = 0x80000000;
    }
    foreach ($tr as &$row) {
        $row['posted'] = null;
        $itemKey = $row['id'] . ':' . $row['bonusset'];
        if (!isset($auctionIds[$itemKey])) {
            continue;
        }
        $myId = $auctionIds[$itemKey];
        if ($myId < 0x20000000) {
            $myId += $rolloverBump;
        }
        $x = count($recentDates) - 1;
        do {
            $maxId = $recentDates[$x]['maxid'];
            if ($maxId < 0x20000000) {
                $maxId += $rolloverBump;
            }
            if ($maxId < $myId) {
                break;
            }
            $row['posted'] = $recentDates[$x]['upd'];
        } while (--$x >= 0);
    }
    unset($row);
    return $tr;
}
예제 #6
0
파일: search.php 프로젝트: erorus/newsstand
require_once '../../incl/incl.php';
require_once '../../incl/memcache.incl.php';
require_once '../../incl/api.incl.php';
if (!isset($_GET['house']) || !isset($_GET['search'])) {
    json_return(array());
}
$house = intval($_GET['house'], 10);
$search = mb_strtolower(substr(trim($_GET['search'], " \t\n\r[]"), 0, 50));
if ($search == '') {
    json_return(array());
}
BotCheck();
HouseETag($house);
$locale = GetLocale();
$searchCacheKey = 'search_b2_' . $locale . '_' . md5($search);
if ($json = MCGetHouse($house, $searchCacheKey)) {
    PopulateLocaleCols($json['battlepets'], [['func' => 'GetPetNames', 'key' => 'id', 'name' => 'name']]);
    PopulateLocaleCols($json['items'], [['func' => 'GetItemNames', 'key' => 'id', 'name' => 'name'], ['func' => 'GetItemBonusTagsByTag', 'key' => 'tagurl', 'name' => 'bonustag']]);
    json_return($json);
}
DBConnect();
$json = array('items' => SearchItems($house, $search, $locale), 'sellers' => SearchSellers($house, $search), 'battlepets' => SearchBattlePets($house, $search, $locale));
$ak = array_keys($json);
foreach ($ak as $k) {
    if (count($json[$k]) == 0) {
        unset($json[$k]);
    }
}
MCSetHouse($house, $searchCacheKey, $json);
PopulateLocaleCols($json['battlepets'], [['func' => 'GetPetNames', 'key' => 'id', 'name' => 'name']]);
PopulateLocaleCols($json['items'], [['func' => 'GetItemNames', 'key' => 'id', 'name' => 'name'], ['func' => 'GetItemBonusTagsByTag', 'key' => 'tagurl', 'name' => 'bonustag']]);
예제 #7
0
파일: seller.php 프로젝트: erorus/newsstand
function SellerPetAuctions($house, $seller)
{
    $cacheKey = 'seller_petauctions_' . $seller;
    if (($tr = MCGetHouse($house, $cacheKey)) !== false) {
        PopulateLocaleCols($tr, [['func' => 'GetPetNames', 'key' => 'species', 'name' => 'name']], true);
        return $tr;
    }
    $db = DBConnect();
    $sql = <<<EOF
SELECT ap.species, ap.breed, quantity, bid, buy, ap.level, ap.quality, p.icon, p.type, p.npc,
(SELECT ifnull(sum(quantity),0)
from tblAuctionPet ap2
join tblAuction a2 on a2.house = ap2.house and a2.id = ap2.id
where ap2.house=a.house and ap2.species = ap.species and ap2.level >= ap.level and
((a.buy > 0 and a2.buy > 0 and (a2.buy / a2.quantity < a.buy / a.quantity)) or (a.buy = 0 and (a2.bid / a2.quantity < a.bid / a.quantity)))) cheaper
FROM `tblAuction` a
JOIN `tblAuctionPet` ap on a.house = ap.house and a.id = ap.id
JOIN `tblDBCPet` `p` on `p`.`id` = `ap`.`species`
WHERE a.house = ? and a.seller = ? and a.item = 82800
EOF;
    $stmt = $db->prepare($sql);
    $stmt->bind_param('ii', $house, $seller);
    $stmt->execute();
    $result = $stmt->get_result();
    $tr = $result->fetch_all(MYSQLI_ASSOC);
    $result->close();
    $stmt->close();
    MCSetHouse($house, $cacheKey, $tr);
    PopulateLocaleCols($tr, [['func' => 'GetPetNames', 'key' => 'species', 'name' => 'name']], true);
    return $tr;
}
예제 #8
0
파일: item.php 프로젝트: erorus/newsstand
function ItemAuctions($house, $item)
{
    global $db;
    $cacheKey = 'item_auctions_lb3_' . $item;
    if (($tr = MCGetHouse($house, $cacheKey)) !== false) {
        foreach ($tr as &$rows) {
            PopulateLocaleCols($rows, [['func' => 'GetItemBonusNames', 'key' => 'bonuses', 'name' => 'bonusname'], ['func' => 'GetItemBonusTags', 'key' => 'bonuses', 'name' => 'bonustag'], ['func' => 'GetRandEnchantNames', 'key' => 'rand', 'name' => 'randname']], true);
        }
        unset($rows);
        return $tr;
    }
    DBConnect();
    $sql = <<<EOF
SELECT ifnull(ae.bonusset,0) bonusset, a.quantity, a.bid, a.buy, ifnull(ae.`rand`,0) `rand`, ifnull(ae.seed,0) `seed`, 
ifnull(@lootedLevel := ae.lootedlevel,0) `lootedlevel`, ifnull(ae.level, i.level) level,
s.realm sellerrealm, ifnull(s.name, '???') sellername,
concat_ws(':',ae.bonus1,ae.bonus2,ae.bonus3,ae.bonus4,ae.bonus5,ae.bonus6) bonuses
FROM `tblAuction` a
join tblDBCItem i on a.item=i.id
left join tblSeller s on a.seller=s.id
left join tblAuctionExtra ae on ae.house=a.house and ae.id=a.id
left join tblDBCRandEnchants re on re.id = ae.rand
WHERE a.house=? and a.item=?
group by a.id
EOF;
    $stmt = $db->prepare($sql);
    $stmt->bind_param('ii', $house, $item);
    $stmt->execute();
    $result = $stmt->get_result();
    $tr = DBMapArray($result, array('bonusset', null));
    $stmt->close();
    MCSetHouse($house, $cacheKey, $tr);
    foreach ($tr as &$rows) {
        PopulateLocaleCols($rows, [['func' => 'GetItemBonusNames', 'key' => 'bonuses', 'name' => 'bonusname'], ['func' => 'GetItemBonusTags', 'key' => 'bonuses', 'name' => 'bonustag'], ['func' => 'GetRandEnchantNames', 'key' => 'rand', 'name' => 'randname']], true);
    }
    unset($rows);
    return $tr;
}
예제 #9
0
function HouseETag($house, $includeFetches = false)
{
    $curTag = $includeFetches ? MCGet('housecheck_' . $house) : '';
    if ($curTag === false) {
        $curTag = 'x';
    }
    $curTag = 'W/"' . MCGetHouse($house) . $curTag . '"';
    $theirTag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : '';
    if ($curTag && $curTag == $theirTag) {
        header('HTTP/1.1 304 Not Modified');
        exit;
    }
    header('ETag: ' . $curTag);
}