-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·63 lines (42 loc) · 1.4 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
let express = require('express');
let app = express();
let server = require('http').Server(app);
let io = require('socket.io')(server);
module.exports.io = io;
let config = require('./config').general;
let common = require('./common/commonFunctions');
let listHelper = require('./common/listHelper');
let playerFunctions = require('./modelFunctions/playerFunctions');
app.get('/', function (req, res) {
res.sendFile(__dirname + '/client/index.html');
});
app.use('/client', express.static(__dirname + '/client'));
server.listen(1919);
// Main socket actions
io.sockets.on('connection', function (socket) {
socket.on('sign', function (data) {
playerFunctions.sign(socket, data);
});
socket.on('keyEvent', function (data) {
playerFunctions.onKeyEvent(data, socket.id);
});
socket.on('messageFromPlayer', function (data) {
listHelper.getPlayer(socket.id, function (error, player) {
if(player)
common.sendDataToUsers('consoleMessage', playerFunctions.setMessage(player, data));
else
common.sendDataToUsers('consoleMessage', '-Anon-: ' + data);
});
});
socket.on('disconnect', function () {
playerFunctions.disconnect(socket);
});
});
// MAIN LOOP
setInterval(function () {
common.mainLoop();
}, config.refreshInterval);
// remove Disconnected Players (Not For Regular Disconnection Case)
setInterval(function () {
common.checkConnections();
}, config.checkConnectionInterval);