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
|
<!doctype html>
<html>
<head>
<title>Vainsocial backend status</title>
</head>
<body>
<p>
<form id="update-form">
<input type="text" id="update-name">
<input type="checkbox" id="update-force">
<label for="update-force">Force refresh</label>
<input type="checkbox" id="update-brawl">
<label for="update-brawl">Get Brawls</label>
<input type="checkbox" id="update-tournament">
<label for="update-tournament">Get Privates (Tournaments)</label>
<input type="submit" value="Update">
</form>
</p>
<p>
<form id="update-random-form">
<input type="submit" value="Update random player">
</form>
</p>
<p>
<form id="get-samples-form">
<input type="submit" value="Download latest samples">
</form>
</p>
<p>
<form id="crunch-form">
<input type="text" id="crunch-name">
<input type="submit" value="Crunch">
</form>
</p>
<p>
<form id="crunchglobal-form">
<input type="checkbox" id="crunch-force">
<label for="crunch-force">Force recrunch</label>
<input type="submit" value="Crunch global stats">
</form>
</p>
<p>
<form id="update-region-form">
<select id="update-region-region">
<option value="tournament-na">NA Tournament server</option>
<option value="tournament-eu">EU Tournament server</option>
<option value="tournament-sg">SG Tournament server</option>
<option value="tournament-sa">SA Tournament server</option>
<option value="tournament-ea">EA Tournament server</option>
</select>
<input type="submit" value="Update region">
</form>
</p>
<ul id="updates"></ul>
<script src="https://cdn.jsdelivr.net/sockjs/1/sockjs.min.js"></script>
<script type="text/javascript" src="/js/webstomp.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
let client;
// set up the client
if ('WebSocket' in window && (typeof WebSocket === 'function' || typeof WebSocket === 'object')) {
client = webstomp.client("ws://localhost:15674/ws");
} else {
// http fallback
client = webstomp.over(SockJS("http://localhost:15674/stomp"));
}
const notif = (text, color) => {
$("#updates").append(
$("<li>")
.text(text)
.css("color", color)
);
};
// connect
client.connect("web", "web", () => {
notif("connected to socket", "purple");
client.subscribe("/topic/#", (msg) => {
let name = "";
if (msg.headers.destination.indexOf("player") != -1)
name = msg.headers.destination.substring(
"/topic/player.".length);
else name = "global";
notif(msg.body, "grey");
switch (msg.body) {
case "search_fail":
notif(name + ": not found", "red"); break;
case "search_success":
notif(name + ": found", "green"); break;
case "grab_fail":
notif(name + ": grabbed everything", "grey"); break;
case "grab_success":
notif(name + ": grabbed a page", "green"); break;
case "matches_update":
notif(name + ": new match(es) available", "orange"); break;
case "stats_update":
notif(name + ": player profile stats updated", "orange"); break;
case "points_update":
notif(name + ": stats updated", "orange"); break;
}
msg.ack();
}, {"ack": "client"});
},
(err) => notif("error connecting to socket: " + JSON.stringify(err), "red"));
$("#update-form").submit((e) => {
e.preventDefault();
const ign = $("#update-name").val(),
force = $("#update-force").is(":checked"),
brawls = $("#update-brawl").is(":checked"),
tournament = $("#update-tournament").is(":checked");
if (force) {
$.post("/api/player/" + ign + "/search");
} else {
if (brawls)
$.post("/api/player/" + ign + "/update/brawl");
else if (tournament)
$.post("/api/player/" + ign + "/update/tournament");
else
$.post("/api/player/" + ign + "/update");
}
});
$("#update-region-form").submit((e) => {
e.preventDefault();
const region = $("#update-region-region").val();
$.post("/api/match/" + region + "/update");
});
$("#update-random-form").submit((e) => {
e.preventDefault();
$.post("/api/player");
});
$("#get-samples-form").submit((e) => {
e.preventDefault();
$.post("/api/samples").done((resp) => {
notif("downloading samples", "green");
});
});
$("#crunch-form").submit((e) => {
e.preventDefault();
const ign = $("#crunch-name").val();
$.post("/api/player/" + ign + "/crunch");
});
$("#crunchglobal-form").submit((e) => {
const force = $("#crunch-force").is(":checked");
e.preventDefault();
if (force)
$.post("/api/recrunch");
else
$.post("/api/crunch");
});
</script>
</body>
</html>
|