-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.coffee
executable file
·51 lines (44 loc) · 1.27 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
global._ = require 'lodash'
# modules
express = require 'express'
nodeHttp = require 'http'
colors = require 'colors'
console = require 'better-console'
db = require './models/db'
ws = require './websockets/websockets'
http = require './services/http'
logger = require './services/logger'
gameController = require './controllers/game_controller'
# config
net = require './config/networking'
constants = require './config/constants'
# DATABASE
# --------
do db.syncSchemas
# EXPRESS / SOCKET.IO
# -------------------
app = express()
httpServer = nodeHttp.Server app
# socket.io
ws.setHttpServer httpServer
# add middlewares
http.addSession app, ws.io
http.addThirdPartyMiddlewares app
http.tuneResponses app
# def routing
api = require './api'
api app
# def static
app.use express.static "#{__dirname}/static/web/build"
# START APPLICATION
# -----------------
# start http + websockets
httpServer.listen net.http.port, ->
logger.info "HTTP/WS listening on *:#{net.http.port}".green
# start game logic
setInterval gameController.manageEnergyUser, constants.energy.user.frequencyMs
setInterval gameController.manageEnergyPoint, constants.energy.point.frequencyMs
setInterval gameController.assignTeams, 30000
# log errors
process.on 'uncaughtException', (err) ->
console.error err.stack