-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (45 loc) · 1.16 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Canvas Of War
* An online 2d multiplayer shooting game
* https://github.com/7andahalf/
* vinayck.com
*/
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use(express.static(__dirname));
var users = [];
io.on('connection', function(socket){
socket.on('message', function(msg){
io.emit('message', msg);
});
socket.on('spawn', function(msg){
io.emit('spawn', msg);
});
socket.on('game', function(msg){
for(var j in users){
if(users[j][1] == socket.id){
users[j][2] = true;
io.emit('game', msg);
//console.log(users);
return;
}
}
users.push([msg.name, socket.id, true, 0, 0]);
io.emit('game', msg);
//console.log(users);
});
socket.on('disconnect', function(){
for(var j in users){
if(users[j][1] == socket.id){
users[j][2] = false;
io.emit('game', {name : users[j][0], plposx : 10, plposy : 10, gunang: 0, bull: 0});
}
}
//console.log(users);
});
});
http.listen(3000, function(){
console.log('Started server @ 3000');
});