// 3rd party. import http from 'http'; // 2nd party. import {SocketServer} from '@avocado/net/server/socket'; // Import directly for HMR hierarchy. import 'register-traits'; // Create fixtures. import './create-fixtures'; // Start game server. import Game from './game'; const socketServer = new SocketServer(); let game; let httpServer; import repl from 'repl'; const instance = repl.start({ prompt: 'humus> ', input: process.stdin, output: process.stdout }); function createGame() { game = new Game(); instance.context.game = game; // Listen for connections. httpServer = http.createServer(); httpServer.listen(8420, '0.0.0.0'); socketServer.on('connect', game.acceptConnection, game); socketServer.open(httpServer); } function destroyGame(fn) { // Stop listening. socketServer.off('connect', game.acceptConnection); socketServer.close(() => { httpServer.close(() => { game.destroy(fn); }) }); } createGame(); if (module.hot) { module.hot.accept([ './game', 'register-traits' ], () => { destroyGame(() => { createGame(); }); }); }