actually handle renames
This commit is contained in:
parent
2f4e22482d
commit
d71fbdaaae
2 changed files with 33 additions and 26 deletions
|
@ -64,6 +64,9 @@ class UserData {
|
||||||
GetName() {
|
GetName() {
|
||||||
return this._name;
|
return this._name;
|
||||||
}
|
}
|
||||||
|
SetName(name: string) {
|
||||||
|
this._name = name;
|
||||||
|
}
|
||||||
GetRank() {
|
GetRank() {
|
||||||
return this._rank;
|
return this._rank;
|
||||||
}
|
}
|
||||||
|
@ -148,7 +151,10 @@ export default abstract class CollabVMClient {
|
||||||
message.length === 3 &&
|
message.length === 3 &&
|
||||||
!IsSystemChatInstruction(message)
|
!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]);
|
this.OnChat(message[1], message[2]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -164,11 +170,14 @@ export default abstract class CollabVMClient {
|
||||||
|
|
||||||
// Handle renames
|
// Handle renames
|
||||||
if (message[0] === "rename") {
|
if (message[0] === "rename") {
|
||||||
if (message.length === 5) {
|
let oldname;
|
||||||
if (message[1] == "1") {
|
if (message[1] == "1") {
|
||||||
this._username = message[3];
|
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);
|
this.OnGuacamoleMessage(message);
|
||||||
|
|
38
src/index.ts
38
src/index.ts
|
@ -1,5 +1,5 @@
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from 'path';
|
import * as path from "path";
|
||||||
import CollabVMClient from "./client.js";
|
import CollabVMClient from "./client.js";
|
||||||
import Config from "./config.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);
|
const blankflp = Buffer.alloc(1440000);
|
||||||
if (!fs.existsSync("media/flp/"))
|
if (!fs.existsSync("media/flp/"))
|
||||||
fs.mkdirSync("media/flp/", {recursive: true});
|
fs.mkdirSync("media/flp/", { recursive: true });
|
||||||
|
|
||||||
function Log(...args: string[]) {
|
function Log(...args: string[]) {
|
||||||
console.log("[AnyOSBot]", args.join(" "));
|
console.log("[AnyOSBot]", args.join(" "));
|
||||||
|
@ -197,8 +197,7 @@ class HelperBot extends CollabVMClient {
|
||||||
QemuChangeFloppy(source: string, readOnly: boolean = true) {
|
QemuChangeFloppy(source: string, readOnly: boolean = true) {
|
||||||
let opts = "raw";
|
let opts = "raw";
|
||||||
if (readOnly) opts += " read-only";
|
if (readOnly) opts += " read-only";
|
||||||
if (this._hasFloppy)
|
if (this._hasFloppy) this.QemuChangeDevice("vm.floppy", source, opts);
|
||||||
this.QemuChangeDevice("vm.floppy", source, opts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OnChat(username: string, message: string) {
|
OnChat(username: string, message: string) {
|
||||||
|
@ -302,7 +301,7 @@ class HelperBot extends CollabVMClient {
|
||||||
{
|
{
|
||||||
command: "myfloppy",
|
command: "myfloppy",
|
||||||
help: "Insert and/or create your personal floppy disk",
|
help: "Insert and/or create your personal floppy disk",
|
||||||
usesFloppy: true
|
usesFloppy: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: "lilyflp [path]",
|
command: "lilyflp [path]",
|
||||||
|
@ -529,21 +528,20 @@ class HelperBot extends CollabVMClient {
|
||||||
`boot_set ${message.slice(message.indexOf(" ") + 1)}`,
|
`boot_set ${message.slice(message.indexOf(" ") + 1)}`,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "myfloppy":
|
case "myfloppy": {
|
||||||
{
|
if (!DoLimit(this.GeneralCmdLimit!)) return;
|
||||||
if (!DoLimit(this.GeneralCmdLimit!)) return;
|
if (!this._hasFloppy) {
|
||||||
if (!this._hasFloppy) {
|
this.Chat("This VM does not have a floppy drive.");
|
||||||
this.Chat("This VM does not have a floppy drive.");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
let flppath = path.resolve(`media/flp/${username}.img`);
|
||||||
let flppath = path.resolve(`media/flp/${username}.img`)
|
if (!fs.existsSync(flppath)) {
|
||||||
if (!fs.existsSync(flppath)) {
|
fs.writeFileSync(flppath, blankflp);
|
||||||
fs.writeFileSync(flppath, blankflp);
|
}
|
||||||
}
|
this.QemuChangeFloppy(flppath, false);
|
||||||
this.QemuChangeFloppy(flppath, false);
|
this.Chat("Tried to put media into specified device.");
|
||||||
this.Chat("Tried to put media into specified device.");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
this.Chat(`Unknown command ${command}. See !help?`);
|
this.Chat(`Unknown command ${command}. See !help?`);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue