function cmd_help() { // Display 'help' message return "Commands list:
" + " -about Information about this website
"+ " -clear Clear terminal screen
" + " -history Displays the command history of this session
" + " -exec Execute arbitrary math and logic equations"; } function cmd_about() { // Display 'about' message return "This website is based on the general idea and design of a terminal.
" + "It serves the purpose of a homepage. It exists just for the fun of creating it."; } function cmd_clear() { // Clear terminal by reloading page window.location.reload(); } function cmd_history() { // Display the command history line by line let output = ""; const hl = history.list; for (let i = 0; i < hl.length; i++) { const lineBreak = (i !== hl.length - 1) ? "
" : ""; output += `${i+1} ${hl[i]}${lineBreak}`; } return output; } function cmd_exec(input) { // No input was given if (input === undefined) return "You must enter parameters!"; // Input contains letters or invalid characters const str = input.join(' '); if (/[',:;a-zA-Z]/.test(str) || str === "") return "Invalid input!"; // Input is inside of character range with exceptions const chars = str.split('').filter(e => { const code = e.charCodeAt(0); const s = code === 32; const a = code > 36; const b = code < 63; const c = code === 94; const d = code === 124; return !(s || a && b || c || d); }); // If exceptions remain, invalid input was given if (chars.length > 0) return "Invalid input!"; // Execute input and return output return (new Function(`return ${str}`))().toString(); } function cmd_echo(input) { if (input === undefined) return " "; return input.join(' '); } function cmd_nick(input) { if (input === undefined) return "No nickname was given!"; user.name = input[0]; fetch('/nickname', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ name: user.name, id: user.id }) }).then(res => { if (res.status === 200) { user.connected = true; return res.json(); } }).then(res => { if (res === undefined) return; if (res) outputText({output: `Applied name '${user.name}'.`}); else { outputText({output: `Name '${user.name}' is already taken!.`}); user.name = ""; } }); return null; } function cmd_msg(input) { if (input === undefined) return "No username given!"; if (!user.connected) return "You are not connected!"; const username = input[0]; pretext = `Chat (${username})> `; chatMode = `msg ${username}`; fetch('/chatInit', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ name: username, id: user.id }) }).then(res => {}); } function cmd_exit() { if (chatMode.split(' ')[0] !== "default") chatMode = "default"; }