1
0
mirror of synced 2025-01-23 23:04:07 +01:00
Bayshore/src/index.ts

120 lines
3.1 KiB
TypeScript
Raw Normal View History

2022-07-11 08:22:41 +01:00
// Bayshore - a Wangan Midnight Maximum Tune 6 private server.
// Made with love by Luna, and part of Project Asakura.
2022-07-12 12:31:18 +01:00
import express, { Router } from 'express';
2022-07-11 08:22:41 +01:00
import {PrismaClient} from '@prisma/client';
2022-07-11 11:45:36 +01:00
import https, {globalAgent} from 'https';
2022-07-12 12:17:36 +01:00
import http from 'http';
2022-07-11 08:38:33 +01:00
import fs from 'fs';
2022-07-11 11:45:36 +01:00
import bodyParser from 'body-parser';
import AllnetModule from './allnet';
import MuchaModule from './mucha';
2022-07-17 15:14:23 +01:00
import { Config } from './config';
import process from 'process';
2022-07-18 11:08:13 +01:00
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import * as dotenv from "dotenv";
dotenv.config({path: __dirname + '/.env'});
2022-07-11 11:45:36 +01:00
globalAgent.options.keepAlive = true;
// @ts-ignore
require('http').globalAgent.options.keepAlive = true;
2022-07-11 08:38:33 +01:00
2022-07-15 15:39:59 +01:00
export const prisma = new PrismaClient();
2022-07-12 12:31:18 +01:00
const appRouter = Router();
const PORT_ALLNET = 80;
const PORT_MUCHA = 10082;
const PORT_BNGI = 9002;
2022-07-11 08:38:33 +01:00
const app = express();
2022-07-11 11:45:36 +01:00
app.use(bodyParser.raw({
type: '*/*'
}));
2022-07-11 08:38:33 +01:00
2022-07-18 11:08:13 +01:00
let useSentry = !!Config.getConfig().sentryDsn;
if (useSentry) {
Sentry.init({
dsn: Config.getConfig().sentryDsn,
integrations: [
new Sentry.Integrations.Http({tracing: true}),
new Tracing.Integrations.Express({
router: appRouter,
})
],
tracesSampleRate: 0.5
});
}
const muchaApp = express();
const allnetApp = express();
2022-07-18 11:08:13 +01:00
if (useSentry) {
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
}
app.use((req, res, next) => {
console.log(`[ MAIN] ${req.method} ${req.url}`);
next()
});
muchaApp.use((req, res, next) => {
console.log(`[ MUCHA] ${req.method} ${req.url}`);
next()
});
allnetApp.use((req, res, next) => {
console.log(`[ALLNET] ${req.method} ${req.url}`);
next()
});
2022-07-11 09:15:30 +01:00
let dirs = fs.readdirSync('dist/modules');
for (let i of dirs) {
if (i.endsWith('.js')) {
let mod = require(`./modules/${i.substring(0, i.length - 3)}`); // .js extension
let inst = new mod.default();
2022-07-12 12:31:18 +01:00
inst.register(appRouter);
2022-07-11 09:15:30 +01:00
}
}
2022-07-12 12:31:18 +01:00
app.use('/', appRouter);
app.use('/wmmt6/', appRouter);
2022-07-11 09:15:30 +01:00
app.all('*', (req, res) => {
2022-07-14 10:00:03 +01:00
console.log(`[ MAIN] ${req.method} ${req.url} is unhandled`);
res.status(200).end();
2022-07-11 09:15:30 +01:00
})
new AllnetModule().register(allnetApp);
new MuchaModule().register(muchaApp);
2022-07-18 11:08:13 +01:00
if (useSentry)
app.use(Sentry.Handlers.errorHandler());
let key = fs.readFileSync('./server_wangan.key');
let cert = fs.readFileSync('./server_wangan.crt');
2022-07-12 12:17:36 +01:00
http.createServer(allnetApp).listen(PORT_ALLNET, '0.0.0.0', 511, () => {
console.log(`ALL.net server listening on port ${PORT_ALLNET}!`);
2022-07-17 15:14:23 +01:00
let unix = Config.getConfig().unix;
if (unix && process.platform == 'linux') {
console.log('Downgrading permissions...');
process.setgid!(unix.setgid);
2022-07-17 15:18:56 +01:00
process.setuid!(unix.setuid);
2022-07-17 15:14:23 +01:00
console.log('Done!');
}
})
2022-07-12 12:17:36 +01:00
https.createServer({key, cert}, muchaApp).listen(PORT_MUCHA, '0.0.0.0', 511, () => {
console.log(`Mucha server listening on port ${PORT_MUCHA}!`);
})
2022-07-12 12:17:36 +01:00
https.createServer({key, cert}, app).listen(PORT_BNGI, '0.0.0.0', 511, () => {
console.log(`Game server listening on port ${PORT_BNGI}!`);
})