diff --git a/server/Bot.ts b/server/Bot.ts index e891562..baca4b5 100644 --- a/server/Bot.ts +++ b/server/Bot.ts @@ -5,7 +5,7 @@ import User from "./objects/User"; // Commands import RankingCommand from "./commands/Ranking"; -import LockCommand from "./commands/Lock"; +import AdminCommand from "./commands/Admin"; import MultiplayerCommands from "./commands/Multiplayer"; import HelpCommand from "./commands/Help"; import RollCommand from "./commands/Roll"; @@ -19,7 +19,7 @@ export default class Bot { this.commands["help"] = new HelpCommand(shared, this.commands); this.commands["ranking"] = new RankingCommand(shared); - this.commands["lock"] = new LockCommand(shared); + this.commands["admin"] = new AdminCommand(shared); this.commands["mp"] = new MultiplayerCommands(shared); this.commands["roll"] = new RollCommand(shared); } diff --git a/server/LoginProcess.ts b/server/LoginProcess.ts index 6a2c4d7..8767656 100644 --- a/server/LoginProcess.ts +++ b/server/LoginProcess.ts @@ -139,7 +139,7 @@ export default async function LoginProcess(req:IncomingMessage, res:ServerRespon } // Retreive the newly created user - newUser = shared.users.add(newClientToken, new User(userInfo.id, loginInfo.username, newClientToken, shared)); + newUser = shared.users.add(newClientToken, new User(userInfo.id, loginInfo.username, newClientToken, userInfo.tags, shared)); // Set tourney client flag newUser.isTourneyUser = isTourneyClient; newUser.location = userLocation; diff --git a/server/commands/Admin.ts b/server/commands/Admin.ts new file mode 100644 index 0000000..c8b861c --- /dev/null +++ b/server/commands/Admin.ts @@ -0,0 +1,35 @@ +import { enumHasFlag } from "../Util"; +import { Permissions } from "../enums/Permissions"; +import Channel from "../objects/Channel"; +import User from "../objects/User"; +import BaseCommand from "./BaseCommand"; + +export default class AdminCommand extends BaseCommand { + public readonly adminOnly:boolean = true; + public readonly helpDescription:string = "Locks/Unlocks a channel and limits conversation to mods and above."; + + public exec(channel:Channel, sender:User, args:Array) { + if (!enumHasFlag(sender.permissions, Permissions.Admin) || !enumHasFlag(sender.permissions, Permissions.Peppy)) { + channel.SendBotMessage("You don't have permission to execute that command."); + return; + } + + const subCommand = args[0].toLowerCase(); + args.shift(); + + switch (subCommand) { + case "lock": + return adminLock(channel); + } + } +} + +function adminLock(channel:Channel) { + if (channel.isSpecial) { + channel.SendBotMessage("Multiplayer channels cannot be locked"); + return; + } + + channel.isLocked = !channel.isLocked; + channel.SendBotMessage(`Channel is now ${channel.isLocked ? "locked" : "unlocked"}`); +} \ No newline at end of file diff --git a/server/commands/BaseCommand.ts b/server/commands/BaseCommand.ts index 4cc4460..1d91599 100644 --- a/server/commands/BaseCommand.ts +++ b/server/commands/BaseCommand.ts @@ -5,7 +5,8 @@ import User from "../objects/User"; export default class BaseCommand implements ICommand { public shared:Shared; - public readonly helpText:string = "No help page was found for that command"; + public readonly adminOnly:boolean = false; + public readonly helpText = "No help page was found for that command"; public readonly helpDescription:string = "Command has no description set"; public readonly helpArguments:Array = new Array(); diff --git a/server/commands/Lock.ts b/server/commands/Lock.ts deleted file mode 100644 index e25db53..0000000 --- a/server/commands/Lock.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Channel from "../objects/Channel"; -import User from "../objects/User"; -import BaseCommand from "./BaseCommand"; - -export default class LockCommand extends BaseCommand { - public readonly helpDescription:string = "Locks/Unlocks a channel and limits conversation to mods and above."; - - public exec(channel:Channel, sender:User, args:Array) { - if (channel.isSpecial) { - channel.SendBotMessage("Multiplayer channels cannot be locked"); - return; - } - - channel.isLocked = !channel.isLocked; - channel.SendBotMessage(`Channel is now ${channel.isLocked ? "locked" : "unlocked"}`); - } -} \ No newline at end of file diff --git a/server/interfaces/ICommand.ts b/server/interfaces/ICommand.ts index 53e8a45..4203b8c 100644 --- a/server/interfaces/ICommand.ts +++ b/server/interfaces/ICommand.ts @@ -4,6 +4,7 @@ import User from "../objects/User"; export default interface ICommand { shared:Shared, + adminOnly:boolean, helpText:string, helpDescription:string, exec: (channel:Channel, sender:User, args:Array) => void diff --git a/server/objects/Shared.ts b/server/objects/Shared.ts index 0626890..8703fa5 100644 --- a/server/objects/Shared.ts +++ b/server/objects/Shared.ts @@ -11,6 +11,7 @@ import LatLng from "./LatLng"; import Bot from "../Bot"; import { ConsoleHelper } from "../../ConsoleHelper"; import UserInfoRepository from "../repos/UserInfoRepository"; +import { Permissions } from "../enums/Permissions"; export default class Shared { public readonly chatManager:ChatManager; @@ -36,7 +37,7 @@ export default class Shared { // Add the bot user this.users = new UserArray(); - const botUser = this.users.add("bot", new User(3, "SillyBot", "bot", this)); + const botUser = this.users.add("bot", new User(3, "SillyBot", "bot", Permissions.None, this)); botUser.location = new LatLng(50, -32); this.bot = new Bot(this, botUser); diff --git a/server/objects/User.ts b/server/objects/User.ts index cb12a8f..8963527 100644 --- a/server/objects/User.ts +++ b/server/objects/User.ts @@ -7,6 +7,7 @@ import Shared from "../objects/Shared"; import Slot from "./Slot"; import Channel from "./Channel"; import PresenceData from "../interfaces/PresenceData"; +import { Permissions } from "../enums/Permissions"; const rankingModes = [ "pp_raw", @@ -28,6 +29,7 @@ export default class User { public rankingMode:RankingModes = RankingModes.PP; public spectatorStream?:DataStream; public spectatingUser?:User; + public permissions:Permissions; // osu! data public playMode:number = 0; @@ -65,10 +67,11 @@ export default class User { return user0.uuid === user1.uuid; } - public constructor(id:number, username:string, uuid:string, shared:Shared) { + public constructor(id:number, username:string, uuid:string, permissions:Permissions, shared:Shared) { this.id = id; this.username = username; this.uuid = uuid; + this.permissions = permissions; this.shared = shared; }