1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Seaony\ValorantApi; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
use Illuminate\Support\Arr; |
7
|
|
|
use GuzzleHttp\Cookie\CookieJar; |
8
|
|
|
use Illuminate\Support\Facades\Cache; |
9
|
|
|
use Seaony\ValorantApi\Endpoints\PVPEndpoints; |
10
|
|
|
use Seaony\ValorantApi\Endpoints\StoreEndpoints; |
11
|
|
|
use Seaony\ValorantApi\Endpoints\PreGameEndpoints; |
12
|
|
|
use Seaony\ValorantApi\Endpoints\ContractEndpoints; |
13
|
|
|
use Seaony\ValorantApi\Endpoints\CurrentGameEndpoints; |
14
|
|
|
use Seaony\ValorantApi\Endpoints\AuthenticationEndpoints; |
15
|
|
|
|
16
|
|
|
class Valorant |
17
|
|
|
{ |
18
|
|
|
use PVPEndpoints, |
19
|
|
|
StoreEndpoints, |
20
|
|
|
PreGameEndpoints, |
21
|
|
|
ContractEndpoints, |
22
|
|
|
CurrentGameEndpoints, |
23
|
|
|
AuthenticationEndpoints; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \GuzzleHttp\Client http client |
27
|
|
|
*/ |
28
|
|
|
protected Client $client; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array $version latest riot version |
32
|
|
|
*/ |
33
|
|
|
protected array $version; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string Riot token |
37
|
|
|
*/ |
38
|
|
|
protected string $authorization; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string Riot entitlements |
42
|
|
|
*/ |
43
|
|
|
protected string $entitlements; |
44
|
|
|
|
45
|
|
|
public const ITEM_TYPE_AGENTS = '01bb38e1-da47-4e6a-9b3d-945fe4655707'; |
46
|
|
|
public const ITEM_TYPE_CONTRACTS = 'f85cb6f7-33e5-4dc8-b609-ec7212301948'; |
47
|
|
|
public const ITEM_TYPE_SPRAYS = 'd5f120f8-ff8c-4aac-92ea-f2b5acbe9475'; |
48
|
|
|
public const ITEM_TYPE_GUN_BUDDIES = 'dd3bf334-87f3-40bd-b043-682a57a8dc3a'; |
49
|
|
|
public const ITEM_TYPE_CARDS = '3f296c07-64c3-494c-923b-fe692a4fa1bd'; |
50
|
|
|
public const ITEM_TYPE_SKINS = 'e7c63390-eda7-46e0-bb7a-a6abdacd2433'; |
51
|
|
|
public const ITEM_TYPE_SKIN_VARIANTS = '3ad1b2b2-acdb-4524-852f-954a76ddae0a'; |
52
|
|
|
public const ITEM_TYPE_TITLES = 'de7caa6b-adf7-4588-bbd1-143831e786c6'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
56
|
|
|
*/ |
57
|
|
|
public function __construct(array $config = []) |
58
|
|
|
{ |
59
|
|
|
$this->authorization = Arr::get($config, 'authorization', ''); |
60
|
|
|
|
61
|
|
|
$this->entitlements = Arr::get($config, 'entitlements', ''); |
62
|
|
|
|
63
|
|
|
$this->buildClient( |
64
|
|
|
Arr::get($config, 'cookies', []) |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$this->getLatesVersion(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* send request |
72
|
|
|
* |
73
|
|
|
* @param $method |
74
|
|
|
* @param $uri |
75
|
|
|
* @param array $options |
76
|
|
|
* @param $isArrayResponse |
77
|
|
|
* |
78
|
|
|
* @return mixed|\Psr\Http\Message\ResponseInterface |
79
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
80
|
|
|
*/ |
81
|
|
|
protected function request($method, $uri, array $options = [], $isArrayResponse = true) |
82
|
|
|
{ |
83
|
|
|
$options['headers'] = array_merge( |
84
|
|
|
Arr::get($options, 'headers', []), |
85
|
|
|
array_filter([ |
86
|
|
|
'Content-Type' => 'application/json', |
87
|
|
|
'User-Agent' => $this->latestUserAgent(), |
88
|
|
|
'X-Riot-ClientVersion' => $this->latestRiotClientVersion(), |
89
|
|
|
'X-Riot-ClientPlatform' => $this->latesRiotClientPlatform(), |
90
|
|
|
'Authorization' => $this->authorization, |
91
|
|
|
'X-Riot-Entitlements-JWT' => $this->entitlements, |
92
|
|
|
]) |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$response = $this->client->request($method, $uri, $options); |
96
|
|
|
|
97
|
|
|
if ($isArrayResponse) { |
98
|
|
|
return json_decode($response->getBody()->getContents(), true); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $response; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get cookies after the request |
106
|
|
|
* |
107
|
|
|
* @return mixed Cookies |
108
|
|
|
*/ |
109
|
|
|
public function cookies() |
110
|
|
|
{ |
111
|
|
|
return $this->client->getConfig('cookies')->toArray(); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* set credentials |
116
|
|
|
* |
117
|
|
|
* @param array $config |
118
|
|
|
* |
119
|
|
|
* @return void |
120
|
|
|
*/ |
121
|
|
|
public function setCredentials(array $config = []) |
122
|
|
|
{ |
123
|
|
|
$this->authorization = Arr::get($config, 'authorization', $this->authorization); |
124
|
|
|
|
125
|
|
|
$this->entitlements = Arr::get($config, 'entitlements', $this->entitlements); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Build a http client |
130
|
|
|
* |
131
|
|
|
* @return void |
132
|
|
|
*/ |
133
|
|
|
protected function buildClient(array $cookies = []) |
134
|
|
|
{ |
135
|
|
|
$this->client = new Client([ |
136
|
|
|
'cookies' => $cookies ? new CookieJar(true, $cookies) : true, |
137
|
|
|
'curl' => [ |
138
|
|
|
CURLOPT_SSLVERSION => config('ssl', CURL_SSLVERSION_TLSv1_3), |
139
|
|
|
CURLOPT_SSL_CIPHER_LIST => $this->ciphers(), |
140
|
|
|
CURLOPT_TLS13_CIPHERS => $this->ciphers13(), |
141
|
|
|
], |
142
|
|
|
]); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Bypass encryption required by cloudflare |
147
|
|
|
* |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
protected function ciphers() |
151
|
|
|
{ |
152
|
|
|
$ciphers = config('valorant.ciphers') ?: [ |
153
|
|
|
'ECDHE-ECDSA-CHACHA20-POLY1305', |
154
|
|
|
'ECDHE-RSA-CHACHA20-POLY1305', |
155
|
|
|
'ECDHE-ECDSA-AES128-GCM-SHA256', |
156
|
|
|
'ECDHE-RSA-AES128-GCM-SHA256', |
157
|
|
|
'ECDHE-ECDSA-AES256-GCM-SHA384', |
158
|
|
|
'ECDHE-RSA-AES256-GCM-SHA384', |
159
|
|
|
'ECDHE-ECDSA-AES128-SHA', |
160
|
|
|
'ECDHE-RSA-AES128-SHA', |
161
|
|
|
'ECDHE-ECDSA-AES256-SHA', |
162
|
|
|
'ECDHE-RSA-AES256-SHA', |
163
|
|
|
'AES128-GCM-SHA256', |
164
|
|
|
'AES256-GCM-SHA384', |
165
|
|
|
'AES128-SHA', |
166
|
|
|
'AES256-SHA', |
167
|
|
|
'DES-CBC3-SHA', # most likely not available |
168
|
|
|
]; |
169
|
|
|
|
170
|
|
|
return implode(':', $ciphers); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Bypass encryption required by cloudflare |
175
|
|
|
* |
176
|
|
|
* @return string |
177
|
|
|
*/ |
178
|
|
|
protected function ciphers13() |
179
|
|
|
{ |
180
|
|
|
$ciphers13 = config('valorant.ciphers13') ?: [ |
181
|
|
|
'TLS_CHACHA20_POLY1305_SHA256', |
182
|
|
|
'TLS_AES_128_GCM_SHA256', |
183
|
|
|
'TLS_AES_256_GCM_SHA384', |
184
|
|
|
]; |
185
|
|
|
|
186
|
|
|
return implode(':', $ciphers13); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Get the latest version of the client |
191
|
|
|
* |
192
|
|
|
* @return mixed |
193
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
194
|
|
|
*/ |
195
|
|
|
protected function getLatesVersion() |
196
|
|
|
{ |
197
|
|
|
$key = 'VALORANT_VERSION'; |
198
|
|
|
|
199
|
|
|
if (!Cache::has($key)) { |
200
|
|
|
Cache::put($key, ValorantAsset::version(), now()->addMinutes(60)); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
$this->version = Cache::get($key); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Generate the latest User-Agent |
208
|
|
|
* |
209
|
|
|
* @return string |
210
|
|
|
*/ |
211
|
|
|
protected function latestUserAgent() |
212
|
|
|
{ |
213
|
|
|
return implode('', [ |
214
|
|
|
'RiotClient/', |
215
|
|
|
Arr::get($this->version, 'riotClientBuild'), |
216
|
|
|
' rso-auth (Windows; 10;;Professional, x64)', |
217
|
|
|
]); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Generate platform identifiers |
222
|
|
|
* |
223
|
|
|
* @return string |
224
|
|
|
*/ |
225
|
|
|
protected function latesRiotClientPlatform() |
226
|
|
|
{ |
227
|
|
|
$platform = config('valorant.platform') ?: [ |
228
|
|
|
'platformType' => 'PC', |
229
|
|
|
'platformOS' => 'Windows', |
230
|
|
|
'platformOSVersion' => '10.0.19042.1.256.64bit', |
231
|
|
|
'platformChipset' => 'Unknown', |
232
|
|
|
]; |
233
|
|
|
|
234
|
|
|
return base64_encode(json_encode($platform)); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Get the latest Riot client version |
239
|
|
|
* |
240
|
|
|
* @return array|\ArrayAccess|mixed |
241
|
|
|
*/ |
242
|
|
|
protected function latestRiotClientVersion() |
243
|
|
|
{ |
244
|
|
|
return Arr::get($this->version, 'riotClientVersion'); |
245
|
|
|
} |
246
|
|
|
} |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.