Skip to content

Commit 96ff2ae

Browse files
committed
feat(login): update register to SsoInfoSync
1 parent 4130abb commit 96ff2ae

File tree

5 files changed

+122
-5
lines changed

5 files changed

+122
-5
lines changed

lagrange/client/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
build_register_request,
3030
build_sso_heartbeat_request,
3131
parse_register_response,
32+
build_sso_info_sync,
33+
parse_sso_info_sync_rsp,
3234
)
3335
from .wtlogin.tlv import CommonTlvBuilder, QrCodeTlvBuilder
3436

@@ -407,6 +409,18 @@ async def register(self) -> bool:
407409
log.login.error("Register failure")
408410
return False
409411

412+
async def register_new(self) -> bool:
413+
response = await self.send_uni_packet(
414+
"trpc.msg.register_proxy.RegisterProxy.SsoInfoSync",
415+
build_sso_info_sync(self.app_info, self.device_info),
416+
)
417+
if parse_sso_info_sync_rsp(response.data):
418+
self._online.set()
419+
log.login.info("Register(new) successful")
420+
return True
421+
log.login.error("Register(new) failure")
422+
return False
423+
410424
async def sso_heartbeat(self, calc_latency=False, timeout=10) -> float:
411425
start_time = time.time()
412426
await self.send_uni_packet(

lagrange/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def push_deliver(self) -> PushDeliver:
105105
return self._push_deliver
106106

107107
async def register(self) -> bool:
108-
if await super().register():
108+
if await super().register_new():
109109
self._events.emit(ClientOnline(), self)
110110
return True
111111
self._events.emit(ClientOffline(recoverable=False), self)

lagrange/client/server_push/binder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ def subscribe(self, cmd: str, func: Callable[["Client", SSOPacket], Coroutine[No
2121

2222
async def execute(self, cmd: str, sso: SSOPacket):
2323
if cmd not in self._handle_map:
24-
logger.warning(f"Unsupported command: {cmd}")
24+
logger.warning(f"Unsupported command: {cmd}({len(sso.data)})")
2525
else:
2626
return await self._handle_map[cmd](self._client, sso)

lagrange/client/wtlogin/status_service.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
from lagrange.info import AppInfo, DeviceInfo
2-
from lagrange.pb.login.register import PBRegisterRequest, PBRegisterResponse
32
from lagrange.utils.binary.protobuf import proto_encode
43
from lagrange.utils.log import log
4+
from lagrange.pb.login.register import (
5+
PBRegisterRequest,
6+
PBRegisterResponse,
7+
PBSsoInfoSyncRequest,
8+
PBSsoInfoSyncResponse,
9+
)
510

611

712
# trpc.qq_new_tech.status_svc.StatusService.Register
813
def build_register_request(app: AppInfo, device: DeviceInfo) -> bytes:
914
return PBRegisterRequest.build(app, device).encode()
1015

1116

17+
# trpc.msg.register_proxy.RegisterProxy.SsoInfoSync
18+
def build_sso_info_sync(app: AppInfo, device: DeviceInfo) -> bytes:
19+
return PBSsoInfoSyncRequest.build(app, device).encode()
20+
21+
1222
# trpc.qq_new_tech.status_svc.StatusService.SsoHeartBeat
1323
def build_sso_heartbeat_request() -> bytes:
1424
return proto_encode({1: 1})
@@ -20,3 +30,15 @@ def parse_register_response(response: bytes) -> bool:
2030
return True
2131
log.network.error("register fail, reason: %s", pb.message)
2232
return False
33+
34+
35+
def parse_sso_info_sync_rsp(response: bytes) -> bool:
36+
pb = PBSsoInfoSyncResponse.decode(response)
37+
if pb.reg_rsp:
38+
if pb.reg_rsp.message == "register success":
39+
return True
40+
else:
41+
log.network.error("register fail, reason: %s", pb.reg_rsp.message)
42+
else:
43+
log.network.error("register fail, reason: WrongRsp")
44+
return False

lagrange/pb/login/register.py

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import random
2+
13
from lagrange.info import AppInfo, DeviceInfo
4+
from lagrange.pb.message.msg_push import MsgPushBody
25
from lagrange.utils.binary.protobuf import proto_field, ProtoStruct
36

47

8+
# trpc.qq_new_tech.status_svc.StatusService.Register
59
class _DeviceInfo(ProtoStruct):
610
device_name: str = proto_field(1)
711
vendor_os: str = proto_field(2)
@@ -12,9 +16,9 @@ class _DeviceInfo(ProtoStruct):
1216

1317
class PBRegisterRequest(ProtoStruct):
1418
guid: str = proto_field(1)
15-
field_2: int = proto_field(2, default=0)
19+
kick_pc: int = proto_field(2, default=0) # ?
1620
current_version: str = proto_field(3)
17-
field_4: int = proto_field(4, default=0)
21+
field_4: int = proto_field(4, default=0) # IsFirstRegisterProxyOnline
1822
locale_id: int = proto_field(5, default=2052)
1923
device_info: _DeviceInfo = proto_field(6)
2024
set_mute: int = proto_field(7, default=0) # ?
@@ -38,3 +42,80 @@ def build(cls, app: AppInfo, device: DeviceInfo) -> "PBRegisterRequest":
3842
class PBRegisterResponse(ProtoStruct):
3943
message: str = proto_field(2)
4044
timestamp: int = proto_field(3)
45+
46+
47+
# trpc.msg.register_proxy.RegisterProxy.SsoInfoSync
48+
class C2cMsgCookie(ProtoStruct):
49+
last_msg_time: int = proto_field(1)
50+
51+
52+
class SsoC2cInfo(ProtoStruct):
53+
msg_cookie: C2cMsgCookie = proto_field(1)
54+
last_msg_time: int = proto_field(2)
55+
last_msg_cookie: C2cMsgCookie = proto_field(3)
56+
57+
@classmethod
58+
def build(cls, last_msg_time=0) -> "SsoC2cInfo":
59+
return cls(
60+
msg_cookie=C2cMsgCookie(last_msg_time=last_msg_time),
61+
last_msg_cookie=C2cMsgCookie(last_msg_time=last_msg_time),
62+
last_msg_time=last_msg_time,
63+
)
64+
65+
66+
class NormalCfg(ProtoStruct):
67+
int_cfg: dict = proto_field(1, default=None) # dict[int, int]
68+
69+
70+
class CurrentAppState(ProtoStruct):
71+
is_delay_request: bool = proto_field(1)
72+
app_state: int = proto_field(2)
73+
silence_state: int = proto_field(3)
74+
75+
@classmethod
76+
def build(cls) -> "CurrentAppState":
77+
return cls(
78+
is_delay_request=False,
79+
app_state=0,
80+
silence_state=0,
81+
)
82+
83+
84+
class UnknownInfo(ProtoStruct):
85+
grp_code: int = proto_field(1, default=0)
86+
f2: int = proto_field(2, default=2)
87+
88+
89+
class PBSsoInfoSyncRequest(ProtoStruct):
90+
sync_flag: int = proto_field(1)
91+
req_rand: int = proto_field(2)
92+
current_active_stats: int = proto_field(4)
93+
grp_last_msg_time: int = proto_field(5)
94+
c2c_info: SsoC2cInfo = proto_field(6)
95+
normal_cfg: NormalCfg = proto_field(8)
96+
register_info: PBRegisterRequest = proto_field(9)
97+
unknown_f10: UnknownInfo = proto_field(10)
98+
app_state: CurrentAppState = proto_field(11)
99+
100+
@classmethod
101+
def build(cls, app: AppInfo, device: DeviceInfo) -> "PBSsoInfoSyncRequest":
102+
return cls(
103+
sync_flag=735,
104+
req_rand=random.randint(114, 514), # ?
105+
current_active_stats=2,
106+
grp_last_msg_time=0,
107+
c2c_info=SsoC2cInfo.build(),
108+
normal_cfg=NormalCfg(int_cfg=dict()),
109+
register_info=PBRegisterRequest.build(app, device),
110+
unknown_f10=UnknownInfo(),
111+
app_state=CurrentAppState.build()
112+
)
113+
114+
115+
class PBSsoInfoSyncResponse(ProtoStruct):
116+
# f3: int = proto_field(3)
117+
# f4: int = proto_field(4)
118+
# f6: int = proto_field(6)
119+
reg_rsp: PBRegisterResponse = proto_field(7)
120+
# f9: int = proto_field(9)
121+

0 commit comments

Comments
 (0)