Beispiel #1
0
function UpdatePetInfo($house, &$petInfo, $snapshot)
{
    global $db, $maxPacketSize;
    $hour = date('H', $snapshot);
    $dateString = date('Y-m-d', $snapshot);
    $snapshotString = date('Y-m-d H:i:s', $snapshot);
    $sqlStart = 'INSERT INTO tblPetSummary (house, species, breed, price, quantity, lastseen) VALUES ';
    $sqlEnd = ' on duplicate key update quantity=values(quantity), price=if(quantity=0,price,values(price)), lastseen=if(quantity=0,lastseen,values(lastseen))';
    $sql = '';
    $sqlHistoryStart = sprintf('INSERT INTO tblPetHistoryHourly (house, species, breed, `when`, `silver%1$s`, `quantity%1$s`) VALUES ', $hour);
    $sqlHistoryEnd = sprintf(' on duplicate key update `silver%1$s`=if(values(`quantity%1$s`) > ifnull(`quantity%1$s`,0), values(`silver%1$s`), `silver%1$s`), `quantity%1$s`=if(values(`quantity%1$s`) > ifnull(`quantity%1$s`,0), values(`quantity%1$s`), `quantity%1$s`)', $hour);
    $sqlHistory = '';
    foreach ($petInfo as $species => &$breeds) {
        foreach ($breeds as $breed => &$info) {
            $price = GetMarketPrice($info);
            $sqlBit = sprintf('(%d,%u,%u,%u,%u,\'%s\')', $house, $species, $breed, $price, $info['tq'], $snapshotString);
            if (strlen($sql) + strlen($sqlBit) + strlen($sqlEnd) + 5 > $maxPacketSize) {
                DBQueryWithError($db, $sql . $sqlEnd);
                $sql = '';
            }
            $sql .= ($sql == '' ? $sqlStart : ',') . $sqlBit;
            if ($info['tq'] > 0) {
                $sqlHistoryBit = sprintf('(%d,%u,%u,\'%s\',%u,%u)', $house, $species, $breed, $dateString, round($price / 100), $info['tq']);
                if (strlen($sqlHistory) + strlen($sqlHistoryBit) + strlen($sqlHistoryEnd) + 5 > $maxPacketSize) {
                    DBQueryWithError($db, $sqlHistory . $sqlHistoryEnd);
                    $sqlHistory = '';
                }
                $sqlHistory .= ($sqlHistory == '' ? $sqlHistoryStart : ',') . $sqlHistoryBit;
            }
        }
        unset($info);
    }
    unset($breeds);
    if ($sql != '') {
        DBQueryWithError($db, $sql . $sqlEnd);
    }
    if ($sqlHistory != '') {
        DBQueryWithError($db, $sqlHistory . $sqlHistoryEnd);
    }
}
Beispiel #2
0
function WatchSatisfied(&$itemAuctions, $direction, $quantity, $price)
{
    if (is_null($price)) {
        // qty notification
        if ($direction == 'Over' && $itemAuctions[ARRAY_INDEX_QUANTITY] > $quantity || $direction != 'Over' && $itemAuctions[ARRAY_INDEX_QUANTITY] < $quantity) {
            return $itemAuctions[ARRAY_INDEX_QUANTITY];
        }
    } else {
        $curPrice = GetMarketPrice($itemAuctions, $quantity);
        if (is_null($curPrice)) {
            // fewer than $quantity are available
            return false;
        }
        if ($direction == 'Over' && $curPrice > $price || $direction != 'Over' && $curPrice < $price) {
            return $curPrice;
        }
    }
    return false;
}