-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
20 lines (18 loc) · 788 Bytes
/
index.js
File metadata and controls
20 lines (18 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 60001 });
const requireDir = require('require-dir');
const commands = requireDir('./API-Calls');
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
let date = new Date();
let formatted ="[" + date.getDate() + "." + date.getMonth() + " | " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "] "
console.log(formatted + message);
let contentArgs = message.split(" "); //Split Message for simpler Access
try {
commands[contentArgs[0]][contentArgs[0]](ws,message);
} catch (error) {
console.log('Command was not Found: ');
console.log(error);
}
});
});