diff --git a/.gitignore b/.gitignore index 35b34ee..3ad23e9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ package-lock.json yarn.lock config.js config.json -dist/ \ No newline at end of file +dist/ +media/ \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index c0aef2f..e49d773 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,13 @@ -import { readFileSync } from "fs"; +import * as fs from "fs"; +import * as path from 'path'; import CollabVMClient from "./client.js"; import Config from "./config.js"; -let config: Config = JSON.parse(readFileSync("config.json", "utf-8")); +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}); function Log(...args: string[]) { console.log("[AnyOSBot]", args.join(" ")); @@ -292,6 +297,11 @@ class HelperBot extends CollabVMClient { help: "Change Floppy image to Dartz IMG/flp image", usesFloppy: true, }, + { + command: "myfloppy", + help: "Insert and/or create your personal floppy disk", + usesFloppy: true + }, { command: "lilyflp [path]", help: "Change Floppy image to Lily IMG/flp image", @@ -517,7 +527,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); + break; + } default: this.Chat(`Unknown command ${command}. See !help?`); break;