-
Notifications
You must be signed in to change notification settings - Fork 35
/
api.php
115 lines (97 loc) · 4.04 KB
/
api.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
<?php
require_once("inc/config.php");
if (empty($_GET['type'])) {
die("No API given!");
}
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
if ($_GET['type'] == "token" && !empty($_GET['token'])) {
$q = $pdo->prepare("SELECT COUNT(id) as count, id FROM users WHERE apitoken = ?");
$q->execute([$_GET['token']]);
$row = $q->fetch(PDO::FETCH_ASSOC);
if ($row['count'] == 0) {
echo 0;
} else {
echo $row['id'];
}
}
if ($_GET['type'] == "tactkeys") {
$q = $pdo->query("SELECT * FROM wow_tactkey WHERE keybytes IS NOT NULL");
$tactkeys = $q->fetchAll(PDO::FETCH_ASSOC);
foreach ($tactkeys as $tactkey) {
echo $tactkey['keyname'] . " " . $tactkey['keybytes'] . "\n";
}
}
if ($_GET['type'] == "dblist") {
if (empty($_GET['build'])) {
die("No build given");
}
$buildExpl = explode(".", $_GET['build']);
if (count($buildExpl) != 4) {
die("Invalid build");
}
$buildDesc = "WOW-" . $buildExpl[3] . "patch" . $buildExpl[0] . "." . $buildExpl[1] . "." . $buildExpl[2];
$q = $pdo->prepare("SELECT filename FROM wow_rootfiles JOIN wow_rootfiles_builds_erorus ON ORD(MID(wow_rootfiles_builds_erorus.files, 1 + FLOOR(wow_rootfiles.id / 8), 1)) & (1 << (wow_rootfiles.id % 8)) WHERE wow_rootfiles_builds_erorus.build = (SELECT id FROM wow_buildconfig WHERE description LIKE ? LIMIT 1) AND wow_rootfiles.type = 'db2'");
$q->execute([$buildDesc . "%"]);
$all = $q->fetchAll(PDO::FETCH_COLUMN);
echo implode(',', $all);
}
if ($_GET['type'] == "latestbuilds") {
$builds = [];
$urlq = $pdo->query("SELECT id, name, url FROM ngdp_urls WHERE url LIKE '%wow%versions' ORDER BY ID ASC");
$histq = $pdo->prepare("SELECT newvalue, timestamp FROM ngdp_history WHERE url_id = ? AND event = 'valuechange' ORDER BY ID DESC LIMIT 1");
while ($row = $urlq->fetch(PDO::FETCH_ASSOC)) {
$histq->execute([$row['id']]);
$product = str_replace("/versions", "", substr($row['url'], strpos($row['url'], "wow")));
$highestBuild = 0;
$highestBuildName = "";
$histr = $histq->fetch(PDO::FETCH_ASSOC);
if (!empty($histr)) {
$bc = parseBPSV(explode("\n", $histr['newvalue']));
foreach ($bc as $bcregion) {
if ($bcregion['BuildId'] > $highestBuild) {
$highestBuild = $bcregion['BuildId'];
$highestBuildName = $bcregion['VersionsName'];
}
}
}
if (!empty($highestBuildName)) {
$builds[$product] = $highestBuildName;
}
}
echo json_encode($builds);
}
if ($_GET['type'] == "currentbc") {
$builds = [];
$urlq = $pdo->query("SELECT id, name, url FROM ngdp_urls WHERE url LIKE '%wow%versions' ORDER BY ID ASC");
$histq = $pdo->prepare("SELECT newvalue, timestamp FROM ngdp_history WHERE url_id = ? AND event = 'valuechange' ORDER BY ID DESC LIMIT 1");
while ($row = $urlq->fetch(PDO::FETCH_ASSOC)) {
$histq->execute([$row['id']]);
$product = str_replace("/versions", "", substr($row['url'], strpos($row['url'], "wow")));
$highestBuild = 0;
$highestBuildConfig = "";
$histr = $histq->fetch(PDO::FETCH_ASSOC);
if (!empty($histr)) {
$bc = parseBPSV(explode("\n", $histr['newvalue']));
foreach ($bc as $bcregion) {
if ($bcregion['BuildId'] > $highestBuild) {
$highestBuild = $bcregion['BuildId'];
$highestBuildConfig = $bcregion['BuildConfig'];
}
}
}
if (!empty($highestBuildConfig)) {
$builds[$product] = $highestBuildConfig;
}
}
echo json_encode($builds);
}
if ($_GET['type'] == "namebybc") {
$bcq = $pdo->prepare("SELECT `description` FROM wow_buildconfig WHERE hash = ?");
$bcq->execute([$_GET['hash']]);
$buildName = "";
while ($row = $bcq->fetch(PDO::FETCH_ASSOC)) {
$buildName = parseBuildName($row['description'])['full'];
}
echo $buildName;
}