diff options
author | meltland <[email protected]> | 2025-03-27 16:58:53 -0400 |
---|---|---|
committer | meltland <[email protected]> | 2025-03-27 16:58:53 -0400 |
commit | 29bba5f2ab57135f18fa109ed774b5bb364c2645 (patch) | |
tree | b5d4f61203851f2ed47d066354376c1109102260 /main.py | |
parent | 434183e65fca9e94b38f8a9d998a74b5e917b5c0 (diff) |
ratelimit
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/main.py b/main.py index b1f709f..19035df 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,8 @@ error_contexts = { "lockdown": "Maintenance is in progress.", "authed": "You are already authenticated.", "unauthorized": "You must be authorized to perform this action.", - "deprecated": "This command is no longer supported." + "deprecated": "This command is no longer supported.", + "ratelimited": "You are ratelimited." } deprecated = { @@ -45,6 +46,8 @@ deprecated = { ulist = {} client_data = {} +ratelimits = {} + clients = [] invite_codes = [] @@ -143,9 +146,17 @@ async def handler(websocket): global invite_codes clients.append(websocket) + ratelimits[str(websocket.id)] = 0 await websocket.send(util.greeting()) try: async for message in websocket: + print(ratelimits[str(websocket.id)]) + print(time.time()) + print(time.time() > ratelimits[str(websocket.id)]) + if not ratelimits[str(websocket.id)] <= time.time(): + await websocket.send(util.error("ratelimited", None)) + continue + ratelimits[str(websocket.id)] = time.time() + 0.35 try: r = json.loads(message) except: @@ -556,6 +567,8 @@ async def handler(websocket): finally: if str(websocket.id) in client_data: util.loggedout(client_data[str(websocket.id)]["username"], str(websocket.id), websocket) + if str(websocket.id) in ratelimits: + del ratelimits[str(websocket.id)] if websocket in clients: clients.remove(websocket) |