-
Notifications
You must be signed in to change notification settings - Fork 73
/
app.js
executable file
·40 lines (30 loc) · 906 Bytes
/
app.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
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
console.log(err.stack);
});
// http
var http = require('http');
var server = http.createServer();
var port = parseInt(process.env.TANX_PORT || '30043', 10) || 30043;
var host = process.env.TANX_HOST || '0.0.0.0';
server.listen(port, host, function () {
var host = server.address();
console.log('Listening on %s:%s', host.address, host.port);
});
// socket
var WebSocketServer = require('./modules/socket-server');
var ws = new WebSocketServer({
http: server,
prefix: '/socket'
});
// lobby
var Lobby = require('./modules/lobby');
var lobby = new Lobby();
// socket connection
ws.on('connection', function(client) {
// console.log('connected', client.id);
client.send('init', {
id: client.id
});
lobby.join(client);
});