-
Notifications
You must be signed in to change notification settings - Fork 35
/
scrum_cards_server.js
62 lines (50 loc) · 1.54 KB
/
scrum_cards_server.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
57
58
59
60
61
var app = require('express').createServer(),
io = require('socket.io').listen(app),
sockDict = new Array();
adminSocket = null,
config = require('./settings.js');
app.listen(config.port);
io.sockets.on('connection',function(socket){
socket.on('signIn',function(data,fn){
if(process.argv.length <= 2){
fn(false,'Not enough startup arguments when starting the server app');
return;
}
for(sock in sockDict){
var name = sockDict[sock];
if(name == data.userName){
fn(false,"Username taken!");
return;
}
}
sockDict[socket.id] = data.userName;
if(data.userName == process.argv[2]){
adminSocket = socket;
}else{
if(adminSocket != null){
adminSocket.emit('userSignedIn',{ 'userName' : data.userName});
}
}
if(adminSocket == null){
fn(false,'No server started, try again later');
}
fn(true,{ 'points' : config.points} );
});
socket.on('vote',function(data){
adminSocket.emit('voteOccured', data);
});
socket.on('resetCmd',function(){
if(sockDict == null) return;
socket.broadcast.emit('reset',{ 'userName' : sockDict[socket.id] });
});
socket.on('disconnect',function(){
if(adminSocket != null && socket == adminSocket){
adminSocket = null;
socket.broadcast.emit('adminDisconnected', { 'userName' : sockDict[socket.id] });
sockDict = new Array();
}else{
adminSocket.emit('clientDisconnect', {userName : sockDict[socket.id] });
}
sockDict[socket.id] = null;
});
});