$allUsersArr = array(); foreach ($allItems as $item) { array_push($allUsersArr, $item['ownerSteamId64']); } $allUserIDsStr = join(',', $allUsersArr); # Get all user info for the steam user IDs $key = getSteamAPIKey(); $usersInfoStr = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={$key}&steamids={$allUserIDsStr}"); $allItemsInPrevGame = array(); foreach ($allItems as $item) { $id = $item['id']; $itemName = $item['itemName']; $itemPrice = $item['itemPrice']; $itemIcon = $item['itemIcon']; $itemOwnerId64 = $item['ownerSteamId64']; $steamUserInfo = getSteamProfileInfoForSteamID($usersInfoStr, $itemOwnerId64); $arr = array('itemID' => $id, 'itemSteamOwnerInfo' => $steamUserInfo, 'itemName' => $itemName, 'itemPrice' => $itemPrice, 'itemIcon' => $itemIcon); array_push($allItemsInPrevGame, $arr); } $allItemsJsonForDB = json_encode($allItemsInPrevGame); # Get the round id, from mostRecentHistory, above $roundId = $mostRecentHistory['id']; # Update the history entry for this round to add all the items and the winner $sql = 'UPDATE history SET winnerSteamId32 = :id32, winnerSteamId64 = :id64, userPutInPrice = :userprice, potPrice = :potprice, allItemsJson = :allitemsjson, date = NOW() WHERE id = :roundid'; $stmt = $db->prepare($sql); $stmt->bindValue(':id32', $winnerSteamId32); $stmt->bindValue(':id64', $winnerSteamId64); $stmt->bindValue(':userprice', $userPrice); $stmt->bindValue(':potprice', $totalPotPrice);
$itemName = $itemInPot['itemName']; if ($itemName[0] === '?') { $itemName = substr($itemName, 2); } $itemPrice = $itemInPot['itemPrice']; $itemIcon = $itemInPot['itemIcon']; $itemRarityColor = $itemInPot['itemRarityColor']; $itemOwnerSteamID = $itemInPot['ownerSteamId64']; $steamUserInfo = getSteamProfileInfoForSteamID($usersInfoStr, $itemOwnerSteamID); $arr = array('itemID' => $itemID, 'itemSteamOwnerInfo' => $steamUserInfo, 'itemName' => $itemName, 'itemPrice' => $itemPrice, 'itemIcon' => $itemIcon, 'itemRarityColor' => $itemRarityColor); array_push($currentPot, $arr); $potPrice += $itemPrice; } # Get the time left in the current round $roundEndTime = is_null($currentRound) ? null : $currentRound['endTime']; $stmt = $db->query('SELECT * FROM history ORDER BY id DESC'); $mostRecentInHistory = $stmt->fetch(); $mostRecentAllItems = $mostRecentInHistory['allItemsJson']; # Get the past pot and check if someone just now won $prevGameID = $prevPot['id']; $winnerSteamId64 = $prevPot['winnerSteamId64']; $userPutInPrice = $prevPot['userPutInPrice']; $prevPotPrice = $prevPot['potPrice']; $allItems = $prevPot['allItemsJson']; $winnerSteamInfo = getSteamProfileInfoForSteamID($usersInfoStr, $winnerSteamId64); $winnerSteamInfo['personaname'] = html_entity_decode($winnerSteamInfo['personaname']); # The information for the previous round $mostRecentGame = array('prevGameID' => $prevGameID, 'winnerSteamInfo' => $winnerSteamInfo, 'userPutInPrice' => $userPutInPrice, 'potPrice' => $prevPotPrice, 'allItems' => $allItems); # The information for the current round $data = array('chat' => $chatMessagesArr, 'pot' => $currentPot, 'potPrice' => $potPrice, 'roundEndTime' => $roundEndTime, 'mostRecentAllItems' => $mostRecentAllItems, 'mostRecentGame' => $mostRecentGame); echo jsonSuccess($data);
$allUserIDsPot = array(); foreach ($currentPotArr as $item) { $steamUserID = $item['ownerSteamUserID']; array_push($allUserIDsPot, $steamUserID); } # Convert array to csv for steam API call $allUserIDsPotStr = join(',', $allUserIDsPot); # Get all user info for the steam user IDs for the pot $potAPIKey = getSteamAPIKey('pot'); $usersInfoStrPot = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={$chatAPIKey}&steamids={$allUserIDsStr}"); $currentPot = array(); $potPrice = 0; foreach ($currentPotArr as $itemInPot) { $itemID = $itemInPot['id']; $itemName = $itemInPot['itemName']; $itemPrice = $itemInPot['itemPrice']; $itemOwnerSteamID = $itemInPot['ownerSteamID']; $steamUserInfo = getSteamProfileInfoForSteamID($usersInfoStrPot, $itemOwnerSteamID); $arr = array('itemID' => $itemID, 'itemSteamOwnerInfo' => $steamUserInfo, 'itemName' => $itemName, 'itemPrice' => $itemPrice); array_push($currentPot, $arr); $potPrice += $itemPrice; } # Get the past pot and check if someone just now won $stmt = $db->query('SELECT * FROM history ORDER BY id DESC'); if ($stmt->rowCount() > 0) { $mostRecentGame = $stmt->fetch(); } else { $mostRecentGame = null; } $data = array('chat' => $chatMessagesArr, 'pot' => $currentPot, 'potPrice' => $potPrice, 'mostRecentGame' => $mostRecentGame); echo jsonSuccess($data);