Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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 }`);
app.use(cors());
app.use(express.json());
const port = Number(config.app.port);
const server = http.createServer(app);
// game server:
const gameServer = new Colyseus.Server({
server: server,
express: app
});
// main room:
gameServer.define(share.ROOM_GAME, RoomGame);
// game monitor:
if(config.app.colyseusMonitor){
const monitor = require('@colyseus/monitor');
// (optional) attach web monitoring panel:
app.use('/colyseus', monitor.monitor(gameServer));
console.log('NOTIFICATION - Attached Colyseus Monitor.');
}
// server shutdown:
gameServer.onShutdown(function(){
console.log('NOTIFICATION - Game Server is going down.');
});
// @TODO: optimize the query.
// loading scenes data:
let queryString = `SELECT
s.*,
CONCAT('[',
GROUP_CONCAT(
DISTINCT
'{"i":"', sc.tile_index,
'", "n":', (SELECT CONCAT('"', name, '"') FROM scenes WHERE id = sc.next_scene_id),
'}'
app.use(express.json());
// Game server
const server = new Server({
server: createServer(app),
express: app,
});
// Game Rooms
server.define(Constants.ROOM_NAME, GameRoom);
// Serve static resources from the "public" folder
app.use(express.static(join(__dirname, 'public')));
// If you don't want people accessing your server stats, comment this line.
app.use('/colyseus', monitor(server));
// Serve the frontend client
app.get('*', (req: any, res: any) => {
res.sendFile(join(__dirname, 'public', 'index.html'));
});
server.onShutdown(() => {
console.log(`Shutting down...`);
});
server.listen(PORT);
console.log(`Listening on ws://localhost:${PORT}`);
initMonitor()
{
return monitor.monitor(this);
}