if($getLastDate['lastUpdated']==$date){ echo 'dates match'; }*/ /*Reads through the tbluser table by row. @@Then Grabs the selected row's steamid and date @@Then Checks the date, if it is null then it will @@add the users friends to the userstable, and the tblusers users gameslist to mongo */ for ($i = 0; $i < $numrows; $i++) { $getLastDate = mysqli_query($db1, "select lastUpdated from tbluser limit {$i},1;"); //select 1 row at index i $userdate = mysqli_fetch_assoc($getLastDate); //echo $userdate["lastUpdated"]; $fetchid = mysqli_query($db1, "select steamid from tbluser limit {$i},1;"); $sid = mysqli_fetch_assoc($fetchid); $steamid = $sid["steamid"]; if ($userdate["lastUpdated"] == null) { if (mysqli_fetch_assoc($getLastDate) != $date) { echo 'dates dont match'; $newDate = "UPDATE tbluser SET lastUpdated='{$date}' WHERE steamid='{$steamid}'"; $sendquery = mysqli_query($db1, $newDate); addFriendsToUsers($steamid); sendMongo($steamid, 2); } //end if1 } //end if0 } //end for } //end while
function showFriends($steamID) { /* @this function will retrieve the users friends list from steam @then it will compare it to our tables. if the friend is in the database @it will pull it from there and display it @otherwise it will add it to the database then pull it. */ $apikey1 = "238E8D6B70BF7499EE36312EF39F91AA"; $pushFriends = "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key={$apikey1}&steamid={$steamID}&relationship=friend"; //echo "addFriends initialized"; //echo $apikey1; $jsonList = file_get_contents($pushFriends); $json_decode = json_decode($jsonList); //echo $json_decode->friendslist->friends[0]->steamid; $db1 = mysqli_connect("localhost", "root", "password", "profile"); if (!mysqli_ping($db1)) { echo 'Lost connection, exiting after query #1'; exit; } //$i=0; $friendArray = array(); foreach ($json_decode->friendslist->friends as $friend) { $friendID = $friend->steamid; //echo $friendID; $sql_fetch_id = "SELECT * FROM users WHERE steamid = {$friendID}"; $query_id = mysqli_query($db1, $sql_fetch_id); //echo $friendID; if (mysqli_num_rows($query_id) > 0) { //echo "true"; $sql_fetch_avatar = "SELECT avatar FROM users WHERE steamid = {$friendID}"; $sql_fetch_id = "SELECT steamid FROM users WHERE steamid = {$friendID}"; $sql_fetch_name = "SELECT name FROM users WHERE steamid = {$friendID}"; $query_avatar = mysqli_query($db1, $sql_fetch_avatar); $row_avatar = mysqli_fetch_assoc($query_avatar); //$query_id= mysqli_query($db1,$sql_fetch_id); //$row_id=mysqli_fetch_assoc($query_id); $query_name = mysqli_query($db1, $sql_fetch_name); $row_name = mysqli_fetch_assoc($query_name); $avatar = $row_avatar["avatar"]; //$fID=$row_avatar["id"]; $fName = $row_name["name"]; array_push($friendArray, $avatar, $fName); //echo "<img src=$avatar>"; //echo "\r\n"; //echo $fName; //echo "<br>"; } else { addFriendsToUsers($steamID); } } return $friendArray; }
function requestProcessor($request) { echo "received request" . PHP_EOL; var_dump($request); if (!isset($request['type'])) { return "ERROR: unsupported message type"; } switch ($request['type']) { case "login": //return doLogin($request['username'],$request['password']); $auth = doLogin($request['username'], $request['password']); if ($auth == true) { return array('hello' => 'world'); } case "validate_session": return doValidate($request['sessionId']); //in case friends this will return a list of friends from //the the steam user, and send it in an array to the client. //in case friends this will return a list of friends from //the the steam user, and send it in an array to the client. case "showFriends": return showFriends($request['steamid']); case "popFri": addFriendsToUsers($request['steamid']); case "add": retrieveUserInfo($request['steamid']); //return array("returnCode" => '0', 'message'=>"Server received request and processed"); } //return array("returnCode" => '0', 'message'=>"Server received request and processed"); }