Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
update cl3 kick to async
Browse files Browse the repository at this point in the history
  • Loading branch information
tnix100 committed Sep 9, 2024
1 parent 86e8d37 commit aa7c986
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions rest_api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ async def ban_user(username, data: UpdateUserBanBody):
data.state == "temp_ban" and data.expires > time.time()
):
for client in app.cl.usernames.get(username, []):
client.kick()
await client.websocket.close()
else:
app.cl.send_event("update_config", {"ban": data.model_dump()}, usernames=[username])

Expand Down Expand Up @@ -1217,7 +1217,7 @@ async def create_netblock(cidr, data: NetblockBody):
if data.type == 0:
for client in copy(app.cl.clients):
if blocked_ips.search_best(client.ip):
client.kick()
await client.websocket.close()

# Add log
security.add_audit_log(
Expand Down Expand Up @@ -1319,7 +1319,7 @@ async def kick_all_clients():

# Kick all clients
for client in copy(app.cl.clients):
client.kick()
await client.websocket.close()

# Add log
security.add_audit_log("kicked_all", request.user, request.ip, {})
Expand All @@ -1341,7 +1341,7 @@ async def enable_repair_mode():

# Kick all clients
for client in copy(app.cl.clients):
client.kick()
await client.websocket.close()

# Add log
security.add_audit_log("enabled_repair_mode", request.user, request.ip, {})
Expand Down
6 changes: 3 additions & 3 deletions supporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from threading import Thread
from typing import Optional, Iterable, Any
import uuid, time, msgpack, pymongo, re, copy
import uuid, time, msgpack, pymongo, re, copy, asyncio

from cloudlink import CloudlinkServer
from database import db, rdb
Expand Down Expand Up @@ -134,7 +134,7 @@ def listen_for_admin_pubsub(self):
for c in self.cl.usernames.get(msg["user"], []):
if "sid" in msg and msg["sid"] != c.acc_session_id:
continue
c.kick()
asyncio.run(c.kick())
case "alert_user":
self.create_post("inbox", msg["user"], msg["content"])
case "ban_user":
Expand Down Expand Up @@ -168,7 +168,7 @@ def listen_for_admin_pubsub(self):

# Logout user (can't kick because of async stuff)
for c in self.cl.usernames.get(username, []):
c.kick()
asyncio.run(c.kick())
except:
continue

Expand Down

0 comments on commit aa7c986

Please sign in to comment.