forked from waylaidwanderer/PHP-SteamCommunity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetwork.php
More file actions
165 lines (134 loc) · 5.31 KB
/
Copy pathNetwork.php
File metadata and controls
165 lines (134 loc) · 5.31 KB
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
<?php
namespace waylaidwanderer\SteamCommunity;
use waylaidwanderer\SteamCommunity\SteamCommunity;
class Network
{
/**
* Proxy Format
*
* array(
* 'type' => CURLPROXY_HTTP,
* 'address' => '127.0.0.1:8888',
* 'auth' => 'user:password'
* )
*
*/
public static $DEFAULT_MOBILE_COOKIES = ['mobileClientVersion' => '0 (2.1.3)', 'mobileClient' => 'android', 'Steam_Language' => 'english', 'dob' => ''];
private $defaultProxyType = CURLPROXY_HTTP;
private $proxies = array();
private $interfaces = array();
public function __construct()
{
if ($proxies = SteamCommunity::getInstance()->get('proxies')) {
foreach ($proxies as $proxy) {
if ($this->validateProxy($proxy)) {
$this->proxies[] = $proxy;
}
}
}
if ($interfaces = SteamCommunity::getInstance()->get('interfaces')) {
foreach ($interfaces as $interface) {
$this->interfaces[] = $interface;
}
}
}
public function cURL($url, $ref = null, $postData = null, array $options = array(), $type = false)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if (isset($options['connectionTimeOut'])) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $options['connectionTimeOut']);
}
if (isset($options['timeOut'])) {
curl_setopt($ch, CURLOPT_TIMEOUT, $options['timeOut']);
}
curl_setopt($ch, CURLOPT_TCP_FASTOPEN, 1);
curl_setopt($ch, CURLOPT_TCP_NODELAY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
if (!$type) {
$type = (SteamCommunity::getInstance()->get('mobile') ? 'mobile' : 'web');
}
$cookie = SteamCommunity::getInstance()->getClassFromCache('Auth\Auth')->getCookieFilePath($type);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
if (SteamCommunity::getInstance()->get('mobile')) {
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Requested-With: com.valvesoftware.android.steam.community"]);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
curl_setopt($ch, CURLOPT_COOKIE, SteamCommunity::getInstance()->getClassFromCache('Auth\Auth')->buildCookie(self::$DEFAULT_MOBILE_COOKIES));
} else {
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0');
}
if (isset($ref)) {
curl_setopt($ch, CURLOPT_REFERER, $ref);
}
if (isset($postData)) {
curl_setopt($ch, CURLOPT_POST, true);
if (is_array($postData)) {
$postStr = "";
foreach ($postData as $key => $value) {
if ($postStr)
$postStr .= "&";
$postStr .= $key . "=" . $value;
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postStr);
}
}
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this, 'outputCURLHeaders'));
if (!isset($options['defaultNetwork']) || !$options['defaultNetwork']) {
if ($proxy = $this->chooseRandomProxy()) {
$defaultProxyType = $this->defaultProxyType;
curl_setopt($ch, CURLOPT_PROXYTYPE, $defaultProxyType);
if (isset($proxy['type'])) {
curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy['type']);
}
if (isset($proxy['auth'])) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy['auth']);
}
curl_setopt($ch, CURLOPT_PROXY, $proxy['address']);
}
if ($interface = $this->chooseRandomInterface()) {
curl_setopt($ch, CURLOPT_INTERFACE, $interface);
}
}
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
public function chooseRandomProxy()
{
if (empty($this->proxies)) {
return false;
}
return $this->proxies[array_rand($this->proxies)];
}
public function chooseRandomInterface()
{
if (empty($this->interfaces)) {
return false;
}
return $this->interfaces[array_rand($this->interfaces)];
}
protected function outputCURLHeaders($curl, $headerLine)
{
// echo '<pre>'; var_dump($headerLine); echo '</pre>';
return strlen($headerLine);
}
protected function validateProxy($proxy)
{
if (!isset($proxy['address'])) {
return false;
}
if (count(explode(':', $proxy['address'])) !== 2) {
return false;
}
if (isset($proxy['auth']) && count(explode(':', $proxy['auth'])) !== 2) {
return false;
}
return true;
}
}