-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
186 lines (166 loc) · 5.86 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
require_once('config.php');
// Page to compare owned Steam games for users to find something to play...
if( ($_SERVER['REQUEST_METHOD'] == "GET") and (strlen($_GET['SteamNames']) > 1))
{ // Let's go ahead and grab user info and go from there...
$AllUsers = array();
$AllGames = array();
$Users = explode(",",$_GET['SteamNames']);
foreach($Users as $SteamName)
{
$ch = curl_init("http://steamcommunity.com/id/".$SteamName."/?xml=1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HEADER, 0);
$Output = curl_exec($ch);
$p = xml_parser_create();
xml_parse_into_struct($p, $Output, $Vals, $index);
$SteamID64 = $Vals[ $index['STEAMID64'][0] ]['value'];
echo $SteamName.": Steam ID is ".$SteamID64."<br/>";
// Now we have the 64bit SteamID. We should go and
$SteamGamesOwned = pullAllSteamGames($SteamID64, $SteamAPIKey);
//print_r($SteamGamesOwned);
$SteamGames = parseSteamGames($SteamGamesOwned);
//print_r($SteamGames);
//
//Now we should pack this into the earlier array and move on.
$AllUsers[] = array("SteamName" => $SteamName, "SteamID" => $SteamID64, "Games" => $SteamGames);
curl_close($ch);
flush();
}
//print_r($AllUsers);
echo "Beginning analysis of games for ".count($AllUsers)." people....<br/>";
flush();
// Now that we have arrays with all of the games, we'll need to compare them...
$TempGames = $AllUsers[0]['Games'];
for($i = 1; $i < count($AllUsers); $i++)
{ // Compare keys between the first user and all other users.
echo " Comparing ".$AllUsers[0]['SteamName']." to ".$AllUsers[$i]['SteamName']."...<br/>";
$KeysToRemove = array_diff_key($TempGames, $AllUsers[$i]['Games']);
echo " We started with ".count($TempGames)." eligible games and are removing ".count($KeysToRemove).", resulting in ". (count($TempGames)-count($KeysToRemove))." games overall.<br/>";
//print_r($KeysToRemove);
foreach($KeysToRemove as $k => $v)
{
unset($TempGames[$k]);
}
}
//Remove any games that aren't multiplayer
echo "Removing single player only games:<br/>";
flush();
foreach($TempGames as $GameID => $Gametime)
{
$GameInfo = parseApp($GameID);
$GameInfo['name'] = preg_replace("/[^A-Za-z0-9 ]/", '', $GameInfo['name']);
$MetaInfo = $GameInfo['categories'];
$IsMulti = FALSE;
foreach($MetaInfo as $InfoArr)
{
if($InfoArr['description'] == 'Multi-player')
{
$IsMulti = TRUE;
}
if($InfoArr['description'] == 'Co-op')
{
$IsMulti = TRUE;
}
}
// We need to search to see if it has multiplayer. If it doesn't? Don't play it.
if($IsMulti)
{
$AllGames[$GameID] = $GameInfo;
}
else
{
echo " ".$GameInfo['name']."<br/>";
unset($TempGames[$GameID]);
}
flush();
}
echo "After removing non-multiplayer games, we have ".count($TempGames)." games left.<br/>";
//Now we have all of the games sorted out
echo "Games have been analyzed. Determining best games to play...<br/>";
echo " Most popular 5 games:<br/>";
//print_r($TempGames);
$SortedGametime = sumGametime($TempGames, $AllUsers);
//Now get the top 5 app info...
$Keys = array_keys($SortedGametime);
//print_r($Keys);
$GamesFound = 0;
$i = 0;
while( ($GamesFound < 5) and ($i < count($SortedGametime)))
{
echo "<a href='http://store.steampowered.com/app/".$Keys[$i]."'><img src='".$AllGames[$Keys[$i]]['header_image']."' width='153' height='72'/>".$AllGames[$Keys[$i]]['name']."</a><br/>";
$GamesFound++;
flush();
$i++;
}
//Randomly pick 5 games.
shuffle($Keys);
echo " 5 random games:<br/>";
$GamesFound = 0;
$i = 0;
while( ($GamesFound < 5) and ($i < count($SortedGametime)))
{
echo "<a href='http://store.steampowered.com/app/".$Keys[$i]."'><img src='".$AllGames[$Keys[$i]]['header_image']."' width='153' height='72'/>".$AllGames[$Keys[$i]]['name']."</a><br/>";
$GamesFound++;
flush();
$i++;
}
}
echo "Find the person's Steam Community ID by going to something like http://steamcommunity.com/id/xxxxxxxxxx/ . Mine is <a>http://steamcommunity.com/id/a10waveracer/</a>.<br/>";
echo "<form method='GET' action='index.php' ><br/>
Enter Steam Community IDs, separated by commas:<br/>
<input type='text' name='SteamNames' /><br/>
<input type='submit' value='Find me some games!' />
</form>";
function pullAllSteamGames($SteamID, $APIKey)
{
$ch2 = curl_init("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=".$APIKey."&steamid=".$SteamID."&format=json");
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2,CURLOPT_HEADER, 0);
$CurlOutput = curl_exec($ch2);
curl_close($ch2);
// Now parse the json
$GetOwnedGames = json_decode($CurlOutput, TRUE);
return $GetOwnedGames;
}
function parseSteamGames($GamesArray)
{
$OwnedGames = array();
$GamesArray = $GamesArray['response']['games'];
foreach($GamesArray as $Game)
{
$OwnedGames[$Game['appid']] = $Game['playtime_forever'];
}
return $OwnedGames;
}
function sumGametime($OwnedGames, $AllUsers)
{ // Given a games array with array('appid' => 'gametime')
$OutputArr = array();
foreach($OwnedGames as $GameID => $Gametime)
{
$OutputArr[$GameID] = 0;
for($i = 0; $i < count($AllUsers); $i++)
{
$OutputArr[$GameID] += $AllUsers[$i]['Games'][$GameID];
}
}
arsort($OutputArr);
return $OutputArr;
}
function printDelim()
{
echo "<br/>***************************************<br/>";
}
function parseApp($AppID)
{
$ch2 = curl_init("http://store.steampowered.com/api/appdetails/?appids=".$AppID);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2,CURLOPT_HEADER, 0);
$CurlOutput = curl_exec($ch2);
curl_close($ch2);
// Now parse the json
$GameInfo = json_decode($CurlOutput, TRUE);
$GameInfo = $GameInfo[$AppID]['data'];
return $GameInfo;
}
?>