Binato/server/objects/Shared.ts

60 lines
2.5 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-10-04 15:10:38 +01:00
import UserInfoRepository from "../repos/UserInfoRepository";
2023-10-04 16:13:16 +01:00
import { Permissions } from "../enums/Permissions";
2023-10-07 13:09:10 +01:00
import UserModesInfoRepository from "../repos/UserModesInfoRepository";
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;
2023-10-04 15:10:38 +01:00
public readonly userInfoRepository:UserInfoRepository;
2023-10-07 13:09:10 +01:00
public readonly userModesInfoRepository:UserModesInfoRepository;
2023-10-04 15:10:38 +01:00
2023-08-20 13:03:01 +01:00
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();
2023-10-04 16:13:16 +01:00
const botUser = this.users.add("bot", new User(3, "SillyBot", "bot", Permissions.None, this));
2023-08-20 13:03:01 +01:00
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);
2023-10-04 15:10:38 +01:00
// DB Repos
this.userInfoRepository = new UserInfoRepository(this);
2023-10-07 13:09:10 +01:00
this.userModesInfoRepository = new UserModesInfoRepository(this);
2023-08-20 13:03:01 +01:00
}
}