-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
94 lines (71 loc) · 2.02 KB
/
Copy pathserver.js
File metadata and controls
94 lines (71 loc) · 2.02 KB
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
var express = require('express'),
app = express(app),
server = require('http').createServer(app),
io = require('socket.io')(server),
ip = require('ip'),
currentIp = ip.address(),
serverPort = 8080;
app.set('view engine', 'ejs');
app.use(express.static('views'));
app.get('/index.html', function(req, res) {
res.render('index.ejs', {
ip: currentIp,
port: serverPort
});
});
app.get('/', function(req, res) {
res.render('index.ejs', {
ip: currentIp,
port: serverPort
});
});
server.listen(serverPort, '0.0.0.0', function() {
console.log('listening on *:' + serverPort + ' & ' + currentIp);
});
var pong = io.of('/pong');
pong.on('connection', function(pongSocket) {
console.log('a Pong user connected ' + pongSocket.id);
pongSocket.on('disconnect', function() {
console.log('Pong user disconnected ' + pongSocket.id);
id = (pongSocket.id).slice(6);
pong.emit('disconnect', id);
});
pongSocket.on('join', function(data) {
pong.emit('join', data)
});
pongSocket.on('check', function(data) {
pong.emit('check', data)
});
pongSocket.on('spaces', function(data) {
pong.emit('spaces', data)
});
pongSocket.on('available', function(msg) {
pong.emit('available', msg);
});
pongSocket.on('Lcontrol message', function(msg) {
pong.emit('Lcontrol message', msg);
});
pongSocket.on('Rcontrol message', function(msg) {
pong.emit('Rcontrol message', msg);
});
pongSocket.on('score', function(msg) {
pong.emit('score', msg);
});
pongSocket.on('winner', function(msg) {
pong.emit('winner', msg);
});
pongSocket.on('newGame', function(msg) {
pong.emit('newGame', msg);
});
});
var cube = io.of('/cube');
cube.on('connection', function(cubeSocket) {
console.log('a CUBE user connected ' + cubeSocket.id);
cubeSocket.on('message', function(data) {
cube.emit('message', data);
});
cubeSocket.on('shutdown', function() {
console.log('shutdown call recived');
require('child_process').exec('sudo shutdown now');
});
});