actually handle renames

This commit is contained in:
Elijah R 2024-06-23 22:20:48 -04:00
parent 2f4e22482d
commit d71fbdaaae
2 changed files with 33 additions and 26 deletions

View file

@ -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);

View file

@ -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;