-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (47 loc) · 1.46 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
var app = require('meryl');
var file = new(require('node-static').Server)('./public');
var GamesController = require('./lib/games_controller.js');
app.get('/css|js', function(req, res){
res.removeHeader('content-type');
file.serve(req, res);
});
app.get('/', function(req, res){
file.serveFile("index.html", 200, {}, req, res);
});
//
// app.get('/game/{name}', function(req, res){
// var game = GamesController.get(req.params.name);
//
// res.setHeader('content-type', 'text/json');
// res.end(game.serialized());
// });
//
// app.post('/game/{name}/add', function(req, res){
// var game = GamesController.get(req.params.name);
// var params = JSON.parse(req.postdata);
// console.time('update')
// if(!game.get(params.x, params.y).length){
// var adds = game.add(params.x, params.y, params.data);
// }
// console.timeEnd('update')
//
// res.setHeader('content-type', 'text/json');
// res.end(JSON.stringify(adds || []));
// });
var server = require('http').createServer(app.cgi());
var io = require('socket.io').listen(server);
io.configure(function () {
io.set('transports', ['websocket', 'xhr-polling']);
io.set('log level', 1);
});
io.sockets.on('connection', function (socket) {
socket.on('set name', function (name) {
socket.set('name', name, function () {
// console.log('name', name)
var game = GamesController.get(name);
game.setSocket(socket);
socket.emit('ready');
});
});
});
server.listen(8000);