forked from Glennmen/PMSF
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathraw_data.php
199 lines (175 loc) · 6.9 KB
/
raw_data.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
<?php
$timing['start'] = microtime(true);
include('config/config.php');
global $map, $fork;
$now = new DateTime();
$now->sub(new DateInterval('PT20S'));
$d = array();
$d["timestamp"] = $now->getTimestamp();
$swLat = !empty($_POST['swLat']) ? $_POST['swLat'] : 0;
$neLng = !empty($_POST['neLng']) ? $_POST['neLng'] : 0;
$swLng = !empty($_POST['swLng']) ? $_POST['swLng'] : 0;
$neLat = !empty($_POST['neLat']) ? $_POST['neLat'] : 0;
$oSwLat = !empty($_POST['oSwLat']) ? $_POST['oSwLat'] : 0;
$oSwLng = !empty($_POST['oSwLng']) ? $_POST['oSwLng'] : 0;
$oNeLat = !empty($_POST['oNeLat']) ? $_POST['oNeLat'] : 0;
$oNeLng = !empty($_POST['oNeLng']) ? $_POST['oNeLng'] : 0;
$luredonly = !empty($_POST['luredonly']) ? $_POST['luredonly'] : false;
$lastpokemon = !empty($_POST['lastpokemon']) ? $_POST['lastpokemon'] : false;
$lastgyms = !empty($_POST['lastgyms']) ? $_POST['lastgyms'] : false;
$lastpokestops = !empty($_POST['lastpokestops']) ? $_POST['lastpokestops'] : false;
$lastlocs = !empty($_POST['lastslocs']) ? $_POST['lastslocs'] : false;
$lastspawns = !empty($_POST['lastspawns']) ? $_POST['lastspawns'] : false;
$d["lastpokestops"] = !empty($_POST['pokestops']) ? $_POST['pokestops'] : false;
$d["lastgyms"] = !empty($_POST['gyms']) ? $_POST['gyms'] : false;
$d["lastslocs"] = !empty($_POST['scanned']) ? $_POST['scanned'] : false;
$d["lastspawns"] = !empty($_POST['spawnpoints']) ? $_POST['spawnpoints'] : false;
$d["lastpokemon"] = !empty($_POST['pokemon']) ? $_POST['pokemon'] : false;
$timestamp = !empty($_POST['timestamp']) ? $_POST['timestamp'] : 0;
$useragent = $_SERVER['HTTP_USER_AGENT'];
if (empty($swLat) || empty($swLng) || empty($neLat) || empty($neLng) || preg_match("/curl|libcurl/", $useragent)) {
http_response_code(400);
die();
}
if ($maxLatLng > 0 && ((($neLat - $swLat) > $maxLatLng) || (($neLng - $swLng) > $maxLatLng))) {
http_response_code(400);
die();
}
if (!validateToken($_POST['token'])) {
http_response_code(400);
die();
}
// init map
if ($map == "monocle") {
if ($fork == "asner") {
$scanner = new \Scanner\Monocle_Asner();
} elseif ($fork == "monkey") {
$scanner = new \Scanner\Monocle_Monkey();
} else {
$scanner = new \Scanner\Monocle();
}
} elseif ($map == "rm") {
if ($fork == "sloppy") {
$scanner = new \Scanner\RocketMap_Sloppy();
} else {
$scanner = new \Scanner\RocketMap();
}
}
$newarea = false;
if (($oSwLng < $swLng) && ($oSwLat < $swLat) && ($oNeLat > $neLat) && ($oNeLng > $neLng)) {
$newarea = false;
} elseif (($oSwLat != $swLat) && ($oSwLng != $swLng) && ($oNeLat != $neLat) && ($oNeLng != $neLng)) {
$newarea = true;
} else {
$newarea = false;
}
$d["oSwLat"] = $swLat;
$d["oSwLng"] = $swLng;
$d["oNeLat"] = $neLat;
$d["oNeLng"] = $neLng;
$ids = array();
$eids = array();
$reids = array();
$debug['1_before_functions'] = microtime(true) - $timing['start'];
global $noPokemon;
if (!$noPokemon) {
if ($d["lastpokemon"] == "true") {
if ($lastpokemon != 'true') {
$d["pokemons"] = $scanner->get_active($swLat, $swLng, $neLat, $neLng);
} else {
if ($newarea) {
$d["pokemons"] = $scanner->get_active($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng);
} else {
$d["pokemons"] = $scanner->get_active($swLat, $swLng, $neLat, $neLng, $timestamp);
}
}
if (!empty($_POST['eids'])) {
$eids = explode(",", $_POST['eids']);
foreach ($d['pokemons'] as $elementKey => $element) {
foreach ($element as $valueKey => $value) {
if ($valueKey == 'pokemon_id') {
if (in_array($value, $eids)) {
//delete this particular object from the $array
unset($d['pokemons'][$elementKey]);
}
}
}
}
}
if (!empty($_POST['reids'])) {
$reids = explode(",", $_POST['reids']);
$d["pokemons"] = array_merge($d["pokemons"], $scanner->get_active_by_id($reids, $swLat, $swLng, $neLat, $neLng));
$d["reids"] = !empty($_POST['reids']) ? $reids : null;
}
}
}
$debug['2_after_pokemon'] = microtime(true) - $timing['start'];
global $noPokestops;
if (!$noPokestops) {
if ($d["lastpokestops"] == "true") {
if ($lastpokestops != "true") {
$d["pokestops"] = $scanner->get_stops($swLat, $swLng, $neLat, $neLng, 0, 0, 0, 0, 0, $luredonly);
} else {
if ($newarea) {
$d["pokestops"] = $scanner->get_stops($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng, $luredonly);
} else {
$d["pokestops"] = $scanner->get_stops($swLat, $swLng, $neLat, $neLng, $timestamp, 0, 0, 0, 0, $luredonly);
}
}
}
}
$debug['3_after_pokestops'] = microtime(true) - $timing['start'];
global $noGyms, $noRaids;
if (!$noGyms || !$noRaids) {
if ($d["lastgyms"] == "true") {
if ($lastgyms != "true") {
$d["gyms"] = $scanner->get_gyms($swLat, $swLng, $neLat, $neLng);
} else {
if ($newarea) {
$d["gyms"] = $scanner->get_gyms($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng);
} else {
$d["gyms"] = $scanner->get_gyms($swLat, $swLng, $neLat, $neLng, $timestamp);
}
}
}
}
$debug['4_after_gyms'] = microtime(true) - $timing['start'];
global $noSpawnPoints;
if (!$noSpawnPoints) {
if ($d["lastspawns"] == "true") {
if ($lastspawns != "true") {
$d["spawnpoints"] = $scanner->get_spawnpoints($swLat, $swLng, $neLat, $neLng);
} else {
if ($newarea) {
$d["spawnpoints"] = $scanner->get_spawnpoints($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng);
} else {
$d["spawnpoints"] = $scanner->get_spawnpoints($swLat, $swLng, $neLat, $neLng, $timestamp);
}
}
}
}
$debug['5_after_spawnpoints'] = microtime(true) - $timing['start'];
global $noScannedLocations;
if (!$noScannedLocations) {
if ($d["lastslocs"] == "true") {
if ($lastlocs != "true") {
$d["scanned"] = $scanner->get_recent($swLat, $swLng, $neLat, $neLng);
} else {
if ($newarea) {
$d["scanned"] = $scanner->get_recent($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng);
} else {
$d["scanned"] = $scanner->get_recent($swLat, $swLng, $neLat, $neLng, $timestamp);
}
}
}
}
$debug['6_after_recent'] = microtime(true) - $timing['start'];
$d['token'] = refreshCsrfToken();
$debug['7_end'] = microtime(true) - $timing['start'];
if ($enableDebug == true) {
foreach ($debug as $k => $v) {
header("X-Debug-Time-" . $k . ": " . $v);
}
}
$jaysson = json_encode($d);
echo $jaysson;