48 lines
1 KiB
TypeScript
48 lines
1 KiB
TypeScript
import ioserver from 'socket.io';
|
|
import express from 'express';
|
|
import { Server } from 'http';
|
|
import cors from 'cors';
|
|
import { applyArrayPlugins, Random, serverInformationEndpoint } from 'shared';
|
|
import minimist from 'minimist';
|
|
|
|
import { glMatrix } from 'gl-matrix';
|
|
|
|
import { GameServer } from './game-server';
|
|
|
|
import { defaultOptions } from './default-options';
|
|
|
|
glMatrix.setMatrixArrayType(Array);
|
|
applyArrayPlugins();
|
|
|
|
const optionOverrides = minimist(process.argv.slice(2));
|
|
const options = {
|
|
...defaultOptions,
|
|
...optionOverrides,
|
|
};
|
|
|
|
Random.seed = options.seed;
|
|
|
|
const app = express();
|
|
const server = new Server(app);
|
|
const io = ioserver(server);
|
|
|
|
const gameServer = new GameServer(io, options);
|
|
|
|
app.use(
|
|
cors({
|
|
origin: (origin, callback) => {
|
|
callback(null, true);
|
|
},
|
|
credentials: true,
|
|
}),
|
|
);
|
|
|
|
app.get(serverInformationEndpoint, (req, res) => {
|
|
res.json(gameServer.serverInfo);
|
|
});
|
|
|
|
server.listen(options.port, () => {
|
|
console.log(`server started at http://localhost:${options.port}`);
|
|
});
|
|
|
|
gameServer.start();
|