From 168d42398e76008092d9b21efe578c71fc11304d Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sat, 21 Jan 2023 21:49:12 +0100 Subject: [PATCH] exit output bugfix and nickname in pretext --- js/commands.js | 14 ++++++++++---- js/networking.js | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/js/commands.js b/js/commands.js index a117fdf..c41ea42 100644 --- a/js/commands.js +++ b/js/commands.js @@ -5,14 +5,14 @@ function runCommand(input) { return ""; // Exit current level - if (input.toLowerCase().startsWith("exit")) { + const modeSplit = chatMode.split(' ')[0]; + if (input.toLowerCase().startsWith("exit") && modeSplit !== "default") { cmd_exit(); return ""; } // Handle different chat modes - const modeSplit = chatMode.split(' '); - switch (modeSplit[0]) { + switch (modeSplit) { case "msg": directMessage(modeSplit[1], input); renameToSelf(); @@ -88,6 +88,10 @@ function cmd_clear() { for (let i = tbc.length-3; i > 1; i--) tbDiv.removeChild(tbc[i]); + const prelink = document.createElement("a"); + prelink.innerHTML = pretext.original; + tbDiv.replaceChild(prelink, tbc[1]); + pretext.current = pretext.original; cursorPosition = 0; cursorYOffset = 7; @@ -173,8 +177,10 @@ function cmd_msg(input) { // Exit current level (example: chat -> main) function cmd_exit(error) { const level = chatMode.split(' ')[0]; - if (level === "default") + if (level === "default") { + console.log("Test!"); return "Already at top-level!"; + } // Set mode to default and reset pretext chatMode = "default"; diff --git a/js/networking.js b/js/networking.js index eb75950..3b8f4ff 100644 --- a/js/networking.js +++ b/js/networking.js @@ -42,6 +42,7 @@ function connect(name) { // Save provided id const { id } = res; user.id = id; + pretext.original = pretext.current = `${user.name}@baipyr.us:~# `; outputText({output: `Connected as '${name}#${id}'.`}); }); } @@ -49,6 +50,7 @@ function connect(name) { // Send nickname to server, receive verification function sendNickname(name) { + user.name = name; fetch('/nickname', { method: 'POST', headers: { @@ -69,8 +71,8 @@ function sendNickname(name) { return; // Receive name and save it const { id } = res; - user.name = name; user.id = id; + pretext.original = pretext.current = `${user.name}@baipyr.us:~# `; // Reply whether name is taken or not outputText({output: `Applied name '${name}#${id}'.`}); });