casper 4 months ago
parent
commit
02d1ab0987
2 changed files with 15 additions and 11 deletions
  1. 4 4
      sri-server-bg01/test/test-1000.py
  2. 11 7
      sri-server-bg03/lib/Connection_e1.py

+ 4 - 4
sri-server-bg01/test/test-1000.py

@@ -8,11 +8,11 @@ data = {
     # 'username': 'admin',  # 登录账户
     # 'password': '123456',  # 登录密码
 
-    # 'username': 'test003',  # 登录账户
-    # 'password': '123456',  # 登录密码
-
-    'username': 'test01',  # 登录账户
+    'username': 'test003',  # 登录账户
     'password': '123456',  # 登录密码
+
+    # 'username': 'test01',  # 登录账户
+    # 'password': '123456',  # 登录密码
 }
 response = requests.post(url=url, json=data)
 code = response.json().get('code')

+ 11 - 7
sri-server-bg03/lib/Connection_e1.py

@@ -1,6 +1,6 @@
 """
 """
-from hub import methods, Global
+# from hub import methods, Global
 
 from werkzeug.security import check_password_hash
 import struct
@@ -21,6 +21,8 @@ sys.path.append(r'C:\SRI-DINO.Server-py\sri-pysdk')
 
 protobuf = importlib.import_module(f"xprotobuf.protocol_pb2")
 methods = importlib.import_module(f"xlib")
+mdb = importlib.import_module(f"xclient.xmongo").Client(host='127.0.0.1', port=47017, database='bg',
+                                                        username='admin', password='admin')
 clients = {}  # {<ipv4>: (socket, update_at, type)} | {<连接id>: (socket对象, 最后一次请求时间, 客户端类型)}
 serial_rid_dict = {
     '65F7171A-5585-46C7-A9D6-967ABA9EB223': 1000000,
@@ -179,7 +181,7 @@ class SRIConnection(asyncio.Protocol):
                                       f"command_id: {command_id}, body_length: {body_length}")
 
                 # 检查命令ID是否有效
-                if not (2000 <= command_id < 5000):
+                if not (1000 < command_id < 9000):
                     self.message_data = b''  # 清空无效数据
                     break
 
@@ -276,7 +278,7 @@ class SRIConnection(asyncio.Protocol):
 
     def message2000(self, body_data):
 
-        # --- 解析消息体
+        # --- 解析消息体 2000
         object = protobuf.CSSign()
         object.ParseFromString(body_data)
         methods.debug_log(f"{self.connection_id}|SRIConnection162", f"#account: {object.account}")
@@ -288,12 +290,14 @@ class SRIConnection(asyncio.Protocol):
             ret = False
 
         # --- check ---
-        user = Global.mdb.get_one('UserInfo', {'username': object.account})
+        user = mdb.get_one('UserInfo', {'username': object.account})
+        name = ''
         if not user:
             ret = False
         elif not check_password_hash(user['password'], object.password):
             ret = False
         else:
+            name = user.get('name')
             ret = True
 
         # --- update ---
@@ -302,15 +306,15 @@ class SRIConnection(asyncio.Protocol):
             self.client_info = {
                 'connection_id': self.connection_id,
                 'uid': 3,  # 对应数据库里的ego的id
-                'name': 'ego',  # 对应数据库里
+                'name': object.account,  # 对应数据库里
                 'egotype': 1,  # 舱端类型
             }
 
         # --- send 4000
         object = protobuf.SCSign()
         object.ret = ret
-        object.uid = self.client_info.get('connection_id')
-        object.name = self.client_info.get('name')
+        object.uid = self.connection_id
+        object.name = name  # 人员名称
         re_command_id = protobuf.SC_Sign  # 4000
         re_body_length = object.ByteSize()
         re_head_data = struct.pack(self.head_sequence, re_command_id, re_body_length)