-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_accounts_in_room_json.php
70 lines (56 loc) · 1.68 KB
/
search_accounts_in_room_json.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
<?php
date_default_timezone_set('Europe/Moscow');
mb_internal_encoding('UTF-8');
$data = file_get_contents('php://input');
if (!empty($data)) {
if (!empty($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {
$parse = json_decode($data, true);
$_REQUEST = array_merge($_REQUEST, $parse);
}
}
if (empty($_REQUEST['room_id']) || empty($_REQUEST['account_id'])) {
return;
}
$roomId = intval($_REQUEST['room_id']);
$accountId = $_REQUEST['account_id'];
$context = stream_context_create(array('http' =>
array(
'timeout' => 5,
)
));
$response = @file_get_contents('http://steamapi-a.akamaihd.net/ITowerAttackMiniGameService/GetPlayerNames/v0001/?input_json=%7B%22gameid%22%3A%22' . $roomId . '%22%2C%22accountids%22%3A%5B%5D%7D', null, $context);
if ($response === false) {
return;
}
$gameInfo = json_decode($response);
if ($gameInfo === false) {
return;
}
if (!property_exists($gameInfo, 'response')) {
return;
}
if (!property_exists($gameInfo->response, 'names')) {
return;
}
$players = count($gameInfo->response->names);
$exists = false;
$accountsFound = array();
foreach ($gameInfo->response->names as $player) {
if (is_array($accountId)) {
if (in_array($player->accountid, $accountId)) {
$exists = true;
$accountsFound[] = $player->accountid;
}
} else {
if ($player->accountid == $accountId) {
$exists = true;
$accountsFound[] = $player->accountid;
}
}
}
echo json_encode(array(
'room_id' => $roomId,
'players' => $players,
'exists' => $exists,
'accounts_found' => $accountsFound
), JSON_FORCE_OBJECT);