From 95e18d831b6e1e3509e24e1fe3eed9f1d0b70f6d Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 31 七月 2025 14:13:27 +0800
Subject: [PATCH] 添加推送日志

---
 socket_manager.py |   44 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/socket_manager.py b/socket_manager.py
index 0971129..ae6847a 100644
--- a/socket_manager.py
+++ b/socket_manager.py
@@ -1,10 +1,17 @@
 import threading
 import time
 
+from utils import tool
+
 
 class ClientSocketManager:
     # 瀹㈡埛绔被鍨�
+    CLIENT_TYPE_COMMON = "common"
     CLIENT_TYPE_TRADE = "trade"
+    CLIENT_TYPE_TRADE_SELL = "trade_sell"
+    CLIENT_TYPE_TRADE_LOW_SUCTION = "trade_low_suction"
+    # 鍙浆鍊哄鎴风
+    CLIENT_TYPE_TRADE_CB = "trade_cb"
 
     socket_client_dict = {}
     socket_client_lock_dict = {}
@@ -12,7 +19,8 @@
 
     @classmethod
     def add_client(cls, _type, rid, sk):
-        if _type == cls.CLIENT_TYPE_TRADE:
+        if _type in {cls.CLIENT_TYPE_COMMON, cls.CLIENT_TYPE_TRADE, cls.CLIENT_TYPE_TRADE_SELL,
+                     cls.CLIENT_TYPE_TRADE_CB, cls.CLIENT_TYPE_TRADE_LOW_SUCTION}:
             # 浜ゆ槗鍒楄〃
             if _type not in cls.socket_client_dict:
                 cls.socket_client_dict[_type] = []
@@ -24,10 +32,12 @@
 
     @classmethod
     def acquire_client(cls, _type):
-        if _type == cls.CLIENT_TYPE_TRADE:
+        if _type in {cls.CLIENT_TYPE_COMMON, cls.CLIENT_TYPE_TRADE, cls.CLIENT_TYPE_TRADE_SELL,
+                     cls.CLIENT_TYPE_TRADE_CB, cls.CLIENT_TYPE_TRADE_LOW_SUCTION}:
             if _type in cls.socket_client_dict:
                 # 鏍规嵁鎺掑簭娲昏穬鏃堕棿鎺掑簭
-                client_list = sorted(cls.socket_client_dict[_type], key=lambda x: cls.active_client_dict.get(x[0]) if x[0] in cls.active_client_dict else 0,
+                client_list = sorted(cls.socket_client_dict[_type], key=lambda x: cls.active_client_dict.get(x[0]) if x[
+                                                                                                                          0] in cls.active_client_dict else 0,
                                      reverse=True)
                 for d in client_list:
                     if d[0] in cls.socket_client_lock_dict:
@@ -64,11 +74,19 @@
                 for d in cls.socket_client_dict[t]:
                     if d[0] == rid:
                         cls.socket_client_dict[t].remove(d)
+                        try:
+                            d[1].close()
+                        except:
+                            pass
                         break
 
             elif type(cls.socket_client_dict[t]) == tuple:
                 if cls.socket_client_dict[t][0] == rid:
                     cls.socket_client_dict.pop(t)
+                    try:
+                        t[1].close()
+                    except:
+                        pass
                     break
 
     # 蹇冭烦淇℃伅
@@ -82,4 +100,22 @@
         for k in cls.active_client_dict.keys():
             if time.time() - cls.active_client_dict[k] > 20:
                 # 蹇冭烦鏃堕棿闂撮殧20s浠ヤ笂瑙嗕负鏃犳晥
-                cls.del_client(k)
\ No newline at end of file
+                cls.del_client(k)
+
+    @classmethod
+    def list_client(cls, type_=None):
+        _type = type_
+        if not _type:
+            _type = cls.CLIENT_TYPE_TRADE
+        client_list = sorted(cls.socket_client_dict[_type],
+                             key=lambda x: cls.active_client_dict.get(x[0]) if x[0] in cls.active_client_dict else 0,
+                             reverse=True)
+        fdata = []
+        for client in client_list:
+            active_time = cls.active_client_dict.get(client[0])
+            if active_time is None:
+                active_time = 0
+            active_time = tool.to_time_str(int(active_time))
+            fdata.append(
+                (client[0], cls.socket_client_lock_dict[client[0]].locked(), active_time))
+        return fdata

--
Gitblit v1.8.0