-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.ts
38 lines (28 loc) · 1.19 KB
/
index.ts
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
import * as path from 'path';
import * as express from 'express';
import * as serveIndex from 'serve-index';
import { createServer } from 'http';
import { Server } from 'colyseus';
import { monitor } from '@colyseus/monitor';
// Import demo room handlers
import { GameRoom as ExampleRoom } from "./Games/Example/GameRoom";
import { GameRoom as ExampleBodiesRoom } from './Games/ExampleBodies/GameRoom';
import { GameRoom as BattleGroundRoom } from './Games/BattleGround/GameRoom';
const port = Number(process.env.PORT || 2567);
const app = express();
// Attach WebSocket Server on HTTP Server.
const gameServer = new Server({
server: createServer(app)
});
gameServer.register("ExampleRoom", ExampleRoom);
gameServer.register("ExampleBodiesRoom", ExampleBodiesRoom);
gameServer.register("BattleGroundRoom", BattleGroundRoom);
app.use('/', express.static(path.join(__dirname, "static")));
app.use('/', serveIndex(path.join(__dirname, "static"), {'icons': true}))
// (optional) attach web monitoring panel
app.use('/colyseus', monitor(gameServer));
gameServer.onShutdown(function(){
console.log(`game server is going down.`);
});
gameServer.listen(port);
console.log(`Listening on http://localhost:${ port }`);