forked from d-zone-org/d-zone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (39 loc) · 1.7 KB
/
index.js
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
'use strict';
var discordConfig = require('./discord-config');
var socketConfig = require('./socket-config');
var Inbox = require('./script/inbox.js');
console.log('Initializing server');
var WebSock = require('./script/websock.js');
var inbox = new Inbox(discordConfig);
var webSock;
inbox.on('connected',function() {
webSock = new WebSock(socketConfig,
function onConnect(socket) {
socket.send(JSON.stringify({ type: 'server-list', data: inbox.getServers() }));
},
function onJoinServer(socket, connectRequest) {
var users = inbox.getUsers(connectRequest);
if(users == 'unknown-server') {
socket.send(JSON.stringify({
type: 'error', data: { message: 'Sorry, couldn\'t connect to that Discord server.' }
}));
} else if(users == 'bad-password') {
socket.send(JSON.stringify({
type: 'error', data: { message: 'Sorry, wrong password for that Discord server.' }
}));
console.log('Client used wrong password to join server',connectRequest.server);
} else {
socket.discordServer = users.server.discordID;
// Send list of current online users to set up initial client state
console.log('Client joined server', users.server.name);
socket.send(JSON.stringify({
type: 'server-join', data: {
users: users.userList, request: connectRequest
}
}));
}
}
);
inbox.on('message',webSock.sendData.bind(webSock));
inbox.on('presence',webSock.sendData.bind(webSock));
});