Binato/server/objects/Shared.ts

50 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-09-10 12:59:22 +01:00
import ChatManager from "../ChatManager";
import Config from "../interfaces/Config";
import Database from "../objects/Database";
import DataStreamArray from "../objects/DataStreamArray";
import MultiplayerManager from "../MultiplayerManager";
import PrivateChatManager from "../PrivateChatManager";
2023-09-10 20:37:46 +01:00
import { existsSync, readFileSync } from "fs";
2023-09-10 12:59:22 +01:00
import UserArray from "../objects/UserArray";
import User from "./User";
import LatLng from "./LatLng";
import Bot from "../Bot";
2023-09-10 20:37:46 +01:00
import { ConsoleHelper } from "../../ConsoleHelper";
2023-08-20 13:03:01 +01:00
2023-09-10 12:59:22 +01:00
export default class Shared {
2023-08-20 13:03:01 +01:00
public readonly chatManager:ChatManager;
public readonly config:Config;
public readonly database:Database;
public readonly multiplayerManager:MultiplayerManager;
public readonly privateChatManager:PrivateChatManager;
public readonly streams:DataStreamArray;
public readonly users:UserArray;
public readonly bot:Bot;
public constructor() {
2023-09-10 20:37:46 +01:00
if (!existsSync("./config.json")) {
ConsoleHelper.printError("Config file missing!");
ConsoleHelper.printError("Check the GitHub for an example or create one with the example you have.");
process.exit(1);
}
2023-08-20 13:03:01 +01:00
this.config = JSON.parse(readFileSync("./config.json").toString()) as Config;
this.database = new Database(this.config.database.address, this.config.database.port, this.config.database.username, this.config.database.password, this.config.database.name);
this.streams = new DataStreamArray();
// Add the bot user
this.users = new UserArray();
const botUser = this.users.add("bot", new User(3, "SillyBot", "bot", this));
botUser.location = new LatLng(50, -32);
this.bot = new Bot(this, botUser);
this.chatManager = new ChatManager(this);
// Setup chat channels
this.chatManager.AddChatChannel("osu", "The main channel", true);
this.chatManager.AddChatChannel("lobby", "Talk about multiplayer stuff");
this.chatManager.AddChatChannel("english", "Talk in exclusively English");
this.chatManager.AddChatChannel("japanese", "Talk in exclusively Japanese");
this.multiplayerManager = new MultiplayerManager(this);
this.privateChatManager = new PrivateChatManager(this);
}
}