forked from Glennmen/PMSF
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgym_data.php
288 lines (260 loc) · 8.34 KB
/
gym_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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
include('config/config.php');
include('adapter.php');
if (empty($_POST['id'])) {
http_response_code(400);
die();
}
if (!validateToken($_POST['token'])) {
http_response_code(400);
die();
}
$id = $_POST['id'];
global $map;
global $adapter;
if (!is_null($adapter)) {
$gym = $adapter->get_gym($id);
$gym['token'] = refreshCsrfToken();
echo json_encode($gym);
die();
}
global $db;
if ($map == "monocle") {
$row = $db->query("SELECT t3.external_id,
t3.lat,
t3.lon,
t1.last_modified,
t1.team,
t1.slots_available,
t1.guard_pokemon_id
FROM (SELECT fort_id,
Max(last_modified) AS MaxLastModified
FROM fort_sightings
GROUP BY fort_id) t2
LEFT JOIN fort_sightings t1
ON t2.fort_id = t1.fort_id
AND t2.maxlastmodified = t1.last_modified
LEFT JOIN forts t3
ON t1.fort_id = t3.id
WHERE t3.external_id = :id ", [':id'=>$id])->fetch();
} else {
global $fork;
if ($fork != "sloppy")
$row = $db->query("SELECT gym.gym_id
AS
external_id,
latitude
AS lat,
longitude
AS lon,
guard_pokemon_id,
slots_available,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone))
AS
last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00',
@@global.time_zone)) AS
last_scanned,
team_id
AS team,
enabled,
name,
level,
pokemon_id,
cp,
move_1,
move_2,
Unix_timestamp(Convert_tz(start, '+00:00', @@global.time_zone))
AS raid_start,
Unix_timestamp(Convert_tz(end, '+00:00', @@global.time_zone))
AS raid_end
FROM gym
LEFT JOIN gymdetails
ON gym.gym_id = gymdetails.gym_id
LEFT JOIN raid
ON gym.gym_id = raid.gym_id
WHERE gym.gym_id = :id", [':id'=>$id])->fetch();
else
$row = $db->query("SELECT gym.gym_id
AS
external_id,
latitude
AS lat,
longitude
AS lon,
guard_pokemon_id,
slots_available,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone))
AS
last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00',
@@global.time_zone)) AS
last_scanned,
team_id
AS team,
enabled,
name,
raid_level
AS level,
raid_pokemon_id
AS pokemon_id,
raid_pokemon_cp
AS cp,
raid_pokemon_move_1
AS move_1,
raid_pokemon_move_2
AS move_2,
Unix_timestamp(Convert_tz(raid_battle, '+00:00', @@global.time_zone))
AS
raid_start,
Unix_timestamp(Convert_tz(raid_end, '+00:00', @@global.time_zone))
AS raid_end
FROM gym
LEFT JOIN gymdetails
ON gym.gym_id = gymdetails.gym_id
WHERE gym.gym_id = :id". [':id'=>$id])->fetch();
}
$json_poke = "static/data/pokemon.json";
$json_contents = file_get_contents($json_poke);
$data = json_decode($json_contents, TRUE);
$p = array();
$lat = floatval($row["lat"]);
$lon = floatval($row["lon"]);
$gpid = intval($row["guard_pokemon_id"]);
$sa = intval($row["slots_available"]);
$lm = $row["last_modified"] * 1000;
$ls = !empty($row["last_scanned"]) ? $row["last_scanned"] * 1000 : null;
$ti = isset($row["team"]) ? intval($row["team"]) : null;
$p["enabled"] = isset($row["enabled"]) ? boolval($row["enabled"]) : true;
$p["guard_pokemon_id"] = $gpid;
$p["gym_id"] = $row["external_id"];
$p["slots_available"] = $sa;
$p["last_modified"] = $lm;
$p["last_scanned"] = $ls;
$p["latitude"] = $lat;
$p["longitude"] = $lon;
$p["name"] = !empty($row["name"]) ? $row["name"] : null;
$p["team_id"] = $ti;
if ($gpid)
$p["guard_pokemon_name"] = i8ln($data[$gpid]['name']);
if ($map != "monocle") {
$rpid = intval($row['pokemon_id']);
$p['raid_level'] = intval($row['level']);
if ($rpid)
$p['raid_pokemon_id'] = $rpid;
if ($rpid)
$p['raid_pokemon_name'] = i8ln($data[$rpid]['name']);
$p['raid_pokemon_cp'] = !empty($row['cp']) ? intval($row['cp']) : null;
$p['raid_pokemon_move_1'] = !empty($row['move_1']) ? intval($row['move_1']) : null;
$p['raid_pokemon_move_2'] = !empty($row['move_2']) ? intval($row['move_2']) : null;
$p['raid_start'] = $row["raid_start"] * 1000;
$p['raid_end'] = $row["raid_end"] * 1000;
}
unset($row);
$j = 0;
if ($map != "monocle") {
$json_moves = "static/data/moves.json";
$json_contents = file_get_contents($json_moves);
$moves = json_decode($json_contents, TRUE);
$pokemons = $db->query("SELECT gymmember.gym_id,
pokemon_id,
cp,
trainer.name,
trainer.level,
move_1,
move_2,
iv_attack,
iv_defense,
iv_stamina
FROM gymmember
JOIN gympokemon
ON gymmember.pokemon_uid = gympokemon.pokemon_uid
JOIN trainer
ON gympokemon.trainer_name = trainer.name
JOIN gym
ON gym.gym_id = gymmember.gym_id
WHERE gymmember.last_scanned > gym.last_modified
AND gymmember.gym_id IN ( :id )
GROUP BY name
ORDER BY gympokemon.cp DESC ", [':id'=>$id])->fetchAll();
foreach ($pokemons as $pokemon) {
$pid = $pokemon["pokemon_id"];
$p1 = array();
$p1["pokemon_id"] = $pid;
$p1["pokemon_name"] = i8ln($data[$pid]['name']);
$p1["trainer_name"] = $pokemon["name"];
$p1["trainer_level"] = $pokemon["level"];
$p1["pokemon_cp"] = $pokemon["cp"];
$p1["iv_attack"] = intval($pokemon["iv_attack"]);
$p1["iv_defense"] = intval($pokemon["iv_defense"]);
$p1["iv_stamina"] = intval($pokemon["iv_stamina"]);
$p1['move_1_name'] = i8ln($moves[$pokemon['move_1']]['name']);
$p1['move_1_damage'] = $moves[$pokemon['move_1']]['damage'];
$p1['move_1_energy'] = $moves[$pokemon['move_1']]['energy'];
$p1['move_1_type']['type'] = i8ln($moves[$pokemon['move_1']]['type']);
$p1['move_1_type']['type_en'] = $moves[$pokemon['move_1']]['type'];
$p1['move_2_name'] = i8ln($moves[$pokemon['move_2']]['name']);
$p1['move_2_damage'] = $moves[$pokemon['move_2']]['damage'];
$p1['move_2_energy'] = $moves[$pokemon['move_2']]['energy'];
$p1['move_2_type']['type'] = i8ln($moves[$pokemon['move_2']]['type']);
$p1['move_2_type']['type_en'] = $moves[$pokemon['move_2']]['type'];
$p['pokemon'][] = $p1;
unset($pokemons[$j]);
$j++;
}
} else {
global $fork;
if ($fork != "asner")
$raid = $db->query("SELECT t3.external_id,
t1.fort_id,
level,
pokemon_id,
time_battle AS raid_start,
time_end AS raid_end,
move_1,
move_2
FROM (SELECT fort_id,
Max(time_end) AS MaxTimeEnd
FROM raids
GROUP BY fort_id) t1
LEFT JOIN raids t2
ON t1.fort_id = t2.fort_id
AND maxtimeend = time_end
LEFT JOIN forts t3
ON t3.id = t1.fort_id
WHERE t3.external_id IN ( :id ) ", [':id'=>$id])->fetch();
else
$raid = $db->query("SELECT t3.external_id,
t1.fort_id,
raid_level AS level,
pokemon_id,
cp,
move_1,
move_2,
raid_start,
raid_end
FROM (SELECT fort_id,
Max(raid_end) AS MaxTimeEnd
FROM raid_info
GROUP BY fort_id) t1
LEFT JOIN raid_info t2
ON t1.fort_id = t2.fort_id
AND maxtimeend = raid_end
JOIN forts t3
ON t2.fort_id = t3.id
WHERE t3.external_id IN ( :id ) ", [':id'=>$id])->fetch();
$rpid = intval($raid['pokemon_id']);
$p['raid_level'] = intval($raid['level']);
if ($rpid)
$p['raid_pokemon_id'] = $rpid;
if ($rpid)
$p['raid_pokemon_name'] = i8ln($data[$rpid]['name']);
$p['raid_pokemon_cp'] = !empty($raid['cp']) ? intval($raid['cp']) : null;
$p['raid_pokemon_move_1'] = !empty($raid['move_1']) ? intval($raid['move_1']) : null;
$p['raid_pokemon_move_2'] = !empty($raid['move_2']) ? intval($raid['move_2']) : null;
$p['raid_start'] = $raid["raid_start"] * 1000;
$p['raid_end'] = $raid["raid_end"] * 1000;
unset($raid);
}
$p['token'] = refreshCsrfToken();
echo json_encode($p);