-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (35 loc) · 953 Bytes
/
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
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var users = [][];
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
socket.on("adduser", function(user,score){
socket.user = user;
users.push(user);
updateClients();
});
socket.on('ip', function (myip) {
console.log('a user with ip', myip, 'connected.');
console.log("Finding match for", myip, ".");
var findMatch = require(".\src\FindMatch.js");
findMatch.start(myip);
});
socket.on('disconnect', function(){
for(var i = 0; i < users.length; i++){
if(users[i] == socket.user){
delete users[users[i]];
}
}
updateClients();
console.log('user disconnected');
});
function updateClients(){
io.sockets.emit('update', users);
}
});
http.listen(3000, function(){
console.log('listening on *:3000');
});