diff --git a/files/assets/js/chat.js b/files/assets/js/chat.js index 89be097d5..e8d4b7e1e 100644 --- a/files/assets/js/chat.js +++ b/files/assets/js/chat.js @@ -54,7 +54,10 @@ function flash(){ else { icon.href = `/i/${site_name}/icon.webp?x=6` notifs = 0 - title.innerHTML = 'Chat'; + if (location.pathname == '/chat') + title.innerHTML = 'Chat'; + else + title.innerHTML = 'Orgy'; } if (is_typing) { diff --git a/files/assets/js/emoji_modal.js b/files/assets/js/emoji_modal.js index a230e05c9..41de53c03 100644 --- a/files/assets/js/emoji_modal.js +++ b/files/assets/js/emoji_modal.js @@ -422,7 +422,7 @@ function populate_speed_emoji_modal(results, textbox) close_inline_speed_emoji_modal() textbox.value = textbox.value.replace(new RegExp(current_word+"(?=\\s|$)", "gi"), `:${name}: `) textbox.focus() - if (location.pathname != '/chat'){ + if (!['/chat','/orgy'].includes(location.pathname)) { markdown(textbox) } }); diff --git a/files/routes/admin.py b/files/routes/admin.py index ce6fd08fc..d10220c0f 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1973,7 +1973,7 @@ def start_orgy(v): ) g.db.add(orgy) - return {"message": "Orgy started successfully!"} + return redirect('/orgy') @app.post("/admin/stop_orgy") @admin_level_required(PERMS['ORGIES']) diff --git a/files/routes/chat.py b/files/routes/chat.py index b086987f1..eb4daf40e 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -2,7 +2,7 @@ import atexit import time import uuid -from flask_socketio import SocketIO, emit +from flask_socketio import SocketIO, emit, join_room, leave_room from flask import request from files.helpers.actions import * @@ -22,12 +22,23 @@ socketio = SocketIO( async_mode='gevent', ) -typing = [] -online = [] sessions = [] -cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0) muted = cache.get(f'muted') or {} -messages = cache.get(f'messages') or {} + +messages = cache.get(f'messages') or { + f'{SITE_FULL}/chat': {}, + f'{SITE_FULL}/orgy': {}, +} +typing = { + f'{SITE_FULL}/chat': [], + f'{SITE_FULL}/orgy': [], +} +online = { + f'{SITE_FULL}/chat': [], + f'{SITE_FULL}/orgy': [], +} + +cache.set(CHAT_ONLINE_CACHE_KEY, len(online[f'{SITE_FULL}/chat']), timeout=0) def is_not_banned_socketio(f): def wrapper(*args, **kwargs): @@ -57,18 +68,33 @@ def chat(v): if not v.allowed_in_chat: abort(403, CHAT_ERROR_MESSAGE) + displayed_messages = {k: val for k, val in messages[f"{SITE_FULL}/chat"].items() if val["user_id"] not in v.userblocks} + + return render_template("chat.html", v=v, messages=displayed_messages) + +@app.get("/orgy") +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@is_not_permabanned +def orgy(v): + if not v.allowed_in_chat: + abort(403, CHAT_ERROR_MESSAGE) + orgy = get_orgy() - displayed_messages = {k: val for k, val in messages.items() if val["user_id"] not in v.userblocks} + if not orgy: + abort(404, "An orgy isn't currently in progress!") - if orgy: - return render_template("orgy.html", v=v, messages=displayed_messages, orgy=orgy, site=SITE) - else: - return render_template("chat.html", v=v, messages=displayed_messages) + displayed_messages = {k: val for k, val in messages[f"{SITE_FULL}/orgy"].items() if val["user_id"] not in v.userblocks} + + return render_template("orgy.html", v=v, messages=displayed_messages, orgy=orgy, site=SITE) @socketio.on('speak') @is_not_banned_socketio def speak(data, v): + if not request.referrer: + return '', 400 + image = None if data['file']: name = f'/chat_images/{time.time()}'.replace('.','') + '.webp' @@ -100,30 +126,30 @@ def speak(data, v): self_only = True else: del muted[vname] - emit("online", [online, muted], broadcast=True) + emit("online", [online[request.referrer], muted], room=request.referrer, broadcast=True) if SITE == 'rdrama.net': def shut_up(): self_only = True muted_until = int(time.time() + 600) muted[vname] = muted_until - emit("online", [online, muted], broadcast=True) + emit("online", [online[request.referrer], muted], room=request.referrer, broadcast=True) if not self_only: - identical = [x for x in list(messages.values())[-5:] if v.id == x['user_id'] and text == x['text']] + identical = [x for x in list(messages[request.referrer].values())[-5:] if v.id == x['user_id'] and text == x['text']] if len(identical) >= 3: shut_up() if not self_only: - count = len([x for x in list(messages.values())[-12:] if v.id == x['user_id']]) + count = len([x for x in list(messages[request.referrer].values())[-12:] if v.id == x['user_id']]) if count >= 10: shut_up() if not self_only: - count = len([x for x in list(messages.values())[-25:] if v.id == x['user_id']]) + count = len([x for x in list(messages[request.referrer].values())[-25:] if v.id == x['user_id']]) if count >= 20: shut_up() data = { "id": id, - "quotes": quotes if messages.get(quotes) else '', + "quotes": quotes if messages[request.referrer].get(quotes) else '', "hat": v.hat_active(v)[0], "user_id": v.id, "username": v.username, @@ -143,41 +169,46 @@ def speak(data, v): username = i.group(1).lower() muted_until = int(int(i.group(2)) * 60 + time.time()) muted[username] = muted_until - emit("online", [online, muted], broadcast=True) + emit("online", [online[request.referrer], muted], room=request.referrer, broadcast=True) self_only = True if self_only or v.shadowbanned or execute_blackjack(v, None, text, "chat"): emit('speak', data) else: - emit('speak', data, broadcast=True) - messages[id] = data - messages = dict(list(messages.items())[-250:]) + emit('speak', data, room=request.referrer, broadcast=True) + messages[request.referrer][id] = data + messages[request.referrer] = dict(list(messages[request.referrer].items())[-250:]) typing = [] return '', 204 def refresh_online(): - emit("online", [online, muted], broadcast=True) - cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0) + emit("online", [online[request.referrer], muted], room=request.referrer, broadcast=True) + if request.referrer == f'{SITE_FULL}/chat': + cache.set(CHAT_ONLINE_CACHE_KEY, len(online[f'{SITE_FULL}/chat']), timeout=0) @socketio.on('connect') @is_not_permabanned_socketio def connect(v): + if not request.referrer: + return '', 400 - if any(v.id in session for session in sessions) and [v.username, v.id, v.name_color, v.patron] not in online: + join_room(request.referrer) + + if any(v.id in session for session in sessions) and [v.username, v.id, v.name_color, v.patron] not in online[request.referrer]: # user has previous running sessions with a different username or name_color - for chat_user in online: - if v.id == chat_user[1]: - online.remove(chat_user) + for val in online.values(): + if [v.username, v.id, v.name_color, v.patron] in val: + val.remove([v.username, v.id, v.name_color, v.patron]) sessions.append([v.id, request.sid]) - if [v.username, v.id, v.name_color, v.patron] not in online: - online.append([v.username, v.id, v.name_color, v.patron]) + if [v.username, v.id, v.name_color, v.patron] not in online[request.referrer]: + online[request.referrer].append([v.username, v.id, v.name_color, v.patron]) refresh_online() - emit('typing', typing) + emit('typing', typing[request.referrer], room=request.referrer) return '', 204 @socketio.on('disconnect') @@ -189,34 +220,48 @@ def disconnect(v): # user has other running sessions return '', 204 - for chat_user in online: - if v.id == chat_user[1]: - online.remove(chat_user) - if chat_user[0] in typing: - typing.remove(chat_user[0]) + for val in online.values(): + if [v.username, v.id, v.name_color, v.patron] in val: + val.remove([v.username, v.id, v.name_color, v.patron]) + + for val in typing.values(): + if v.username in val: + val.remove(v.username) refresh_online() + if request.referrer: + leave_room(request.referrer) + return '', 204 @socketio.on('typing') @is_not_banned_socketio def typing_indicator(data, v): - if data and v.username not in typing: - typing.append(v.username) - elif not data and v.username in typing: - typing.remove(v.username) + if not request.referrer: + return '', 400 - emit('typing', typing, broadcast=True) + if data and v.username not in typing[request.referrer]: + typing[request.referrer].append(v.username) + elif not data and v.username in typing[request.referrer]: + typing[request.referrer].remove(v.username) + + emit('typing', typing[request.referrer], room=request.referrer, broadcast=True) return '', 204 @socketio.on('delete') @admin_level_required(PERMS['POST_COMMENT_MODERATION']) def delete(id, v): - del messages[id] + if not request.referrer: + return '', 400 - emit('delete', id, broadcast=True) + for k, val in messages[request.referrer].items(): + if k == id: + del messages[request.referrer][k] + break + + emit('delete', id, room=request.referrer, broadcast=True) return '', 204 diff --git a/files/templates/admin/orgy_control.html b/files/templates/admin/orgy_control.html index f426c9192..e7075fa0d 100644 --- a/files/templates/admin/orgy_control.html +++ b/files/templates/admin/orgy_control.html @@ -13,7 +13,7 @@
{% if not orgy %} -
+
diff --git a/files/templates/chat.html b/files/templates/chat.html index 972c8a8a7..f2ab6f900 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -34,6 +34,7 @@ + diff --git a/files/templates/header.html b/files/templates/header.html index 9f9a4c50a..ccdde2fcd 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -391,7 +391,7 @@ {% endif %}
  • - {% if request.path.endswith("/chat") %} + {% if request.path in ['/chat', '/orgy'] %}
    Users Online




    diff --git a/files/templates/orgy.html b/files/templates/orgy.html index eca5ec1c2..0776f16f9 100644 --- a/files/templates/orgy.html +++ b/files/templates/orgy.html @@ -1,5 +1,5 @@ {%- extends 'root.html' -%} -{% block pagetitle -%}Chat{%- endblock %} +{% block pagetitle -%}Orgy{%- endblock %} {% block pagetype %}chat{% endblock %} {% block body_attributes %}class="has_header"{% endblock %} {% block body %} @@ -50,6 +50,7 @@ + diff --git a/files/templates/util/html_head.html b/files/templates/util/html_head.html index 1aa6aad0e..95e723ec8 100644 --- a/files/templates/util/html_head.html +++ b/files/templates/util/html_head.html @@ -136,10 +136,6 @@ {% endif %} {% endif %} - - {% if request.path.endswith('/chat') %} - - {% endif %} {% endmacro %} {% macro stylesheets_lower() %} diff --git a/nginx.conf b/nginx.conf index e950e522c..15612d54d 100644 --- a/nginx.conf +++ b/nginx.conf @@ -20,6 +20,9 @@ server { location /chat { proxy_pass http://localhost:5001/chat; } + location /orgy { + proxy_pass http://localhost:5001/orgy; + } location =/offline.html { alias /d/files/templates/errors/offline.html; }