summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--main.py12
2 files changed, 9 insertions, 6 deletions
diff --git a/README.md b/README.md
index 370437a..4309a8f 100644
--- a/README.md
+++ b/README.md
@@ -18,8 +18,7 @@ soktdeer rewrite
   - [x] get message
   - [x] chat history (v1)
 - [x] get inbox
-- [~] client names
-  - client names will not be implemented in helium
+- [x] client names
 ### moderation (from hydrogen)
 - [ ] bans
 - [ ] invite codes
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