summary refs log tree commit diff
path: root/main.py
diff options
context:
space:
mode:
authormeltland <[email protected]>2025-03-10 10:22:11 -0400
committermeltland <[email protected]>2025-03-10 10:22:11 -0400
commit3f3e3eda8504f27cdebbb66ec095a89e4b7c4251 (patch)
tree221a32b817b26ec418eaa84753fe37da0662fa30 /main.py
parent0f93b0be310d3b60fa18f9d97fac5e8afebff6a6 (diff)
client names by popular demand
Diffstat (limited to 'main.py')
-rw-r--r--main.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/main.py b/main.py
index 2df74e6..b191e91 100644
--- a/main.py
+++ b/main.py
@@ -95,8 +95,12 @@ class util:
         del data["profile"]

         return data

     

-    def authorize(username, conn_id, websocket, client=""):

-        ulist[username] = client

+    def authorize(username, conn_id, websocket, client):

+        # TODO: statuses

+        if client:

+            if not re.fullmatch("[a-zA-Z0-9-_. ]{1,50}", client):

+                client = ""

+        ulist[username] = {"client": client, "status": ""}

         client_data[conn_id] = {"username": username, "client": client, "websocket": websocket}

         data = db.acc.get(username)

         del data["secure"]

@@ -213,7 +217,7 @@ async def handler(websocket):
                     continue

             valid = db.acc.verify_pswd(r["username"], r["password"])

             if type(valid) == dict:

-                userdata = util.authorize(r["username"], str(websocket.id), websocket)

+                userdata = util.authorize(r["username"], str(websocket.id), websocket, r.get("client"))

                 await websocket.send(json.dumps({"error": False, "token": valid["token"], "user": userdata, "listener": listener}))

                 util.ulist()

                 continue

@@ -240,7 +244,7 @@ async def handler(websocket):
                     await websocket.send(util.error("banned", listener, db.acc.get_ban(valid["username"])))

                     continue

                 else:

-                    userdata = util.authorize(valid["username"], str(websocket.id), websocket)

+                    userdata = util.authorize(valid["username"], str(websocket.id), websocket, r.get("client"))

                     await websocket.send(json.dumps({"error": False, "user": userdata, "listener": listener}))

                     util.ulist()

                     continue