2023-03-15 15:20:08 +00:00
|
|
|
// Imports
|
|
|
|
import fig from "figlet";
|
|
|
|
import http from "http";
|
|
|
|
import express from "express";
|
|
|
|
import { INFO, OK, logInfo } from "./util/logging.js";
|
|
|
|
|
|
|
|
// Import Core Modules
|
|
|
|
import buildRoutes from "./server/router.js";
|
|
|
|
import injectSockets from "./server/sockets.js";
|
2023-12-20 03:20:04 +00:00
|
|
|
import pg from "./database/postgres.js";
|
2023-03-15 15:20:08 +00:00
|
|
|
|
|
|
|
// Constants
|
|
|
|
const title = "MCL";
|
|
|
|
const port = process.env.MCL_DEV_PORT ?? 52000;
|
|
|
|
|
|
|
|
// Class
|
|
|
|
export default class Minecluster {
|
|
|
|
constructor(options = {}) {
|
|
|
|
for (var k in options) this[k] = options[k];
|
|
|
|
this.port = options.port ?? port;
|
|
|
|
}
|
|
|
|
|
|
|
|
async _preinitialize() {
|
|
|
|
logInfo(fig.textSync(title, "Larry 3D"));
|
|
|
|
INFO("INIT", "Initializing...");
|
|
|
|
this.app = express();
|
2023-12-20 03:20:04 +00:00
|
|
|
this.pg = pg;
|
2023-03-15 15:20:08 +00:00
|
|
|
this.server = http.createServer(this.app);
|
|
|
|
this.sockets = injectSockets(this.server, this.jobs);
|
|
|
|
this.routes = buildRoutes(this.sockets);
|
|
|
|
this.app.use(this.routes);
|
|
|
|
OK("INIT", "Initialized!");
|
|
|
|
}
|
|
|
|
|
|
|
|
async _connect() {
|
2023-12-20 03:20:04 +00:00
|
|
|
await this.pg.connect();
|
2023-03-15 15:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
const mcl = this;
|
2023-12-20 03:20:04 +00:00
|
|
|
|
2023-03-15 15:20:08 +00:00
|
|
|
return new Promise(async function init(res) {
|
|
|
|
mcl._preinitialize();
|
|
|
|
await mcl._connect();
|
|
|
|
mcl.server.listen(mcl.port, function onStart() {
|
|
|
|
OK("SERVER", `Running on ${mcl.port}`);
|
|
|
|
res();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|