# If the most recent round in history has items in it, then the current round doesn't have any items in it, # and there isn't a current round in the history table yet if (strlen($mostRecentRound['allItemsJson']) > 0) { $prevPot = $mostRecentRound; $currentRound = null; } else { $prevPot = $allRounds[1]; $currentRound = $mostRecentRound; } $prevWinner = $prevPot['winnerSteamId64']; $prevWinnerArr = array($prevWinner); # Create array of all users, without repeats $allUsersArr = array_unique(array_merge($allUserIDsChat, $allUserIDsPot, $prevWinnerArr)); $allUserIDsStr = join(',', $allUsersArr); # Get all user info for the steam user IDs $chatAPIKey = getSteamAPIKey(); $usersInfoStr = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={$chatAPIKey}&steamids={$allUserIDsStr}"); $chatMessagesArr = array(); for ($i1 = count($chatMessages) - 1; $i1 >= 0; $i1--) { $message = $chatMessages[$i1]; $id = $message['id']; $text = htmlspecialchars(stripcslashes($message['text'])); $date = $message['date']; $time = $message['time']; $steamUserID = $message['steamUserID']; $steamUserInfo = getSteamProfileInfoForSteamID($usersInfoStr, $steamUserID); $arr = array('id' => $id, 'text' => $text, 'date' => $date, 'time' => $time, 'steamUserInfo' => $steamUserInfo); array_push($chatMessagesArr, $arr); } # Get the current pot $stmt = $db->query('SELECT * FROM currentPot ORDER BY id DESC');
if ($keepPercentage + $itemPercentage >= 0.02 && $keepPercentage < 0.02) { array_push($itemsToKeep, $item); $give = true; continue; } array_push($itemsToKeep, $item); $keepPercentage += $itemPercentage; } # Generate JSON string for all items for database $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'];
function getMemberGroups($id) { $params = array('key' => getSteamAPIKey(), 'steamid' => $id, 'format' => 'json'); $reply = geturl('http://api.steampowered.com/ISteamUser/GetUserGroupList/v0001/', $params); if ($reply == false) { return false; } $details = json_decode($reply, true); return $details['response']; }
$alreadyLoadedCount = isset($_GET['count']) ? $_GET['count'] : null; $alreadyLoadedCount = (int) $alreadyLoadedCount; if ($alreadyLoadedCount === 0) { $sql = 'SELECT * FROM history ORDER BY id DESC LIMIT 0, 11'; } else { $sql = "SELECT * FROM history ORDER BY id DESC LIMIT {$alreadyLoadedCount}, 10"; } $stmt = $db->query($sql); $allRounds = $stmt->fetchAll(); $allUserSteam64Ids = array(); foreach ($allRounds as $round) { $id = $round['winnerSteamId64']; array_push($allUserSteam64Ids, $id); } $allUserSteam64IdsStr = join(',', $allUserSteam64Ids); $apiKey = getSteamAPIKey(); $usersInfoStr = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={$apiKey}&steamids={$allUserSteam64IdsStr}"); $roundsArr = array(); $count = 0; foreach ($allRounds as $round) { if (strlen($round['allItemsJson']) === 0) { continue; } if ($count === 10) { continue; } $count++; $id = $round['id']; $winnerSteamId64 = $round['winnerSteamId64']; $winnerInfo = getSteamProfileInfoForSteamID($usersInfoStr, $winnerSteamId64); $userPutInPrice = $round['userPutInPrice'];
$steamUserInfo = getSteamProfileInfoForSteamID($usersInfoStr, $steamUserID); $arr = array('id' => $id, 'text' => $text, 'date' => $date, 'time' => $time, 'steamUserInfo' => $steamUserInfo); array_push($chatMessagesArr, $arr); } # Get the current pot $stmt = $db->query('SELECT * FROM `currentPot`'); $currentPotArr = $stmt->fetchAll(); $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');