Last active
August 24, 2016 20:15
-
-
Save fr34kyn01535/8bdee9d6ac6bf86de9111133302b67cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Requirements: php-redis | |
*/ | |
if(php_sapi_name() != 'cli') die(); | |
define("REDIS_HOST","bespin.bam.yt"); | |
define("STEAM_API_KEY",$argv[1]); | |
define("REDIS_AUTH",$argv[2]); | |
if(isset($argv[3])){ | |
define("IP",$argv[3]); | |
} | |
echo("Connecting on ".STEAM_API_KEY."@".REDIS_HOST." using: ".STEAM_API_KEY."\n\n"); | |
reconnect(); | |
function curl_get_contents($url){ | |
$s = curl_init(); | |
curl_setopt($s,CURLOPT_URL,$url); | |
curl_setopt($s, CURLOPT_HEADER, 0); | |
curl_setopt($s, CURLOPT_RETURNTRANSFER, true); | |
if(defined("IP")) | |
curl_setopt($s, CURLOPT_INTERFACE, IP) ; | |
$response = curl_exec($s); | |
curl_close($s); | |
return $response; | |
} | |
function reconnect(){ | |
global $redisi, $redisp; | |
$redisi = new Redis(); | |
$redisi->pconnect(REDIS_HOST, 6379, 2.5, 'ids'); | |
$redisi->auth(REDIS_AUTH); | |
$redisi->select(3); | |
$redisp = new Redis(); | |
$redisp->pconnect(REDIS_HOST, 6379, 2.5, 'profiles'); | |
$redisp->auth(REDIS_AUTH); | |
$redisp->select(0); | |
} | |
function updateProfile($steamID){ | |
global $redisp; | |
if(!$steamID) return false; | |
if(strlen($steamID) != 17 || !is_numeric($steamID)) return false; | |
$result = getProfileSync($steamID); | |
$result->lastUpdate = time(); | |
$redisp->set($steamID,$result); | |
if(isset($result->profile->isLimitedAccount) && $result->profile->isLimitedAccount == 1){ | |
echo " [LIMITED]"; | |
$redisp->setTimeout($steamID, 86400); | |
}else if(count($result->profile["steamID"]) == 0){ | |
echo " [NO PROFILE]"; | |
$redisp->setTimeout($steamID, 86400); | |
} | |
else{ | |
$redisp->setTimeout($steamID, 604800); | |
} | |
} | |
function getProfileSync($steamID){ | |
$profile = new stdClass; | |
$profile->meta = @json_decode(@curl_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".STEAM_API_KEY."&steamids=$steamID&format=json"))->response->players[0]; | |
$profile->profile = @json_decode(@json_encode(simplexml_load_string(curl_get_contents("http://steamcommunity.com/profiles/$steamID?xml=1"), "SimpleXMLElement", LIBXML_NOCDATA)),true); | |
$profile->playtime = @json_decode(@curl_get_contents("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=".STEAM_API_KEY."&steamid=$steamID&format=json"))->response; | |
$profile->level = @json_decode(@curl_get_contents("http://api.steampowered.com/IPlayerService/GetSteamLevel/v1/?key=".STEAM_API_KEY."&steamid=$steamID&format=json"))->response; | |
$profile->bans = @json_decode(@curl_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=".STEAM_API_KEY."&steamids=$steamID&format=json"))->players[0]; | |
preg_match("/has_profile_background \" style=\"background-image: url\\( '(.*)'/i", curl_get_contents("http://steamcommunity.com/profiles/".$steamID), $matches); | |
if(count($matches) != 0) | |
$profile->background = $matches[1]; | |
$profile->unturned = @json_decode(@curl_get_contents("http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=304930&key=".STEAM_API_KEY."&steamid=$steamID&format=json")); | |
return $profile; | |
} | |
while(true){ | |
try { | |
$profile = $redisi->randomKey(); | |
if($profile){ | |
echo("+ ".$profile); | |
$redisi->delete($profile); | |
updateProfile($profile); | |
echo("\n"); | |
} | |
} catch (Exception $e) { | |
echo 'Exception: ', $e->getMessage(), "\n"; | |
echo "Reconnecting...\n"; | |
reconnect(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wget https://gist.githubusercontent.com/fr34kyn01535/8bdee9d6ac6bf86de9111133302b67cf/raw/profiles.php --no-cache -qO profiles.php && php profiles.php <STEAM API KEY> <REDIS AUTH>