|
@@ -1,7 +1,8 @@
|
|
|
"""
|
|
|
"""
|
|
|
-# from hub import methods, Global
|
|
|
+from hub import methods, Global
|
|
|
|
|
|
+from werkzeug.security import check_password_hash
|
|
|
import struct
|
|
|
import asyncio
|
|
|
import time
|
|
@@ -51,8 +52,9 @@ class SRIConnection(asyncio.Protocol):
|
|
|
建立客户端连接
|
|
|
"""
|
|
|
peername = client.get_extra_info('peername')
|
|
|
- # self.connection_id = f"{peername[0].replace('.', '')}-{peername[1]}" # 12700130000 客户端id
|
|
|
- self.connection_id = int(f"{peername[0].replace('.', '')}")
|
|
|
+ # self.connection_id = f"{peername[0].replace('.', '')}-{peername[1]}" # 客户端id
|
|
|
+ self.connection_id = int(f"{peername[1]}") # 客户端id(公网情况)
|
|
|
+ # self.connection_id = int(f"{peername[0].replace('.', '')}") # 客户端id(固定ip情况)
|
|
|
self.client = client
|
|
|
# self.data = b''
|
|
|
self.client_type = None
|
|
@@ -174,7 +176,7 @@ class SRIConnection(asyncio.Protocol):
|
|
|
command_id, body_length = struct.unpack(self.head_sequence, head_data)
|
|
|
if command_id not in [2008]:
|
|
|
methods.debug_log(f'{self.connection_id}|SRIConnection176',
|
|
|
- f"command_id: {command_id}, body_length: {body_length}")
|
|
|
+ f"command_id: {command_id}, body_length: {body_length}")
|
|
|
|
|
|
# 检查命令ID是否有效
|
|
|
if not (2000 <= command_id < 5000):
|
|
@@ -281,18 +283,32 @@ class SRIConnection(asyncio.Protocol):
|
|
|
methods.debug_log(f"{self.connection_id}|SRIConnection162", f"#password: {object.password}")
|
|
|
|
|
|
# --- update ---
|
|
|
- self.client_type = 'cockpit'
|
|
|
- self.client_info = {
|
|
|
- 'connection_id': self.connection_id,
|
|
|
- 'uid': 3, # 对应数据库里的ego的id
|
|
|
- 'name': 'ego', # 对应数据库里
|
|
|
- 'egotype': 1, # 舱端类型
|
|
|
- }
|
|
|
+ ret = True
|
|
|
+ if object.account == "Ego" and object.password != '123456':
|
|
|
+ ret = False
|
|
|
+
|
|
|
+ # --- check ---
|
|
|
+ user = Global.mdb.get_one('UserInfo', {'username': object.account})
|
|
|
+ if not user:
|
|
|
+ ret = False
|
|
|
+ elif not check_password_hash(user['password'], object.password):
|
|
|
+ ret = False
|
|
|
+ else:
|
|
|
+ ret = True
|
|
|
+
|
|
|
+ # --- update ---
|
|
|
+ if ret:
|
|
|
+ self.client_type = 'cockpit'
|
|
|
+ self.client_info = {
|
|
|
+ 'connection_id': self.connection_id,
|
|
|
+ 'uid': 3, # 对应数据库里的ego的id
|
|
|
+ 'name': 'ego', # 对应数据库里
|
|
|
+ 'egotype': 1, # 舱端类型
|
|
|
+ }
|
|
|
|
|
|
# --- send 4000
|
|
|
object = protobuf.SCSign()
|
|
|
- object.ret = True
|
|
|
- # object.uid = self.client_info.get('uid')
|
|
|
+ object.ret = ret
|
|
|
object.uid = self.client_info.get('connection_id')
|
|
|
object.name = self.client_info.get('name')
|
|
|
re_command_id = protobuf.SC_Sign # 4000
|