Skip to content

Commit c61fbb1

Browse files
committed
feat(push): decoded ServerPush after login
1 parent afc20c7 commit c61fbb1

File tree

3 files changed

+137
-4
lines changed

3 files changed

+137
-4
lines changed
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
from .binder import PushDeliver
22
from .msg import msg_push_handler
3-
from .service import server_kick_handler
3+
from .service import (
4+
server_kick_handler,
5+
server_info_sync_handler,
6+
server_push_param_handler,
7+
server_push_req_handler
8+
)
49

510

611
def bind_services(pd: PushDeliver):
712
pd.subscribe("trpc.msg.olpush.OlPushService.MsgPush", msg_push_handler)
8-
pd.subscribe(
9-
"trpc.qq_new_tech.status_svc.StatusService.KickNT", server_kick_handler
10-
)
13+
14+
pd.subscribe("trpc.qq_new_tech.status_svc.StatusService.KickNT", server_kick_handler)
15+
pd.subscribe("trpc.msg.register_proxy.RegisterProxy.InfoSyncPush", server_info_sync_handler)
16+
pd.subscribe("trpc.msg.register_proxy.RegisterProxy.PushParams", server_push_param_handler)
17+
pd.subscribe("ConfigPushSvc.PushReq", server_push_req_handler)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,66 @@
1+
import os
2+
import datetime
3+
14
from lagrange.pb.status.kick import KickNT
5+
from lagrange.pb.login.register import PBSsoInfoSyncPush, PBServerPushParams
26

37
from ..events.service import ServerKick
48
from ..wtlogin.sso import SSOPacket
59

10+
DBG_EN = bool(os.environ.get("PUSH_DEBUG", False))
611

712
async def server_kick_handler(_, sso: SSOPacket):
813
ev = KickNT.decode(sso.data)
914
return ServerKick(tips=ev.tips, title=ev.title)
15+
16+
17+
async def server_info_sync_handler(_, sso: SSOPacket):
18+
if not DBG_EN:
19+
return
20+
ev = PBSsoInfoSyncPush.decode(sso.data)
21+
if ev.cmd_type == 5: # grp info
22+
print("GroupInfo Sync:")
23+
for i in ev.grp_info:
24+
print(
25+
"%i(%s): lostsync: %i, time: %s" % (
26+
i.grp_id, i.grp_name, i.last_msg_seq - i.last_msg_seq_read,
27+
datetime.datetime.fromtimestamp(i.last_msg_timestamp).strftime("%Y-%m-%d %H:%M:%S")
28+
)
29+
)
30+
elif ev.cmd_type == 2:
31+
print("MsgPush Sync:")
32+
for i in ev.grp_msgs.inner:
33+
print(
34+
"%i msgs(%i->%i) in %i, time: %s" %(
35+
len(i.msgs), i.start_seq, i.end_seq, i.grp_id,
36+
datetime.datetime.fromtimestamp(i.last_msg_time).strftime("%Y-%m-%d %H:%M:%S")
37+
)
38+
)
39+
print("EventPush Sync:")
40+
for i in ev.sys_events.inner:
41+
print(
42+
"%i events in %i, time: %s" % (
43+
len(i.events), i.grp_id,
44+
datetime.datetime.fromtimestamp(i.last_evt_time).strftime("%Y-%m-%d %H:%M:%S")
45+
)
46+
)
47+
else:
48+
print(f"Unknown cmd_type: {ev.cmd_type}({ev.f4})")
49+
print("END")
50+
51+
52+
async def server_push_param_handler(_, sso: SSOPacket):
53+
if not DBG_EN:
54+
return
55+
print("Server Push Params:")
56+
ev = PBServerPushParams.decode(sso.data)
57+
for dev in ev.online_devices:
58+
print(f"Device:{dev.device_name} on {dev.os_name} Platform, sub_id: {dev.sub_id}")
59+
print("end")
60+
61+
62+
async def server_push_req_handler(_, sso: SSOPacket):
63+
"""
64+
JCE packet, ignore
65+
"""
66+
return None

lagrange/pb/login/register.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,72 @@ class PBSsoInfoSyncResponse(ProtoStruct):
119119
reg_rsp: PBRegisterResponse = proto_field(7)
120120
# f9: int = proto_field(9)
121121

122+
123+
# trpc.msg.register_proxy.RegisterProxy.InfoSyncPush: From Server
124+
class InfoSyncPushGrpInfo(ProtoStruct):
125+
grp_id: int = proto_field(1)
126+
last_msg_seq: int = proto_field(2)
127+
last_msg_seq_read: int = proto_field(3) # bot最后一次标记已读
128+
f4: int = proto_field(4) # 1
129+
last_msg_timestamp: int = proto_field(8, default=0)
130+
grp_name: str = proto_field(9)
131+
last_msg_seq_sent: int = proto_field(10, default=0) # bot最后一次发信 TODO: 可能不太对?确认下
132+
f10: int = proto_field(10, default=None) # u32, unknown
133+
f12: int = proto_field(12, default=None) # 1
134+
f13: int = proto_field(13, default=None) # 1
135+
f14: int = proto_field(14, default=None) # u16?
136+
f15: int = proto_field(15, default=None) # 1
137+
f16: int = proto_field(16, default=None) # u16?
138+
139+
140+
class InnerGrpMsg(ProtoStruct):
141+
grp_id: int = proto_field(3)
142+
start_seq: int = proto_field(4)
143+
end_seq: int = proto_field(5)
144+
msgs: list[MsgPushBody] = proto_field(6) # last 30 msgs
145+
last_msg_time: int = proto_field(8)
146+
147+
148+
class InfoSyncGrpMsgs(ProtoStruct):
149+
inner: list[InnerGrpMsg] = proto_field(3)
150+
151+
152+
class InnerSysEvt(ProtoStruct):
153+
grp_id: int = proto_field(1)
154+
grp_id_str: str = proto_field(2)
155+
last_evt_time: int = proto_field(5)
156+
events: list[MsgPushBody] = proto_field(8) # TODO: parse event (like MsgPush?)
157+
158+
159+
# with FriendMessage
160+
class InfoSyncSysEvents(ProtoStruct):
161+
# f3: dict = proto_field(3) # {1: LAST_EVT_TIME}
162+
inner: list[InnerSysEvt] = proto_field(4)
163+
# f5: dict = proto_field(5) # {1: LAST_EVT_TIME}
164+
165+
166+
class PBSsoInfoSyncPush(ProtoStruct):
167+
cmd_type: int = proto_field(3) # 5: GrpInfo(f6), 2: HUGE msg push block(f7&f8), 1&4: unknown(empty)
168+
f4: int = proto_field(4) # 393
169+
grp_info: list[InfoSyncPushGrpInfo] = proto_field(6, default=None)
170+
grp_msgs: InfoSyncGrpMsgs = proto_field(7, default=None)
171+
sys_events: InfoSyncSysEvents = proto_field(8, default=None)
172+
173+
174+
# trpc.msg.register_proxy.RegisterProxy.PushParams
175+
class PPOnlineDevices(ProtoStruct):
176+
sub_id: int = proto_field(1)
177+
# f2: int = proto_field(2) # 2
178+
# f3: int = proto_field(3) # 1
179+
# f4: int = proto_field(4) # 109
180+
os_name: str = proto_field(5)
181+
# f6:int = proto_field(6)
182+
device_name: str = proto_field(7)
183+
184+
185+
class PBServerPushParams(ProtoStruct):
186+
online_devices: list[PPOnlineDevices] = proto_field(4, default_factory=list)
187+
# f6: dict = proto_field(6) # {2: 9}
188+
# f7: str = proto_field(7) # value: ""(empty)
189+
# f8: list[int] = proto_field(8) # multi long int
190+
# f9: int = proto_field(9) # 8640000, 100days

0 commit comments

Comments
 (0)