-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.coffee
54 lines (40 loc) · 1.23 KB
/
server.coffee
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
express = require("express")
app = express()
http = require('http')
app.configure ->
app.set('port', process.env.PORT || 3000);
app.use express.bodyParser()
app.use app.router
app.use express.static "#{__dirname}/public"
app.set "views", "#{__dirname}/views"
app.set "view engine", "jade"
app.get "/", (req, res) ->
res.render "index"
app.get "/game", (req, res) ->
res.render "game"
app.get "/about", (req, res) ->
res.render "about"
app.get "/camera", (req, res) ->
res.render "camera"
app.get "/pong", (req, res) ->
res.render "pong"
app.get "/preview", (req, res) ->
res.render "preview"
server = http.createServer(app).listen app.get('port'), ->
console.log("Express server listening on port " + app.get('port'))
Game = require('./lib/game/start')
io = require('socket.io').listen(server, app)
io.set('log level', 1)
global.canvas_width = 800
global.canvas_height = 600
games = []
io.sockets.on 'connection', (socket) ->
console.log("you have connected, there are currently #{games.length} games")
if games.length == 0
games.push(new Game(socket))
else
openGames = games.filter (game) -> game.open
if openGames.length > 0
openGames[0].join(socket)
else
games.push(new Game(socket))