-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
330 lines (297 loc) · 13.7 KB
/
index.html
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>WebSocket Bnut</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<link href="divstyles.css" rel="stylesheet" type="text/css" />
<script src="jquery.min.js"></script>
<script src="angular.min.js"></script>
<script src="functions.js"></script>
<script src="bnetcontrol.js"></script>
<script language="javascript" type="text/javascript">
var wsUri = "wss://connect-bot.classic.blizzard.com/v1/rpc/chat";
var wsProto = "json";
var apiKey = "";
var output;
var btnConnect;
var btnSend;
var staticCommandInput;
var channeltitle;
var lastRequestId = 0;
var connected = false;
var loggedonname = false;
var loggedname = "";
var endofuserlisting = false;
$users = {};
var messageHandlers = {
"Botapichat.DisconnectResponse": OnDisconnectRequest,
"Botapichat.DisconnectEventRequest": OnChatDisconnect,
"Botapichat.SendSetModeratorResponse": OnChatSendOpResponse,
"Botapichat.KickUserResponse": OnChatSendKickUserResponse,
"Botapichat.UnbanUserResponse": OnChatSendUnbanUserResponse,
"Botapichat.BanUserResponse": OnChatSendBanUserResponse,
"Botapichat.SendEmoteResponse": OnChatSendEmoteResponse,
"Botapichat.SendMessageResponse": OnChatSendMessageResponse,
"Botapichat.SendWhisperResponse": OnChatSendWhisperResponse,
"Botapichat.UserLeaveEventRequest": OnUserLeaveEvent,
"Botapiauth.AuthenticateResponse": OnAuthResponse,
"Botapichat.ConnectResponse": OnChatConnectResponse,
"Botapichat.ConnectEventRequest": OnChatConnect,
"Botapichat.MessageEventRequest": OnMessageEvent,
"Botapichat.UserUpdateEventRequest": OnUserUpdateEvent
};
function OnClick_btnConnect(evt)
{
if($("#apikey").val() == "") {
NotificationMessage('error', 'Your API key is not present (enter your key and try again).');
return;
}
apiKey = $("#apikey").val();
if(btnConnect.defaultValue == "Disconnect")
{
websocket.close();
}
if(btnConnect.defaultValue == "Connect")
{
init();
}
}
function ProcessSendMessage(text) {
if(text == undefined) { return; } //text is null
if(text.length < 1) { return; } //no text in the buffer
var $tempbuffer = "";
var userid;
var res = text.split(" ");
if(res[0].toLowerCase() == "/w" || res[0].toLowerCase() == "/whisper") {
//0 = command
if(text.length < res[0].length + 1 || text.length == res[0].length + 1) { return; } //empty whisper command
$tempbuffer = text.substring(res[0].length + 1);
//1 = username
//get id from this name
userid = $GetUserID(res[1]);
if(userid == "-1") {
NotificationMessage('error', 'While you are able to whisper users, they must be in your channel for you to do so (Battle.Net Classic Chat API Cons).');
return;
} //non existant/visable user
if($tempbuffer.length < res[1].length + 1 || $tempbuffer.length == res[1].length + 1) {
NotificationMessage('error', 'Error: Missing message for intended whispered user.');
NotificationMessage('error', 'Error: Message can not be blank.');
return;
} //no message to be sent
$tempbuffer = $tempbuffer.substring(res[1].length + 1);
//whisper message
SendWhisperMessage(userid,$tempbuffer);
return;
}
if(res[0].toLowerCase() == "/me" || res[0].toLowerCase() == "/emote") {
if(text.length < res[0].length + 1 || text.length == res[0].length + 1) { return; } //empty command
$tempbuffer = text.substring(res[0].length + 1);
SendEmoteMessage($tempbuffer);
return;
}
if(res[0].toLowerCase() == "/ban") {
if(text.length < res[0].length + 1 || text.length == res[0].length + 1) { return; } //empty command
$tempbuffer = text.substring(res[0].length + 1);
userid = $GetUserID($tempbuffer);
if(userid == "-1") {
NotificationMessage('error', 'If you cant see them you cant ban them. (Battle.Net Classic Chat API Cons).');
return;
} //non existant/visable user
SendBanMessage(userid);
return;
}
if(res[0].toLowerCase() == "/unban") {
if(text.length < res[0].length + 1 || text.length == res[0].length + 1) { return; } //empty command
$tempbuffer = text.substring(res[0].length + 1);
SendUnbanMessage($tempbuffer);
return;
}
if(res[0].toLowerCase() == "/kick") {
if(text.length < res[0].length + 1 || text.length == res[0].length + 1) { return; } //empty command
$tempbuffer = text.substring(res[0].length + 1);
userid = $GetUserID($tempbuffer);
if(userid == "-1") {
NotificationMessage('error', 'If you cant see them you cant kick them. (Battle.Net Classic Chat API Cons).');
return;
} //non existant/visable user
SendKickMessage(userid);
return;
}
if(res[0].toLowerCase() == "/op") {
if(text.length < res[0].length + 1 || text.length == res[0].length + 1) { return; } //empty command
$tempbuffer = text.substring(res[0].length + 1);
userid = $GetUserID($tempbuffer);
if(userid == "-1") {
NotificationMessage('error', 'If you cant see them you cant Op them. (Battle.Net Classic Chat API Cons).');
return;
} //non existant/visable user
SendOpMessage(userid);
return;
}
if(res[0].toLowerCase() == "/disconnect") {
SendDisconnectMessage();
return;
}
if(res[0].toLowerCase() == "/?" || res[0].toLowerCase() == "/help") {
NotificationMessage('warning', 'Current Commands allowed at this moment:');
NotificationMessage('warning', '(/? || /help)');
NotificationMessage('warning', '(/w || /whisper) username message');
NotificationMessage('warning', '(/me || /emote) message');
NotificationMessage('warning', '(/ban) username');
NotificationMessage('warning', '(/unban) username');
NotificationMessage('warning', '(/kick) username');
NotificationMessage('warning', '(/op) username');
NotificationMessage('warning', '(/disconnect)');
NotificationMessage('warning', 'Hint: You dont have to hit send, you can also hit enter.');
return;
}
SendTextMessage(text);
}
function SendTextMessage(text) {
var textmessage = {
"command": "Botapichat.SendMessageRequest",
"request_id": ++lastRequestId,
"payload": {
"message": text,
}
};
OnSelfMessage(loggedname, text);
doSend(JSON.stringify(textmessage));
}
function OnClick_btnSend(evt) {
var text = $("#command-input").val();
if(text == "") { return; } //empty message dont send.
$("#command-input").val("");
if(connected == false) { return; } //were not connected.
ProcessSendMessage(text);
}
function OnKeyPressed_staticCommandInput(evt) {
if(evt["key"] == "Enter") { //then send the message
var text = $("#command-input").val();
if(text == "") { return; } //empty message dont send.
$("#command-input").val("");
if(connected == false) { return; } //were not connected.
ProcessSendMessage(text);
}
}
function init()
{
channeltitle = document.getElementById("main-channel-title");
channeltitle.innerText = "";
output = document.getElementById("main-chat");
btnConnect = document.getElementById("con-button");
btnConnect.onclick = function(evt) { OnClick_btnConnect(evt) };
btnConnect.defaultValue = "Connect";
btnSend = document.getElementById("command-button");
btnSend.onclick = function(evt) { OnClick_btnSend(evt) }
staticCommandInput = document.getElementById("command-input");
staticCommandInput.onkeypress = function(evt) { OnKeyPressed_staticCommandInput(evt) }
testWebSocket();
}
function testWebSocket()
{
websocket = new WebSocket(wsUri, wsProto);
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}
function onOpen(evt)
{
if($("#apikey").val() == "") {
//NotificationMessage('error', 'Your API key is not present (enter your key and try again).');
return;
}
apiKey = $("#apikey").val();
connected = true;
btnConnect.defaultValue = "Disconnect";
NotificationMessage('1', 'Connected.');
var auth = {
"command": "Botapiauth.AuthenticateRequest",
"request_id": ++lastRequestId,
"payload": {
"api_key": apiKey,
}
};
doSend(JSON.stringify(auth));
}
function onClose(evt)
{
connected = false;
loggedonname = false;
endofuserlisting = false;
btnConnect.defaultValue = "Connect";
ClearUsers();
var myNode = document.getElementById("userlisting");
while (myNode.firstChild) {
myNode.removeChild(myNode.firstChild);
}
channeltitle.innerText = ""; //reset the channel title
NotificationMessage('3', 'Disconnected.');
}
function onMessage(evt)
{
var msg = JSON.parse(evt.data);
var handler = messageHandlers[msg["command"]];
if (handler) {
handler(msg["status"], msg["payload"]);
} else {
writeToScreen('Recved unknown message: ' + msg["command"]);
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data + '</span>');
}
}
function onError(evt)
{
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
function doSend(message)
{
websocket.send(message);
}
function writeToScreen(message)
{
var pre = document.createElement("li");
pre.style.wordWrap = "break-word";
pre.innerText = message;
messagelisting.appendChild(pre);
output.scrollTop = output.scrollHeight;
}
window.addEventListener("load", init, false);
</script>
</head>
<body>
<div class="window-location">
<div class="main-window">
<div class="table">
<div class="table-row">
<div class="table-cell" id="main-apikey">
<input id="apikey" value="" ng-disabled="connected" type="password"></input>
</div>
<div class="table-cell" id="main-connect-button">
<input class="button-cls" type="button" value="{{ connected ? 'Disconnect' : 'Connect' }}" id="con-button"></input>
</div>
</div>
<div class="table-row">
<div class="table-cell" id="main-chat">
<ul id="messagelisting" ng-repeat="message in messages track by $index">
</ul>
</div>
<div class="table-cell" id="main-channel-title">-channel name here-</div>
<div class="table-cell" id="main-userlist">
<ul id="userlisting" ng-repeat="user in users">
</ul>
</div>
</div>
<div class="table-row">
<div class="table-cell" id="main-send-chat">
<input id="command-input" value="" ng-disabled="!connected"></input>
</div>
<div class="table-cell" id="main-send-chat-button">
<input class="button-cls" type="button" value="Send" id="command-button" ng-disabled="!connected"></input>
</div>
</div>
</div>
</div>
</div>
</body>
</html>