diff --git a/TS3AudioBot/MainCommands.cs b/TS3AudioBot/MainCommands.cs index 3e9a1dd6..16e29505 100644 --- a/TS3AudioBot/MainCommands.cs +++ b/TS3AudioBot/MainCommands.cs @@ -1275,11 +1275,11 @@ public static void CommandSettings() public static void CommandSettingsDelete(ConfRoot config, string name) => config.DeleteBotConfig(name).UnwrapThrow(); [Command("settings get")] - public static ConfigPart CommandSettingsGet(ConfBot config, string path = "") + public static ConfigPart CommandSettingsGet(ConfBot config, string path = null) => SettingsGet(config, path); [Command("settings set")] - public static void CommandSettingsSet(ConfBot config, string path, string value = "") + public static void CommandSettingsSet(ConfBot config, string path, string value = null) { SettingsSet(config, path, value); if (!config.SaveWhenExists()) @@ -1290,7 +1290,7 @@ public static void CommandSettingsSet(ConfBot config, string path, string value } [Command("settings bot get", "cmd_settings_get_help")] - public static ConfigPart CommandSettingsBotGet(BotManager bots, ConfRoot config, string bot, string path = "") + public static ConfigPart CommandSettingsBotGet(BotManager bots, ConfRoot config, string bot, string path = null) { using (var botlock = bots.GetBotLock(bot)) { @@ -1300,7 +1300,7 @@ public static ConfigPart CommandSettingsBotGet(BotManager bots, ConfRoot config, } [Command("settings bot set", "cmd_settings_set_help")] - public static void CommandSettingsBotSet(BotManager bots, ConfRoot config, string bot, string path, string value = "") + public static void CommandSettingsBotSet(BotManager bots, ConfRoot config, string bot, string path, string value = null) { using (var botlock = bots.GetBotLock(bot)) { @@ -1319,11 +1319,11 @@ public static void CommandSettingsReload(ConfRoot config, string name = null) } [Command("settings global get")] - public static ConfigPart CommandSettingsGlobalGet(ConfRoot config, string path = "") + public static ConfigPart CommandSettingsGlobalGet(ConfRoot config, string path = null) => SettingsGet(config, path); [Command("settings global set")] - public static void CommandSettingsGlobalSet(ConfRoot config, string path, string value = "") + public static void CommandSettingsGlobalSet(ConfRoot config, string path, string value = null) { SettingsSet(config, path, value); if (!config.Save()) @@ -1358,14 +1358,14 @@ private static ConfBot GetConf(Bot bot, ConfRoot config, string name) } } - private static ConfigPart SettingsGet(ConfigPart config, string path) => config.ByPathAsArray(path).SettingsGetSingle(); + private static ConfigPart SettingsGet(ConfigPart config, string path = null) => config.ByPathAsArray(path ?? "").SettingsGetSingle(); private static void SettingsSet(ConfigPart config, string path, string value) { var setConfig = config.ByPathAsArray(path).SettingsGetSingle(); if (setConfig is IJsonSerializable jsonConfig) { - var result = jsonConfig.FromJson(value); + var result = jsonConfig.FromJson(value ?? ""); if (!result.Ok) throw new CommandException($"Failed to set the value ({result.Error}).", CommandExceptionReason.CommandError); // LOC: TODO } diff --git a/TS3AudioBot/Sessions/TokenManager.cs b/TS3AudioBot/Sessions/TokenManager.cs index 4d1f5492..45a9313c 100644 --- a/TS3AudioBot/Sessions/TokenManager.cs +++ b/TS3AudioBot/Sessions/TokenManager.cs @@ -22,12 +22,10 @@ public class TokenManager private const string ApiTokenTable = "apiToken"; private readonly LiteCollection dbTokenList; // Map: Uid => ApiToken - private readonly Dictionary liveTokenList; + private readonly Dictionary liveTokenList = new Dictionary(); public TokenManager(DbStore database) { - Util.Init(out liveTokenList); - dbTokenList = database.GetCollection(ApiTokenTable); dbTokenList.EnsureIndex(x => x.UserUid, true); dbTokenList.EnsureIndex(x => x.Token, true); diff --git a/WebInterface/src/ts/Api.ts b/WebInterface/src/ts/Api.ts index 4ed3142e..44887219 100644 --- a/WebInterface/src/ts/Api.ts +++ b/WebInterface/src/ts/Api.ts @@ -8,7 +8,7 @@ export class ErrorObject { export class Get { public static AuthData: ApiAuth = ApiAuth.Anonymous; - public static EndpointData: ApiEndpoint = ApiEndpoint.SameAddress; + public static EndpointData: ApiEndpoint = ApiEndpoint.Localhost; public static async site(site: string): Promise { const response = await fetch(site); @@ -67,12 +67,12 @@ export class Get { export class Api { public constructor(private buildAddr: string) { } - public static call(...params: (string | number | Api)[]) { + public static call(...params: (string | number | boolean | Api)[]) { let buildStr = ""; for (const param of params) { if (typeof param === "string") { buildStr += "/" + encodeURIComponent(param).replace(/\(/, "%28").replace(/\)/, "%29"); - } else if (typeof param === "number") { + } else if (typeof param === "number" || typeof param === "boolean") { buildStr += "/" + param.toString(); } else if (param instanceof Api) { buildStr += "/(" + param.done() + ")"; diff --git a/WebInterface/src/ts/ApiObjects.ts b/WebInterface/src/ts/ApiObjects.ts index 59a220c9..1e53b5cc 100644 --- a/WebInterface/src/ts/ApiObjects.ts +++ b/WebInterface/src/ts/ApiObjects.ts @@ -1,14 +1,20 @@ import { BotStatus } from "./Model/BotStatus"; import { TargetSendMode } from "./Model/TargetSendMode"; -// tslint:disable: interface-name - export interface IVersion { build: string; platform: string; sign: string; } +export interface IPassword { + pw: string; + hashed: false; + autohash: false; +} + +// tslint:disable: interface-name + export interface CmdBotInfo { Id: number | null; Name: string | null; diff --git a/WebInterface/src/ts/Components/SettingsField.vue b/WebInterface/src/ts/Components/SettingsField.vue index dcd39c24..5bdc40cc 100644 --- a/WebInterface/src/ts/Components/SettingsField.vue +++ b/WebInterface/src/ts/Components/SettingsField.vue @@ -15,11 +15,12 @@ diff --git a/WebInterface/src/ts/Model/SettingsLevel.ts b/WebInterface/src/ts/Model/SettingsLevel.ts new file mode 100644 index 00000000..21de6ffb --- /dev/null +++ b/WebInterface/src/ts/Model/SettingsLevel.ts @@ -0,0 +1,10 @@ +export enum SettLevel { + Beginner = 0, + Advanced = 1, + Expert = 2, +} + +export interface ISettFilter { + text: string; + level: SettLevel; +} diff --git a/WebInterface/src/ts/Pages/BotSettings.vue b/WebInterface/src/ts/Pages/BotSettings.vue index 92e18885..e2744337 100644 --- a/WebInterface/src/ts/Pages/BotSettings.vue +++ b/WebInterface/src/ts/Pages/BotSettings.vue @@ -52,26 +52,34 @@ Test (TODO) - + + + (Cool dropdown i guess) - + >(TODO) - + + + - - + + + :key="ver.build + ver.platform" + :value="ver" + >{{ver.build}} : {{ver.platform}} - @@ -159,6 +167,7 @@ import Vue from "vue"; import SettingsField from "../Components/SettingsField.vue"; import SettingsGroup from "../Components/SettingsGroup.vue"; +import SettingsPassword from "../Components/SettingsPassword.vue"; import { bot, cmd } from "../Api"; import { IVersion } from "../ApiObjects"; import { Util } from "../Util"; @@ -197,21 +206,35 @@ export default Vue.extend({ volume: {}, bitrate: 0 }, - connect: {}, + connect: { + server_password: {}, + channel_password: {} + }, commands: {} } as any }; }, async created() { const res = await this.requestModel(); - fetch("https://raw.githubusercontent.com/ReSpeak/tsdeclarations/master/Versions.csv") + fetch( + "https://raw.githubusercontent.com/ReSpeak/tsdeclarations/master/Versions.csv" + ) .then(v => v.text()) .then(csv => { - this.versions = csv.split(/\n/gm).slice(1).map(line => line.split(/,/g)).map(parts => { return { - build: parts[0], - platform: parts[1], - sign: parts[2], - }}) + this.versions = csv + .split(/\n/gm) + .slice(1) + .map(line => line.split(/,/g)) + .map(parts => ({ + build: parts[0], + platform: parts[1], + sign: parts[2] + })) + .filter(ver => { + const buildM = ver.build.match(/\[Build: (\d+)\]/); + if (buildM == null) return true; + return Number(buildM[1]) > 1513163251; // > 3.1.7 required + }); }); if (!Util.check(this, res, "Failed to retrieve settings")) return; @@ -237,14 +260,6 @@ export default Vue.extend({ this.model.audio.volume.min = value[0]; this.model.audio.volume.max = value[1]; } - }, - bind_bot_version: { - get(): IVersion { - return this.model.connect.client_version; - }, - set(val: IVersion) { - this.model.connect.client_version = val; - } } }, methods: { @@ -259,10 +274,11 @@ export default Vue.extend({ this.botId.toString() ).get(); }, - sendValue(confVal: string, val: string | number) { + sendValue(confVal: string, val: string | number | object) { + if (typeof val === "object") val = JSON.stringify(val); if (this.online) return bot( - cmd("settings", "set", confVal, val.toString()), + cmd("settings", "set", confVal, val), this.botId ).get(); else @@ -272,17 +288,23 @@ export default Vue.extend({ "set", this.botId.toString(), confVal, - val.toString() + val ).get(); }, + isSettingsObjectGroup(path: string): boolean { + return path.startsWith("connect.client_version"); + }, bindRecursive(path: string, obj: any) { for (const childKey of Object.keys(obj)) { var child: any = obj[childKey]; var childPath = (path ? path + "." : "") + childKey; - if (typeof child === "object" && !Array.isArray(child)) { + if ( + typeof child === "object" && + !Array.isArray(child) && + !this.isSettingsObjectGroup(childPath) + ) { this.bindRecursive(childPath, child); - } /*if (typeof child === "number" || typeof child === "string") */ else { - //console.log("binding", childPath); + } else { this.doWatch(childPath, child); } } @@ -325,7 +347,8 @@ export default Vue.extend({ }, components: { SettingsField, - SettingsGroup + SettingsGroup, + SettingsPassword } });