-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.ts
69 lines (37 loc) · 1.35 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import path from 'path';
import express from 'express';
import serveIndex from 'serve-index';
import cors from 'cors';
import { createServer } from 'http';
import { Server } from 'colyseus';
import { monitor } from '@colyseus/monitor';
// Import demo room handlers
import { ChatRoom } from "./rooms/01-chat-room";
import { StateHandlerRoom } from "./rooms/02-state-handler";
import { AuthRoom } from "./rooms/03-auth";
//游戏房间
import { GameRoom } from "./rooms/GameRoom";
const port = Number(process.env.PORT || 2567) + Number(process.env.NODE_APP_INSTANCE || 0);
const app = express();
app.use(cors());
app.use(express.json());
const gameServer = new Server({
server: createServer(app),
express: app,
});
gameServer.define("chat", ChatRoom);
gameServer.define("chat_with_options", ChatRoom, {
custom_options: "you can use me on Room#onCreate"
});
gameServer.define("state_handler", StateHandlerRoom);
gameServer.define("auth", AuthRoom);
//声明游戏房间
gameServer.define('game', GameRoom);
app.use('/', express.static(path.join(__dirname, "static")));
app.use('/', serveIndex(path.join(__dirname, "static"), { 'icons': true }))
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}`);