-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserstatus.php
220 lines (166 loc) · 6.6 KB
/
userstatus.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/*
We should allow for overriding of the script password for testing by specifying a parameter. call it by adding
?password=xx&email=your@email.com
*/
if (!isset($_GET) || empty($_GET))
{
$email = $_GET['email'];
$password = $_GET['password'];
}
else
{
/* If you are running it on your server and want to hide logs seeing your info,
you can edit the ones below to contain your password and email.
*/
$email = "sampleemail@address.com.au";
$password = "samplepassword";
}
class battleLog
{
public $baseUrl;
public $debug;
private $loginResult;
public $serverName;
public $serverGuid;
public $isPlaying;
public function __construct($email, $password)
{
$this->baseUrl = 'https://battlelog.battlefield.com/bf3/';
$this->debug = true;
// Create required post fields
$postchars = http_build_query(array(
'redirect' => '|bf3|',
'email' => $email,
'password' => $password,
'submit' => 'Sign+in'
), '', '&');
echo $postchars;
$url = $this->baseUrl . 'gate/login/';
// First we need to do a login for the commands we will be doing.
// This will give us some session data.
if ($this->debug) echo "<h3>the post url will be:</h3> " . $url ."<br>";
// Do a login using your information.
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postchars);
curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$this->loginresult = curl_exec($ch);
// Some way to verify login?
if ($this->debug) echo "<br> Curl Error for " . $info['url'] . " : " . curl_errno($ch) . " <br>";
if ($this->debug) echo "<br><h3>Attempting login</h3>" . curl_getinfo ($ch, CURLINFO_HTTP_CODE) . " - Is the resulting code. 302 is a redirect, 200 is ok.";
curl_close($ch);
}
public function SoldierOverview($soldierName)
{
//http://battlelog.battlefield.com/bf3/user/overviewBoxStats/2832660534553355381/
$url = $this->baseUrl . "user/superroach/";
$url = $this->baseUrl . "user/MonkeyCrumpets/";
$url = $this->baseUrl . "user/SumwhatKrazy/";
$url = $this->baseUrl . "user/bb_turn/";
$url = $this->baseUrl . "user/DrMon/";
$url = $this->baseUrl . "user/-Vultur3z-/";
$url = $this->baseUrl . "user/$soldierName/";
echo $url;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $postchars);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('X-Requested-With: XMLHttpRequest','X-AjaxNavigation: 1'));
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0');
$soldierResult = curl_exec($ch);
if ($this->debug) echo "<br><h3>Attempting soldier request.</h3>" . curl_getinfo ($ch, CURLINFO_HTTP_CODE) . " - Is the resulting code. 302 is a redirect, 200 is ok.";
$info = curl_getinfo($ch);
if ($this->debug) echo "<br> Curl Error for " . $info['url'] . " : " . curl_errno($ch) . " <br>";
//echo "<br>" . $soldierData;
//var_dump($soldierData);
//$jsonSoldier = json_encode( $soldierData );
$soldierData = json_decode($soldierResult, true);
$this->isPlaying = (bool) $soldierData['context']['profileCommon']['user']['presence']['isPlaying'];
$this->serverName = $soldierData['context']['profileCommon']['user']['presence']['serverName'];
$this->serverGuid = $soldierData['context']['profileCommon']['user']['presence']['serverGuid'];
if ($this->debug) var_dump( $this->isPlaying );
if ($this->debug) echo "<br> Are they playing?: <b>" . $this->isPlaying . "</b><br>";
if ($this->debug) echo "<br> Checking their server name: <b>" . $soldierData['context']['profileCommon']['user']['presence']['serverName'] . "</b><br><br>";
// if ($this->debug) echo "<br> And :".var_dump( $soldierData['context']['profileCommon']['user'] )."</br>";
echo "<pre>";
// Uncomment this for the whole shebang.
// if ($this->debug) print_r($soldierData);
echo "</pre>";
curl_close($ch);
return $soldierData;
}
public function SoldierStats($soldierID)
{
/*
if (empty($this->loginResult))
{
echo "<Br>The returned result from logining in is empty";
return false;
}
*/
// I've got rid of stream usage while debugging this script.
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'content-type: application/x-www-form-urlencoded\r\n' .
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0' .
'Connection: keep-alive' .
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'content' => $dataUrl,
'timeout' => 3,
)
));
$url = $this->baseUrl . "overviewPopulateStats/$soldierID/None/1/";
echo $url;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $postchars);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('X-Requested-With: XMLHttpRequest','X-AjaxNavigation: 1'));
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0');
$soldierResult = curl_exec($ch);
echo "<br><h3>Attempting soldier request.</h3>" . curl_getinfo ($ch, CURLINFO_HTTP_CODE) . " - Is the resulting code. 302 is a redirect, 200 is ok.";
$info = curl_getinfo($ch);
echo "<br> Curl Error for " . $info['url'] . " : " . curl_errno($ch) . " <br>";
//echo "<br>" . $soldierData;
//var_dump($soldierData);
//$jsonSoldier = json_encode( $soldierData );
$soldierData = json_decode($soldierResult, true);
//echo "<br>" . $soldierData[user][prescence]['userId'] ;
//echo "<br>" . print_r($soldierData['data']);
//echo "<br>" . $soldierData['user']['username'] ;
//var_dump($soldierData);
// $soldierInfoData = json_decode( $jsonSoldier , true );
//print_r( $soldierInfoData);
// echo $soldierInfoData['type'];
// echo $soldierData['type'] . " ";
// echo $jsonSoldier.user.username . " ";
curl_close($ch);
return $soldierData;
}
}
// SuperRoach
//The battlelog soldier id.
$soldier = "235161522";
if (!empty($_GET['soldier']))
{
$soldier = $_GET['soldier'];
}
//$ret = file_get_contents($url, false, $context);
/*
$test = new battleLog($email, $password);
$soldierStatus = $test->SoldierOverview($soldier);
$newServer = null;
if ($test->isPlaying)
{
$newServer = $test->serverName;
}
echo $newServer;
*/
?>