diff --git a/src/client.ts b/src/client.ts index 38ac4c0..9280ea0 100644 --- a/src/client.ts +++ b/src/client.ts @@ -64,6 +64,9 @@ class UserData { GetName() { return this._name; } + SetName(name: string) { + this._name = name; + } GetRank() { return this._rank; } @@ -148,7 +151,10 @@ export default abstract class CollabVMClient { message.length === 3 && !IsSystemChatInstruction(message) ) { - if (message[1] != this._username && this._users.some(u => u.GetName() === message[1])) { + if ( + message[1] != this._username && + this._users.some((u) => u.GetName() === message[1]) + ) { this.OnChat(message[1], message[2]); return; } @@ -164,11 +170,14 @@ export default abstract class CollabVMClient { // Handle renames if (message[0] === "rename") { - if (message.length === 5) { - if (message[1] == "1") { - this._username = message[3]; - } - } + let oldname; + if (message[1] == "1") { + oldname = this._username; + this._username = message[3]; + } else oldname = message[2]; + let _user = this._users.find((u) => u.GetName() === oldname); + if (_user === undefined) return; + _user.SetName(message[3]); } this.OnGuacamoleMessage(message); diff --git a/src/index.ts b/src/index.ts index d361c61..32fa4ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import * as fs from "fs"; -import * as path from 'path'; +import * as path from "path"; import CollabVMClient from "./client.js"; import Config from "./config.js"; @@ -7,7 +7,7 @@ let config: Config = JSON.parse(fs.readFileSync("config.json", "utf-8")); const blankflp = Buffer.alloc(1440000); if (!fs.existsSync("media/flp/")) - fs.mkdirSync("media/flp/", {recursive: true}); + fs.mkdirSync("media/flp/", { recursive: true }); function Log(...args: string[]) { console.log("[AnyOSBot]", args.join(" ")); @@ -197,8 +197,7 @@ class HelperBot extends CollabVMClient { QemuChangeFloppy(source: string, readOnly: boolean = true) { let opts = "raw"; if (readOnly) opts += " read-only"; - if (this._hasFloppy) - this.QemuChangeDevice("vm.floppy", source, opts); + if (this._hasFloppy) this.QemuChangeDevice("vm.floppy", source, opts); } OnChat(username: string, message: string) { @@ -302,7 +301,7 @@ class HelperBot extends CollabVMClient { { command: "myfloppy", help: "Insert and/or create your personal floppy disk", - usesFloppy: true + usesFloppy: true, }, { command: "lilyflp [path]", @@ -529,21 +528,20 @@ class HelperBot extends CollabVMClient { `boot_set ${message.slice(message.indexOf(" ") + 1)}`, ); break; - case "myfloppy": - { - if (!DoLimit(this.GeneralCmdLimit!)) return; - if (!this._hasFloppy) { - this.Chat("This VM does not have a floppy drive."); - return; - } - let flppath = path.resolve(`media/flp/${username}.img`) - if (!fs.existsSync(flppath)) { - fs.writeFileSync(flppath, blankflp); - } - this.QemuChangeFloppy(flppath, false); - this.Chat("Tried to put media into specified device."); - break; - } + case "myfloppy": { + if (!DoLimit(this.GeneralCmdLimit!)) return; + if (!this._hasFloppy) { + this.Chat("This VM does not have a floppy drive."); + return; + } + let flppath = path.resolve(`media/flp/${username}.img`); + if (!fs.existsSync(flppath)) { + fs.writeFileSync(flppath, blankflp); + } + this.QemuChangeFloppy(flppath, false); + this.Chat("Tried to put media into specified device."); + break; + } default: this.Chat(`Unknown command ${command}. See !help?`); break;