2019-03-20 15:28:18 -05:00
|
|
|
import http from 'http';
|
|
|
|
import {Server} from '@avocado/server/socket';
|
2019-04-20 14:59:14 -05:00
|
|
|
// Import directly for HMR hierarchy.
|
|
|
|
import '../register-traits';
|
2019-03-20 15:28:18 -05:00
|
|
|
const httpServer = http.createServer();
|
|
|
|
// Start game server.
|
2019-04-20 14:16:06 -05:00
|
|
|
import Game from './game';
|
2019-03-20 15:28:18 -05:00
|
|
|
const avocadoServer = new Server(httpServer);
|
2019-04-20 14:16:06 -05:00
|
|
|
|
|
|
|
let game;
|
|
|
|
|
|
|
|
function createGame() {
|
|
|
|
game = new Game();
|
2019-04-20 19:46:45 -05:00
|
|
|
// Listen for connections.
|
|
|
|
httpServer.listen(8420, '0.0.0.0');
|
2019-04-20 14:16:06 -05:00
|
|
|
avocadoServer.on('connect', game.acceptConnection, game);
|
2019-04-20 19:46:45 -05:00
|
|
|
avocadoServer.open();
|
2019-04-20 14:16:06 -05:00
|
|
|
}
|
|
|
|
|
2019-04-20 19:46:45 -05:00
|
|
|
function destroyGame(fn) {
|
|
|
|
// Stop listening.
|
2019-04-20 14:16:06 -05:00
|
|
|
avocadoServer.off('connect', game.acceptConnection);
|
2019-04-20 19:46:45 -05:00
|
|
|
avocadoServer.close(() => {
|
|
|
|
httpServer.close(() => {
|
|
|
|
game.destroy(fn);
|
|
|
|
})
|
|
|
|
});
|
2019-04-20 14:16:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
createGame();
|
|
|
|
|
|
|
|
if (module.hot) {
|
2019-04-20 14:59:14 -05:00
|
|
|
module.hot.accept([
|
|
|
|
'./game',
|
|
|
|
'../register-traits'
|
|
|
|
], () => {
|
2019-04-20 19:46:45 -05:00
|
|
|
destroyGame(() => {
|
|
|
|
createGame();
|
|
|
|
});
|
2019-04-20 14:16:06 -05:00
|
|
|
});
|
|
|
|
}
|