From 85ccd7b96e4a3720ae347fe235a98ae51da4e45e Mon Sep 17 00:00:00 2001 From: n9k Date: Sat, 16 Jul 2022 22:17:53 +0000 Subject: [PATCH 1/3] Never gonna give broadcaster a clock captcha --- anonstream/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anonstream/chat.py b/anonstream/chat.py index a097f77..68ceaba 100644 --- a/anonstream/chat.py +++ b/anonstream/chat.py @@ -114,7 +114,7 @@ def add_chat_message(user, nonce, comment, ignore_empty=False): # Deverify user every n messages if CONFIG['CHAT_DEVERIFY_CLOCK'] is not None: user['clock'] = (user['clock'] + 1) % CONFIG['CHAT_DEVERIFY_CLOCK'] - if user['clock'] == 0: + if user['clock'] == 0 and not user['broadcaster']: user['verified'] = False # Notify event sockets that a chat message was added From 70036ca23402313f3e5b319e54375ef7a17145e8 Mon Sep 17 00:00:00 2001 From: n9k Date: Sat, 16 Jul 2022 23:48:34 +0000 Subject: [PATCH 2/3] Minor formatting --- anonstream/static/anonstream.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/anonstream/static/anonstream.js b/anonstream/static/anonstream.js index 76ca2a1..9c91adc 100644 --- a/anonstream/static/anonstream.js +++ b/anonstream/static/anonstream.js @@ -284,26 +284,26 @@ const delete_chat_messages = (seqs) => { const hexdigest = async (string, bytelength) => { uint8array = new TextEncoder().encode(string); - arraybuffer = await crypto.subtle.digest('sha-256', uint8array); + arraybuffer = await crypto.subtle.digest("sha-256", uint8array); array = Array.from(new Uint8Array(arraybuffer).slice(0, bytelength)); - hex = array.map(b => b.toString(16).padStart(2, '0')).join(''); + hex = array.map(b => b.toString(16).padStart(2, "0")).join(""); return hex } const escape_css_string = (string) => { /* https://drafts.csswg.org/cssom/#common-serializing-idioms */ const result = []; for (const char of string) { - if (char === '\0') { - result.push('\ufffd'); - } else if (char < '\u0020' || char == '\u007f') { + if (char === "\0") { + result.push("\ufffd"); + } else if (char < "\u0020" || char == "\u007f") { result.push(`\\${char.charCodeAt().toString(16)}`); - } else if (char == '"' || char == '\\') { + } else if (char == '"' || char == "\\") { result.push(`\\${char}`); } else { result.push(char); } } - return result.join(''); + return result.join(""); } const update_emotes = async (emotes) => { const rules = []; From 9edeea1491700c9be4a9258ef1e09ea2df523f6d Mon Sep 17 00:00:00 2001 From: n9k Date: Sat, 16 Jul 2022 23:47:25 +0000 Subject: [PATCH 3/3] Emotes: sheet filename config option --- anonstream/config.py | 1 + anonstream/routes/nojs.py | 1 + anonstream/static/anonstream.js | 6 ++++-- anonstream/templates/nojs_chat_messages.html | 2 +- anonstream/websocket.py | 1 + config.toml | 1 + 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/anonstream/config.py b/anonstream/config.py index e9f842f..023a241 100644 --- a/anonstream/config.py +++ b/anonstream/config.py @@ -169,5 +169,6 @@ def toml_to_flask_section_nojs(config): def toml_to_flask_section_emote(config): cfg = config['emote'] return { + 'EMOTE_SHEET': cfg['sheet'], 'EMOTE_SCHEMA': cfg['schema'], } diff --git a/anonstream/routes/nojs.py b/anonstream/routes/nojs.py index cf1179f..a487174 100644 --- a/anonstream/routes/nojs.py +++ b/anonstream/routes/nojs.py @@ -55,6 +55,7 @@ async def nojs_chat_messages(timestamp, user): user=user, users_by_token=USERS_BY_TOKEN, emotes=EMOTES, + emotesheet=CONFIG['EMOTE_SHEET'], emotehash=get_emotehash(tuple(EMOTES)), messages=get_scrollback(current_app.messages), timeout=CONFIG['NOJS_TIMEOUT_CHAT'], diff --git a/anonstream/static/anonstream.js b/anonstream/static/anonstream.js index 9c91adc..e8665ca 100644 --- a/anonstream/static/anonstream.js +++ b/anonstream/static/anonstream.js @@ -315,7 +315,7 @@ const update_emotes = async (emotes) => { } rules.sort(); const emotehash = await hexdigest(rules.toString(), 6); - const emotehash_rule = `.emote { background-image: url("/static/emotes.png?coords=${escape_css_string(encodeURIComponent(emotehash))}"); }`; + const emotehash_rule = `.emote { background-image: url("/static/${escape_css_string(escape(emotesheet))}?coords=${escape_css_string(encodeURIComponent(emotehash))}"); }`; const rules_set = new Set([emotehash_rule, ...rules]); const to_delete = []; @@ -337,6 +337,7 @@ let users = {}; let stats = null; let stats_received = null; let default_name = {true: "Broadcaster", false: "Anonymous"}; +let emotesheet = "emotes.png"; let max_chat_scrollback = 256; let pingpong_period = 8.0; let ping = null; @@ -734,7 +735,8 @@ const on_websocket_message = async (event) => { chat_appearance_form_name.setAttribute("placeholder", default_name[user.broadcaster]); chat_appearance_form_color.setAttribute("value", user.color); - // emote coordinates + // emotes + emotesheet = receipt.emotesheet; await update_emotes(receipt.emotes); // insert new messages diff --git a/anonstream/templates/nojs_chat_messages.html b/anonstream/templates/nojs_chat_messages.html index 43f0390..8b59731 100644 --- a/anonstream/templates/nojs_chat_messages.html +++ b/anonstream/templates/nojs_chat_messages.html @@ -134,7 +134,7 @@ line-height: 1.3125; } .emote { - background-image: url("{{ escape_css_string(url_for('static', filename='emotes.png', coords=emotehash)) | safe }}"); + background-image: url("{{ escape_css_string(url_for('static', filename=emotesheet, coords=emotehash)) | safe }}"); display: inline-block; font-size: 0; vertical-align: middle; diff --git a/anonstream/websocket.py b/anonstream/websocket.py index 66bbc11..4e5aa5e 100644 --- a/anonstream/websocket.py +++ b/anonstream/websocket.py @@ -38,6 +38,7 @@ async def websocket_outbound(queue, user): 'digest': get_random_captcha_digest_for(user), 'pingpong': CONFIG['TASK_BROADCAST_PING'], 'emotes': get_emotes_for_websocket(), + 'emotesheet': CONFIG['EMOTE_SHEET'], }) while True: payload = await queue.get() diff --git a/config.toml b/config.toml index e727d6d..076ddef 100644 --- a/config.toml +++ b/config.toml @@ -91,4 +91,5 @@ refresh_users = 6.0 timeout_chat = 30.0 [emote] +sheet = "emotes.png" schema = "emotes.json"