From 667412e6aef06b18c45315477c15c12606eda463 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 23 Sep 2020 21:01:29 +0200 Subject: [PATCH] Implement /set command. --- README | 3 +++ static/sfu.css | 5 +++++ static/sfu.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/README b/README index 84717fe..9091fcd 100644 --- a/README +++ b/README @@ -109,6 +109,9 @@ to all users: - `/me text`: sends a chat message starting with the sender's username; - `/leave`: equivalent to clicking the *Disconnect* button. + - `/set var val`: sets the value of a configuration variable without any + error checking. Without parameters, displays the current configuration. + - `/unset var`: removes a configuration variable. The following commands are only available to users with operator privileges: diff --git a/static/sfu.css b/static/sfu.css index 61cf72a..066af4e 100644 --- a/static/sfu.css +++ b/static/sfu.css @@ -297,6 +297,11 @@ textarea.form-reply { background: #ececec; } +.message-system { + font-size: 10px; + background: #ececec; +} + .message-row:after, .message-row:before { display: table; content: " "; diff --git a/static/sfu.js b/static/sfu.js index c3dc35e..767d294 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -126,6 +126,27 @@ function updateSettings(settings) { storeSettings(s); } +/** + * @param {string} key + * @param {any} value + */ +function updateSetting(key, value) { + let s = {}; + s[key] = value; + updateSettings(s); +} + +/** + * @param {string} key + */ +function delSetting(key) { + let s = getSettings(); + if(!(key in s)) + return; + delete(s[key]); + storeSettings(s) +} + /** * @param {string} id */ @@ -1209,8 +1230,10 @@ function addToChatbox(peerId, nick, kind, message){ let container = document.createElement('div'); container.classList.add('message'); row.appendChild(container); - if (userpass.username === nick) { - container.classList.add('message-sender'); + if(!peerId) + container.classList.add('message-system'); + else if(userpass.username === nick) { + container.classList.add('message-sender'); } if(kind !== 'me') { let p = formatLines(message.split('\n')); @@ -1333,6 +1356,33 @@ function handleInput() { } serverConnection.groupAction('clearchat'); return; + case '/set': + if(!rest) { + let settings = getSettings(); + let s = ""; + for(let key in settings) + s = s + `${key}: ${JSON.stringify(settings[key])}\n` + addToChatbox(null, null, null, s); + return; + } + let parsed = parseCommand(rest); + let value; + if(parsed[1]) { + try { + value = JSON.parse(parsed[1]) + } catch(e) { + displayError(e); + return; + } + } else { + value = true; + } + updateSetting(parsed[0], value); + reflectSettings(); + return; + case '/unset': + delSetting(rest.trim()); + return; case '/lock': case '/unlock': if(!serverConnection.permissions.op) {