Migrate project to pnpm monorepo
Restructure the repository into a pnpm workspace under packages/ (core, webui, runtime). Move source files for core and webui into packages/*, add package manifests for @snowluma/core and @snowluma/runtime, and remove the old launcher package.json. Update root package.json to be a monorepo controller (scripts delegate to pnpm filters, set packageManager and Node engine). Configure build outputs to emit into the repo-root dist/ (vite config changes) so the existing release pipeline continues to work. Add .npmrc with mirrors, expand .gitignore for monorepo layout, add tsconfig base and package-level tsconfigs, and add vitest config for the core package. Adjust injector native search paths and update tests import paths to the new package layout. Small CI/workflow comment added to clarify build behavior and README updated with monorepo structure and common commands.
This commit is contained in:
1 parent
6bba36bba6
commit
39f1672b29
122 files changed
+279
-85
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,335 @@
|
||||
// Contact / info-fetching operations extracted from Bridge.
|
||||
|
||||
import type { Bridge } from './bridge';
|
||||
import type { DownloadRKeyInfo } from './bridge';
|
||||
import type { FriendInfo, QQGroupInfo, GroupMemberInfo, UserProfileInfo, GroupRequestInfo } from './qq-info';
|
||||
import { protoDecode } from '../protobuf/decode';
|
||||
import { sendOidbAndDecode } from './bridge-oidb';
|
||||
import {
|
||||
OidbSvcTrpcTcp0xFD4_1ResponseSchema,
|
||||
OidbSvcTrpcTcp0xFE5_2ResponseSchema,
|
||||
OidbSvcTrpcTcp0xFE7_3ResponseSchema,
|
||||
OidbSvcTrpcTcp0x10C0ResponseSchema,
|
||||
} from './proto/oidb';
|
||||
import {
|
||||
OidbFriendListRequestSchema,
|
||||
OidbGroupListRequestSchema,
|
||||
OidbGroupMemberListRequestSchema,
|
||||
OidbUserInfoRequestSchema,
|
||||
OidbUserInfoResponseSchema,
|
||||
AvatarInfoSchema,
|
||||
OidbGroupRequestListSchema,
|
||||
NTV2RichMediaReqSchema,
|
||||
NTV2RichMediaRespSchema,
|
||||
} from './proto/oidb-action';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export function buildFriendProperties(raw: any): Map<number, string> {
|
||||
const props = new Map<number, string>();
|
||||
for (const additional of raw.additional ?? []) {
|
||||
if ((additional.type ?? 0) !== 1 || !additional.layer1) continue;
|
||||
for (const property of additional.layer1.properties ?? []) {
|
||||
props.set(property.code ?? 0, property.value ?? '');
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
export function permissionToRole(permission: number): string {
|
||||
switch (permission) {
|
||||
case 1: return 'owner';
|
||||
case 2: return 'admin';
|
||||
default: return 'member';
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Friend list
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchFriendList(bridge: Bridge): Promise<FriendInfo[]> {
|
||||
const friends: FriendInfo[] = [];
|
||||
let nextUin: number | null = null;
|
||||
|
||||
do {
|
||||
const body: any = {
|
||||
friendCount: 300,
|
||||
field4: 0,
|
||||
field6: 1,
|
||||
field7: 0x7FFFFFFF,
|
||||
body: [
|
||||
{ type: 1, number: { numbers: [103, 102, 20002, 27394] } },
|
||||
{ type: 4, number: { numbers: [100, 101, 102] } },
|
||||
],
|
||||
field10002: [13578, 13579, 13573, 13572, 13568],
|
||||
field10003: 4051,
|
||||
};
|
||||
if (nextUin !== null) {
|
||||
body.nextUin = { uin: nextUin };
|
||||
}
|
||||
|
||||
const resp = await sendOidbAndDecode<any>(
|
||||
bridge, 'OidbSvcTrpcTcp.0xfd4_1', 0xFD4, 1, body,
|
||||
OidbFriendListRequestSchema, OidbSvcTrpcTcp0xFD4_1ResponseSchema);
|
||||
|
||||
if (resp?.friends) {
|
||||
for (const raw of resp.friends) {
|
||||
const props = buildFriendProperties(raw);
|
||||
friends.push({
|
||||
uin: raw.uin ?? 0,
|
||||
uid: raw.uid ?? '',
|
||||
nickname: props.get(20002) ?? String(raw.uin ?? 0),
|
||||
remark: props.get(103) ?? '',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
nextUin = resp?.next?.uin ?? null;
|
||||
if (nextUin === 0) nextUin = null;
|
||||
} while (nextUin !== null);
|
||||
|
||||
bridge.qqInfo.setFriends(friends);
|
||||
return friends;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Group list
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchGroupList(bridge: Bridge): Promise<QQGroupInfo[]> {
|
||||
const allTrue = true;
|
||||
const body = {
|
||||
config: {
|
||||
config1: {
|
||||
groupOwner: allTrue, field2: allTrue, memberMax: allTrue, memberCount: allTrue,
|
||||
groupName: allTrue, field8: allTrue, field9: allTrue, field10: allTrue,
|
||||
field11: allTrue, field12: allTrue, field13: allTrue, field14: allTrue,
|
||||
field15: allTrue, field16: allTrue, field17: allTrue, field18: allTrue,
|
||||
question: allTrue, field20: allTrue, field22: allTrue, field23: allTrue,
|
||||
field24: allTrue, field25: allTrue, field26: allTrue, field27: allTrue,
|
||||
field28: allTrue, field29: allTrue, field30: allTrue, field31: allTrue,
|
||||
field32: allTrue, field5001: allTrue, field5002: allTrue, field5003: allTrue,
|
||||
},
|
||||
config2: {
|
||||
field1: allTrue, field2: allTrue, field3: allTrue, field4: allTrue,
|
||||
field5: allTrue, field6: allTrue, field7: allTrue, field8: allTrue,
|
||||
},
|
||||
config3: { field5: allTrue, field6: allTrue },
|
||||
},
|
||||
};
|
||||
|
||||
const resp = await sendOidbAndDecode<any>(
|
||||
bridge, 'OidbSvcTrpcTcp.0xfe5_2', 0xFE5, 2, body,
|
||||
OidbGroupListRequestSchema, OidbSvcTrpcTcp0xFE5_2ResponseSchema, true);
|
||||
|
||||
const groups: QQGroupInfo[] = [];
|
||||
if (resp?.groups) {
|
||||
for (const raw of resp.groups) {
|
||||
groups.push({
|
||||
groupId: raw.groupUin ?? 0,
|
||||
groupName: raw.info?.groupName ?? '',
|
||||
remark: raw.customInfo?.remark ?? '',
|
||||
memberCount: raw.info?.memberCount ?? 0,
|
||||
memberMax: raw.info?.memberMax ?? 0,
|
||||
members: new Map(),
|
||||
});
|
||||
}
|
||||
}
|
||||
bridge.qqInfo.setGroups(groups);
|
||||
return groups;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Group member list
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchGroupMemberList(bridge: Bridge, groupId: number): Promise<GroupMemberInfo[]> {
|
||||
const members: GroupMemberInfo[] = [];
|
||||
let token = '';
|
||||
|
||||
do {
|
||||
const body: any = {
|
||||
groupUin: groupId,
|
||||
field2: 5,
|
||||
field3: 2,
|
||||
body: {
|
||||
memberName: true, memberCard: true, level: true, field13: true,
|
||||
field16: true, specialTitle: true, field18: true, field20: true,
|
||||
field21: true, joinTimestamp: true, lastMsgTimestamp: true,
|
||||
shutUpTimestamp: true, field103: true, field104: true, field105: true,
|
||||
field106: true, permission: true, field200: true, field201: true,
|
||||
},
|
||||
};
|
||||
if (token) body.token = token;
|
||||
|
||||
const resp = await sendOidbAndDecode<any>(
|
||||
bridge, 'OidbSvcTrpcTcp.0xfe7_3', 0xFE7, 3, body,
|
||||
OidbGroupMemberListRequestSchema, OidbSvcTrpcTcp0xFE7_3ResponseSchema);
|
||||
|
||||
if (resp?.members) {
|
||||
for (const raw of resp.members) {
|
||||
members.push({
|
||||
uin: raw.uin?.uin ?? 0,
|
||||
uid: raw.uin?.uid ?? '',
|
||||
nickname: raw.memberName ?? '',
|
||||
card: raw.memberCard?.memberCard ?? '',
|
||||
role: permissionToRole(raw.permission ?? 0),
|
||||
level: raw.level?.level ?? 0,
|
||||
title: raw.specialTitle ?? '',
|
||||
joinTime: raw.joinTimestamp ?? 0,
|
||||
lastSentTime: raw.lastMsgTimestamp ?? 0,
|
||||
shutUpTime: raw.shutUpTimestamp ?? 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
token = resp?.token ?? '';
|
||||
} while (token);
|
||||
|
||||
bridge.qqInfo.setGroupMembers(groupId, members);
|
||||
return members;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// User profile
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchUserProfile(bridge: Bridge, uin: number): Promise<UserProfileInfo> {
|
||||
const keys = [20002, 27394, 20009, 20031, 101, 103, 102, 20020, 20003, 20026, 105, 27372, 27406, 20037];
|
||||
const body = {
|
||||
uin,
|
||||
field2: 0,
|
||||
keys: keys.map(k => ({ key: k })),
|
||||
};
|
||||
|
||||
const resp = await sendOidbAndDecode<any>(
|
||||
bridge, 'OidbSvcTrpcTcp.0xfe1_2', 0xFE1, 2, body,
|
||||
OidbUserInfoRequestSchema, OidbUserInfoResponseSchema);
|
||||
|
||||
if (!resp?.body) throw new Error('user info response body missing');
|
||||
|
||||
const info: UserProfileInfo = {
|
||||
uin: resp.body.uin ?? uin,
|
||||
uid: resp.body.uid ?? '',
|
||||
nickname: '', remark: '', qid: '', sex: 'unknown', age: 0, sign: '', avatar: '',
|
||||
};
|
||||
|
||||
if (resp.body.properties) {
|
||||
const bytesMap = new Map<number, Uint8Array>();
|
||||
const numMap = new Map<number, number>();
|
||||
for (const bp of resp.body.properties.bytesProperties ?? []) {
|
||||
bytesMap.set(bp.code ?? 0, bp.value ?? new Uint8Array(0));
|
||||
}
|
||||
for (const np of resp.body.properties.numberProperties ?? []) {
|
||||
numMap.set(np.number1 ?? 0, np.number2 ?? 0);
|
||||
}
|
||||
|
||||
const getString = (code: number) => {
|
||||
const b = bytesMap.get(code);
|
||||
return b ? Buffer.from(b).toString('utf8') : '';
|
||||
};
|
||||
|
||||
info.nickname = getString(20002);
|
||||
info.remark = getString(103);
|
||||
info.qid = getString(27394);
|
||||
info.sign = getString(102);
|
||||
|
||||
const avatarBytes = bytesMap.get(101);
|
||||
if (avatarBytes) {
|
||||
const av = protoDecode(avatarBytes, AvatarInfoSchema);
|
||||
if (av?.url) info.avatar = av.url + '640';
|
||||
}
|
||||
|
||||
const sexNum = numMap.get(20009) ?? 0;
|
||||
info.sex = sexNum === 1 ? 'male' : sexNum === 2 ? 'female' : 'unknown';
|
||||
info.age = numMap.get(20037) ?? 0;
|
||||
}
|
||||
|
||||
bridge.qqInfo.setUserProfile(info);
|
||||
const selfUin = parseInt(bridge.qqInfo.uin, 10) || 0;
|
||||
if (info.uin === selfUin) bridge.qqInfo.setSelfProfile(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Group requests
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchGroupRequests(bridge: Bridge, filtered = false): Promise<GroupRequestInfo[]> {
|
||||
const subCmd = filtered ? 2 : 1;
|
||||
const cmd = filtered ? 'OidbSvcTrpcTcp.0x10c0_2' : 'OidbSvcTrpcTcp.0x10c0_1';
|
||||
const resp = await sendOidbAndDecode<any>(
|
||||
bridge, cmd, 0x10C0, subCmd, { count: 20, field2: 0 },
|
||||
OidbGroupRequestListSchema, OidbSvcTrpcTcp0x10C0ResponseSchema);
|
||||
|
||||
const requests: GroupRequestInfo[] = [];
|
||||
for (const raw of resp?.requests ?? []) {
|
||||
requests.push({
|
||||
groupId: raw.group?.groupUin ?? 0,
|
||||
groupName: raw.group?.groupName ?? '',
|
||||
targetUid: raw.target?.uid ?? '',
|
||||
targetUin: 0,
|
||||
targetName: raw.target?.name ?? '',
|
||||
invitorUid: raw.invitor?.uid ?? '',
|
||||
invitorUin: 0,
|
||||
invitorName: raw.invitor?.name ?? '',
|
||||
operatorUid: raw.operatorUser?.uid ?? '',
|
||||
operatorUin: 0,
|
||||
operatorName: raw.operatorUser?.name ?? '',
|
||||
sequence: Number(raw.sequence ?? 0),
|
||||
state: raw.state ?? 0,
|
||||
eventType: raw.eventType ?? 0,
|
||||
comment: raw.comment ?? '',
|
||||
filtered,
|
||||
});
|
||||
}
|
||||
return requests;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Download RKeys
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchDownloadRKeys(bridge: Bridge): Promise<DownloadRKeyInfo[]> {
|
||||
const PRIVATE_IMAGE = 10;
|
||||
const GROUP_IMAGE = 20;
|
||||
const FALLBACK_IMAGE = 2;
|
||||
|
||||
const body = {
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 202 },
|
||||
scene: { requestType: 2, businessType: 1, sceneType: 0 },
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
downloadRkey: {
|
||||
types: [PRIVATE_IMAGE, GROUP_IMAGE, FALLBACK_IMAGE],
|
||||
},
|
||||
};
|
||||
|
||||
const resp = await sendOidbAndDecode<any>(
|
||||
bridge, 'OidbSvcTrpcTcp.0x9067_202', 0x9067, 202, body,
|
||||
NTV2RichMediaReqSchema, NTV2RichMediaRespSchema, true);
|
||||
|
||||
if (resp?.respHead?.retCode && resp.respHead.retCode !== 0) {
|
||||
throw new Error(resp.respHead.message ?? 'fetch download rkey failed');
|
||||
}
|
||||
|
||||
const result: DownloadRKeyInfo[] = [];
|
||||
for (const entry of resp?.downloadRkey?.rkeys ?? []) {
|
||||
const rkey = entry.rkey ?? '';
|
||||
const type = entry.type ?? 0;
|
||||
if (rkey && type) {
|
||||
result.push({
|
||||
rkey,
|
||||
ttlSeconds: Number(entry.rkeyTtlSec ?? 0),
|
||||
storeId: entry.storeId ?? 0,
|
||||
createTime: entry.rkeyCreateTime ?? 0,
|
||||
type,
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// OIDB protocol helpers -- encode requests, send+check, send+decode, UID resolution.
|
||||
|
||||
import type { Bridge } from './bridge';
|
||||
import type { ProtoSchema } from '../protobuf/decode';
|
||||
import { protoEncode, protoDecode } from '../protobuf/decode';
|
||||
import { makeOidbBaseSchema } from './proto/oidb';
|
||||
|
||||
/**
|
||||
* Build a raw OIDB request buffer (base envelope wrapping a typed body).
|
||||
*/
|
||||
export function makeOidbRequest(
|
||||
command: number, subCommand: number,
|
||||
body: any, bodySchema: ProtoSchema, isUid = false,
|
||||
): Uint8Array {
|
||||
const baseSchema = makeOidbBaseSchema(bodySchema);
|
||||
return protoEncode({
|
||||
command,
|
||||
subCommand,
|
||||
errorCode: 0,
|
||||
body,
|
||||
errorMsg: '',
|
||||
reserved: isUid ? 1 : 0,
|
||||
}, baseSchema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an OIDB packet and verify it succeeded (no decode of body).
|
||||
*/
|
||||
export async function sendOidbAndCheck(
|
||||
bridge: Bridge,
|
||||
serviceCmd: string, command: number, subCommand: number,
|
||||
body: any, bodySchema: ProtoSchema, isUid = false,
|
||||
): Promise<void> {
|
||||
const request = makeOidbRequest(command, subCommand, body, bodySchema, isUid);
|
||||
const result = await bridge.sendRawPacket(serviceCmd, request);
|
||||
if (!result.success) throw new Error(result.errorMessage || 'packet send failed');
|
||||
if (!result.gotResponse) throw new Error(result.errorMessage || 'no response');
|
||||
// Check OIDB error code if response present
|
||||
if (result.responseData && result.responseData.length > 0) {
|
||||
const emptyBase = makeOidbBaseSchema({ _dummy: { field: 99, type: 'uint32' as const } });
|
||||
const resp = protoDecode(result.responseData, emptyBase);
|
||||
if (resp && (resp as any).errorCode && (resp as any).errorCode !== 0) {
|
||||
throw new Error(`OIDB error ${(resp as any).errorCode}: ${(resp as any).errorMsg ?? ''}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an OIDB packet and decode the response body with the given schema.
|
||||
*/
|
||||
export async function sendOidbAndDecode<T>(
|
||||
bridge: Bridge,
|
||||
serviceCmd: string, command: number, subCommand: number,
|
||||
body: any, bodySchema: ProtoSchema, responseSchema: ProtoSchema, isUid = false,
|
||||
): Promise<T> {
|
||||
const request = makeOidbRequest(command, subCommand, body, bodySchema, isUid);
|
||||
const result = await bridge.sendRawPacket(serviceCmd, request);
|
||||
if (!result.success) throw new Error(result.errorMessage || 'packet send failed');
|
||||
if (!result.gotResponse || !result.responseData) throw new Error(result.errorMessage || 'no response');
|
||||
|
||||
const baseSchema = makeOidbBaseSchema(responseSchema);
|
||||
const resp = protoDecode(result.responseData, baseSchema);
|
||||
if (!resp) throw new Error('failed to decode OIDB response');
|
||||
if ((resp as any).errorCode && (resp as any).errorCode !== 0) {
|
||||
throw new Error(`OIDB error ${(resp as any).errorCode}: ${(resp as any).errorMsg ?? ''}`);
|
||||
}
|
||||
return (resp as any).body as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a UIN to a UID string, using cache or fetching as needed.
|
||||
* Mirrors C++ resolve_user_uid_for_action.
|
||||
*/
|
||||
export async function resolveUserUid(bridge: Bridge, uin: number, groupId?: number): Promise<string> {
|
||||
// Try group member first
|
||||
if (groupId !== undefined) {
|
||||
const uid = bridge.qqInfo.findUidByUinInGroup(groupId, uin);
|
||||
if (uid) return uid;
|
||||
// Try fetching member list
|
||||
try { await bridge.fetchGroupMemberList(groupId); } catch { /* ignore */ }
|
||||
const uid2 = bridge.qqInfo.findUidByUinInGroup(groupId, uin);
|
||||
if (uid2) return uid2;
|
||||
}
|
||||
// Try cached
|
||||
const uid = bridge.qqInfo.findUidByUin(uin);
|
||||
if (uid) return uid;
|
||||
// Fetch profile
|
||||
const profile = await bridge.fetchUserProfile(uin);
|
||||
if (profile.uid) return profile.uid;
|
||||
throw new Error(`failed to resolve UID for UIN ${uin}`);
|
||||
}
|
||||
@@ -0,0 +1,495 @@
|
||||
// Bridge — per-UIN session: handler registration, packet dispatch, event routing.
|
||||
// Supports packet sending via native addon.
|
||||
// Heavy OIDB / contact / action logic is split into bridge-oidb, bridge-contacts, bridge-actions.
|
||||
|
||||
import type { PacketInfo } from '../protocol/types';
|
||||
import type { ForwardNodePayload, QQEventVariant, MessageElement } from './events';
|
||||
import type { FriendInfo, QQGroupInfo, GroupMemberInfo, UserProfileInfo, GroupRequestInfo } from './qq-info';
|
||||
import { QQInfo } from './qq-info';
|
||||
import { MSG_PUSH_CMD, parseMsgPush } from './handlers/msg-push-handler';
|
||||
import type { PacketSender, SendPacketResult } from '../protocol/packet-sender';
|
||||
import { protoEncode, protoDecode } from '../protobuf/decode';
|
||||
import { buildSendElems } from './builders/element-builder';
|
||||
import { createLogger } from '../utils/logger';
|
||||
import {
|
||||
SendMessageRequestSchema,
|
||||
SendMessageResponseSchema,
|
||||
} from './proto/action';
|
||||
|
||||
// Delegated modules
|
||||
import { resolveUserUid as resolveUserUid_ } from './bridge-oidb';
|
||||
import {
|
||||
fetchFriendList as fetchFriendList_,
|
||||
fetchGroupList as fetchGroupList_,
|
||||
fetchGroupMemberList as fetchGroupMemberList_,
|
||||
fetchUserProfile as fetchUserProfile_,
|
||||
fetchGroupRequests as fetchGroupRequests_,
|
||||
fetchDownloadRKeys as fetchDownloadRKeys_,
|
||||
} from './bridge-contacts';
|
||||
import {
|
||||
muteGroupMember as muteGroupMember_,
|
||||
muteGroupAll as muteGroupAll_,
|
||||
kickGroupMember as kickGroupMember_,
|
||||
leaveGroup as leaveGroup_,
|
||||
setGroupAdmin as setGroupAdmin_,
|
||||
setGroupCard as setGroupCard_,
|
||||
setGroupName as setGroupName_,
|
||||
setGroupSpecialTitle as setGroupSpecialTitle_,
|
||||
setFriendAddRequest as setFriendAddRequest_,
|
||||
deleteFriend as deleteFriend_,
|
||||
uploadGroupFile as uploadGroupFile_,
|
||||
uploadPrivateFile as uploadPrivateFile_,
|
||||
fetchGroupFiles as fetchGroupFiles_,
|
||||
fetchGroupFileUrl as fetchGroupFileUrl_,
|
||||
fetchPrivateFileUrl as fetchPrivateFileUrl_,
|
||||
fetchGroupPttUrlByNode as fetchGroupPttUrlByNode_,
|
||||
fetchPrivatePttUrlByNode as fetchPrivatePttUrlByNode_,
|
||||
fetchGroupVideoUrlByNode as fetchGroupVideoUrlByNode_,
|
||||
fetchPrivateVideoUrlByNode as fetchPrivateVideoUrlByNode_,
|
||||
uploadForwardNodes as uploadForwardNodes_,
|
||||
fetchForwardNodes as fetchForwardNodes_,
|
||||
deleteGroupFile as deleteGroupFile_,
|
||||
moveGroupFile as moveGroupFile_,
|
||||
createGroupFileFolder as createGroupFileFolder_,
|
||||
deleteGroupFileFolder as deleteGroupFileFolder_,
|
||||
renameGroupFileFolder as renameGroupFileFolder_,
|
||||
setGroupAddRequest as setGroupAddRequest_,
|
||||
sendPoke as sendPoke_,
|
||||
sendLike as sendLike_,
|
||||
setGroupEssence as setGroupEssence_,
|
||||
setGroupReaction as setGroupReaction_,
|
||||
recallGroupMessage as recallGroupMessage_,
|
||||
recallPrivateMessage as recallPrivateMessage_,
|
||||
setFriendRemark as setFriendRemark_,
|
||||
fetchGroupFileCount as fetchGroupFileCount_,
|
||||
} from './bridge-actions';
|
||||
import type { GroupFilesResult } from './bridge-actions';
|
||||
import type { MediaIndexNode } from './bridge-actions';
|
||||
|
||||
export type BridgeEventCallback = (event: QQEventVariant) => void;
|
||||
|
||||
type CmdParser = (pkt: PacketInfo, qqInfo: QQInfo) => QQEventVariant[];
|
||||
|
||||
export interface SendMessageReceipt {
|
||||
messageId: number;
|
||||
sequence: number;
|
||||
clientSequence: number;
|
||||
random: number;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export interface DownloadRKeyInfo {
|
||||
rkey: string;
|
||||
ttlSeconds: number;
|
||||
storeId: number;
|
||||
createTime: number;
|
||||
type: number;
|
||||
}
|
||||
|
||||
const log = createLogger('Bridge');
|
||||
const eventLog = createLogger('Event');
|
||||
|
||||
export class Bridge {
|
||||
private static readonly SEND_MSG_CMD = 'MessageSvc.PbSendMsg';
|
||||
|
||||
private qqInfo_: QQInfo;
|
||||
private pids_ = new Set<number>();
|
||||
private eventCallback_: BridgeEventCallback | null = null;
|
||||
private cmdHandlers_ = new Map<string, CmdParser[]>();
|
||||
private packetClient_: PacketSender | null = null;
|
||||
private memberRefreshTasks_ = new Map<number, Promise<void>>();
|
||||
|
||||
// Sequence and random generators for outgoing messages
|
||||
private clientSeq_ = 100000000 + (Date.now() % 1000000000);
|
||||
private msgRandom_ = (Date.now() & 0xFFFFFFFF) >>> 0;
|
||||
|
||||
constructor(qqInfo: QQInfo) {
|
||||
this.qqInfo_ = qqInfo;
|
||||
this.registerDefaultHandlers();
|
||||
}
|
||||
|
||||
get qqInfo(): QQInfo { return this.qqInfo_; }
|
||||
|
||||
setPacketClient(client: PacketSender): void {
|
||||
this.packetClient_ = client;
|
||||
}
|
||||
|
||||
private registerDefaultHandlers(): void {
|
||||
this.registerCmd(MSG_PUSH_CMD, parseMsgPush);
|
||||
}
|
||||
|
||||
registerCmd(cmd: string, parser: CmdParser): void {
|
||||
const arr = this.cmdHandlers_.get(cmd) ?? [];
|
||||
arr.push(parser);
|
||||
this.cmdHandlers_.set(cmd, arr);
|
||||
}
|
||||
|
||||
setEventCallback(cb: BridgeEventCallback): void {
|
||||
this.eventCallback_ = cb;
|
||||
}
|
||||
|
||||
handlesCmd(cmd: string): boolean {
|
||||
return this.cmdHandlers_.has(cmd);
|
||||
}
|
||||
|
||||
// --- PID management ---
|
||||
|
||||
attachPid(pid: number): void {
|
||||
this.pids_.add(pid);
|
||||
}
|
||||
detachPid(pid: number): void {
|
||||
this.pids_.delete(pid);
|
||||
}
|
||||
hasPid(pid: number): boolean { return this.pids_.has(pid); }
|
||||
get empty(): boolean { return this.pids_.size === 0; }
|
||||
get activePid(): number | null {
|
||||
for (const pid of this.pids_) return pid;
|
||||
return null;
|
||||
}
|
||||
|
||||
// --- Packet dispatch ---
|
||||
|
||||
onPacket(pkt: PacketInfo): void {
|
||||
const handlers = this.cmdHandlers_.get(pkt.serviceCmd);
|
||||
if (!handlers) return;
|
||||
|
||||
for (const handler of handlers) {
|
||||
try {
|
||||
const events = handler(pkt, this.qqInfo_);
|
||||
for (const event of events) {
|
||||
this.triggerMemberCacheRefresh(event);
|
||||
printEvent(event);
|
||||
this.emitEvent(event);
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('handler error for %s: %s', pkt.serviceCmd, e instanceof Error ? (e.stack ?? e.message) : String(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private emitEvent(event: QQEventVariant): void {
|
||||
if (this.eventCallback_) {
|
||||
try { this.eventCallback_(event); } catch (e) {
|
||||
log.error('event callback error: %s', e instanceof Error ? (e.stack ?? e.message) : String(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private triggerMemberCacheRefresh(event: QQEventVariant): void {
|
||||
let groupId = 0;
|
||||
let reason = '';
|
||||
switch (event.kind) {
|
||||
case 'group_member_join':
|
||||
groupId = event.groupId;
|
||||
reason = 'group_member_join';
|
||||
break;
|
||||
case 'group_member_leave':
|
||||
groupId = event.groupId;
|
||||
reason = 'group_member_leave';
|
||||
break;
|
||||
case 'group_admin':
|
||||
groupId = event.groupId;
|
||||
reason = 'group_admin';
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (groupId <= 0) return;
|
||||
if (this.memberRefreshTasks_.has(groupId)) return;
|
||||
|
||||
const task = (async () => {
|
||||
try {
|
||||
if (!this.qqInfo_.findGroup(groupId)) {
|
||||
try { await this.fetchGroupList(); } catch { /* ignore */ }
|
||||
}
|
||||
await this.fetchGroupMemberList(groupId);
|
||||
log.debug('member cache refreshed: group=%d reason=%s', groupId, reason);
|
||||
} catch (e) {
|
||||
log.warn('failed to refresh member cache: group=%d reason=%s err=%s',
|
||||
groupId, reason, e instanceof Error ? e.message : String(e));
|
||||
} finally {
|
||||
this.memberRefreshTasks_.delete(groupId);
|
||||
}
|
||||
})();
|
||||
|
||||
this.memberRefreshTasks_.set(groupId, task);
|
||||
}
|
||||
|
||||
// --- Sequence / random generators ---
|
||||
|
||||
private nextClientSequence(): number {
|
||||
return ++this.clientSeq_;
|
||||
}
|
||||
|
||||
private nextMessageRandom(): number {
|
||||
this.msgRandom_ = (this.msgRandom_ + 0x9E3779B9) >>> 0;
|
||||
return this.msgRandom_ & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
// --- Send packet (raw) ---
|
||||
|
||||
async sendRawPacket(serviceCmd: string, body: Uint8Array, timeoutMs = 15000): Promise<SendPacketResult> {
|
||||
if (!this.packetClient_) {
|
||||
return {
|
||||
success: false, gotResponse: false, errorCode: -1,
|
||||
errorMessage: 'no packet sender attached', responseData: null,
|
||||
};
|
||||
}
|
||||
return this.packetClient_.sendPacket(serviceCmd, Buffer.from(body), timeoutMs);
|
||||
}
|
||||
|
||||
// --- Send message (high-level) ---
|
||||
|
||||
async sendGroupMessage(groupId: number, elements: MessageElement[]): Promise<SendMessageReceipt> {
|
||||
if (elements.length === 0) throw new Error('message is empty');
|
||||
|
||||
const protoElems = await buildSendElems(elements, { bridge: this, groupId });
|
||||
const random = this.nextMessageRandom();
|
||||
|
||||
const request = protoEncode({
|
||||
routingHead: {
|
||||
grp: { groupCode: BigInt(groupId) },
|
||||
} as any,
|
||||
contentHead: {
|
||||
type: 1,
|
||||
} as any,
|
||||
messageBody: {
|
||||
richText: {
|
||||
elems: protoElems,
|
||||
},
|
||||
} as any,
|
||||
clientSequence: 0,
|
||||
random,
|
||||
syncCookie: new Uint8Array(0),
|
||||
via: 0,
|
||||
dataStatist: 0,
|
||||
multiSendSeq: 0,
|
||||
}, SendMessageRequestSchema);
|
||||
|
||||
const result = await this.sendRawPacket(Bridge.SEND_MSG_CMD, request);
|
||||
|
||||
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||
throw new Error(`send group message failed: ${result.errorMessage || 'no response'}`);
|
||||
}
|
||||
|
||||
const response = protoDecode(result.responseData, SendMessageResponseSchema);
|
||||
if (!response) {
|
||||
throw new Error('failed to decode SendMessageResponse');
|
||||
}
|
||||
if (response.result !== undefined && response.result !== 0) {
|
||||
throw new Error(`send group message rejected: result=${response.result} err=${response.errMsg ?? ''}`);
|
||||
}
|
||||
|
||||
const seq = response.groupSequence ?? 0;
|
||||
const messageId = (random & 0x7FFFFFFF) || seq;
|
||||
const timestamp = response.timestamp1 ?? Math.floor(Date.now() / 1000);
|
||||
|
||||
return {
|
||||
messageId,
|
||||
sequence: seq,
|
||||
clientSequence: 0,
|
||||
random,
|
||||
timestamp,
|
||||
};
|
||||
}
|
||||
|
||||
async sendPrivateMessage(userUin: number, elements: MessageElement[]): Promise<SendMessageReceipt> {
|
||||
if (elements.length === 0) throw new Error('message is empty');
|
||||
|
||||
// Resolve UID for image upload (C++ resolves UID before building elems)
|
||||
let userUid = '';
|
||||
const hasMedia = elements.some(e => e.type === 'image' || e.type === 'record' || e.type === 'video');
|
||||
if (hasMedia) {
|
||||
userUid = await this.resolveUserUid(userUin);
|
||||
}
|
||||
|
||||
const protoElems = await buildSendElems(elements, { bridge: this, userUid });
|
||||
const random = this.nextMessageRandom();
|
||||
const clientSeq = this.nextClientSequence();
|
||||
|
||||
const request = protoEncode({
|
||||
routingHead: {
|
||||
c2c: {
|
||||
uin: userUin,
|
||||
},
|
||||
} as any,
|
||||
contentHead: {
|
||||
type: 1,
|
||||
subType: 0,
|
||||
c2cCmd: 11,
|
||||
} as any,
|
||||
messageBody: {
|
||||
richText: {
|
||||
elems: protoElems,
|
||||
},
|
||||
} as any,
|
||||
clientSequence: clientSeq,
|
||||
random,
|
||||
syncCookie: new Uint8Array(0),
|
||||
via: 0,
|
||||
dataStatist: 0,
|
||||
ctrl: {
|
||||
msgFlag: Math.floor(Date.now() / 1000),
|
||||
} as any,
|
||||
multiSendSeq: 0,
|
||||
}, SendMessageRequestSchema);
|
||||
|
||||
const result = await this.sendRawPacket(Bridge.SEND_MSG_CMD, request);
|
||||
|
||||
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||
throw new Error(`send private message failed: ${result.errorMessage || 'no response'}`);
|
||||
}
|
||||
|
||||
const response = protoDecode(result.responseData, SendMessageResponseSchema);
|
||||
if (!response) {
|
||||
throw new Error('failed to decode SendMessageResponse');
|
||||
}
|
||||
if (response.result !== undefined && response.result !== 0) {
|
||||
throw new Error(`send private message rejected: result=${response.result} err=${response.errMsg ?? ''}`);
|
||||
}
|
||||
|
||||
const seq = response.privateSequence ?? 0;
|
||||
const messageId = (random & 0x7FFFFFFF) || seq;
|
||||
const timestamp = response.timestamp1 ?? Math.floor(Date.now() / 1000);
|
||||
|
||||
return {
|
||||
messageId,
|
||||
sequence: seq,
|
||||
clientSequence: clientSeq,
|
||||
random,
|
||||
timestamp,
|
||||
};
|
||||
}
|
||||
|
||||
// --- Delegated: OIDB helpers ---
|
||||
|
||||
async resolveUserUid(uin: number, groupId?: number): Promise<string> {
|
||||
return resolveUserUid_(this, uin, groupId);
|
||||
}
|
||||
|
||||
// --- Delegated: Contact / info queries ---
|
||||
|
||||
async fetchFriendList(): Promise<FriendInfo[]> { return fetchFriendList_(this); }
|
||||
async fetchGroupList(): Promise<QQGroupInfo[]> { return fetchGroupList_(this); }
|
||||
async fetchGroupMemberList(groupId: number): Promise<GroupMemberInfo[]> { return fetchGroupMemberList_(this, groupId); }
|
||||
async fetchUserProfile(uin: number): Promise<UserProfileInfo> { return fetchUserProfile_(this, uin); }
|
||||
async fetchGroupRequests(filtered = false): Promise<GroupRequestInfo[]> { return fetchGroupRequests_(this, filtered); }
|
||||
async fetchDownloadRKeys(): Promise<DownloadRKeyInfo[]> { return fetchDownloadRKeys_(this); }
|
||||
|
||||
// --- Delegated: Admin / action methods ---
|
||||
|
||||
async muteGroupMember(groupId: number, userId: number, duration: number): Promise<void> { return muteGroupMember_(this, groupId, userId, duration); }
|
||||
async muteGroupAll(groupId: number, enable: boolean): Promise<void> { return muteGroupAll_(this, groupId, enable); }
|
||||
async kickGroupMember(groupId: number, userId: number, reject: boolean, reason = ''): Promise<void> { return kickGroupMember_(this, groupId, userId, reject, reason); }
|
||||
async leaveGroup(groupId: number): Promise<void> { return leaveGroup_(this, groupId); }
|
||||
async setGroupAdmin(groupId: number, userId: number, enable: boolean): Promise<void> { return setGroupAdmin_(this, groupId, userId, enable); }
|
||||
async setGroupCard(groupId: number, userId: number, card: string): Promise<void> { return setGroupCard_(this, groupId, userId, card); }
|
||||
async setGroupName(groupId: number, name: string): Promise<void> { return setGroupName_(this, groupId, name); }
|
||||
async setGroupSpecialTitle(groupId: number, userId: number, title: string): Promise<void> { return setGroupSpecialTitle_(this, groupId, userId, title); }
|
||||
async setFriendAddRequest(uidOrFlag: string, approve: boolean): Promise<void> { return setFriendAddRequest_(this, uidOrFlag, approve); }
|
||||
async deleteFriend(userId: number, block = false): Promise<void> { return deleteFriend_(this, userId, block); }
|
||||
async uploadGroupFile(groupId: number, file: string, name = '', folderId = '/', uploadFile = true): Promise<{ fileId: string | null }> {
|
||||
return uploadGroupFile_(this, groupId, file, name, folderId, uploadFile);
|
||||
}
|
||||
async uploadPrivateFile(userId: number, file: string, name = '', uploadFile = true): Promise<{ fileId: string | null }> {
|
||||
return uploadPrivateFile_(this, userId, file, name, uploadFile);
|
||||
}
|
||||
async fetchGroupFiles(groupId: number, folderId = '/'): Promise<GroupFilesResult> { return fetchGroupFiles_(this, groupId, folderId); }
|
||||
async fetchGroupFileUrl(groupId: number, fileId: string, busId = 102): Promise<string> { return fetchGroupFileUrl_(this, groupId, fileId, busId); }
|
||||
async fetchPrivateFileUrl(userId: number, fileId: string, fileHash: string): Promise<string> { return fetchPrivateFileUrl_(this, userId, fileId, fileHash); }
|
||||
async fetchGroupPttUrlByNode(groupId: number, node: MediaIndexNode): Promise<string> { return fetchGroupPttUrlByNode_(this, groupId, node); }
|
||||
async fetchPrivatePttUrlByNode(node: MediaIndexNode): Promise<string> { return fetchPrivatePttUrlByNode_(this, node); }
|
||||
async fetchGroupVideoUrlByNode(groupId: number, node: MediaIndexNode): Promise<string> { return fetchGroupVideoUrlByNode_(this, groupId, node); }
|
||||
async fetchPrivateVideoUrlByNode(node: MediaIndexNode): Promise<string> { return fetchPrivateVideoUrlByNode_(this, node); }
|
||||
async uploadForwardNodes(nodes: ForwardNodePayload[], groupId?: number): Promise<string> { return uploadForwardNodes_(this, nodes, groupId); }
|
||||
async fetchForwardNodes(resId: string): Promise<ForwardNodePayload[]> { return fetchForwardNodes_(this, resId); }
|
||||
async deleteGroupFile(groupId: number, fileId: string): Promise<void> { return deleteGroupFile_(this, groupId, fileId); }
|
||||
async moveGroupFile(groupId: number, fileId: string, parentDirectory: string, targetDirectory: string): Promise<void> { return moveGroupFile_(this, groupId, fileId, parentDirectory, targetDirectory); }
|
||||
async createGroupFileFolder(groupId: number, name: string, parentId = '/'): Promise<void> { return createGroupFileFolder_(this, groupId, name, parentId); }
|
||||
async deleteGroupFileFolder(groupId: number, folderId: string): Promise<void> { return deleteGroupFileFolder_(this, groupId, folderId); }
|
||||
async renameGroupFileFolder(groupId: number, folderId: string, newFolderName: string): Promise<void> { return renameGroupFileFolder_(this, groupId, folderId, newFolderName); }
|
||||
async setGroupAddRequest(groupId: number, sequence: number, eventType: number, approve: boolean, reason = '', filtered = false): Promise<void> { return setGroupAddRequest_(this, groupId, sequence, eventType, approve, reason, filtered); }
|
||||
async sendPoke(isGroup: boolean, peerUin: number, targetUin?: number): Promise<void> { return sendPoke_(this, isGroup, peerUin, targetUin); }
|
||||
async sendLike(userId: number, count: number): Promise<void> { return sendLike_(this, userId, count); }
|
||||
async setGroupEssence(groupId: number, sequence: number, random: number, enable: boolean): Promise<void> { return setGroupEssence_(this, groupId, sequence, random, enable); }
|
||||
async setGroupReaction(groupId: number, sequence: number, code: string, isSet: boolean): Promise<void> { return setGroupReaction_(this, groupId, sequence, code, isSet); }
|
||||
async recallGroupMessage(groupId: number, sequence: number): Promise<void> { return recallGroupMessage_(this, groupId, sequence); }
|
||||
async recallPrivateMessage(userUin: number, clientSeq: number, msgSeq: number, random: number, timestamp: number): Promise<void> { return recallPrivateMessage_(this, userUin, clientSeq, msgSeq, random, timestamp); }
|
||||
async setFriendRemark(userId: number, remark: string): Promise<void> { return setFriendRemark_(this, userId, remark); }
|
||||
async fetchGroupFileCount(groupId: number): Promise<{ fileCount: number; maxCount: number }> { return fetchGroupFileCount_(this, groupId); }
|
||||
}
|
||||
|
||||
// --- Module-level helper functions ---
|
||||
|
||||
function elementsToText(elements: MessageElement[]): string {
|
||||
return elements.map(e => {
|
||||
switch (e.type) {
|
||||
case 'text': return e.text ?? '';
|
||||
case 'at': return `@${e.targetUin ?? 'all'}`;
|
||||
case 'face': return `[表情:${e.faceId}]`;
|
||||
case 'mface': return `[${e.summary ?? '表情'}]`;
|
||||
case 'image': return '[图片]';
|
||||
case 'video': return '[视频]';
|
||||
case 'record': return '[语音]';
|
||||
case 'file': return `[文件:${e.fileName ?? ''}]`;
|
||||
case 'json': return '[JSON卡片]';
|
||||
case 'xml': return '[XML卡片]';
|
||||
case 'reply': return `[回复:${e.replySeq}]`;
|
||||
case 'poke': return '[戳一戳]';
|
||||
case 'forward': return '[合并转发]';
|
||||
case 'markdown': return '[Markdown]';
|
||||
default: return `[${e.type}]`;
|
||||
}
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function printEvent(event: QQEventVariant): void {
|
||||
switch (event.kind) {
|
||||
case 'group_message': {
|
||||
const c = elementsToText(event.elements);
|
||||
const s = event.senderCard || event.senderNick || String(event.senderUin);
|
||||
eventLog.success('群 %d | %s(%d): %s', event.groupId, s, event.senderUin, c);
|
||||
break;
|
||||
}
|
||||
case 'friend_message':
|
||||
eventLog.info('私聊 %s(%d): %s', event.senderNick || String(event.senderUin), event.senderUin, elementsToText(event.elements));
|
||||
break;
|
||||
case 'temp_message':
|
||||
eventLog.info('临时 %d(群%d): %s', event.senderUin, event.groupId, elementsToText(event.elements));
|
||||
break;
|
||||
case 'group_recall':
|
||||
eventLog.warn('群撤回 %d | %d 被 %d 撤回', event.groupId, event.authorUin, event.operatorUin);
|
||||
break;
|
||||
case 'friend_recall':
|
||||
eventLog.warn('私聊撤回 %d 撤回了消息', event.userUin);
|
||||
break;
|
||||
case 'group_member_join':
|
||||
eventLog.info('入群 %d 加入 %d', event.userUin, event.groupId);
|
||||
break;
|
||||
case 'group_member_leave':
|
||||
eventLog.warn('退群 %d %s %d', event.userUin, event.isKick ? '被踢出' : '退出', event.groupId);
|
||||
break;
|
||||
case 'group_mute':
|
||||
eventLog.warn('禁言 %d | %d %d秒', event.groupId, event.userUin, event.duration);
|
||||
break;
|
||||
case 'group_admin':
|
||||
eventLog.info('管理 %d | %d %s管理员', event.groupId, event.userUin, event.set ? '+' : '-');
|
||||
break;
|
||||
case 'friend_poke':
|
||||
eventLog.info('戳一戳 %d -> %d', event.userUin, event.targetUin);
|
||||
break;
|
||||
case 'group_poke':
|
||||
eventLog.info('群戳 %d | %d -> %d', event.groupId, event.userUin, event.targetUin);
|
||||
break;
|
||||
case 'friend_request':
|
||||
eventLog.warn('好友请求 %d: %s', event.fromUin, event.message);
|
||||
break;
|
||||
case 'group_invite':
|
||||
eventLog.warn('群邀请 %d -> 群%d', event.fromUin, event.groupId);
|
||||
break;
|
||||
case 'group_essence':
|
||||
eventLog.info('精华 %d | %s精华', event.groupId, event.set ? '+' : '-');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// Element Builder — converts internal MessageElement[] into proto Elem objects
|
||||
// for encoding with protoEncode(SendMessageRequestSchema).
|
||||
// Port of src/bridge/src/bridge_messages.cpp build_send_elems()
|
||||
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { MessageElement } from '../events';
|
||||
import type { ProtoDecoded } from '../../protobuf/decode';
|
||||
import { protoEncode } from '../../protobuf/decode';
|
||||
import {
|
||||
ElemSchema,
|
||||
} from '../proto/element';
|
||||
import {
|
||||
MentionExtraSendSchema,
|
||||
MarkdownDataSchema,
|
||||
} from '../proto/action';
|
||||
import { uploadImageMsgInfo } from '../highway/image-upload';
|
||||
|
||||
type ProtoElem = Partial<ProtoDecoded<typeof ElemSchema>>;
|
||||
|
||||
export interface SendContext {
|
||||
bridge: Bridge;
|
||||
groupId?: number;
|
||||
userUid?: string;
|
||||
}
|
||||
|
||||
function makeTextElem(text: string): ProtoElem {
|
||||
return {
|
||||
text: { str: text } as any,
|
||||
};
|
||||
}
|
||||
|
||||
function makeFaceElem(faceId: number): ProtoElem {
|
||||
return {
|
||||
face: { index: faceId } as any,
|
||||
};
|
||||
}
|
||||
|
||||
function makeMentionElem(element: MessageElement): ProtoElem {
|
||||
const mentionAll = element.uid === 'all' || element.targetUin === 0;
|
||||
|
||||
const extra = protoEncode({
|
||||
type: mentionAll ? 1 : 2,
|
||||
uin: mentionAll ? 0 : (element.targetUin ?? 0),
|
||||
field5: 0,
|
||||
uid: mentionAll ? 'all' : (element.uid ?? ''),
|
||||
}, MentionExtraSendSchema);
|
||||
|
||||
return {
|
||||
text: {
|
||||
str: element.text || (mentionAll ? '@全体成员 ' : `@${element.targetUin} `),
|
||||
pbReserve: extra,
|
||||
} as any,
|
||||
};
|
||||
}
|
||||
|
||||
function makeReplyElem(element: MessageElement): ProtoElem {
|
||||
return {
|
||||
srcMsg: {
|
||||
origSeqs: [element.replySeq! & 0xFFFFFFFF],
|
||||
} as any,
|
||||
};
|
||||
}
|
||||
|
||||
function makeJsonElem(element: MessageElement): ProtoElem {
|
||||
const content = element.text ?? '';
|
||||
const payload = new Uint8Array(content.length + 1);
|
||||
payload[0] = 0x00;
|
||||
const encoded = new TextEncoder().encode(content);
|
||||
payload.set(encoded, 1);
|
||||
|
||||
return {
|
||||
richMsg: {
|
||||
serviceId: 1,
|
||||
template1: payload,
|
||||
} as any,
|
||||
};
|
||||
}
|
||||
|
||||
function makeXmlElem(element: MessageElement): ProtoElem {
|
||||
const content = element.text ?? '';
|
||||
const payload = new Uint8Array(content.length + 1);
|
||||
payload[0] = 0x00;
|
||||
const encoded = new TextEncoder().encode(content);
|
||||
payload.set(encoded, 1);
|
||||
|
||||
return {
|
||||
richMsg: {
|
||||
serviceId: element.subType === 0 ? 35 : (element.subType ?? 35),
|
||||
template1: payload,
|
||||
} as any,
|
||||
};
|
||||
}
|
||||
|
||||
function makeMarkdownElem(element: MessageElement): ProtoElem {
|
||||
const data = protoEncode({ content: element.text ?? '' }, MarkdownDataSchema);
|
||||
|
||||
return {
|
||||
commonElem: {
|
||||
serviceType: 45,
|
||||
pbElem: data,
|
||||
businessType: 1,
|
||||
} as any,
|
||||
};
|
||||
}
|
||||
|
||||
function makeForwardElem(element: MessageElement): ProtoElem {
|
||||
const resId = (element.resId ?? '').trim();
|
||||
if (!resId) {
|
||||
throw new Error('forward resId is required');
|
||||
}
|
||||
|
||||
const xml = `<?xml version="1.0" encoding="utf-8"?><msg templateID="1" action="viewMultiMsg" serviceID="35" brief="[聊天记录]" m_resid="${resId}" m_fileName="${resId}" actionData="${resId}" tSum="2" sourceMsgId="0" flag="3" adverSign="0" multiMsgFlag="0"><item layout="1"><title size="34" color="#000000">聊天记录</title><title size="26" color="#777777">查看转发消息</title><summary size="26" color="#808080">查看转发消息</summary></item><source name="" icon="" action="" appid="-1"/></msg>`;
|
||||
const encodedXml = new TextEncoder().encode(xml);
|
||||
const payload = new Uint8Array(encodedXml.length + 1);
|
||||
payload[0] = 0x00;
|
||||
payload.set(encodedXml, 1);
|
||||
|
||||
return {
|
||||
richMsg: {
|
||||
serviceId: 35,
|
||||
template1: payload,
|
||||
} as any,
|
||||
};
|
||||
}
|
||||
|
||||
async function makeImageElem(ctx: SendContext, element: MessageElement): Promise<ProtoElem> {
|
||||
const isGroup = ctx.groupId !== undefined;
|
||||
const targetIdOrUid = isGroup ? ctx.groupId! : (ctx.userUid ?? '');
|
||||
if (!isGroup && !targetIdOrUid) {
|
||||
throw new Error('private image target uid is missing');
|
||||
}
|
||||
|
||||
const msgInfo = await uploadImageMsgInfo(ctx.bridge, isGroup, targetIdOrUid, element);
|
||||
|
||||
return {
|
||||
commonElem: {
|
||||
serviceType: 48,
|
||||
pbElem: msgInfo,
|
||||
businessType: isGroup ? 20 : 10,
|
||||
} as any,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Build proto Elem objects from an array of MessageElements.
|
||||
* Supports: text, face, at, reply, json, xml, markdown, image.
|
||||
* Image elements trigger highway upload via the SendContext.
|
||||
*/
|
||||
export async function buildSendElems(elements: MessageElement[], ctx?: SendContext): Promise<ProtoElem[]> {
|
||||
const result: ProtoElem[] = [];
|
||||
|
||||
for (const elem of elements) {
|
||||
switch (elem.type) {
|
||||
case 'text':
|
||||
if (elem.text) result.push(makeTextElem(elem.text));
|
||||
break;
|
||||
|
||||
case 'face':
|
||||
if (elem.faceId !== undefined) result.push(makeFaceElem(elem.faceId));
|
||||
break;
|
||||
|
||||
case 'at':
|
||||
result.push(makeMentionElem(elem));
|
||||
break;
|
||||
|
||||
case 'reply':
|
||||
if (elem.replySeq) result.push(makeReplyElem(elem));
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
if (elem.text) result.push(makeJsonElem(elem));
|
||||
break;
|
||||
|
||||
case 'xml':
|
||||
if (elem.text) result.push(makeXmlElem(elem));
|
||||
break;
|
||||
|
||||
case 'markdown':
|
||||
if (elem.text) result.push(makeMarkdownElem(elem));
|
||||
break;
|
||||
|
||||
case 'image':
|
||||
if (ctx) {
|
||||
result.push(await makeImageElem(ctx, elem));
|
||||
} else {
|
||||
console.warn('[ElemBuilder] image send requires SendContext');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'forward':
|
||||
if (elem.resId) result.push(makeForwardElem(elem));
|
||||
break;
|
||||
|
||||
case 'record':
|
||||
case 'video':
|
||||
console.warn(`[ElemBuilder] ${elem.type} send not yet implemented`);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn(`[ElemBuilder] unsupported element type for send: ${elem.type}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
// Bridge event types and MessageElement.
|
||||
// Port of src/bridge/include/bridge/events.h
|
||||
|
||||
export interface MessageElement {
|
||||
type: string; // 'text'|'at'|'face'|'mface'|'image'|'video'|'record'|'file'|'json'|'xml'|'reply'|'poke'|'forward'
|
||||
text?: string;
|
||||
faceId?: number;
|
||||
targetUin?: number;
|
||||
uid?: string;
|
||||
imageUrl?: string;
|
||||
fileId?: string;
|
||||
thumbFileId?: string;
|
||||
fileName?: string;
|
||||
fileSize?: number;
|
||||
replySeq?: number;
|
||||
url?: string;
|
||||
subType?: number;
|
||||
duration?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
summary?: string;
|
||||
flash?: boolean;
|
||||
resId?: string;
|
||||
fileHash?: string;
|
||||
mediaNode?: {
|
||||
fileUuid?: string;
|
||||
storeId?: number;
|
||||
uploadTime?: number;
|
||||
ttl?: number;
|
||||
subType?: number;
|
||||
info?: {
|
||||
fileSize?: number;
|
||||
fileHash?: string;
|
||||
fileSha1?: string;
|
||||
fileName?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
time?: number;
|
||||
original?: number;
|
||||
type?: {
|
||||
type?: number;
|
||||
picFormat?: number;
|
||||
videoFormat?: number;
|
||||
voiceFormat?: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface ForwardNodePayload {
|
||||
userUin: number;
|
||||
nickname: string;
|
||||
elements: MessageElement[];
|
||||
}
|
||||
|
||||
export interface QQEvent {
|
||||
time: number;
|
||||
selfUin: number;
|
||||
}
|
||||
|
||||
export interface FriendMessage extends QQEvent {
|
||||
kind: 'friend_message';
|
||||
senderUin: number;
|
||||
senderNick: string;
|
||||
msgSeq: number;
|
||||
msgId: number;
|
||||
elements: MessageElement[];
|
||||
}
|
||||
|
||||
export interface GroupMessage extends QQEvent {
|
||||
kind: 'group_message';
|
||||
groupId: number;
|
||||
senderUin: number;
|
||||
senderNick: string;
|
||||
senderCard: string;
|
||||
senderRole: string;
|
||||
msgSeq: number;
|
||||
msgId: number;
|
||||
elements: MessageElement[];
|
||||
}
|
||||
|
||||
export interface TempMessage extends QQEvent {
|
||||
kind: 'temp_message';
|
||||
senderUin: number;
|
||||
groupId: number;
|
||||
senderNick: string;
|
||||
msgSeq: number;
|
||||
elements: MessageElement[];
|
||||
}
|
||||
|
||||
export interface GroupMemberJoin extends QQEvent {
|
||||
kind: 'group_member_join';
|
||||
groupId: number;
|
||||
userUin: number;
|
||||
operatorUin: number;
|
||||
}
|
||||
|
||||
export interface GroupMemberLeave extends QQEvent {
|
||||
kind: 'group_member_leave';
|
||||
groupId: number;
|
||||
userUin: number;
|
||||
operatorUin: number;
|
||||
isKick: boolean;
|
||||
}
|
||||
|
||||
export interface GroupMuteEvent extends QQEvent {
|
||||
kind: 'group_mute';
|
||||
groupId: number;
|
||||
userUin: number;
|
||||
operatorUin: number;
|
||||
duration: number;
|
||||
}
|
||||
|
||||
export interface GroupAdminEvent extends QQEvent {
|
||||
kind: 'group_admin';
|
||||
groupId: number;
|
||||
userUin: number;
|
||||
set: boolean;
|
||||
}
|
||||
|
||||
export interface FriendRecall extends QQEvent {
|
||||
kind: 'friend_recall';
|
||||
userUin: number;
|
||||
msgSeq: number;
|
||||
}
|
||||
|
||||
export interface GroupRecallEvent extends QQEvent {
|
||||
kind: 'group_recall';
|
||||
groupId: number;
|
||||
operatorUin: number;
|
||||
authorUin: number;
|
||||
msgSeq: number;
|
||||
}
|
||||
|
||||
export interface FriendRequestEvent extends QQEvent {
|
||||
kind: 'friend_request';
|
||||
fromUin: number;
|
||||
message: string;
|
||||
flag: string;
|
||||
}
|
||||
|
||||
export interface GroupInviteEvent extends QQEvent {
|
||||
kind: 'group_invite';
|
||||
groupId: number;
|
||||
fromUin: number;
|
||||
subType: string;
|
||||
message: string;
|
||||
flag: string;
|
||||
}
|
||||
|
||||
export interface FriendPokeEvent extends QQEvent {
|
||||
kind: 'friend_poke';
|
||||
userUin: number;
|
||||
targetUin: number;
|
||||
action: string;
|
||||
suffix: string;
|
||||
actionImgUrl: string;
|
||||
}
|
||||
|
||||
export interface GroupPokeEvent extends QQEvent {
|
||||
kind: 'group_poke';
|
||||
groupId: number;
|
||||
userUin: number;
|
||||
targetUin: number;
|
||||
action: string;
|
||||
suffix: string;
|
||||
actionImgUrl: string;
|
||||
}
|
||||
|
||||
export interface GroupEssenceEvent extends QQEvent {
|
||||
kind: 'group_essence';
|
||||
groupId: number;
|
||||
senderUin: number;
|
||||
operatorUin: number;
|
||||
msgSeq: number;
|
||||
random: number;
|
||||
set: boolean;
|
||||
}
|
||||
|
||||
export interface GroupFileUploadEvent extends QQEvent {
|
||||
kind: 'group_file_upload';
|
||||
groupId: number;
|
||||
userUin: number;
|
||||
fileId: string;
|
||||
fileName: string;
|
||||
fileSize: number;
|
||||
busId: number;
|
||||
}
|
||||
|
||||
export interface FriendAddEvent extends QQEvent {
|
||||
kind: 'friend_add';
|
||||
userUin: number;
|
||||
}
|
||||
|
||||
export type QQEventVariant =
|
||||
| FriendMessage
|
||||
| GroupMessage
|
||||
| TempMessage
|
||||
| GroupMemberJoin
|
||||
| GroupMemberLeave
|
||||
| GroupMuteEvent
|
||||
| GroupAdminEvent
|
||||
| FriendRecall
|
||||
| GroupRecallEvent
|
||||
| FriendRequestEvent
|
||||
| GroupInviteEvent
|
||||
| FriendPokeEvent
|
||||
| GroupPokeEvent
|
||||
| GroupEssenceEvent
|
||||
| GroupFileUploadEvent
|
||||
| FriendAddEvent;
|
||||
@@ -0,0 +1,857 @@
|
||||
// MsgPush packet handler — parses trpc.msg.olpush.OlPushService.MsgPush
|
||||
// into bridge events. Port of src/bridge/src/handlers/msg_push_handler.h/.cpp
|
||||
|
||||
import { inflateSync } from 'zlib';
|
||||
import { protoDecode } from '../../protobuf/decode';
|
||||
import { WireMessage } from '../../protobuf/wire';
|
||||
import { PushMsgSchema } from '../proto/message';
|
||||
import {
|
||||
MentionExtraSchema, QFaceExtraSchema, QSmallFaceExtraSchema,
|
||||
MsgInfoSchema, GroupFileExtraSchema, NotOnlineImageSchema,
|
||||
} from '../proto/element';
|
||||
import { FileExtraSchema } from '../proto/message';
|
||||
import {
|
||||
GroupChangeSchema, GroupAdminSchema, GroupJoinSchema,
|
||||
GroupInvitationSchema, GroupInviteSchema,
|
||||
FriendRequestSchema, FriendRecallSchema,
|
||||
GroupMuteSchema, NotifyMessageBodySchema,
|
||||
GeneralGrayTipInfoSchema, OperatorInfoSchema,
|
||||
} from '../proto/notify';
|
||||
import type { QQInfo } from '../qq-info';
|
||||
import type { PacketInfo } from '../../protocol/types';
|
||||
import type {
|
||||
QQEventVariant, MessageElement,
|
||||
FriendMessage, GroupMessage, TempMessage,
|
||||
GroupMemberJoin, GroupMemberLeave, GroupMuteEvent, GroupAdminEvent,
|
||||
FriendRecall, GroupRecallEvent, FriendRequestEvent, GroupInviteEvent,
|
||||
FriendPokeEvent, GroupPokeEvent, GroupEssenceEvent,
|
||||
} from '../events';
|
||||
import type { ProtoDecoded, ProtoSchema } from '../../protobuf/decode';
|
||||
|
||||
// --- PkgType enum ---
|
||||
const enum PkgType {
|
||||
ForwardFakePrivateMessage = 9,
|
||||
PrivateMessage = 166,
|
||||
GroupMessage = 82,
|
||||
TempMessage = 141,
|
||||
Event0x210 = 528,
|
||||
Event0x2DC = 732,
|
||||
PrivateRecordMessage = 208,
|
||||
PrivateFileMessage = 529,
|
||||
GroupRequestInvitationNotice = 525,
|
||||
GroupRequestJoinNotice = 84,
|
||||
GroupInviteNotice = 87,
|
||||
GroupAdminChangedNotice = 44,
|
||||
GroupMemberIncreaseNotice = 33,
|
||||
GroupMemberDecreaseNotice = 34,
|
||||
}
|
||||
|
||||
const enum Event0x2DCSubType {
|
||||
GroupMuteNotice = 12,
|
||||
GroupRecallNotice = 17,
|
||||
GroupGreyTipNotice = 20,
|
||||
GroupEssenceNotice = 21,
|
||||
}
|
||||
|
||||
const enum Event0x210SubType {
|
||||
FriendRequestNotice = 35,
|
||||
FriendRecallNotice = 138,
|
||||
FriendPokeNotice = 290,
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
function makeImageUrl(origUrl: string): string {
|
||||
if (!origUrl) return '';
|
||||
if (origUrl.includes('rkey')) return 'https://multimedia.nt.qq.com.cn' + origUrl;
|
||||
return 'http://gchat.qpic.cn' + origUrl;
|
||||
}
|
||||
|
||||
const HEX_CHARS = '0123456789ABCDEF';
|
||||
function bytesToHex(data: Uint8Array): string {
|
||||
let r = '';
|
||||
for (const b of data) { r += HEX_CHARS[b >> 4]; r += HEX_CHARS[b & 0x0f]; }
|
||||
return r;
|
||||
}
|
||||
|
||||
function decompressData(data: Uint8Array): string {
|
||||
if (!data || data.length === 0) return '';
|
||||
if (data[0] === 0x01 && data.length > 1) {
|
||||
try {
|
||||
const inflated = inflateSync(Buffer.from(data.subarray(1)));
|
||||
return inflated.toString('utf8');
|
||||
} catch { return ''; }
|
||||
}
|
||||
if (data[0] === 0x00 && data.length > 1) {
|
||||
return Buffer.from(data.subarray(1)).toString('utf8');
|
||||
}
|
||||
return Buffer.from(data).toString('utf8');
|
||||
}
|
||||
|
||||
function isNumericUin(value: string): boolean {
|
||||
return value.length > 0 && /^\d+$/.test(value);
|
||||
}
|
||||
|
||||
function parseU64OrZero(value: string): number {
|
||||
if (!value) return 0;
|
||||
const n = parseInt(value, 10);
|
||||
return isNaN(n) ? 0 : n;
|
||||
}
|
||||
|
||||
function resolveUidToUin(qqInfo: QQInfo, groupId: number, uid: string, fallback = 0): number {
|
||||
if (!uid) return fallback;
|
||||
if (isNumericUin(uid)) {
|
||||
const n = parseInt(uid, 10);
|
||||
if (!isNaN(n)) return n;
|
||||
}
|
||||
if (groupId) {
|
||||
const uin = qqInfo.resolveGroupMemberUid(groupId, uid);
|
||||
if (uin !== null) return uin;
|
||||
}
|
||||
const uin = qqInfo.resolveUid(uid);
|
||||
if (uin !== null) return uin;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function decodeOperatorUid(bytes: Uint8Array): string {
|
||||
if (!bytes || bytes.length === 0) return '';
|
||||
const info = protoDecode(bytes, OperatorInfoSchema);
|
||||
if (info?.operatorField?.uid) return info.operatorField.uid;
|
||||
return Buffer.from(bytes).toString('utf8');
|
||||
}
|
||||
|
||||
function buildTemplateMap(params: Array<{name?: string; value?: string}>): Map<string, string> {
|
||||
const map = new Map<string, string>();
|
||||
for (const p of params) {
|
||||
if (p.name !== undefined) map.set(p.name, p.value ?? '');
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
function findTemplateValue(map: Map<string, string>, ...keys: string[]): string {
|
||||
for (const k of keys) {
|
||||
const v = map.get(k);
|
||||
if (v) return v;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function unwrapGroupNotifyPayload(content: Uint8Array): Uint8Array | null {
|
||||
if (content.length <= 7) return null;
|
||||
const lenBe = (content[5] << 8) | content[6];
|
||||
const lenLe = content[5] | (content[6] << 8);
|
||||
if (7 + lenBe <= content.length) return content.subarray(7, 7 + lenBe);
|
||||
if (7 + lenLe <= content.length) return content.subarray(7, 7 + lenLe);
|
||||
return content.subarray(7);
|
||||
}
|
||||
|
||||
// --- Element conversion ---
|
||||
|
||||
type ElemDecoded = ProtoDecoded<typeof import('../proto/element').ElemSchema>;
|
||||
|
||||
function convertElements(elems: ElemDecoded[]): MessageElement[] {
|
||||
const result: MessageElement[] = [];
|
||||
let skipNext = false;
|
||||
|
||||
for (const elem of elems) {
|
||||
if (skipNext) { skipNext = false; continue; }
|
||||
|
||||
// Reply / quote
|
||||
if (elem.srcMsg?.origSeqs && elem.srcMsg.origSeqs.length > 0) {
|
||||
result.push({ type: 'reply', replySeq: elem.srcMsg.origSeqs[0] });
|
||||
}
|
||||
|
||||
// Text (with possible @ detection)
|
||||
if (elem.text) {
|
||||
const t = elem.text;
|
||||
let mention: ProtoDecoded<typeof MentionExtraSchema> | null = null;
|
||||
if (t.pbReserve && t.pbReserve.length > 0) {
|
||||
mention = protoDecode(t.pbReserve, MentionExtraSchema);
|
||||
}
|
||||
const hasAttr6 = t.attr6Buf && t.attr6Buf.length > 11;
|
||||
const hasMention = mention && (mention.type === 1 || mention.type === 2);
|
||||
|
||||
if (hasAttr6 || hasMention) {
|
||||
const me: MessageElement = { type: 'at', text: t.str ?? '' };
|
||||
if (hasAttr6) {
|
||||
const buf = t.attr6Buf!;
|
||||
me.targetUin = ((buf[7] << 24) | (buf[8] << 16) | (buf[9] << 8) | buf[10]) >>> 0;
|
||||
}
|
||||
if (hasMention && mention) {
|
||||
me.uid = mention.uid ?? '';
|
||||
if (!me.targetUin) me.targetUin = mention.uin ?? 0;
|
||||
}
|
||||
result.push(me);
|
||||
} else {
|
||||
const text = t.str ?? '';
|
||||
if (text) result.push({ type: 'text', text });
|
||||
}
|
||||
}
|
||||
|
||||
// Face
|
||||
if (elem.face) {
|
||||
result.push({ type: 'face', faceId: elem.face.index ?? 0 });
|
||||
}
|
||||
|
||||
// MarketFace
|
||||
if (elem.marketFace) {
|
||||
result.push({
|
||||
type: 'mface',
|
||||
text: elem.marketFace.faceName ?? '',
|
||||
faceId: elem.marketFace.tabId ?? 0,
|
||||
subType: elem.marketFace.subType ?? 0,
|
||||
});
|
||||
}
|
||||
|
||||
// NotOnlineImage (C2C image)
|
||||
if (elem.notOnlineImage) {
|
||||
const img = elem.notOnlineImage;
|
||||
if (img.picMd5 && img.picMd5.length > 0) {
|
||||
const urlPath = img.origUrl || img.bigUrl || '';
|
||||
result.push({
|
||||
type: 'image',
|
||||
imageUrl: makeImageUrl(urlPath),
|
||||
fileId: img.filePath ?? '',
|
||||
fileSize: img.fileLen ?? 0,
|
||||
width: img.picWidth ?? 0,
|
||||
height: img.picHeight ?? 0,
|
||||
subType: img.pbRes?.subType ?? 0,
|
||||
summary: img.pbRes?.summary ?? '[image]',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// CustomFace (group image)
|
||||
if (elem.customFace) {
|
||||
const img = elem.customFace;
|
||||
if (img.md5 && img.md5.length > 0) {
|
||||
result.push({
|
||||
type: 'image',
|
||||
imageUrl: makeImageUrl(img.origUrl ?? ''),
|
||||
fileId: img.filePath ?? '',
|
||||
fileSize: img.size ?? 0,
|
||||
width: img.width ?? 0,
|
||||
height: img.height ?? 0,
|
||||
subType: img.pbRes?.subType ?? 0,
|
||||
summary: img.pbRes?.summary ?? '[image]',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// VideoFile
|
||||
if (elem.videoFile) {
|
||||
const v = elem.videoFile;
|
||||
result.push({
|
||||
type: 'video',
|
||||
fileId: v.fileUuid ?? '',
|
||||
fileName: v.fileName ?? '',
|
||||
fileSize: v.fileSize ?? 0,
|
||||
duration: v.fileTime ?? 0,
|
||||
fileHash: v.fileMd5 && v.fileMd5.length > 0 ? bytesToHex(v.fileMd5) : '',
|
||||
mediaNode: {
|
||||
fileUuid: v.fileUuid ?? '',
|
||||
info: {
|
||||
fileSize: v.fileSize ?? 0,
|
||||
fileHash: v.fileMd5 && v.fileMd5.length > 0 ? bytesToHex(v.fileMd5) : '',
|
||||
fileName: v.fileName ?? '',
|
||||
width: v.fileWidth ?? 0,
|
||||
height: v.fileHeight ?? 0,
|
||||
time: v.fileTime ?? 0,
|
||||
type: {
|
||||
type: 2,
|
||||
videoFormat: v.fileFormat ?? 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// GroupFile
|
||||
if (elem.groupFile) {
|
||||
const f = elem.groupFile;
|
||||
result.push({
|
||||
type: 'file',
|
||||
fileId: f.fileId ?? '',
|
||||
fileName: f.filename ?? '',
|
||||
fileSize: f.fileSize !== undefined ? Number(f.fileSize) : 0,
|
||||
});
|
||||
}
|
||||
|
||||
// TransElem type=24 (group file via transport)
|
||||
if (elem.transElem) {
|
||||
const te = elem.transElem;
|
||||
if ((te.elemType ?? 0) === 24 && te.elemValue && te.elemValue.length > 3) {
|
||||
const val = te.elemValue;
|
||||
const len = (val[1] << 8) | val[2];
|
||||
if (val.length >= 3 + len) {
|
||||
const extra = protoDecode(val.subarray(3, 3 + len), GroupFileExtraSchema);
|
||||
if (extra?.inner?.info) {
|
||||
const info = extra.inner.info;
|
||||
result.push({
|
||||
type: 'file',
|
||||
fileName: info.fileName ?? '',
|
||||
fileSize: info.fileSize !== undefined ? Number(info.fileSize) : 0,
|
||||
fileId: info.fileId ?? '',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RichMsg
|
||||
if (elem.richMsg) {
|
||||
const rm = elem.richMsg;
|
||||
if (rm.template1 && rm.template1.length > 0) {
|
||||
const content = decompressData(rm.template1);
|
||||
if (content) {
|
||||
const svcId = rm.serviceId ?? 0;
|
||||
if (svcId === 35) {
|
||||
const pos = content.indexOf('m_resid="');
|
||||
if (pos !== -1) {
|
||||
const start = pos + 9;
|
||||
const end = content.indexOf('"', start);
|
||||
if (end !== -1) {
|
||||
result.push({ type: 'forward', resId: content.substring(start, end) });
|
||||
continue;
|
||||
}
|
||||
}
|
||||
result.push({ type: 'xml', text: content, subType: svcId });
|
||||
} else if (svcId === 1) {
|
||||
result.push({ type: 'json', text: content });
|
||||
} else {
|
||||
result.push({ type: 'xml', text: content, subType: svcId });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// LightApp
|
||||
if (elem.lightApp) {
|
||||
const la = elem.lightApp;
|
||||
if (la.data && la.data.length > 0) {
|
||||
const content = decompressData(la.data);
|
||||
if (content) result.push({ type: 'json', text: content });
|
||||
}
|
||||
}
|
||||
|
||||
// CommonElem
|
||||
if (elem.commonElem) {
|
||||
const ce = elem.commonElem;
|
||||
const svcType = ce.serviceType ?? 0;
|
||||
const bizType = ce.businessType ?? 0;
|
||||
|
||||
if (svcType === 2) {
|
||||
// Poke
|
||||
result.push({ type: 'poke', subType: bizType });
|
||||
} else if (svcType === 3 && ce.pbElem && ce.pbElem.length > 1) {
|
||||
// Flash image
|
||||
const pb = ce.pbElem;
|
||||
let pos = 1;
|
||||
let length = 0, shift = 0;
|
||||
while (pos < pb.length) {
|
||||
const b = pb[pos++];
|
||||
length |= (b & 0x7f) << shift;
|
||||
shift += 7;
|
||||
if ((b & 0x80) === 0) break;
|
||||
}
|
||||
if (pos + length <= pb.length) {
|
||||
const img = protoDecode(pb.subarray(pos, pos + length), NotOnlineImageSchema);
|
||||
if (img) {
|
||||
const me: MessageElement = {
|
||||
type: 'image', fileId: img.filePath ?? '',
|
||||
fileSize: img.fileLen ?? 0, width: img.picWidth ?? 0,
|
||||
height: img.picHeight ?? 0, flash: true, summary: '[flash image]',
|
||||
};
|
||||
if (img.pbRes) me.subType = img.pbRes.subType ?? 0;
|
||||
if (img.picMd5 && img.picMd5.length > 0) {
|
||||
me.imageUrl = 'http://gchat.qpic.cn/gchatpic_new/0/0-0-' + bytesToHex(img.picMd5) + '/0';
|
||||
}
|
||||
result.push(me);
|
||||
}
|
||||
}
|
||||
skipNext = true;
|
||||
} else if (ce.pbElem && (svcType === 48 || bizType === 10 || bizType === 20 || bizType === 11 || bizType === 21 || bizType === 12 || bizType === 22)) {
|
||||
// NTQQ new protocol image/record/video
|
||||
const info = protoDecode(ce.pbElem, MsgInfoSchema);
|
||||
if (info?.msgInfoBody && info.msgInfoBody.length > 0) {
|
||||
const body = info.msgInfoBody[0];
|
||||
if (body.index?.info) {
|
||||
const idx = body.index;
|
||||
const fi = idx.info!;
|
||||
|
||||
if (bizType === 10 || bizType === 20) {
|
||||
// Image
|
||||
let url = '';
|
||||
if (body.picture) {
|
||||
const domain = body.picture.domain ?? 'multimedia.nt.qq.com.cn';
|
||||
const path = body.picture.urlPath ?? '';
|
||||
if (path) {
|
||||
url = 'https://' + domain + path;
|
||||
if (body.picture.ext?.originalParameter) {
|
||||
url += body.picture.ext.originalParameter;
|
||||
}
|
||||
}
|
||||
}
|
||||
const me: MessageElement = {
|
||||
type: 'image', fileId: fi.fileName ?? '',
|
||||
fileSize: fi.fileSize ?? 0, width: fi.width ?? 0,
|
||||
height: fi.height ?? 0, imageUrl: url,
|
||||
};
|
||||
if (info.extBizInfo?.pic) {
|
||||
me.subType = info.extBizInfo.pic.bizType ?? 0;
|
||||
me.summary = info.extBizInfo.pic.textSummary || '[image]';
|
||||
}
|
||||
result.push(me);
|
||||
} else if (bizType === 12 || bizType === 22) {
|
||||
// Record
|
||||
result.push({
|
||||
type: 'record', fileName: fi.fileName ?? '',
|
||||
fileId: idx.fileUuid ?? '', duration: fi.time ?? 0,
|
||||
fileHash: fi.fileHash ?? '',
|
||||
mediaNode: {
|
||||
fileUuid: idx.fileUuid,
|
||||
storeId: idx.storeId,
|
||||
uploadTime: idx.uploadTime,
|
||||
ttl: idx.ttl,
|
||||
subType: idx.subType,
|
||||
info: {
|
||||
fileSize: fi.fileSize,
|
||||
fileHash: fi.fileHash,
|
||||
fileSha1: fi.fileSha1,
|
||||
fileName: fi.fileName,
|
||||
width: fi.width,
|
||||
height: fi.height,
|
||||
time: fi.time,
|
||||
original: fi.original,
|
||||
type: {
|
||||
type: fi.type?.type,
|
||||
picFormat: fi.type?.picFormat,
|
||||
videoFormat: fi.type?.videoFormat,
|
||||
voiceFormat: fi.type?.voiceFormat,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else if (bizType === 11 || bizType === 21) {
|
||||
// Video
|
||||
result.push({
|
||||
type: 'video', fileName: fi.fileName ?? '',
|
||||
fileId: idx.fileUuid ?? '', fileSize: fi.fileSize ?? 0,
|
||||
duration: fi.time ?? 0,
|
||||
fileHash: fi.fileHash ?? '',
|
||||
mediaNode: {
|
||||
fileUuid: idx.fileUuid,
|
||||
storeId: idx.storeId,
|
||||
uploadTime: idx.uploadTime,
|
||||
ttl: idx.ttl,
|
||||
subType: idx.subType,
|
||||
info: {
|
||||
fileSize: fi.fileSize,
|
||||
fileHash: fi.fileHash,
|
||||
fileSha1: fi.fileSha1,
|
||||
fileName: fi.fileName,
|
||||
width: fi.width,
|
||||
height: fi.height,
|
||||
time: fi.time,
|
||||
original: fi.original,
|
||||
type: {
|
||||
type: fi.type?.type,
|
||||
picFormat: fi.type?.picFormat,
|
||||
videoFormat: fi.type?.videoFormat,
|
||||
voiceFormat: fi.type?.voiceFormat,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (svcType === 33 && ce.pbElem) {
|
||||
// Small face
|
||||
const extra = protoDecode(ce.pbElem, QSmallFaceExtraSchema);
|
||||
if (extra) result.push({ type: 'face', faceId: extra.faceId ?? 0 });
|
||||
} else if (svcType === 37 && ce.pbElem) {
|
||||
// Big face
|
||||
const extra = protoDecode(ce.pbElem, QFaceExtraSchema);
|
||||
if (extra?.qsid !== undefined) result.push({ type: 'face', faceId: extra.qsid });
|
||||
skipNext = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function extractRichtextExtras(
|
||||
rt: ProtoDecoded<typeof import('../proto/message').RichTextSchema>,
|
||||
elements: MessageElement[],
|
||||
isGroup = false
|
||||
): void {
|
||||
// Ptt (voice)
|
||||
if (rt.ptt) {
|
||||
const p = rt.ptt;
|
||||
const me: MessageElement = {
|
||||
type: 'record', fileName: p.fileName ?? '',
|
||||
fileSize: p.fileSize ?? 0, duration: p.time ?? 0,
|
||||
fileHash: p.fileMd5 && p.fileMd5.length > 0 ? bytesToHex(p.fileMd5) : '',
|
||||
};
|
||||
if (isGroup && (p.fileId ?? 0n) !== 0n) {
|
||||
me.fileId = p.groupFileKey ?? '';
|
||||
} else {
|
||||
if (p.fileUuid && p.fileUuid.length > 0) {
|
||||
me.fileId = Buffer.from(p.fileUuid).toString('utf8');
|
||||
}
|
||||
}
|
||||
me.mediaNode = {
|
||||
fileUuid: me.fileId ?? '',
|
||||
info: {
|
||||
fileSize: p.fileSize ?? 0,
|
||||
fileHash: p.fileMd5 && p.fileMd5.length > 0 ? bytesToHex(p.fileMd5) : '',
|
||||
fileName: p.fileName ?? '',
|
||||
time: p.time ?? 0,
|
||||
type: {
|
||||
type: 3,
|
||||
voiceFormat: p.format ?? 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
elements.push(me);
|
||||
}
|
||||
|
||||
// NotOnlineFile (C2C file)
|
||||
if (rt.notOnlineFile) {
|
||||
const f = rt.notOnlineFile;
|
||||
elements.push({
|
||||
type: 'file', fileId: f.fileUuid ?? '',
|
||||
fileName: f.fileName ?? '',
|
||||
fileSize: f.fileSize !== undefined ? Number(f.fileSize) : 0,
|
||||
fileHash: f.fileHash ?? '',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function extractMsgContent(msgContent: Uint8Array, elements: MessageElement[]): void {
|
||||
const extra = protoDecode(msgContent, FileExtraSchema);
|
||||
if (!extra?.file) return;
|
||||
const f = extra.file;
|
||||
if (f.fileSize !== undefined && f.fileName && f.fileMd5 && f.fileUuid && f.fileHash) {
|
||||
elements.push({
|
||||
type: 'file', fileName: f.fileName, fileId: f.fileUuid,
|
||||
fileSize: f.fileSize !== undefined ? Number(f.fileSize) : 0,
|
||||
fileHash: f.fileHash,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// --- Main handler ---
|
||||
|
||||
export const MSG_PUSH_CMD = 'trpc.msg.olpush.OlPushService.MsgPush';
|
||||
|
||||
export function parseMsgPush(pkt: PacketInfo, qqInfo: QQInfo): QQEventVariant[] {
|
||||
if (pkt.body.length === 0) return [];
|
||||
|
||||
const push = protoDecode(Buffer.from(pkt.body), PushMsgSchema);
|
||||
if (!push?.message) return [];
|
||||
|
||||
const msg = push.message;
|
||||
if (!msg.contentHead) return [];
|
||||
|
||||
const head = msg.contentHead;
|
||||
const msgType = head.msgType ?? 0;
|
||||
const subType = head.subType ?? 0;
|
||||
const sequence = head.sequence ?? 0;
|
||||
const timestamp = head.timestamp ?? 0;
|
||||
const msgId = head.msgId ?? 0;
|
||||
|
||||
let fromUin = 0;
|
||||
let fromUid = '';
|
||||
if (msg.responseHead) {
|
||||
fromUin = msg.responseHead.fromUin ?? 0;
|
||||
fromUid = msg.responseHead.fromUid ?? '';
|
||||
}
|
||||
|
||||
let selfUin = 0;
|
||||
if (pkt.uin) {
|
||||
const n = parseInt(pkt.uin, 10);
|
||||
if (!isNaN(n)) selfUin = n;
|
||||
}
|
||||
|
||||
const content = (msg.body?.msgContent) ? msg.body.msgContent : new Uint8Array(0);
|
||||
|
||||
const buildElements = (isGroup: boolean): MessageElement[] => {
|
||||
const elements: MessageElement[] = [];
|
||||
if (msg.body?.richText) {
|
||||
const rt = msg.body.richText;
|
||||
if (rt.elems) elements.push(...convertElements(rt.elems as ElemDecoded[]));
|
||||
extractRichtextExtras(rt, elements, isGroup);
|
||||
}
|
||||
if (msg.body?.msgContent && msg.body.msgContent.length > 0) {
|
||||
extractMsgContent(msg.body.msgContent, elements);
|
||||
}
|
||||
return elements;
|
||||
};
|
||||
|
||||
// --- Switch on msgType ---
|
||||
|
||||
switch (msgType as PkgType) {
|
||||
case PkgType.GroupMemberIncreaseNotice: {
|
||||
const change = protoDecode(content, GroupChangeSchema);
|
||||
if (!change) return [];
|
||||
const ev: GroupMemberJoin = {
|
||||
kind: 'group_member_join', time: timestamp, selfUin,
|
||||
groupId: change.groupUin ?? 0,
|
||||
userUin: resolveUidToUin(qqInfo, change.groupUin ?? 0, change.memberUid ?? '', fromUin),
|
||||
operatorUin: resolveUidToUin(qqInfo, change.groupUin ?? 0,
|
||||
decodeOperatorUid(change.operatorBytes ?? new Uint8Array(0)), fromUin),
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
|
||||
case PkgType.GroupMemberDecreaseNotice: {
|
||||
const change = protoDecode(content, GroupChangeSchema);
|
||||
if (!change) return [];
|
||||
const dt = change.decreaseType ?? 0;
|
||||
const ev: GroupMemberLeave = {
|
||||
kind: 'group_member_leave', time: timestamp, selfUin,
|
||||
groupId: change.groupUin ?? 0,
|
||||
userUin: resolveUidToUin(qqInfo, change.groupUin ?? 0, change.memberUid ?? '', fromUin),
|
||||
operatorUin: resolveUidToUin(qqInfo, change.groupUin ?? 0,
|
||||
decodeOperatorUid(change.operatorBytes ?? new Uint8Array(0)), fromUin),
|
||||
isKick: dt !== 0 && dt !== 130,
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
|
||||
case PkgType.GroupAdminChangedNotice: {
|
||||
const admin = protoDecode(content, GroupAdminSchema);
|
||||
if (!admin?.body) return [];
|
||||
const extra = admin.body.extraEnable ?? admin.body.extraDisable;
|
||||
if (!extra) return [];
|
||||
const ev: GroupAdminEvent = {
|
||||
kind: 'group_admin', time: timestamp, selfUin,
|
||||
groupId: admin.groupUin ?? 0,
|
||||
userUin: resolveUidToUin(qqInfo, admin.groupUin ?? 0, extra.adminUid ?? '', fromUin),
|
||||
set: admin.body.extraEnable !== undefined,
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
|
||||
case PkgType.GroupRequestJoinNotice: {
|
||||
const join = protoDecode(content, GroupJoinSchema);
|
||||
if (!join) return [];
|
||||
const ev: GroupInviteEvent = {
|
||||
kind: 'group_invite', time: timestamp, selfUin,
|
||||
groupId: join.groupUin ?? 0,
|
||||
fromUin: resolveUidToUin(qqInfo, join.groupUin ?? 0, join.targetUid ?? '', fromUin),
|
||||
subType: 'add', message: '',
|
||||
flag: 'add:' + (join.groupUin ?? 0) + ':' + (join.targetUid ?? ''),
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
|
||||
case PkgType.GroupRequestInvitationNotice: {
|
||||
const invitation = protoDecode(content, GroupInvitationSchema);
|
||||
if (!invitation?.info?.inner) return [];
|
||||
const inner = invitation.info.inner;
|
||||
const ev: GroupInviteEvent = {
|
||||
kind: 'group_invite', time: timestamp, selfUin,
|
||||
groupId: inner.groupUin ?? 0,
|
||||
fromUin: resolveUidToUin(qqInfo, inner.groupUin ?? 0, inner.invitorUid ?? '', fromUin),
|
||||
subType: 'invite', message: '',
|
||||
flag: 'invite:' + (inner.groupUin ?? 0) + ':' + (inner.invitorUid ?? ''),
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
|
||||
case PkgType.GroupInviteNotice: {
|
||||
const invite = protoDecode(content, GroupInviteSchema);
|
||||
if (!invite) return [];
|
||||
const ev: GroupInviteEvent = {
|
||||
kind: 'group_invite', time: timestamp, selfUin,
|
||||
groupId: invite.groupUin ?? 0,
|
||||
fromUin: resolveUidToUin(qqInfo, invite.groupUin ?? 0, invite.invitorUid ?? '', fromUin),
|
||||
subType: 'invite', message: '',
|
||||
flag: 'invite:' + (invite.groupUin ?? 0) + ':' + (invite.invitorUid ?? ''),
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
|
||||
case PkgType.Event0x210: {
|
||||
switch (subType as Event0x210SubType) {
|
||||
case Event0x210SubType.FriendRequestNotice: {
|
||||
const request = protoDecode(content, FriendRequestSchema);
|
||||
if (!request?.info) return [];
|
||||
const sourceUid = request.info.newSource || request.info.sourceUid || '';
|
||||
const ev: FriendRequestEvent = {
|
||||
kind: 'friend_request', time: timestamp, selfUin,
|
||||
fromUin: resolveUidToUin(qqInfo, 0, sourceUid, fromUin),
|
||||
message: request.info.message ?? '', flag: sourceUid,
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
case Event0x210SubType.FriendRecallNotice: {
|
||||
const recall = protoDecode(content, FriendRecallSchema);
|
||||
if (!recall?.info) return [];
|
||||
const ev: FriendRecall = {
|
||||
kind: 'friend_recall', time: recall.info.time ?? timestamp, selfUin,
|
||||
userUin: resolveUidToUin(qqInfo, 0, recall.info.fromUid ?? '', fromUin),
|
||||
msgSeq: recall.info.clientSequence ?? 0,
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
case Event0x210SubType.FriendPokeNotice: {
|
||||
const grayTip = protoDecode(content, GeneralGrayTipInfoSchema);
|
||||
if (!grayTip || (grayTip.busiType ?? 0n) !== 12n) return [];
|
||||
const templates = buildTemplateMap(grayTip.msgTemplParam ?? []);
|
||||
const actor = findTemplateValue(templates, 'uin_str1');
|
||||
const target = findTemplateValue(templates, 'uin_str2');
|
||||
const ev: FriendPokeEvent = {
|
||||
kind: 'friend_poke', time: timestamp, selfUin,
|
||||
userUin: resolveUidToUin(qqInfo, 0, actor, parseU64OrZero(actor)),
|
||||
targetUin: resolveUidToUin(qqInfo, 0, target, parseU64OrZero(target)),
|
||||
action: findTemplateValue(templates, 'action_str', 'alt_str1'),
|
||||
suffix: findTemplateValue(templates, 'suffix_str'),
|
||||
actionImgUrl: findTemplateValue(templates, 'action_img_url'),
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case PkgType.Event0x2DC: {
|
||||
switch (subType as Event0x2DCSubType) {
|
||||
case Event0x2DCSubType.GroupMuteNotice: {
|
||||
const mute = protoDecode(content, GroupMuteSchema);
|
||||
if (!mute?.data?.state) return [];
|
||||
const duration = mute.data.state.duration ?? 0;
|
||||
const ev: GroupMuteEvent = {
|
||||
kind: 'group_mute', time: mute.data.timestamp ?? timestamp, selfUin,
|
||||
groupId: mute.groupUin ?? 0,
|
||||
operatorUin: resolveUidToUin(qqInfo, mute.groupUin ?? 0, mute.operatorUid ?? '', fromUin),
|
||||
userUin: resolveUidToUin(qqInfo, mute.groupUin ?? 0, mute.data.state.targetUid ?? '', 0),
|
||||
duration: duration === 0xFFFFFFFF ? 0x7FFFFFFF : duration,
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
case Event0x2DCSubType.GroupRecallNotice: {
|
||||
const payload = unwrapGroupNotifyPayload(content);
|
||||
if (!payload) return [];
|
||||
const notify = protoDecode(payload, NotifyMessageBodySchema);
|
||||
if (!notify?.recall?.recallMessages || notify.recall.recallMessages.length === 0) return [];
|
||||
const recalled = notify.recall.recallMessages[0];
|
||||
const ev: GroupRecallEvent = {
|
||||
kind: 'group_recall', time: recalled.time ?? timestamp, selfUin,
|
||||
groupId: notify.groupUin ?? 0,
|
||||
operatorUin: resolveUidToUin(qqInfo, notify.groupUin ?? 0,
|
||||
notify.recall.operatorUid || notify.operatorUid || '', fromUin),
|
||||
authorUin: resolveUidToUin(qqInfo, notify.groupUin ?? 0, recalled.authorUid ?? '', fromUin),
|
||||
msgSeq: recalled.sequence ?? 0,
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
case Event0x2DCSubType.GroupGreyTipNotice: {
|
||||
const payload = unwrapGroupNotifyPayload(content);
|
||||
if (!payload) return [];
|
||||
const notify = protoDecode(payload, NotifyMessageBodySchema);
|
||||
if (!notify?.generalGrayTip || (notify.generalGrayTip.busiType ?? 0n) !== 12n) return [];
|
||||
const templates = buildTemplateMap(notify.generalGrayTip.msgTemplParam ?? []);
|
||||
const actor = findTemplateValue(templates, 'uin_str1');
|
||||
const target = findTemplateValue(templates, 'uin_str2');
|
||||
const ev: GroupPokeEvent = {
|
||||
kind: 'group_poke', time: timestamp, selfUin,
|
||||
groupId: notify.groupUin ?? 0,
|
||||
userUin: resolveUidToUin(qqInfo, notify.groupUin ?? 0, actor, parseU64OrZero(actor)),
|
||||
targetUin: resolveUidToUin(qqInfo, notify.groupUin ?? 0, target, parseU64OrZero(target)),
|
||||
action: findTemplateValue(templates, 'action_str', 'alt_str1'),
|
||||
suffix: findTemplateValue(templates, 'suffix_str'),
|
||||
actionImgUrl: findTemplateValue(templates, 'action_img_url'),
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
case Event0x2DCSubType.GroupEssenceNotice: {
|
||||
const payload = unwrapGroupNotifyPayload(content);
|
||||
if (!payload) return [];
|
||||
const notify = protoDecode(payload, NotifyMessageBodySchema);
|
||||
if (!notify?.essenceMessage) return [];
|
||||
const essence = notify.essenceMessage;
|
||||
const setFlag = essence.setFlag ?? essence.setFlag2 ?? 0;
|
||||
const ev: GroupEssenceEvent = {
|
||||
kind: 'group_essence', time: essence.timestamp ?? timestamp, selfUin,
|
||||
groupId: essence.groupUin ?? notify.groupUin ?? 0,
|
||||
senderUin: essence.memberUin ?? 0,
|
||||
operatorUin: essence.operatorUin ?? fromUin,
|
||||
msgSeq: essence.msgSequence ?? essence.msgSequence2 ?? notify.msgSequence ?? 0,
|
||||
random: essence.random ?? 0,
|
||||
set: setFlag === 1,
|
||||
};
|
||||
return [ev];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Message types ---
|
||||
|
||||
if (msgType === PkgType.GroupMessage) {
|
||||
const ev: GroupMessage = {
|
||||
kind: 'group_message', time: timestamp, selfUin,
|
||||
senderUin: fromUin, msgSeq: sequence,
|
||||
msgId: msgId & 0x7FFFFFFF,
|
||||
elements: buildElements(true),
|
||||
groupId: 0, senderNick: '', senderCard: '', senderRole: '',
|
||||
};
|
||||
if (msg.responseHead?.grp) {
|
||||
ev.groupId = msg.responseHead.grp.groupUin ?? 0;
|
||||
ev.senderNick = msg.responseHead.grp.memberName ?? '';
|
||||
}
|
||||
const member = qqInfo.findGroupMember(ev.groupId, fromUin);
|
||||
if (member) {
|
||||
if (!ev.senderNick) ev.senderNick = member.nickname;
|
||||
ev.senderCard = member.card;
|
||||
ev.senderRole = member.role;
|
||||
}
|
||||
return [ev];
|
||||
}
|
||||
|
||||
if (msgType === PkgType.TempMessage) {
|
||||
const ev: TempMessage = {
|
||||
kind: 'temp_message', time: timestamp, selfUin,
|
||||
senderUin: fromUin, msgSeq: sequence,
|
||||
elements: buildElements(false),
|
||||
groupId: 0, senderNick: '',
|
||||
};
|
||||
if (msg.responseHead?.grp) {
|
||||
ev.groupId = msg.responseHead.grp.groupUin ?? 0;
|
||||
ev.senderNick = msg.responseHead.grp.memberName ?? '';
|
||||
}
|
||||
if (!ev.senderNick) {
|
||||
const friend = qqInfo.findFriend(fromUin);
|
||||
if (friend) ev.senderNick = friend.nickname;
|
||||
}
|
||||
return [ev];
|
||||
}
|
||||
|
||||
if (msgType === PkgType.PrivateMessage ||
|
||||
msgType === PkgType.ForwardFakePrivateMessage ||
|
||||
msgType === PkgType.PrivateRecordMessage ||
|
||||
msgType === PkgType.PrivateFileMessage) {
|
||||
const ev: FriendMessage = {
|
||||
kind: 'friend_message', time: timestamp, selfUin,
|
||||
senderUin: fromUin, msgSeq: sequence,
|
||||
msgId: msgId & 0x7FFFFFFF,
|
||||
elements: buildElements(false),
|
||||
senderNick: '',
|
||||
};
|
||||
if (msg.responseHead?.forward?.friendName) {
|
||||
ev.senderNick = msg.responseHead.forward.friendName;
|
||||
}
|
||||
const friend = qqInfo.findFriend(fromUin);
|
||||
if (friend && !ev.senderNick) ev.senderNick = friend.nickname;
|
||||
return [ev];
|
||||
}
|
||||
|
||||
// const preview = bytesToHex(content.subarray(0, Math.min(content.length, 48)));
|
||||
return [];
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
// Highway HTTP client: session fetch and chunked binary upload.
|
||||
// Port of src/bridge/src/highway_client.cpp
|
||||
|
||||
import net from 'net';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { protoEncode, protoDecode } from '../../protobuf/decode';
|
||||
import {
|
||||
HttpConn0x6FF501RequestSchema,
|
||||
HttpConn0x6FF501ResponseSchema,
|
||||
ReqDataHighwayHeadSchema,
|
||||
RespDataHighwayHeadSchema,
|
||||
NTV2RichMediaHighwayExtSchema,
|
||||
HighwayMsgInfoBodySchema,
|
||||
} from '../proto/highway';
|
||||
import { packHighwayFrame, unpackHighwayFrame, computeMd5 } from './utils';
|
||||
|
||||
const HIGHWAY_APP_ID = 1600001604;
|
||||
const HIGHWAY_BLOCK_SIZE = 1024 * 1024;
|
||||
|
||||
export const PRIVATE_IMAGE_CMD_ID = 1003;
|
||||
export const GROUP_IMAGE_CMD_ID = 1004;
|
||||
|
||||
export interface HighwaySession {
|
||||
sigSession: Uint8Array;
|
||||
sessionKey: Uint8Array;
|
||||
host: string;
|
||||
port: number;
|
||||
}
|
||||
|
||||
function ipv4ToString(value: number): string {
|
||||
return `${value & 0xFF}.${(value >> 8) & 0xFF}.${(value >> 16) & 0xFF}.${(value >> 24) & 0xFF}`;
|
||||
}
|
||||
|
||||
export async function fetchHighwaySession(bridge: Bridge): Promise<HighwaySession> {
|
||||
const request = protoEncode({
|
||||
httpConn: {
|
||||
field1: 0, field2: 0, field3: 16, field4: 1, field6: 3,
|
||||
serviceTypes: [1, 5, 10, 21],
|
||||
field9: 2, field10: 9, field11: 8, ver: '1.0.1',
|
||||
},
|
||||
}, HttpConn0x6FF501RequestSchema);
|
||||
|
||||
const result = await bridge.sendRawPacket('HttpConn.0x6ff_501', request);
|
||||
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||
throw new Error(result.errorMessage || 'HttpConn request failed');
|
||||
}
|
||||
|
||||
const resp = protoDecode(result.responseData, HttpConn0x6FF501ResponseSchema);
|
||||
if (!resp?.httpConn) throw new Error('HttpConn response body missing');
|
||||
if (!resp.httpConn.sigSession || (resp.httpConn.sigSession as Uint8Array).length === 0) {
|
||||
throw new Error('HttpConn response missing sig_session');
|
||||
}
|
||||
|
||||
const session: HighwaySession = {
|
||||
sigSession: resp.httpConn.sigSession as Uint8Array,
|
||||
sessionKey: (resp.httpConn.sessionKey as Uint8Array) ?? new Uint8Array(0),
|
||||
host: 'htdata3.qq.com',
|
||||
port: 80,
|
||||
};
|
||||
|
||||
for (const si of resp.httpConn.serverInfos ?? []) {
|
||||
if ((si.serviceType ?? 0) !== 1 || !si.serverAddrs?.length) continue;
|
||||
for (const addr of si.serverAddrs) {
|
||||
const ip = addr.ip ?? 0;
|
||||
const port = addr.port ?? 0;
|
||||
if (ip && port) {
|
||||
session.host = ipv4ToString(ip);
|
||||
session.port = port;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[Highway] session: ${session.host}:${session.port} sig=${(session.sigSession as Uint8Array).length}B`);
|
||||
return session;
|
||||
}
|
||||
|
||||
function makeHighwayHead(
|
||||
uin: string, commandId: number, fileSize: number, offset: number, length: number,
|
||||
chunkMd5: Uint8Array, fileMd5: Uint8Array, sigSession: Uint8Array, extend: Uint8Array,
|
||||
): Uint8Array {
|
||||
return protoEncode({
|
||||
msgBaseHead: {
|
||||
version: 1, uin, command: 'PicUp.DataUp', seq: 0, retryTimes: 0,
|
||||
appId: HIGHWAY_APP_ID, dataFlag: 16, commandId,
|
||||
},
|
||||
msgSegHead: {
|
||||
serviceId: 0, filesize: BigInt(fileSize), dataOffset: BigInt(offset), dataLength: length,
|
||||
retCode: 0, serviceTicket: sigSession, flag: 0, md5: chunkMd5, fileMd5, cacheAddr: 0, cachePort: 0,
|
||||
},
|
||||
bytesReqExtendInfo: extend,
|
||||
timestamp: 0n,
|
||||
msgLoginSigHead: { loginSigType: 8, appId: HIGHWAY_APP_ID },
|
||||
}, ReqDataHighwayHeadSchema);
|
||||
}
|
||||
|
||||
export function buildHighwayExtend(
|
||||
uKey: string, msgInfo: any, ipv4s: any[], sha1: Uint8Array,
|
||||
): Uint8Array {
|
||||
const msgInfoBody = msgInfo?.msgInfoBody ?? [];
|
||||
if (msgInfoBody.length === 0) throw new Error('upload response missing msg_info body');
|
||||
|
||||
const first = msgInfoBody[0];
|
||||
const networkIpv4s: any[] = [];
|
||||
for (const ipv4 of ipv4s ?? []) {
|
||||
const ip = ipv4.outIp ?? 0;
|
||||
const port = ipv4.outPort ?? 0;
|
||||
if (ip && port) {
|
||||
networkIpv4s.push({ domain: { isEnable: true, ip: ipv4ToString(ip) }, port });
|
||||
}
|
||||
}
|
||||
|
||||
return protoEncode({
|
||||
fileUuid: first?.index?.fileUuid ?? '',
|
||||
uKey,
|
||||
network: { ipv4s: networkIpv4s },
|
||||
msgInfoBody: msgInfoBody.map((b: any) => ({
|
||||
index: b.index, picture: b.picture, fileExist: b.fileExist, hashSum: b.hashSum,
|
||||
})),
|
||||
blockSize: HIGHWAY_BLOCK_SIZE,
|
||||
hash: { fileSha1: [sha1] },
|
||||
}, NTV2RichMediaHighwayExtSchema);
|
||||
}
|
||||
|
||||
// --- TCP-based HTTP highway upload ---
|
||||
|
||||
function tcpConnect(host: string, port: number, timeoutMs = 10000): Promise<net.Socket> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const socket = net.createConnection({ host, port }, () => resolve(socket));
|
||||
socket.setTimeout(timeoutMs);
|
||||
socket.on('timeout', () => { socket.destroy(); reject(new Error('TCP connect timeout')); });
|
||||
socket.on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
function socketWrite(socket: net.Socket, data: Uint8Array): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
socket.write(data, (err) => err ? reject(err) : resolve());
|
||||
});
|
||||
}
|
||||
|
||||
function readHttpResponseBody(socket: net.Socket): Promise<Uint8Array> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const chunks: Buffer[] = [];
|
||||
let headerEnd = -1;
|
||||
let contentLength = 0;
|
||||
let totalNeeded = 0;
|
||||
|
||||
const checkComplete = () => {
|
||||
const buf = Buffer.concat(chunks);
|
||||
if (headerEnd < 0) {
|
||||
const idx = buf.indexOf('\r\n\r\n');
|
||||
if (idx >= 0) {
|
||||
headerEnd = idx + 4;
|
||||
const headerStr = buf.subarray(0, headerEnd).toString('ascii').toLowerCase();
|
||||
const clMatch = headerStr.match(/content-length:\s*(\d+)/);
|
||||
contentLength = clMatch ? parseInt(clMatch[1], 10) : 0;
|
||||
totalNeeded = headerEnd + contentLength;
|
||||
}
|
||||
}
|
||||
if (headerEnd >= 0 && buf.length >= totalNeeded) {
|
||||
socket.removeAllListeners('data');
|
||||
socket.removeAllListeners('error');
|
||||
resolve(new Uint8Array(buf.subarray(headerEnd, totalNeeded)));
|
||||
}
|
||||
};
|
||||
|
||||
socket.on('data', (chunk) => { chunks.push(chunk); checkComplete(); });
|
||||
socket.on('error', reject);
|
||||
socket.on('close', () => {
|
||||
const buf = Buffer.concat(chunks);
|
||||
if (headerEnd >= 0) resolve(new Uint8Array(buf.subarray(headerEnd)));
|
||||
else reject(new Error('connection closed before response'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function httpPostFrame(
|
||||
socket: net.Socket, host: string, path: string, body: Uint8Array,
|
||||
): Promise<Uint8Array> {
|
||||
const header = `POST ${path} HTTP/1.1\r\nHost: ${host}\r\nConnection: keep-alive\r\nAccept-Encoding: identity\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2)\r\nContent-Length: ${body.length}\r\n\r\n`;
|
||||
await socketWrite(socket, Buffer.from(header, 'ascii'));
|
||||
if (body.length > 0) await socketWrite(socket, body);
|
||||
return readHttpResponseBody(socket);
|
||||
}
|
||||
|
||||
export async function uploadHighwayHttp(
|
||||
bridge: Bridge, session: HighwaySession, commandId: number,
|
||||
bytes: Uint8Array, fileMd5: Uint8Array, extend: Uint8Array,
|
||||
): Promise<void> {
|
||||
const pathStr = `/cgi-bin/httpconn?htcmd=0x6FF0087&uin=${bridge.qqInfo.uin}`;
|
||||
const socket = await tcpConnect(session.host, session.port);
|
||||
|
||||
try {
|
||||
let offset = 0;
|
||||
while (offset < bytes.length) {
|
||||
const chunkSize = Math.min(HIGHWAY_BLOCK_SIZE, bytes.length - offset);
|
||||
const chunk = bytes.subarray(offset, offset + chunkSize);
|
||||
const chunkMd5 = computeMd5(chunk);
|
||||
const head = makeHighwayHead(
|
||||
bridge.qqInfo.uin, commandId, bytes.length, offset, chunkSize,
|
||||
chunkMd5, fileMd5, session.sigSession, extend,
|
||||
);
|
||||
const frame = packHighwayFrame(head, chunk);
|
||||
const responseBody = await httpPostFrame(socket, session.host, pathStr, frame);
|
||||
const { head: respHead } = unpackHighwayFrame(responseBody);
|
||||
const resp = protoDecode(respHead, RespDataHighwayHeadSchema);
|
||||
if (resp?.errorCode && resp.errorCode !== 0) {
|
||||
throw new Error(`highway upload error_code=${resp.errorCode}`);
|
||||
}
|
||||
offset += chunkSize;
|
||||
console.log(`[Highway] uploaded ${offset}/${bytes.length} bytes`);
|
||||
}
|
||||
} finally {
|
||||
socket.destroy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
// Image upload pipeline: load image, OIDB upload request, highway upload, build message element.
|
||||
// Port of src/bridge/src/highway_upload_req.cpp + highway_client.cpp (image parts)
|
||||
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { MessageElement } from '../events';
|
||||
import { protoEncode, protoDecode } from '../../protobuf/decode';
|
||||
import { makeOidbBaseSchema } from '../proto/oidb';
|
||||
import {
|
||||
NTV2UploadRichMediaReqSchema,
|
||||
NTV2UploadRichMediaRespSchema,
|
||||
EncodableMediaMsgInfoSchema,
|
||||
} from '../proto/highway';
|
||||
import {
|
||||
loadBinarySource, computeHashes, detectImageFormat,
|
||||
} from './utils';
|
||||
import {
|
||||
fetchHighwaySession, uploadHighwayHttp, buildHighwayExtend,
|
||||
PRIVATE_IMAGE_CMD_ID, GROUP_IMAGE_CMD_ID,
|
||||
} from './highway-client';
|
||||
|
||||
interface ImageData {
|
||||
bytes: Uint8Array;
|
||||
md5: Uint8Array;
|
||||
sha1: Uint8Array;
|
||||
md5Hex: string;
|
||||
sha1Hex: string;
|
||||
fileName: string;
|
||||
summary: string;
|
||||
subType: number;
|
||||
width: number;
|
||||
height: number;
|
||||
picFormat: number;
|
||||
}
|
||||
|
||||
function loadImage(element: MessageElement): Promise<ImageData> {
|
||||
return loadImageFromSource(
|
||||
element.url || element.fileId || '',
|
||||
element.fileName ?? '',
|
||||
element.subType ?? 0,
|
||||
element.summary ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
async function loadImageFromSource(source: string, fileName: string, subType: number, summary: string): Promise<ImageData> {
|
||||
const loaded = await loadBinarySource(source, 'image');
|
||||
const hashes = computeHashes(loaded.bytes);
|
||||
const fmt = detectImageFormat(loaded.bytes);
|
||||
|
||||
const extMap: Record<number, string> = { 1000: '.jpg', 1001: '.png', 1002: '.webp', 1005: '.bmp', 2000: '.gif' };
|
||||
const ext = extMap[fmt.format] ?? '.jpg';
|
||||
|
||||
let finalName = fileName || loaded.fileName;
|
||||
if (!finalName) finalName = hashes.md5Hex + ext;
|
||||
|
||||
return {
|
||||
bytes: loaded.bytes,
|
||||
md5: hashes.md5,
|
||||
sha1: hashes.sha1,
|
||||
md5Hex: hashes.md5Hex,
|
||||
sha1Hex: hashes.sha1Hex,
|
||||
fileName: finalName,
|
||||
summary: summary || (subType === 0 ? '[image]' : '[sticker]'),
|
||||
subType,
|
||||
width: fmt.width,
|
||||
height: fmt.height,
|
||||
picFormat: fmt.format,
|
||||
};
|
||||
}
|
||||
|
||||
async function startImageUpload(bridge: Bridge, isGroup: boolean, targetIdOrUid: string | number, image: ImageData): Promise<any> {
|
||||
const body: any = {
|
||||
reqHead: {
|
||||
common: { requestId: 1, command: 100 },
|
||||
scene: {
|
||||
requestType: 2,
|
||||
businessType: 1,
|
||||
sceneType: isGroup ? 2 : 1,
|
||||
...(isGroup
|
||||
? { group: { groupUin: Number(targetIdOrUid) } }
|
||||
: { c2c: { accountType: 2, targetUid: String(targetIdOrUid) } }),
|
||||
},
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
upload: {
|
||||
uploadInfo: [{
|
||||
fileInfo: {
|
||||
fileSize: image.bytes.length,
|
||||
fileHash: image.md5Hex,
|
||||
fileSha1: image.sha1Hex,
|
||||
fileName: image.fileName,
|
||||
type: { type: 1, picFormat: image.picFormat, videoFormat: 0, voiceFormat: 0 },
|
||||
width: image.width,
|
||||
height: image.height,
|
||||
time: 0,
|
||||
original: 1,
|
||||
},
|
||||
subFileType: 0,
|
||||
}],
|
||||
tryFastUploadCompleted: true,
|
||||
srvSendMsg: false,
|
||||
clientRandomId: BigInt(Math.floor(Math.random() * 0x7FFFFFFFFFFFFFFF)),
|
||||
compatQmsgSceneType: isGroup ? 2 : 1,
|
||||
extBizInfo: {
|
||||
pic: {
|
||||
bizType: image.subType,
|
||||
textSummary: image.summary,
|
||||
...(isGroup
|
||||
? { reserveTroop: { subType: image.subType } }
|
||||
: { reserveC2c: { subType: image.subType } }),
|
||||
},
|
||||
video: { bytesPbReserve: new Uint8Array(0) },
|
||||
ptt: {
|
||||
bytesReserve: new Uint8Array(0),
|
||||
bytesPbReserve: new Uint8Array(0),
|
||||
bytesGeneralFlags: new Uint8Array(0),
|
||||
},
|
||||
},
|
||||
clientSeq: 0,
|
||||
noNeedCompatMsg: false,
|
||||
},
|
||||
};
|
||||
|
||||
const oidbCmd = isGroup ? 0x11C4 : 0x11C5;
|
||||
const serviceCmd = isGroup ? 'OidbSvcTrpcTcp.0x11c4_100' : 'OidbSvcTrpcTcp.0x11c5_100';
|
||||
|
||||
const baseSchema = makeOidbBaseSchema(NTV2UploadRichMediaReqSchema);
|
||||
const request = protoEncode({
|
||||
command: oidbCmd, subCommand: 100, errorCode: 0, body, errorMsg: '', reserved: 1,
|
||||
}, baseSchema);
|
||||
|
||||
const result = await bridge.sendRawPacket(serviceCmd, request);
|
||||
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||
throw new Error(result.errorMessage || 'image upload request failed');
|
||||
}
|
||||
|
||||
const respBaseSchema = makeOidbBaseSchema(NTV2UploadRichMediaRespSchema);
|
||||
const resp: any = protoDecode(result.responseData, respBaseSchema);
|
||||
if (!resp) throw new Error('failed to decode upload response');
|
||||
if (resp.errorCode && resp.errorCode !== 0) {
|
||||
throw new Error(`OIDB error ${resp.errorCode}: ${resp.errorMsg ?? ''}`);
|
||||
}
|
||||
|
||||
const uploadBody = resp.body;
|
||||
if (!uploadBody) throw new Error('upload response body missing');
|
||||
if (uploadBody.respHead?.retCode && uploadBody.respHead.retCode !== 0) {
|
||||
throw new Error(uploadBody.respHead.message ?? 'image upload failed');
|
||||
}
|
||||
return uploadBody.upload;
|
||||
}
|
||||
|
||||
function finalizeImageMsgInfo(upload: any, image: ImageData): Uint8Array {
|
||||
if (!upload?.msgInfo) throw new Error('upload response missing msgInfo');
|
||||
|
||||
const msgInfoBody = (upload.msgInfo.msgInfoBody ?? []).map((b: any) => ({
|
||||
index: b.index, picture: b.picture, fileExist: b.fileExist, hashSum: b.hashSum,
|
||||
}));
|
||||
|
||||
const extBizInfo: any = {};
|
||||
if (upload.msgInfo.extBizInfo?.pic) {
|
||||
extBizInfo.pic = { ...upload.msgInfo.extBizInfo.pic };
|
||||
extBizInfo.pic.bizType = extBizInfo.pic.bizType ?? image.subType;
|
||||
extBizInfo.pic.textSummary = extBizInfo.pic.textSummary ?? image.summary;
|
||||
} else {
|
||||
extBizInfo.pic = { bizType: image.subType, textSummary: image.summary };
|
||||
}
|
||||
if (upload.msgInfo.extBizInfo?.video) extBizInfo.video = upload.msgInfo.extBizInfo.video;
|
||||
if (upload.msgInfo.extBizInfo?.ptt) extBizInfo.ptt = upload.msgInfo.extBizInfo.ptt;
|
||||
if (upload.msgInfo.extBizInfo?.busiType !== undefined) extBizInfo.busiType = upload.msgInfo.extBizInfo.busiType;
|
||||
|
||||
return protoEncode({ msgInfoBody, extBizInfo }, EncodableMediaMsgInfoSchema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload an image and return the encoded MsgInfo bytes to embed in a CommonElem.
|
||||
*/
|
||||
export async function uploadImageMsgInfo(
|
||||
bridge: Bridge,
|
||||
isGroup: boolean,
|
||||
targetIdOrUid: string | number,
|
||||
element: MessageElement,
|
||||
): Promise<Uint8Array> {
|
||||
const image = await loadImage(element);
|
||||
const upload = await startImageUpload(bridge, isGroup, targetIdOrUid, image);
|
||||
|
||||
// Upload binary if uKey is present (not fast-uploaded)
|
||||
const uKey = upload?.uKey ?? '';
|
||||
if (uKey && upload?.msgInfo) {
|
||||
const session = await fetchHighwaySession(bridge);
|
||||
const extend = buildHighwayExtend(uKey, upload.msgInfo, upload.ipv4s ?? [], image.sha1);
|
||||
const commandId = isGroup ? GROUP_IMAGE_CMD_ID : PRIVATE_IMAGE_CMD_ID;
|
||||
await uploadHighwayHttp(bridge, session, commandId, image.bytes, image.md5, extend);
|
||||
}
|
||||
|
||||
return finalizeImageMsgInfo(upload, image);
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
// Highway utilities: binary source loading, hashing, image format detection, frame packing.
|
||||
// Port of src/bridge/src/highway_utils.h/.cpp
|
||||
|
||||
import { createHash } from 'crypto';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export interface LoadedBinary {
|
||||
bytes: Uint8Array;
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
export interface ImageHashes {
|
||||
md5: Uint8Array;
|
||||
sha1: Uint8Array;
|
||||
md5Hex: string;
|
||||
sha1Hex: string;
|
||||
}
|
||||
|
||||
export interface ImageFormat {
|
||||
format: number; // 1000=jpg, 1001=png, 1002=webp, 1005=bmp, 2000=gif
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
// --- Binary source loading ---
|
||||
|
||||
export async function loadBinarySource(source: string, resourceName: string): Promise<LoadedBinary> {
|
||||
if (!source) throw new Error(`${resourceName} source is empty`);
|
||||
|
||||
if (source.startsWith('base64://')) {
|
||||
return { bytes: Buffer.from(source.slice(9), 'base64'), fileName: '' };
|
||||
}
|
||||
|
||||
if (source.startsWith('http://') || source.startsWith('https://')) {
|
||||
const resp = await fetch(source);
|
||||
if (!resp.ok) throw new Error(`HTTP download failed: ${resp.status}`);
|
||||
const bytes = new Uint8Array(await resp.arrayBuffer());
|
||||
const fileName = guessFileNameFromUrl(source);
|
||||
return { bytes, fileName };
|
||||
}
|
||||
|
||||
// File path (strip file:// prefix)
|
||||
let filePath = source;
|
||||
if (filePath.startsWith('file://')) filePath = filePath.slice(7);
|
||||
// Windows: strip leading / before drive letter
|
||||
if (/^\/[a-zA-Z]:/.test(filePath)) filePath = filePath.slice(1);
|
||||
|
||||
const bytes = fs.readFileSync(filePath);
|
||||
const fileName = path.basename(filePath);
|
||||
return { bytes, fileName };
|
||||
}
|
||||
|
||||
function guessFileNameFromUrl(url: string): string {
|
||||
const queryPos = url.search(/[?#]/);
|
||||
const pathPart = queryPos >= 0 ? url.slice(0, queryPos) : url;
|
||||
const lastSlash = pathPart.lastIndexOf('/');
|
||||
return lastSlash >= 0 ? pathPart.slice(lastSlash + 1) : '';
|
||||
}
|
||||
|
||||
// --- Hashing ---
|
||||
|
||||
export function computeHashes(data: Uint8Array): ImageHashes {
|
||||
const md5 = createHash('md5').update(data).digest();
|
||||
const sha1 = createHash('sha1').update(data).digest();
|
||||
return {
|
||||
md5: new Uint8Array(md5),
|
||||
sha1: new Uint8Array(sha1),
|
||||
md5Hex: md5.toString('hex'),
|
||||
sha1Hex: sha1.toString('hex'),
|
||||
};
|
||||
}
|
||||
|
||||
export function computeMd5(data: Uint8Array): Uint8Array {
|
||||
return new Uint8Array(createHash('md5').update(data).digest());
|
||||
}
|
||||
|
||||
// --- Image format detection (port of C++ detect_image_format) ---
|
||||
|
||||
function readBE16(data: Uint8Array, offset: number): number {
|
||||
return (data[offset] << 8) | data[offset + 1];
|
||||
}
|
||||
|
||||
function readBE32(data: Uint8Array, offset: number): number {
|
||||
return ((data[offset] << 24) | (data[offset + 1] << 16) | (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
|
||||
}
|
||||
|
||||
function readLE16(data: Uint8Array, offset: number): number {
|
||||
return data[offset] | (data[offset + 1] << 8);
|
||||
}
|
||||
|
||||
function readLE32(data: Uint8Array, offset: number): number {
|
||||
return (data[offset] | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24)) >>> 0;
|
||||
}
|
||||
|
||||
function readBE24(data: Uint8Array, offset: number): number {
|
||||
return (data[offset] << 16) | (data[offset + 1] << 8) | data[offset + 2];
|
||||
}
|
||||
|
||||
export function detectImageFormat(bytes: Uint8Array): ImageFormat {
|
||||
let width = 0;
|
||||
let height = 0;
|
||||
|
||||
// PNG
|
||||
if (bytes.length >= 24 &&
|
||||
bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4E && bytes[3] === 0x47) {
|
||||
width = readBE32(bytes, 16);
|
||||
height = readBE32(bytes, 20);
|
||||
return { format: 1001, width, height };
|
||||
}
|
||||
|
||||
// GIF
|
||||
if (bytes.length >= 10 &&
|
||||
bytes[0] === 0x47 && bytes[1] === 0x49 && bytes[2] === 0x46 && bytes[3] === 0x38 &&
|
||||
(bytes[4] === 0x37 || bytes[4] === 0x39) && bytes[5] === 0x61) {
|
||||
width = readLE16(bytes, 6);
|
||||
height = readLE16(bytes, 8);
|
||||
return { format: 2000, width, height };
|
||||
}
|
||||
|
||||
// BMP
|
||||
if (bytes.length >= 26 && bytes[0] === 0x42 && bytes[1] === 0x4D) {
|
||||
width = readLE32(bytes, 18);
|
||||
height = readLE32(bytes, 22);
|
||||
return { format: 1005, width, height };
|
||||
}
|
||||
|
||||
// WebP
|
||||
if (bytes.length >= 30 &&
|
||||
bytes[0] === 0x52 && bytes[1] === 0x49 && bytes[2] === 0x46 && bytes[3] === 0x46 &&
|
||||
bytes[8] === 0x57 && bytes[9] === 0x45 && bytes[10] === 0x42 && bytes[11] === 0x50) {
|
||||
if (bytes[12] === 0x56 && bytes[13] === 0x50 && bytes[14] === 0x38 && bytes[15] === 0x20) {
|
||||
width = readLE16(bytes, 26);
|
||||
height = readLE16(bytes, 28);
|
||||
return { format: 1002, width, height };
|
||||
}
|
||||
if (bytes[12] === 0x56 && bytes[13] === 0x50 && bytes[14] === 0x38 && bytes[15] === 0x4C) {
|
||||
const bits = readLE32(bytes, 21);
|
||||
width = (bits & 0x3FFF) + 1;
|
||||
height = ((bits >> 14) & 0x3FFF) + 1;
|
||||
return { format: 1002, width, height };
|
||||
}
|
||||
if (bytes[12] === 0x56 && bytes[13] === 0x50 && bytes[14] === 0x38 && bytes[15] === 0x58) {
|
||||
width = readBE24(bytes, 24) + 1;
|
||||
height = readBE24(bytes, 27) + 1;
|
||||
return { format: 1002, width, height };
|
||||
}
|
||||
}
|
||||
|
||||
// JPEG
|
||||
if (bytes.length >= 4 && bytes[0] === 0xFF && bytes[1] === 0xD8) {
|
||||
let offset = 2;
|
||||
while (offset + 9 <= bytes.length) {
|
||||
if (bytes[offset] !== 0xFF) { offset++; continue; }
|
||||
const marker = bytes[offset + 1];
|
||||
if (marker === 0xD8 || marker === 0xD9) { offset += 2; continue; }
|
||||
if (offset + 4 > bytes.length) break;
|
||||
const segLen = readBE16(bytes, offset + 2);
|
||||
if (segLen < 2 || offset + 2 + segLen > bytes.length) break;
|
||||
if ((marker & 0xFC) === 0xC0 && offset + 9 <= bytes.length) {
|
||||
height = readBE16(bytes, offset + 5);
|
||||
width = readBE16(bytes, offset + 7);
|
||||
return { format: 1000, width, height };
|
||||
}
|
||||
offset += 2 + segLen;
|
||||
}
|
||||
return { format: 1000, width: 0, height: 0 };
|
||||
}
|
||||
|
||||
return { format: 1000, width: 0, height: 0 };
|
||||
}
|
||||
|
||||
// --- Highway frame packing/unpacking ---
|
||||
|
||||
export function packHighwayFrame(head: Uint8Array, body: Uint8Array): Uint8Array {
|
||||
const frame = new Uint8Array(9 + head.length + body.length + 1);
|
||||
frame[0] = 0x28;
|
||||
const dv = new DataView(frame.buffer, frame.byteOffset);
|
||||
dv.setUint32(1, head.length, false);
|
||||
dv.setUint32(5, body.length, false);
|
||||
frame.set(head, 9);
|
||||
frame.set(body, 9 + head.length);
|
||||
frame[frame.length - 1] = 0x29;
|
||||
return frame;
|
||||
}
|
||||
|
||||
export function unpackHighwayFrame(frame: Uint8Array): { head: Uint8Array; body: Uint8Array } {
|
||||
if (frame.length < 10 || frame[0] !== 0x28 || frame[frame.length - 1] !== 0x29) {
|
||||
throw new Error('invalid highway response frame');
|
||||
}
|
||||
const dv = new DataView(frame.buffer, frame.byteOffset);
|
||||
const headLen = dv.getUint32(1, false);
|
||||
const bodyLen = dv.getUint32(5, false);
|
||||
return {
|
||||
head: frame.subarray(9, 9 + headLen),
|
||||
body: frame.subarray(9 + headLen, 9 + headLen + bodyLen),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
// BridgeManager — manages per-UIN Bridge sessions.
|
||||
// Wires NtqqHandler packets to appropriate Bridge instances.
|
||||
// Port of src/bridge/include/bridge/manager.h + src/bridge/src/manager.cpp
|
||||
|
||||
import type { NtqqHandler } from '../protocol/ntqq-handler';
|
||||
import type { PacketInfo } from '../protocol/types';
|
||||
import type { QQEventVariant } from './events';
|
||||
import { Bridge } from './bridge';
|
||||
import { QQInfo } from './qq-info';
|
||||
import type { PacketSender } from '../protocol/packet-sender';
|
||||
import { createLogger } from '../utils/logger';
|
||||
|
||||
export type SessionStartedCallback = (uin: string, qqInfo: QQInfo, bridge: Bridge) => void;
|
||||
export type SessionClosedCallback = (uin: string) => void;
|
||||
export type BridgeEventCallback = (uin: string, event: QQEventVariant) => void;
|
||||
|
||||
interface QQSession {
|
||||
qqInfo: QQInfo;
|
||||
bridge: Bridge;
|
||||
}
|
||||
|
||||
const log = createLogger('Bridge');
|
||||
|
||||
export class BridgeManager {
|
||||
private sessions_ = new Map<string, QQSession>();
|
||||
private pidToUin_ = new Map<number, string>();
|
||||
private pidPacketClients_ = new Map<number, PacketSender>();
|
||||
|
||||
private onSessionStarted_: SessionStartedCallback | null = null;
|
||||
private onSessionClosed_: SessionClosedCallback | null = null;
|
||||
private onBridgeEvent_: BridgeEventCallback | null = null;
|
||||
|
||||
setSessionStartedCallback(cb: SessionStartedCallback): void { this.onSessionStarted_ = cb; }
|
||||
setSessionClosedCallback(cb: SessionClosedCallback): void { this.onSessionClosed_ = cb; }
|
||||
setEventCallback(cb: BridgeEventCallback): void { this.onBridgeEvent_ = cb; }
|
||||
|
||||
bind(ntqq: NtqqHandler): void {
|
||||
ntqq.registerCmdAll((pkt: PacketInfo) => this.onPacket(pkt));
|
||||
}
|
||||
|
||||
onPidDisconnected(pid: number): void {
|
||||
this.pidPacketClients_.delete(pid);
|
||||
const uin = this.pidToUin_.get(pid);
|
||||
if (!uin) return;
|
||||
|
||||
this.pidToUin_.delete(pid);
|
||||
const session = this.sessions_.get(uin);
|
||||
if (!session) return;
|
||||
|
||||
session.bridge.detachPid(pid);
|
||||
if (session.bridge.empty) {
|
||||
this.sessions_.delete(uin);
|
||||
log.debug('session closed: UIN=%s', uin);
|
||||
if (this.onSessionClosed_) this.onSessionClosed_(uin);
|
||||
}
|
||||
}
|
||||
|
||||
private static isRealUin(uin: string): boolean {
|
||||
if (!uin || uin === '0') return false;
|
||||
return /^\d+$/.test(uin) && uin.length >= 5;
|
||||
}
|
||||
|
||||
onHookLogin(pid: number, uin: string, packetClient: PacketSender): void {
|
||||
if (!BridgeManager.isRealUin(uin)) return;
|
||||
|
||||
this.pidPacketClients_.set(pid, packetClient);
|
||||
|
||||
const { session, created } = this.ensureSession(uin);
|
||||
session.bridge.attachPid(pid);
|
||||
session.bridge.setPacketClient(packetClient);
|
||||
this.pidToUin_.set(pid, uin);
|
||||
|
||||
if (created) {
|
||||
log.debug('session started: UIN=%s', uin);
|
||||
if (this.onSessionStarted_) {
|
||||
this.onSessionStarted_(uin, session.qqInfo, session.bridge);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private onPacket(pkt: PacketInfo): void {
|
||||
if (!pkt.uin || !BridgeManager.isRealUin(pkt.uin)) return;
|
||||
const uin = pkt.uin;
|
||||
|
||||
// Ensure session exists
|
||||
const { session, created } = this.ensureSession(uin);
|
||||
|
||||
// Attach PID if known
|
||||
if (pkt.pid && this.pidPacketClients_.has(pkt.pid)) {
|
||||
session.bridge.attachPid(pkt.pid);
|
||||
this.pidToUin_.set(pkt.pid, uin);
|
||||
|
||||
const client = this.pidPacketClients_.get(pkt.pid);
|
||||
if (client) session.bridge.setPacketClient(client);
|
||||
}
|
||||
|
||||
// Notify session started on first real packet
|
||||
if (created) {
|
||||
log.debug('session started: UIN=%s', uin);
|
||||
if (this.onSessionStarted_) {
|
||||
this.onSessionStarted_(uin, session.qqInfo, session.bridge);
|
||||
}
|
||||
}
|
||||
|
||||
// Dispatch packet to bridge
|
||||
session.bridge.onPacket(pkt);
|
||||
}
|
||||
|
||||
private ensureSession(uin: string): { session: QQSession; created: boolean } {
|
||||
let session = this.sessions_.get(uin);
|
||||
if (session) return { session, created: false };
|
||||
|
||||
const qqInfo = new QQInfo(uin);
|
||||
const bridge = new Bridge(qqInfo);
|
||||
session = { qqInfo, bridge };
|
||||
this.sessions_.set(uin, session);
|
||||
|
||||
// Wire event callback
|
||||
bridge.setEventCallback((event) => {
|
||||
if (this.onBridgeEvent_) this.onBridgeEvent_(uin, event);
|
||||
});
|
||||
|
||||
return { session, created: true };
|
||||
}
|
||||
|
||||
getSession(uin: string): QQSession | null {
|
||||
return this.sessions_.get(uin) ?? null;
|
||||
}
|
||||
|
||||
get sessions(): Map<string, { qqInfo: QQInfo; bridge: Bridge }> {
|
||||
return this.sessions_;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// Proto schemas for outgoing message actions.
|
||||
// Port of src/bridge/include/bridge/proto/action.h
|
||||
|
||||
import type { ProtoSchema } from '../../protobuf/decode';
|
||||
import { ElemSchema } from './element';
|
||||
|
||||
// --- Routing ---
|
||||
|
||||
export const RoutingC2CSchema = {
|
||||
uin: { field: 1, type: 'uint32' as const },
|
||||
uid: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const RoutingGroupSchema = {
|
||||
groupCode: { field: 1, type: 'uint64' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const RoutingHeadSchema = {
|
||||
c2c: { field: 1, type: 'message' as const, schema: RoutingC2CSchema },
|
||||
grp: { field: 2, type: 'message' as const, schema: RoutingGroupSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Content Head (for send) ---
|
||||
|
||||
export const SendContentHeadSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
subType: { field: 2, type: 'uint32' as const },
|
||||
c2cCmd: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Message Control ---
|
||||
|
||||
export const MessageControlSchema = {
|
||||
msgFlag: { field: 1, type: 'int32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- RichText (for send — only elems) ---
|
||||
|
||||
export const SendRichTextSchema = {
|
||||
elems: { field: 2, type: 'repeated_message' as const, schema: ElemSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- MessageBody (for send) ---
|
||||
|
||||
export const SendMessageBodySchema = {
|
||||
richText: { field: 1, type: 'message' as const, schema: SendRichTextSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- SendMessageRequest ---
|
||||
|
||||
export const SendMessageRequestSchema = {
|
||||
routingHead: { field: 1, type: 'message' as const, schema: RoutingHeadSchema },
|
||||
contentHead: { field: 2, type: 'message' as const, schema: SendContentHeadSchema },
|
||||
messageBody: { field: 3, type: 'message' as const, schema: SendMessageBodySchema },
|
||||
clientSequence: { field: 4, type: 'uint32' as const },
|
||||
random: { field: 5, type: 'uint32' as const },
|
||||
syncCookie: { field: 6, type: 'bytes' as const },
|
||||
via: { field: 8, type: 'uint32' as const },
|
||||
dataStatist: { field: 9, type: 'uint32' as const },
|
||||
ctrl: { field: 12, type: 'message' as const, schema: MessageControlSchema },
|
||||
multiSendSeq: { field: 14, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- SendMessageResponse ---
|
||||
|
||||
export const SendMessageResponseSchema = {
|
||||
result: { field: 1, type: 'int32' as const },
|
||||
errMsg: { field: 2, type: 'string' as const },
|
||||
timestamp1: { field: 3, type: 'uint32' as const },
|
||||
field10: { field: 10, type: 'uint32' as const },
|
||||
groupSequence: { field: 11, type: 'uint32' as const },
|
||||
timestamp2: { field: 12, type: 'uint32' as const },
|
||||
privateSequence: { field: 14, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- MentionExtra (for building @mention text element) ---
|
||||
|
||||
export const MentionExtraSendSchema = {
|
||||
type: { field: 3, type: 'int32' as const },
|
||||
uin: { field: 4, type: 'uint32' as const },
|
||||
field5: { field: 5, type: 'int32' as const },
|
||||
uid: { field: 9, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- MarkdownData ---
|
||||
|
||||
export const MarkdownDataSchema = {
|
||||
content: { field: 1, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
@@ -0,0 +1,418 @@
|
||||
// Proto schemas for QQ message elements.
|
||||
// Port of src/bridge/include/bridge/proto/element.h
|
||||
|
||||
import type { ProtoSchema } from '../../protobuf/decode';
|
||||
|
||||
// --- Nested / helper schemas ---
|
||||
|
||||
export const CustomFacePbReserveSchema = {
|
||||
subType: { field: 1, type: 'int32' as const },
|
||||
summary: { field: 9, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NotOnlineImagePbReserve2Schema = {
|
||||
field1: { field: 1, type: 'int32' as const },
|
||||
field2: { field: 2, type: 'string' as const },
|
||||
field3: { field: 3, type: 'int32' as const },
|
||||
field4: { field: 4, type: 'int32' as const },
|
||||
field5: { field: 5, type: 'int32' as const },
|
||||
field7: { field: 7, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NotOnlineImagePbReserveSchema = {
|
||||
subType: { field: 1, type: 'int32' as const },
|
||||
field3: { field: 3, type: 'int32' as const },
|
||||
field4: { field: 4, type: 'int32' as const },
|
||||
summary: { field: 8, type: 'string' as const },
|
||||
field10: { field: 10, type: 'int32' as const },
|
||||
field20: { field: 20, type: 'message' as const, schema: NotOnlineImagePbReserve2Schema },
|
||||
url: { field: 30, type: 'string' as const },
|
||||
md5Str: { field: 31, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Core element schemas ---
|
||||
|
||||
export const TextElemSchema = {
|
||||
str: { field: 1, type: 'string' as const },
|
||||
link: { field: 2, type: 'string' as const },
|
||||
attr6Buf: { field: 3, type: 'bytes' as const },
|
||||
attr7Buf: { field: 4, type: 'bytes' as const },
|
||||
buf: { field: 11, type: 'bytes' as const },
|
||||
pbReserve: { field: 12, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FaceElemSchema = {
|
||||
index: { field: 1, type: 'int32' as const },
|
||||
oldData: { field: 2, type: 'bytes' as const },
|
||||
buf: { field: 11, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OnlineImageSchema = {
|
||||
guid: { field: 1, type: 'bytes' as const },
|
||||
filePath: { field: 2, type: 'bytes' as const },
|
||||
oldVerSendFile: { field: 3, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NotOnlineImageSchema = {
|
||||
filePath: { field: 1, type: 'string' as const },
|
||||
fileLen: { field: 2, type: 'uint32' as const },
|
||||
downloadPath: { field: 3, type: 'string' as const },
|
||||
oldVerSendFile: { field: 4, type: 'bytes' as const },
|
||||
imgType: { field: 5, type: 'int32' as const },
|
||||
previewsImage: { field: 6, type: 'bytes' as const },
|
||||
picMd5: { field: 7, type: 'bytes' as const },
|
||||
picHeight: { field: 8, type: 'uint32' as const },
|
||||
picWidth: { field: 9, type: 'uint32' as const },
|
||||
resId: { field: 10, type: 'string' as const },
|
||||
flag: { field: 11, type: 'bytes' as const },
|
||||
thumbUrl: { field: 12, type: 'string' as const },
|
||||
original: { field: 13, type: 'int32' as const },
|
||||
bigUrl: { field: 14, type: 'string' as const },
|
||||
origUrl: { field: 15, type: 'string' as const },
|
||||
bizType: { field: 16, type: 'int32' as const },
|
||||
result: { field: 17, type: 'int32' as const },
|
||||
index: { field: 18, type: 'int32' as const },
|
||||
opFaceBuf: { field: 19, type: 'bytes' as const },
|
||||
oldPicMd5: { field: 20, type: 'bool' as const },
|
||||
thumbWidth: { field: 21, type: 'int32' as const },
|
||||
thumbHeight: { field: 22, type: 'int32' as const },
|
||||
fileId: { field: 23, type: 'int32' as const },
|
||||
showLen: { field: 24, type: 'uint32' as const },
|
||||
downloadLen: { field: 25, type: 'uint32' as const },
|
||||
x400Url: { field: 26, type: 'string' as const },
|
||||
x400Width: { field: 27, type: 'int32' as const },
|
||||
x400Height: { field: 28, type: 'int32' as const },
|
||||
pbRes: { field: 29, type: 'message' as const, schema: NotOnlineImagePbReserveSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const TransElemSchema = {
|
||||
elemType: { field: 1, type: 'int32' as const },
|
||||
elemValue: { field: 2, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const MarketFaceSchema = {
|
||||
faceName: { field: 1, type: 'string' as const },
|
||||
itemType: { field: 2, type: 'uint32' as const },
|
||||
faceInfo: { field: 3, type: 'uint32' as const },
|
||||
faceId: { field: 4, type: 'bytes' as const },
|
||||
tabId: { field: 5, type: 'uint32' as const },
|
||||
subType: { field: 6, type: 'uint32' as const },
|
||||
key: { field: 7, type: 'bytes' as const },
|
||||
param: { field: 8, type: 'bytes' as const },
|
||||
mediaType: { field: 9, type: 'uint32' as const },
|
||||
imageWidth: { field: 10, type: 'uint32' as const },
|
||||
imageHeight: { field: 11, type: 'uint32' as const },
|
||||
mobileParam: { field: 12, type: 'bytes' as const },
|
||||
pbReserve: { field: 13, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const CustomFaceSchema = {
|
||||
guid: { field: 1, type: 'bytes' as const },
|
||||
filePath: { field: 2, type: 'string' as const },
|
||||
shortcut: { field: 3, type: 'string' as const },
|
||||
buffer: { field: 4, type: 'bytes' as const },
|
||||
flag: { field: 5, type: 'bytes' as const },
|
||||
oldData: { field: 6, type: 'bytes' as const },
|
||||
fileId: { field: 7, type: 'uint32' as const },
|
||||
serverIp: { field: 8, type: 'int32' as const },
|
||||
serverPort: { field: 9, type: 'int32' as const },
|
||||
fileType: { field: 10, type: 'int32' as const },
|
||||
signature: { field: 11, type: 'bytes' as const },
|
||||
useful: { field: 12, type: 'int32' as const },
|
||||
md5: { field: 13, type: 'bytes' as const },
|
||||
thumbUrl: { field: 14, type: 'string' as const },
|
||||
bigUrl: { field: 15, type: 'string' as const },
|
||||
origUrl: { field: 16, type: 'string' as const },
|
||||
bizType: { field: 17, type: 'int32' as const },
|
||||
repeatIndex: { field: 18, type: 'int32' as const },
|
||||
repeatImage: { field: 19, type: 'int32' as const },
|
||||
imageType: { field: 20, type: 'int32' as const },
|
||||
index: { field: 21, type: 'int32' as const },
|
||||
width: { field: 22, type: 'int32' as const },
|
||||
height: { field: 23, type: 'int32' as const },
|
||||
source: { field: 24, type: 'int32' as const },
|
||||
size: { field: 25, type: 'uint32' as const },
|
||||
origin: { field: 26, type: 'int32' as const },
|
||||
thumbWidth: { field: 27, type: 'int32' as const },
|
||||
thumbHeight: { field: 28, type: 'int32' as const },
|
||||
showLen: { field: 29, type: 'int32' as const },
|
||||
downloadLen: { field: 30, type: 'int32' as const },
|
||||
x400Url: { field: 31, type: 'string' as const },
|
||||
x400Width: { field: 32, type: 'int32' as const },
|
||||
x400Height: { field: 33, type: 'int32' as const },
|
||||
pbRes: { field: 34, type: 'message' as const, schema: CustomFacePbReserveSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const RichMsgSchema = {
|
||||
template1: { field: 1, type: 'bytes' as const },
|
||||
serviceId: { field: 2, type: 'int32' as const },
|
||||
msgResId: { field: 3, type: 'bytes' as const },
|
||||
rand: { field: 4, type: 'int32' as const },
|
||||
seq: { field: 5, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupFileElemSchema = {
|
||||
filename: { field: 1, type: 'string' as const },
|
||||
fileSize: { field: 2, type: 'uint64' as const },
|
||||
fileId: { field: 3, type: 'string' as const },
|
||||
batchId: { field: 4, type: 'string' as const },
|
||||
fileKey: { field: 5, type: 'string' as const },
|
||||
mark: { field: 6, type: 'bytes' as const },
|
||||
sequence: { field: 7, type: 'uint64' as const },
|
||||
batchItemId: { field: 8, type: 'bytes' as const },
|
||||
feedMsgTime: { field: 9, type: 'int32' as const },
|
||||
pbReserve: { field: 10, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const ExtraInfoSchema = {
|
||||
nick: { field: 1, type: 'bytes' as const },
|
||||
groupCard: { field: 2, type: 'bytes' as const },
|
||||
level: { field: 3, type: 'int32' as const },
|
||||
flags: { field: 4, type: 'int32' as const },
|
||||
groupMask: { field: 5, type: 'int32' as const },
|
||||
msgTailId: { field: 6, type: 'int32' as const },
|
||||
senderTitle: { field: 7, type: 'bytes' as const },
|
||||
apnsTips: { field: 8, type: 'bytes' as const },
|
||||
uin: { field: 9, type: 'uint64' as const },
|
||||
msgStateFlag: { field: 10, type: 'int32' as const },
|
||||
apnsSoundType: { field: 11, type: 'int32' as const },
|
||||
newGroupFlag: { field: 12, type: 'int32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const VideoFileSchema = {
|
||||
fileUuid: { field: 1, type: 'string' as const },
|
||||
fileMd5: { field: 2, type: 'bytes' as const },
|
||||
fileName: { field: 3, type: 'string' as const },
|
||||
fileFormat: { field: 4, type: 'int32' as const },
|
||||
fileTime: { field: 5, type: 'int32' as const },
|
||||
fileSize: { field: 6, type: 'int32' as const },
|
||||
thumbWidth: { field: 7, type: 'int32' as const },
|
||||
thumbHeight: { field: 8, type: 'int32' as const },
|
||||
thumbFileMd5: { field: 9, type: 'bytes' as const },
|
||||
source: { field: 10, type: 'bytes' as const },
|
||||
thumbFileSize:{ field: 11, type: 'int32' as const },
|
||||
busiType: { field: 12, type: 'int32' as const },
|
||||
fromChatType: { field: 13, type: 'int32' as const },
|
||||
toChatType: { field: 14, type: 'int32' as const },
|
||||
supportProgressive: { field: 15, type: 'bool' as const },
|
||||
fileWidth: { field: 16, type: 'int32' as const },
|
||||
fileHeight: { field: 17, type: 'int32' as const },
|
||||
subBusiType: { field: 18, type: 'int32' as const },
|
||||
videoAttr: { field: 19, type: 'int32' as const },
|
||||
pbReserve: { field: 24, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const SrcMsgSchema = {
|
||||
origSeqs: { field: 1, type: 'repeated_uint32' as const },
|
||||
senderUin: { field: 2, type: 'uint64' as const },
|
||||
time: { field: 3, type: 'int32' as const },
|
||||
flag: { field: 4, type: 'int32' as const },
|
||||
elemsRaw: { field: 5, type: 'repeated_bytes' as const },
|
||||
type: { field: 6, type: 'int32' as const },
|
||||
richMsg: { field: 7, type: 'bytes' as const },
|
||||
pbReserve: { field: 8, type: 'bytes' as const },
|
||||
sourceMsg: { field: 9, type: 'bytes' as const },
|
||||
toUin: { field: 10, type: 'uint64' as const },
|
||||
troopName: { field: 11, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const LightAppElemSchema = {
|
||||
data: { field: 1, type: 'bytes' as const },
|
||||
msgResid: { field: 2, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const CommonElemSchema = {
|
||||
serviceType: { field: 1, type: 'int32' as const },
|
||||
pbElem: { field: 2, type: 'bytes' as const },
|
||||
businessType: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GeneralFlagsSchema = {
|
||||
bubbleDiyTextId: { field: 1, type: 'int32' as const },
|
||||
groupFlagNew: { field: 2, type: 'int32' as const },
|
||||
uin: { field: 3, type: 'uint64' as const },
|
||||
longTextFlag: { field: 6, type: 'int32' as const },
|
||||
longTextResId: { field: 7, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Elem (union of all element types) ---
|
||||
|
||||
export const ElemSchema = {
|
||||
text: { field: 1, type: 'message' as const, schema: TextElemSchema },
|
||||
face: { field: 2, type: 'message' as const, schema: FaceElemSchema },
|
||||
onlineImage: { field: 3, type: 'message' as const, schema: OnlineImageSchema },
|
||||
notOnlineImage: { field: 4, type: 'message' as const, schema: NotOnlineImageSchema },
|
||||
transElem: { field: 5, type: 'message' as const, schema: TransElemSchema },
|
||||
marketFace: { field: 6, type: 'message' as const, schema: MarketFaceSchema },
|
||||
customFace: { field: 8, type: 'message' as const, schema: CustomFaceSchema },
|
||||
richMsg: { field: 12, type: 'message' as const, schema: RichMsgSchema },
|
||||
groupFile: { field: 13, type: 'message' as const, schema: GroupFileElemSchema },
|
||||
extraInfo: { field: 16, type: 'message' as const, schema: ExtraInfoSchema },
|
||||
videoFile: { field: 19, type: 'message' as const, schema: VideoFileSchema },
|
||||
generalFlags: { field: 37, type: 'message' as const, schema: GeneralFlagsSchema },
|
||||
srcMsg: { field: 45, type: 'message' as const, schema: SrcMsgSchema },
|
||||
lightApp: { field: 51, type: 'message' as const, schema: LightAppElemSchema },
|
||||
commonElem: { field: 53, type: 'message' as const, schema: CommonElemSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Extra decode types (for CommonElem.pbElem sub-messages) ---
|
||||
|
||||
export const MentionExtraSchema = {
|
||||
type: { field: 3, type: 'int32' as const },
|
||||
uin: { field: 4, type: 'uint32' as const },
|
||||
field5: { field: 5, type: 'int32' as const },
|
||||
uid: { field: 9, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const QFaceExtraSchema = {
|
||||
packId: { field: 1, type: 'string' as const },
|
||||
stickerId: { field: 2, type: 'string' as const },
|
||||
qsid: { field: 3, type: 'int32' as const },
|
||||
sourceType: { field: 4, type: 'int32' as const },
|
||||
stickerType: { field: 5, type: 'int32' as const },
|
||||
resultId: { field: 6, type: 'string' as const },
|
||||
text: { field: 7, type: 'string' as const },
|
||||
randomType: { field: 9, type: 'int32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const QSmallFaceExtraSchema = {
|
||||
faceId: { field: 1, type: 'uint32' as const },
|
||||
preview: { field: 2, type: 'string' as const },
|
||||
preview2: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- NTQQ MsgInfo types (CommonElem service_type 48) ---
|
||||
|
||||
export const FileTypeSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
picFormat: { field: 2, type: 'uint32' as const },
|
||||
videoFormat: { field: 3, type: 'uint32' as const },
|
||||
voiceFormat: { field: 4, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileInfoSchema = {
|
||||
fileSize: { field: 1, type: 'uint32' as const },
|
||||
fileHash: { field: 2, type: 'string' as const },
|
||||
fileSha1: { field: 3, type: 'string' as const },
|
||||
fileName: { field: 4, type: 'string' as const },
|
||||
type: { field: 5, type: 'message' as const, schema: FileTypeSchema },
|
||||
width: { field: 6, type: 'uint32' as const },
|
||||
height: { field: 7, type: 'uint32' as const },
|
||||
time: { field: 8, type: 'uint32' as const },
|
||||
original: { field: 9, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const IndexNodeSchema = {
|
||||
info: { field: 1, type: 'message' as const, schema: FileInfoSchema },
|
||||
fileUuid: { field: 2, type: 'string' as const },
|
||||
storeId: { field: 3, type: 'uint32' as const },
|
||||
uploadTime: { field: 4, type: 'uint32' as const },
|
||||
ttl: { field: 5, type: 'uint32' as const },
|
||||
subType: { field: 6, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const PicUrlExtInfoSchema = {
|
||||
originalParameter: { field: 1, type: 'string' as const },
|
||||
bigParameter: { field: 2, type: 'string' as const },
|
||||
thumbParameter: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const PictureInfoSchema = {
|
||||
urlPath: { field: 1, type: 'string' as const },
|
||||
ext: { field: 2, type: 'message' as const, schema: PicUrlExtInfoSchema },
|
||||
domain: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const PicExtDataSchema = {
|
||||
subType: { field: 1, type: 'uint32' as const },
|
||||
textSummary: { field: 9, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const PicExtBizInfoSchema = {
|
||||
bizType: { field: 1, type: 'uint32' as const },
|
||||
textSummary: { field: 2, type: 'string' as const },
|
||||
bytesPbReserveC2c: { field: 11, type: 'bytes' as const },
|
||||
extData: { field: 12, type: 'message' as const, schema: PicExtDataSchema },
|
||||
fromScene: { field: 1001, type: 'uint32' as const },
|
||||
toScene: { field: 1002, type: 'uint32' as const },
|
||||
oldFileId: { field: 1003, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const VideoExtBizInfoSchema = {
|
||||
fromScene: { field: 1, type: 'uint32' as const },
|
||||
toScene: { field: 2, type: 'uint32' as const },
|
||||
bytesPbReserve: { field: 3, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const PttExtBizInfoSchema = {
|
||||
srcUin: { field: 1, type: 'uint64' as const },
|
||||
pttScene: { field: 2, type: 'uint32' as const },
|
||||
pttType: { field: 3, type: 'uint32' as const },
|
||||
changeVoice: { field: 4, type: 'uint32' as const },
|
||||
waveform: { field: 5, type: 'bytes' as const },
|
||||
autoConvertText: { field: 6, type: 'uint32' as const },
|
||||
bytesReserve: { field: 11, type: 'bytes' as const },
|
||||
bytesPbReserve: { field: 12, type: 'bytes' as const },
|
||||
bytesGeneralFlags: { field: 13, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const ExtBizInfoSchema = {
|
||||
pic: { field: 1, type: 'message' as const, schema: PicExtBizInfoSchema },
|
||||
video: { field: 2, type: 'message' as const, schema: VideoExtBizInfoSchema },
|
||||
ptt: { field: 3, type: 'message' as const, schema: PttExtBizInfoSchema },
|
||||
busiType: { field: 10, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const C2cSourceSchema = {
|
||||
friendUid: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const TroopSourceSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const HashSumSchema = {
|
||||
bytesPbReserveC2c: { field: 201, type: 'message' as const, schema: C2cSourceSchema },
|
||||
troopSource: { field: 202, type: 'message' as const, schema: TroopSourceSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const MsgInfoBodySchema = {
|
||||
index: { field: 1, type: 'message' as const, schema: IndexNodeSchema },
|
||||
picture: { field: 2, type: 'message' as const, schema: PictureInfoSchema },
|
||||
fileExist: { field: 5, type: 'bool' as const },
|
||||
hashSum: { field: 6, type: 'message' as const, schema: HashSumSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const MsgInfoSchema = {
|
||||
msgInfoBody: { field: 1, type: 'repeated_message' as const, schema: MsgInfoBodySchema },
|
||||
extBizInfo: { field: 2, type: 'message' as const, schema: ExtBizInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- GroupFileExtra (TransElem type=24) ---
|
||||
|
||||
export const GroupFileInfoSchema = {
|
||||
busId: { field: 1, type: 'uint32' as const },
|
||||
fileId: { field: 2, type: 'string' as const },
|
||||
fileSize: { field: 3, type: 'uint64' as const },
|
||||
fileName: { field: 4, type: 'string' as const },
|
||||
fileSha: { field: 5, type: 'bytes' as const },
|
||||
extInfoString: { field: 6, type: 'string' as const },
|
||||
fileMd5: { field: 7, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupFileExtraInnerSchema = {
|
||||
info: { field: 2, type: 'message' as const, schema: GroupFileInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupFileExtraSchema = {
|
||||
inner: { field: 7, type: 'message' as const, schema: GroupFileExtraInnerSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Preserve (for message receipt info) ---
|
||||
|
||||
export const PreserveSchema = {
|
||||
messageId: { field: 3, type: 'uint64' as const },
|
||||
senderUid: { field: 6, type: 'string' as const },
|
||||
receiverUid: { field: 7, type: 'string' as const },
|
||||
clientSequence: { field: 8, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
@@ -0,0 +1,354 @@
|
||||
// Proto schemas for highway upload protocol.
|
||||
// Port of src/bridge/include/bridge/proto/highway.h + action.h (HttpConn)
|
||||
|
||||
import type { ProtoSchema } from '../../protobuf/decode';
|
||||
import {
|
||||
IndexNodeSchema,
|
||||
PictureInfoSchema,
|
||||
HashSumSchema,
|
||||
PicExtBizInfoSchema,
|
||||
VideoExtBizInfoSchema,
|
||||
PttExtBizInfoSchema,
|
||||
} from '../proto/element';
|
||||
|
||||
// --- DataHighwayHead ---
|
||||
|
||||
export const DataHighwayHeadSchema = {
|
||||
version: { field: 1, type: 'uint32' as const },
|
||||
uin: { field: 2, type: 'string' as const },
|
||||
command: { field: 3, type: 'string' as const },
|
||||
seq: { field: 4, type: 'uint32' as const },
|
||||
retryTimes:{ field: 5, type: 'uint32' as const },
|
||||
appId: { field: 6, type: 'uint32' as const },
|
||||
dataFlag: { field: 7, type: 'uint32' as const },
|
||||
commandId: { field: 8, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const SegHeadSchema = {
|
||||
serviceId: { field: 1, type: 'uint32' as const },
|
||||
filesize: { field: 2, type: 'uint64' as const },
|
||||
dataOffset: { field: 3, type: 'uint64' as const },
|
||||
dataLength: { field: 4, type: 'uint32' as const },
|
||||
retCode: { field: 5, type: 'uint32' as const },
|
||||
serviceTicket: { field: 6, type: 'bytes' as const },
|
||||
flag: { field: 7, type: 'uint32' as const },
|
||||
md5: { field: 8, type: 'bytes' as const },
|
||||
fileMd5: { field: 9, type: 'bytes' as const },
|
||||
cacheAddr: { field: 10, type: 'uint32' as const },
|
||||
cachePort: { field: 13, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const LoginSigHeadSchema = {
|
||||
loginSigType: { field: 1, type: 'uint32' as const },
|
||||
appId: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const ReqDataHighwayHeadSchema = {
|
||||
msgBaseHead: { field: 1, type: 'message' as const, schema: DataHighwayHeadSchema },
|
||||
msgSegHead: { field: 2, type: 'message' as const, schema: SegHeadSchema },
|
||||
bytesReqExtendInfo: { field: 3, type: 'bytes' as const },
|
||||
timestamp: { field: 4, type: 'uint64' as const },
|
||||
msgLoginSigHead: { field: 5, type: 'message' as const, schema: LoginSigHeadSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const RespDataHighwayHeadSchema = {
|
||||
msgBaseHead: { field: 1, type: 'message' as const, schema: DataHighwayHeadSchema },
|
||||
msgSegHead: { field: 2, type: 'message' as const, schema: SegHeadSchema },
|
||||
errorCode: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Highway extend (NTV2RichMediaHighwayExt) ---
|
||||
|
||||
export const HighwayDomainSchema = {
|
||||
isEnable: { field: 1, type: 'bool' as const },
|
||||
ip: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const HighwayIPv4Schema = {
|
||||
domain: { field: 1, type: 'message' as const, schema: HighwayDomainSchema },
|
||||
port: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const HighwayNetworkSchema = {
|
||||
ipv4s: { field: 1, type: 'repeated_message' as const, schema: HighwayIPv4Schema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const HighwayHashSchema = {
|
||||
fileSha1: { field: 1, type: 'repeated_bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const HighwayMsgInfoBodySchema = {
|
||||
index: { field: 1, type: 'message' as const, schema: IndexNodeSchema },
|
||||
picture: { field: 2, type: 'message' as const, schema: PictureInfoSchema },
|
||||
fileExist: { field: 5, type: 'bool' as const },
|
||||
hashSum: { field: 6, type: 'message' as const, schema: HashSumSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2RichMediaHighwayExtSchema = {
|
||||
fileUuid: { field: 1, type: 'string' as const },
|
||||
uKey: { field: 2, type: 'string' as const },
|
||||
network: { field: 5, type: 'message' as const, schema: HighwayNetworkSchema },
|
||||
msgInfoBody: { field: 6, type: 'repeated_message' as const, schema: HighwayMsgInfoBodySchema },
|
||||
blockSize: { field: 10, type: 'uint32' as const },
|
||||
hash: { field: 11, type: 'message' as const, schema: HighwayHashSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- File upload extend (group/private file highway) ---
|
||||
|
||||
export const FileUploadUrlSchema = {
|
||||
unknown: { field: 1, type: 'int32' as const },
|
||||
host: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileUploadHostSchema = {
|
||||
url: { field: 1, type: 'message' as const, schema: FileUploadUrlSchema },
|
||||
port: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileUploadHostConfigSchema = {
|
||||
hosts: { field: 200, type: 'repeated_message' as const, schema: FileUploadHostSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileUploadNameInfoSchema = {
|
||||
fileName: { field: 100, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileUploadClientInfoSchema = {
|
||||
clientType: { field: 100, type: 'int32' as const },
|
||||
appId: { field: 200, type: 'string' as const },
|
||||
terminalType: { field: 300, type: 'int32' as const },
|
||||
clientVer: { field: 400, type: 'string' as const },
|
||||
unknown: { field: 600, type: 'int32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileUploadFileEntrySchema = {
|
||||
fileSize: { field: 100, type: 'uint64' as const },
|
||||
md5: { field: 200, type: 'bytes' as const },
|
||||
checkKey: { field: 300, type: 'bytes' as const },
|
||||
md5S2: { field: 400, type: 'bytes' as const },
|
||||
fileId: { field: 600, type: 'string' as const },
|
||||
uploadKey: { field: 700, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileUploadBusiInfoSchema = {
|
||||
busId: { field: 1, type: 'int32' as const },
|
||||
senderUin: { field: 100, type: 'uint64' as const },
|
||||
receiverUin: { field: 200, type: 'uint64' as const },
|
||||
groupCode: { field: 400, type: 'uint64' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileUploadEntrySchema = {
|
||||
busiBuff: { field: 100, type: 'message' as const, schema: FileUploadBusiInfoSchema },
|
||||
fileEntry: { field: 200, type: 'message' as const, schema: FileUploadFileEntrySchema },
|
||||
clientInfo: { field: 300, type: 'message' as const, schema: FileUploadClientInfoSchema },
|
||||
fileNameInfo: { field: 400, type: 'message' as const, schema: FileUploadNameInfoSchema },
|
||||
host: { field: 500, type: 'message' as const, schema: FileUploadHostConfigSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileUploadExtSchema = {
|
||||
unknown1: { field: 1, type: 'int32' as const },
|
||||
unknown2: { field: 2, type: 'int32' as const },
|
||||
unknown3: { field: 3, type: 'int32' as const },
|
||||
entry: { field: 100, type: 'message' as const, schema: FileUploadEntrySchema },
|
||||
unknown200: { field: 200, type: 'int32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Encodable MsgInfo (for embedding in message element) ---
|
||||
|
||||
export const EncodableMediaExtBizInfoSchema = {
|
||||
pic: { field: 1, type: 'message' as const, schema: PicExtBizInfoSchema },
|
||||
video: { field: 2, type: 'message' as const, schema: VideoExtBizInfoSchema },
|
||||
ptt: { field: 3, type: 'message' as const, schema: PttExtBizInfoSchema },
|
||||
busiType: { field: 10, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const EncodableMediaMsgInfoSchema = {
|
||||
msgInfoBody: { field: 1, type: 'repeated_message' as const, schema: HighwayMsgInfoBodySchema },
|
||||
extBizInfo: { field: 2, type: 'message' as const, schema: EncodableMediaExtBizInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- HttpConn.0x6ff_501 (highway session) ---
|
||||
|
||||
export const HttpConnSchema = {
|
||||
field1: { field: 1, type: 'int32' as const },
|
||||
field2: { field: 2, type: 'int32' as const },
|
||||
field3: { field: 3, type: 'int32' as const },
|
||||
field4: { field: 4, type: 'int32' as const },
|
||||
field6: { field: 6, type: 'int32' as const },
|
||||
serviceTypes: { field: 7, type: 'repeated_uint32' as const },
|
||||
field9: { field: 9, type: 'int32' as const },
|
||||
field10: { field: 10, type: 'int32' as const },
|
||||
field11: { field: 11, type: 'int32' as const },
|
||||
ver: { field: 15, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const HttpConn0x6FF501RequestSchema = {
|
||||
httpConn: { field: 0x501, type: 'message' as const, schema: HttpConnSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const ServerAddrSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
ip: { field: 2, type: 'uint32' as const }, // fixed32 as uint32
|
||||
port: { field: 3, type: 'uint32' as const },
|
||||
area: { field: 4, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const ServerInfoSchema = {
|
||||
serviceType: { field: 1, type: 'uint32' as const },
|
||||
serverAddrs: { field: 2, type: 'repeated_message' as const, schema: ServerAddrSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const HttpConnResponseSchema = {
|
||||
sigSession: { field: 1, type: 'bytes' as const },
|
||||
sessionKey: { field: 2, type: 'bytes' as const },
|
||||
serverInfos: { field: 3, type: 'repeated_message' as const, schema: ServerInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const HttpConn0x6FF501ResponseSchema = {
|
||||
httpConn: { field: 0x501, type: 'message' as const, schema: HttpConnResponseSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- NTV2 Upload Request (for OIDB 0x11C4/0x11C5) ---
|
||||
|
||||
export const NTV2FileTypeSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
picFormat: { field: 2, type: 'uint32' as const },
|
||||
videoFormat: { field: 3, type: 'uint32' as const },
|
||||
voiceFormat: { field: 4, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2FileInfoSchema = {
|
||||
fileSize: { field: 1, type: 'uint32' as const },
|
||||
fileHash: { field: 2, type: 'string' as const },
|
||||
fileSha1: { field: 3, type: 'string' as const },
|
||||
fileName: { field: 4, type: 'string' as const },
|
||||
type: { field: 5, type: 'message' as const, schema: NTV2FileTypeSchema },
|
||||
width: { field: 6, type: 'uint32' as const },
|
||||
height: { field: 7, type: 'uint32' as const },
|
||||
time: { field: 8, type: 'uint32' as const },
|
||||
original: { field: 9, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2UploadInfoSchema = {
|
||||
fileInfo: { field: 1, type: 'message' as const, schema: NTV2FileInfoSchema },
|
||||
subFileType: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2PicReserveC2CSchema = {
|
||||
subType: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2PicReserveTroopSchema = {
|
||||
subType: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2PicExtBizInfoSchema = {
|
||||
bizType: { field: 1, type: 'uint32' as const },
|
||||
textSummary: { field: 2, type: 'string' as const },
|
||||
reserveC2c: { field: 11, type: 'message' as const, schema: NTV2PicReserveC2CSchema },
|
||||
reserveTroop: { field: 12, type: 'message' as const, schema: NTV2PicReserveTroopSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2VideoExtBizInfoSchema = {
|
||||
bytesPbReserve: { field: 3, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2PttExtBizInfoSchema = {
|
||||
bytesReserve: { field: 11, type: 'bytes' as const },
|
||||
bytesPbReserve: { field: 12, type: 'bytes' as const },
|
||||
bytesGeneralFlags: { field: 13, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2ExtBizInfoSchema = {
|
||||
pic: { field: 1, type: 'message' as const, schema: NTV2PicExtBizInfoSchema },
|
||||
video: { field: 2, type: 'message' as const, schema: NTV2VideoExtBizInfoSchema },
|
||||
ptt: { field: 3, type: 'message' as const, schema: NTV2PttExtBizInfoSchema },
|
||||
busiType: { field: 10, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2UploadReqSchema = {
|
||||
uploadInfo: { field: 1, type: 'repeated_message' as const, schema: NTV2UploadInfoSchema },
|
||||
tryFastUploadCompleted: { field: 2, type: 'bool' as const },
|
||||
srvSendMsg: { field: 3, type: 'bool' as const },
|
||||
clientRandomId: { field: 4, type: 'uint64' as const },
|
||||
compatQmsgSceneType: { field: 5, type: 'uint32' as const },
|
||||
extBizInfo: { field: 6, type: 'message' as const, schema: NTV2ExtBizInfoSchema },
|
||||
clientSeq: { field: 7, type: 'uint32' as const },
|
||||
noNeedCompatMsg: { field: 8, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2C2CUserInfoSchema = {
|
||||
accountType: { field: 1, type: 'uint32' as const },
|
||||
targetUid: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2GroupInfoSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2UploadSceneInfoSchema = {
|
||||
requestType: { field: 101, type: 'uint32' as const },
|
||||
businessType: { field: 102, type: 'uint32' as const },
|
||||
sceneType: { field: 200, type: 'uint32' as const },
|
||||
c2c: { field: 201, type: 'message' as const, schema: NTV2C2CUserInfoSchema },
|
||||
group: { field: 202, type: 'message' as const, schema: NTV2GroupInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2CommonHeadSchema = {
|
||||
requestId: { field: 1, type: 'uint32' as const },
|
||||
command: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2ClientMetaSchema = {
|
||||
agentType: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2UploadReqHeadSchema = {
|
||||
common: { field: 1, type: 'message' as const, schema: NTV2CommonHeadSchema },
|
||||
scene: { field: 2, type: 'message' as const, schema: NTV2UploadSceneInfoSchema },
|
||||
client: { field: 3, type: 'message' as const, schema: NTV2ClientMetaSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2UploadRichMediaReqSchema = {
|
||||
reqHead: { field: 1, type: 'message' as const, schema: NTV2UploadReqHeadSchema },
|
||||
upload: { field: 2, type: 'message' as const, schema: NTV2UploadReqSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- NTV2 Upload Response ---
|
||||
|
||||
export const NTV2IPv4Schema = {
|
||||
outIp: { field: 1, type: 'uint32' as const },
|
||||
outPort: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2SubFileInfoRespSchema = {
|
||||
subType: { field: 1, type: 'uint32' as const },
|
||||
uKey: { field: 2, type: 'string' as const },
|
||||
uKeyTtl: { field: 3, type: 'uint32' as const },
|
||||
ipv4s: { field: 4, type: 'repeated_message' as const, schema: NTV2IPv4Schema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2UploadRespMsgInfoSchema = {
|
||||
msgInfoBody: { field: 1, type: 'repeated_message' as const, schema: HighwayMsgInfoBodySchema },
|
||||
extBizInfo: { field: 2, type: 'message' as const, schema: NTV2ExtBizInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2UploadRespBodySchema = {
|
||||
uKey: { field: 1, type: 'string' as const },
|
||||
uKeyTtl: { field: 2, type: 'uint32' as const },
|
||||
ipv4s: { field: 3, type: 'repeated_message' as const, schema: NTV2IPv4Schema },
|
||||
msgSeq: { field: 5, type: 'uint64' as const },
|
||||
msgInfo: { field: 6, type: 'message' as const, schema: NTV2UploadRespMsgInfoSchema },
|
||||
subFileInfos: { field: 10, type: 'repeated_message' as const, schema: NTV2SubFileInfoRespSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2UploadRespHeadSchema = {
|
||||
common: { field: 1, type: 'message' as const, schema: NTV2CommonHeadSchema },
|
||||
retCode: { field: 2, type: 'uint32' as const },
|
||||
message: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2UploadRichMediaRespSchema = {
|
||||
respHead: { field: 1, type: 'message' as const, schema: NTV2UploadRespHeadSchema },
|
||||
upload: { field: 2, type: 'message' as const, schema: NTV2UploadRespBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { ProtoSchema } from '../../protobuf/decode';
|
||||
import { PushMsgBodySchema } from './message';
|
||||
|
||||
export const LongMsgUidSchema = {
|
||||
uid: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const LongMsgSettingsSchema = {
|
||||
field1: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
field4: { field: 4, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const SendLongMsgInfoSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
uid: { field: 2, type: 'message' as const, schema: LongMsgUidSchema },
|
||||
groupUin: { field: 3, type: 'uint32' as const },
|
||||
payload: { field: 4, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const SendLongMsgReqSchema = {
|
||||
info: { field: 2, type: 'message' as const, schema: SendLongMsgInfoSchema },
|
||||
settings: { field: 15, type: 'message' as const, schema: LongMsgSettingsSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const SendLongMsgRespResultSchema = {
|
||||
resId: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const SendLongMsgRespSchema = {
|
||||
result: { field: 2, type: 'message' as const, schema: SendLongMsgRespResultSchema },
|
||||
settings: { field: 15, type: 'message' as const, schema: LongMsgSettingsSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const RecvLongMsgInfoSchema = {
|
||||
uid: { field: 1, type: 'message' as const, schema: LongMsgUidSchema },
|
||||
resId: { field: 2, type: 'string' as const },
|
||||
acquire: { field: 3, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const RecvLongMsgReqSchema = {
|
||||
info: { field: 1, type: 'message' as const, schema: RecvLongMsgInfoSchema },
|
||||
settings: { field: 15, type: 'message' as const, schema: LongMsgSettingsSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const RecvLongMsgRespResultSchema = {
|
||||
resId: { field: 3, type: 'string' as const },
|
||||
payload: { field: 4, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const RecvLongMsgRespSchema = {
|
||||
result: { field: 1, type: 'message' as const, schema: RecvLongMsgRespResultSchema },
|
||||
settings: { field: 15, type: 'message' as const, schema: LongMsgSettingsSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const LongMsgContentSchema = {
|
||||
msgBody: { field: 1, type: 'repeated_message' as const, schema: PushMsgBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const LongMsgActionSchema = {
|
||||
actionCommand: { field: 1, type: 'string' as const },
|
||||
actionData: { field: 2, type: 'message' as const, schema: LongMsgContentSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const LongMsgResultSchema = {
|
||||
action: { field: 2, type: 'repeated_message' as const, schema: LongMsgActionSchema },
|
||||
} satisfies ProtoSchema;
|
||||
@@ -0,0 +1,113 @@
|
||||
// Proto schemas for message envelopes (PushMsg).
|
||||
// Port of src/bridge/include/bridge/proto/message.h
|
||||
|
||||
import type { ProtoSchema } from '../../protobuf/decode';
|
||||
import { ElemSchema } from './element';
|
||||
|
||||
// --- ResponseHead.Grp ---
|
||||
|
||||
export const ResponseGrpSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
memberName: { field: 2, type: 'string' as const },
|
||||
groupName: { field: 4, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const ResponseForwardSchema = {
|
||||
friendName: { field: 6, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- ResponseHead ---
|
||||
|
||||
export const ResponseHeadSchema = {
|
||||
fromUin: { field: 1, type: 'uint32' as const },
|
||||
fromUid: { field: 2, type: 'string' as const },
|
||||
type: { field: 3, type: 'uint32' as const },
|
||||
sigMap: { field: 4, type: 'uint32' as const },
|
||||
toUin: { field: 5, type: 'uint32' as const },
|
||||
toUid: { field: 6, type: 'string' as const },
|
||||
forward: { field: 7, type: 'message' as const, schema: ResponseForwardSchema },
|
||||
grp: { field: 8, type: 'message' as const, schema: ResponseGrpSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- ContentHead ---
|
||||
|
||||
export const ContentHeadSchema = {
|
||||
msgType: { field: 1, type: 'uint32' as const },
|
||||
subType: { field: 2, type: 'uint32' as const },
|
||||
divSeq: { field: 3, type: 'uint32' as const },
|
||||
msgId: { field: 4, type: 'uint32' as const },
|
||||
sequence: { field: 5, type: 'uint32' as const },
|
||||
timestamp: { field: 6, type: 'uint32' as const },
|
||||
field7: { field: 7, type: 'uint64' as const },
|
||||
newId: { field: 12, type: 'uint64' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Ptt (voice) ---
|
||||
|
||||
export const PttSchema = {
|
||||
fileType: { field: 1, type: 'uint32' as const },
|
||||
fileId: { field: 2, type: 'uint64' as const },
|
||||
fileUuid: { field: 3, type: 'bytes' as const },
|
||||
fileMd5: { field: 4, type: 'bytes' as const },
|
||||
fileName: { field: 5, type: 'string' as const },
|
||||
fileSize: { field: 6, type: 'uint32' as const },
|
||||
groupFileKey: { field: 10, type: 'string' as const },
|
||||
fileKey: { field: 14, type: 'bytes' as const },
|
||||
time: { field: 19, type: 'uint32' as const },
|
||||
format: { field: 29, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- NotOnlineFile (C2C file) ---
|
||||
|
||||
export const NotOnlineFileSchema = {
|
||||
fileType: { field: 1, type: 'uint32' as const },
|
||||
fileUuid: { field: 3, type: 'string' as const },
|
||||
fileMd5: { field: 4, type: 'bytes' as const },
|
||||
fileName: { field: 5, type: 'string' as const },
|
||||
fileSize: { field: 6, type: 'uint64' as const },
|
||||
fileHash: { field: 57, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- RichText ---
|
||||
|
||||
export const RichTextSchema = {
|
||||
elems: { field: 2, type: 'repeated_message' as const, schema: ElemSchema },
|
||||
notOnlineFile: { field: 3, type: 'message' as const, schema: NotOnlineFileSchema },
|
||||
ptt: { field: 4, type: 'message' as const, schema: PttSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- MessageBody ---
|
||||
|
||||
export const MessageBodySchema = {
|
||||
richText: { field: 1, type: 'message' as const, schema: RichTextSchema },
|
||||
msgContent: { field: 2, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- FileExtra (for C2C file in msg_content) ---
|
||||
|
||||
export const FileExtraInfoSchema = {
|
||||
fileSize: { field: 1, type: 'uint64' as const },
|
||||
fileName: { field: 2, type: 'string' as const },
|
||||
fileMd5: { field: 3, type: 'bytes' as const },
|
||||
fileUuid: { field: 4, type: 'string' as const },
|
||||
fileHash: { field: 5, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FileExtraSchema = {
|
||||
file: { field: 1, type: 'message' as const, schema: FileExtraInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- PushMsgBody ---
|
||||
|
||||
export const PushMsgBodySchema = {
|
||||
responseHead: { field: 1, type: 'message' as const, schema: ResponseHeadSchema },
|
||||
contentHead: { field: 2, type: 'message' as const, schema: ContentHeadSchema },
|
||||
body: { field: 3, type: 'message' as const, schema: MessageBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- PushMsg (top-level) ---
|
||||
|
||||
export const PushMsgSchema = {
|
||||
message: { field: 1, type: 'message' as const, schema: PushMsgBodySchema },
|
||||
status: { field: 3, type: 'int32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
@@ -0,0 +1,207 @@
|
||||
// Proto schemas for notification types.
|
||||
// Port of src/bridge/include/bridge/proto/notify.h
|
||||
|
||||
import type { ProtoSchema } from '../../protobuf/decode';
|
||||
|
||||
export const OperatorField1Schema = {
|
||||
uid: { field: 1, type: 'string' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
field3: { field: 3, type: 'bytes' as const },
|
||||
field4: { field: 4, type: 'uint32' as const },
|
||||
field5: { field: 5, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OperatorInfoSchema = {
|
||||
operatorField: { field: 1, type: 'message' as const, schema: OperatorField1Schema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupChangeSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
flag: { field: 2, type: 'uint32' as const },
|
||||
memberUid: { field: 3, type: 'string' as const },
|
||||
decreaseType: { field: 4, type: 'uint32' as const },
|
||||
operatorBytes: { field: 5, type: 'bytes' as const },
|
||||
increaseType: { field: 6, type: 'uint32' as const },
|
||||
field7: { field: 7, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupAdminExtraSchema = {
|
||||
adminUid: { field: 1, type: 'string' as const },
|
||||
isPromote: { field: 2, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupAdminBodySchema = {
|
||||
extraDisable: { field: 1, type: 'message' as const, schema: GroupAdminExtraSchema },
|
||||
extraEnable: { field: 2, type: 'message' as const, schema: GroupAdminExtraSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupAdminSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
flag: { field: 2, type: 'uint32' as const },
|
||||
isPromote: { field: 3, type: 'bool' as const },
|
||||
body: { field: 4, type: 'message' as const, schema: GroupAdminBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const InvitationInnerSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
field4: { field: 4, type: 'uint32' as const },
|
||||
targetUid: { field: 5, type: 'string' as const },
|
||||
invitorUid: { field: 6, type: 'string' as const },
|
||||
field7: { field: 7, type: 'uint32' as const },
|
||||
field9: { field: 9, type: 'uint32' as const },
|
||||
field10: { field: 10, type: 'bytes' as const },
|
||||
field11: { field: 11, type: 'uint32' as const },
|
||||
field12: { field: 12, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const InvitationInfoSchema = {
|
||||
inner: { field: 1, type: 'message' as const, schema: InvitationInnerSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupInvitationSchema = {
|
||||
cmd: { field: 1, type: 'int32' as const },
|
||||
info: { field: 2, type: 'message' as const, schema: InvitationInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupInviteSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
field4: { field: 4, type: 'uint32' as const },
|
||||
invitorUid: { field: 5, type: 'string' as const },
|
||||
hashes: { field: 6, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupJoinSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
targetUid: { field: 3, type: 'string' as const },
|
||||
field4: { field: 4, type: 'uint32' as const },
|
||||
field6: { field: 6, type: 'uint32' as const },
|
||||
field7: { field: 7, type: 'string' as const },
|
||||
field8: { field: 8, type: 'uint32' as const },
|
||||
field9: { field: 9, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FriendRequestInfoSchema = {
|
||||
targetUid: { field: 1, type: 'string' as const },
|
||||
sourceUid: { field: 2, type: 'string' as const },
|
||||
newSource: { field: 5, type: 'string' as const },
|
||||
message: { field: 10, type: 'string' as const },
|
||||
source: { field: 11, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FriendRequestSchema = {
|
||||
info: { field: 1, type: 'message' as const, schema: FriendRequestInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FriendRecallTipInfoSchema = {
|
||||
tip: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FriendRecallInfoSchema = {
|
||||
fromUid: { field: 1, type: 'string' as const },
|
||||
toUid: { field: 2, type: 'string' as const },
|
||||
clientSequence: { field: 3, type: 'uint32' as const },
|
||||
newId: { field: 4, type: 'uint64' as const },
|
||||
time: { field: 5, type: 'uint32' as const },
|
||||
random: { field: 6, type: 'uint32' as const },
|
||||
pkgNum: { field: 7, type: 'uint32' as const },
|
||||
pkgIndex: { field: 8, type: 'uint32' as const },
|
||||
divSeq: { field: 9, type: 'uint32' as const },
|
||||
tipInfo: { field: 13, type: 'message' as const, schema: FriendRecallTipInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FriendRecallSchema = {
|
||||
info: { field: 1, type: 'message' as const, schema: FriendRecallInfoSchema },
|
||||
instId: { field: 2, type: 'uint32' as const },
|
||||
appId: { field: 3, type: 'uint32' as const },
|
||||
longMessageFlag: { field: 4, type: 'uint32' as const },
|
||||
reserved: { field: 5, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupMuteStateSchema = {
|
||||
targetUid: { field: 1, type: 'string' as const },
|
||||
duration: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupMuteDataSchema = {
|
||||
timestamp: { field: 1, type: 'uint32' as const },
|
||||
type: { field: 2, type: 'uint32' as const },
|
||||
state: { field: 3, type: 'message' as const, schema: GroupMuteStateSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupMuteSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
subType: { field: 2, type: 'uint32' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
operatorUid: { field: 4, type: 'string' as const },
|
||||
data: { field: 5, type: 'message' as const, schema: GroupMuteDataSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const RecallMessageSchema = {
|
||||
sequence: { field: 1, type: 'uint32' as const },
|
||||
time: { field: 2, type: 'uint32' as const },
|
||||
random: { field: 3, type: 'uint32' as const },
|
||||
type: { field: 4, type: 'uint32' as const },
|
||||
flag: { field: 5, type: 'uint32' as const },
|
||||
authorUid: { field: 6, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupRecallTipInfoSchema = {
|
||||
tip: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupRecallSchema = {
|
||||
operatorUid: { field: 1, type: 'string' as const },
|
||||
recallMessages: { field: 3, type: 'repeated_message' as const, schema: RecallMessageSchema },
|
||||
userDef: { field: 5, type: 'bytes' as const },
|
||||
groupType: { field: 6, type: 'int32' as const },
|
||||
opType: { field: 7, type: 'int32' as const },
|
||||
tipInfo: { field: 9, type: 'message' as const, schema: GroupRecallTipInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const TemplParamSchema = {
|
||||
name: { field: 1, type: 'string' as const },
|
||||
value: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GeneralGrayTipInfoSchema = {
|
||||
busiType: { field: 1, type: 'uint64' as const },
|
||||
busiId: { field: 2, type: 'uint64' as const },
|
||||
ctrlFlag: { field: 3, type: 'uint32' as const },
|
||||
c2cType: { field: 4, type: 'uint32' as const },
|
||||
serviceType: { field: 5, type: 'uint32' as const },
|
||||
templId: { field: 6, type: 'uint64' as const },
|
||||
msgTemplParam: { field: 7, type: 'repeated_message' as const, schema: TemplParamSchema },
|
||||
content: { field: 8, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const EssenceMessageSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
msgSequence: { field: 2, type: 'uint32' as const },
|
||||
random: { field: 3, type: 'uint32' as const },
|
||||
setFlag: { field: 4, type: 'uint32' as const },
|
||||
memberUin: { field: 5, type: 'uint32' as const },
|
||||
operatorUin: { field: 6, type: 'uint32' as const },
|
||||
timestamp: { field: 7, type: 'uint32' as const },
|
||||
msgSequence2: { field: 8, type: 'uint32' as const },
|
||||
operatorNickname: { field: 9, type: 'string' as const },
|
||||
memberNickname: { field: 10, type: 'string' as const },
|
||||
setFlag2: { field: 11, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NotifyMessageBodySchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
groupUin: { field: 4, type: 'uint32' as const },
|
||||
eventParam: { field: 5, type: 'bytes' as const },
|
||||
recall: { field: 11, type: 'message' as const, schema: GroupRecallSchema },
|
||||
field13: { field: 13, type: 'uint32' as const },
|
||||
operatorUid: { field: 21, type: 'string' as const },
|
||||
generalGrayTip: { field: 26, type: 'message' as const, schema: GeneralGrayTipInfoSchema },
|
||||
essenceMessage: { field: 33, type: 'message' as const, schema: EssenceMessageSchema },
|
||||
msgSequence: { field: 37, type: 'uint32' as const },
|
||||
field39: { field: 39, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
@@ -0,0 +1,788 @@
|
||||
// Proto schemas for OIDB action requests.
|
||||
// Port of src/bridge/include/bridge/proto/oidb.h (action-related structs)
|
||||
// and src/bridge/src/bridge.cpp (recall message structs)
|
||||
|
||||
import type { ProtoSchema } from '../../protobuf/decode';
|
||||
|
||||
// --- 0x1253_1: Mute group member ---
|
||||
|
||||
export const OidbMuteMemberBodySchema = {
|
||||
targetUid: { field: 1, type: 'string' as const },
|
||||
duration: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbMuteMemberSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
type: { field: 2, type: 'uint32' as const },
|
||||
body: { field: 3, type: 'message' as const, schema: OidbMuteMemberBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x89A_0: Mute group all ---
|
||||
|
||||
export const OidbMuteAllStateSchema = {
|
||||
state: { field: 17, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbMuteAllSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
muteState: { field: 2, type: 'message' as const, schema: OidbMuteAllStateSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x8A0_1: Kick group member ---
|
||||
|
||||
export const OidbKickMemberSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
targetUid: { field: 3, type: 'string' as const },
|
||||
rejectAddRequest:{ field: 4, type: 'bool' as const },
|
||||
reason: { field: 5, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x1097_1: Leave group ---
|
||||
|
||||
export const OidbLeaveGroupSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0xB5D_44: Friend add request ---
|
||||
|
||||
export const OidbFriendRequestActionSchema = {
|
||||
accept: { field: 1, type: 'uint32' as const },
|
||||
targetUid: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x126B_0: Delete friend ---
|
||||
|
||||
export const OidbDeleteFriendField2Field3Schema = {
|
||||
field1: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbDeleteFriendField2Schema = {
|
||||
field1: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
field3: { field: 3, type: 'message' as const, schema: OidbDeleteFriendField2Field3Schema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbDeleteFriendField1Schema = {
|
||||
targetUid: { field: 1, type: 'string' as const },
|
||||
field2: { field: 2, type: 'message' as const, schema: OidbDeleteFriendField2Schema },
|
||||
block: { field: 3, type: 'bool' as const },
|
||||
field4: { field: 4, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbDeleteFriendSchema = {
|
||||
field1: { field: 1, type: 'message' as const, schema: OidbDeleteFriendField1Schema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x10C8: Group request action ---
|
||||
|
||||
export const OidbGroupRequestBodySchema = {
|
||||
sequence: { field: 1, type: 'uint64' as const },
|
||||
eventType: { field: 2, type: 'uint32' as const },
|
||||
groupUin: { field: 3, type: 'uint32' as const },
|
||||
message: { field: 4, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupRequestActionSchema = {
|
||||
accept: { field: 1, type: 'uint32' as const },
|
||||
body: { field: 2, type: 'message' as const, schema: OidbGroupRequestBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0xED3_1: Poke ---
|
||||
|
||||
export const OidbPokeSchema = {
|
||||
uin: { field: 1, type: 'uint32' as const },
|
||||
groupUin: { field: 2, type: 'uint32' as const },
|
||||
friendUin: { field: 5, type: 'uint32' as const },
|
||||
ext: { field: 6, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0xEAC: Group essence ---
|
||||
|
||||
export const OidbEssenceSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
sequence: { field: 2, type: 'uint32' as const },
|
||||
random: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x1096_1: Set group admin ---
|
||||
|
||||
export const OidbSetAdminSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
uid: { field: 2, type: 'string' as const },
|
||||
isAdmin: { field: 3, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x8FC_3: Set group card (rename member) ---
|
||||
|
||||
export const OidbRenameMemberBodySchema = {
|
||||
targetUid: { field: 1, type: 'string' as const },
|
||||
targetName: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbRenameMemberSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
body: { field: 2, type: 'message' as const, schema: OidbRenameMemberBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x89A_15: Rename group ---
|
||||
|
||||
export const OidbRenameGroupBodySchema = {
|
||||
targetName: { field: 1, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbRenameGroupSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
body: { field: 2, type: 'message' as const, schema: OidbRenameGroupBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x8FC_2: Set group special title ---
|
||||
|
||||
export const OidbSpecialTitleBodySchema = {
|
||||
targetUid: { field: 1, type: 'string' as const },
|
||||
specialTitle:{ field: 5, type: 'string' as const },
|
||||
expireTime: { field: 6, type: 'int32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSpecialTitleSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
body: { field: 2, type: 'message' as const, schema: OidbSpecialTitleBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x7E5_104: Send like ---
|
||||
|
||||
export const OidbLikeSchema = {
|
||||
targetUin: { field: 1, type: 'uint32' as const },
|
||||
count: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x10C0_1 / 0x10C0_2: Group request list ---
|
||||
|
||||
export const OidbGroupRequestListSchema = {
|
||||
count: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0xFE1_2: User profile info ---
|
||||
|
||||
export const OidbUserInfoKeySchema = {
|
||||
key: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbUserInfoRequestSchema = {
|
||||
uin: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
keys: { field: 3, type: 'repeated_message' as const, schema: OidbUserInfoKeySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbTwoNumberSchema = {
|
||||
number1: { field: 1, type: 'uint32' as const },
|
||||
number2: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbBytePropertySchema = {
|
||||
code: { field: 1, type: 'uint32' as const },
|
||||
value: { field: 2, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbUserInfoPropertySchema = {
|
||||
numberProperties: { field: 1, type: 'repeated_message' as const, schema: OidbTwoNumberSchema },
|
||||
bytesProperties: { field: 2, type: 'repeated_message' as const, schema: OidbBytePropertySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbUserInfoResponseBodySchema = {
|
||||
uid: { field: 1, type: 'string' as const },
|
||||
properties: { field: 2, type: 'message' as const, schema: OidbUserInfoPropertySchema },
|
||||
uin: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbUserInfoResponseSchema = {
|
||||
body: { field: 1, type: 'message' as const, schema: OidbUserInfoResponseBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const AvatarInfoSchema = {
|
||||
url: { field: 5, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- FD4_1: Friend list request body fields ---
|
||||
|
||||
export const OidbFriendListNumberSchema = {
|
||||
numbers: { field: 1, type: 'repeated_uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbFriendListBodyItemSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
number: { field: 2, type: 'message' as const, schema: OidbFriendListNumberSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbFriendListNextUinSchema = {
|
||||
uin: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbFriendListRequestSchema = {
|
||||
friendCount: { field: 2, type: 'uint32' as const },
|
||||
field4: { field: 4, type: 'uint32' as const },
|
||||
nextUin: { field: 5, type: 'message' as const, schema: OidbFriendListNextUinSchema },
|
||||
field6: { field: 6, type: 'uint32' as const },
|
||||
field7: { field: 7, type: 'uint32' as const },
|
||||
body: { field: 10001, type: 'repeated_message' as const, schema: OidbFriendListBodyItemSchema },
|
||||
field10002: { field: 10002, type: 'repeated_uint32' as const },
|
||||
field10003: { field: 10003, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- FE5_2: Group list request body (config fields) ---
|
||||
|
||||
export const OidbGroupListConfig1Schema = {
|
||||
groupOwner: { field: 1, type: 'bool' as const },
|
||||
field2: { field: 2, type: 'bool' as const },
|
||||
memberMax: { field: 3, type: 'bool' as const },
|
||||
memberCount: { field: 4, type: 'bool' as const },
|
||||
groupName: { field: 5, type: 'bool' as const },
|
||||
field8: { field: 8, type: 'bool' as const },
|
||||
field9: { field: 9, type: 'bool' as const },
|
||||
field10: { field: 10, type: 'bool' as const },
|
||||
field11: { field: 11, type: 'bool' as const },
|
||||
field12: { field: 12, type: 'bool' as const },
|
||||
field13: { field: 13, type: 'bool' as const },
|
||||
field14: { field: 14, type: 'bool' as const },
|
||||
field15: { field: 15, type: 'bool' as const },
|
||||
field16: { field: 16, type: 'bool' as const },
|
||||
field17: { field: 17, type: 'bool' as const },
|
||||
field18: { field: 18, type: 'bool' as const },
|
||||
question: { field: 19, type: 'bool' as const },
|
||||
field20: { field: 20, type: 'bool' as const },
|
||||
field22: { field: 22, type: 'bool' as const },
|
||||
field23: { field: 23, type: 'bool' as const },
|
||||
field24: { field: 24, type: 'bool' as const },
|
||||
field25: { field: 25, type: 'bool' as const },
|
||||
field26: { field: 26, type: 'bool' as const },
|
||||
field27: { field: 27, type: 'bool' as const },
|
||||
field28: { field: 28, type: 'bool' as const },
|
||||
field29: { field: 29, type: 'bool' as const },
|
||||
field30: { field: 30, type: 'bool' as const },
|
||||
field31: { field: 31, type: 'bool' as const },
|
||||
field32: { field: 32, type: 'bool' as const },
|
||||
field5001: { field: 5001, type: 'bool' as const },
|
||||
field5002: { field: 5002, type: 'bool' as const },
|
||||
field5003: { field: 5003, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupListConfig2Schema = {
|
||||
field1: { field: 1, type: 'bool' as const },
|
||||
field2: { field: 2, type: 'bool' as const },
|
||||
field3: { field: 3, type: 'bool' as const },
|
||||
field4: { field: 4, type: 'bool' as const },
|
||||
field5: { field: 5, type: 'bool' as const },
|
||||
field6: { field: 6, type: 'bool' as const },
|
||||
field7: { field: 7, type: 'bool' as const },
|
||||
field8: { field: 8, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupListConfig3Schema = {
|
||||
field5: { field: 5, type: 'bool' as const },
|
||||
field6: { field: 6, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupListConfigSchema = {
|
||||
config1: { field: 1, type: 'message' as const, schema: OidbGroupListConfig1Schema },
|
||||
config2: { field: 2, type: 'message' as const, schema: OidbGroupListConfig2Schema },
|
||||
config3: { field: 3, type: 'message' as const, schema: OidbGroupListConfig3Schema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupListRequestSchema = {
|
||||
config: { field: 1, type: 'message' as const, schema: OidbGroupListConfigSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- FE7_3: Group member list request body ---
|
||||
|
||||
export const OidbGroupMemberListBodySchema = {
|
||||
memberName: { field: 10, type: 'bool' as const },
|
||||
memberCard: { field: 11, type: 'bool' as const },
|
||||
level: { field: 12, type: 'bool' as const },
|
||||
field13: { field: 13, type: 'bool' as const },
|
||||
field16: { field: 16, type: 'bool' as const },
|
||||
specialTitle: { field: 17, type: 'bool' as const },
|
||||
field18: { field: 18, type: 'bool' as const },
|
||||
field20: { field: 20, type: 'bool' as const },
|
||||
field21: { field: 21, type: 'bool' as const },
|
||||
joinTimestamp: { field: 100, type: 'bool' as const },
|
||||
lastMsgTimestamp: { field: 101, type: 'bool' as const },
|
||||
shutUpTimestamp: { field: 102, type: 'bool' as const },
|
||||
field103: { field: 103, type: 'bool' as const },
|
||||
field104: { field: 104, type: 'bool' as const },
|
||||
field105: { field: 105, type: 'bool' as const },
|
||||
field106: { field: 106, type: 'bool' as const },
|
||||
permission: { field: 107, type: 'bool' as const },
|
||||
field200: { field: 200, type: 'bool' as const },
|
||||
field201: { field: 201, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupMemberListRequestSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
body: { field: 4, type: 'message' as const, schema: OidbGroupMemberListBodySchema },
|
||||
token: { field: 15, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Group recall message (trpc.msg.msg_svc.MsgService.SsoGroupRecallMsg) ---
|
||||
|
||||
export const GroupRecallInfoSchema = {
|
||||
sequence: { field: 1, type: 'uint32' as const },
|
||||
random: { field: 2, type: 'uint32' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupRecallSettingsSchema = {
|
||||
field1: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const GroupRecallRequestSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
groupUin: { field: 2, type: 'uint32' as const },
|
||||
info: { field: 3, type: 'message' as const, schema: GroupRecallInfoSchema },
|
||||
settings: { field: 4, type: 'message' as const, schema: GroupRecallSettingsSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- C2C (private) recall message (trpc.msg.msg_svc.MsgService.SsoC2CRecallMsg) ---
|
||||
|
||||
export const C2CRecallInfoSchema = {
|
||||
clientSequence: { field: 1, type: 'uint32' as const },
|
||||
random: { field: 2, type: 'uint32' as const },
|
||||
messageId: { field: 3, type: 'uint64' as const },
|
||||
timestamp: { field: 4, type: 'uint32' as const },
|
||||
field5: { field: 5, type: 'uint32' as const },
|
||||
messageSequence: { field: 6, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const C2CRecallSettingsSchema = {
|
||||
field1: { field: 1, type: 'bool' as const },
|
||||
field2: { field: 2, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const C2CRecallRequestSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
targetUid:{ field: 3, type: 'string' as const },
|
||||
info: { field: 4, type: 'message' as const, schema: C2CRecallInfoSchema },
|
||||
settings: { field: 5, type: 'message' as const, schema: C2CRecallSettingsSchema },
|
||||
field6: { field: 6, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x9082_1: Set group reaction ---
|
||||
|
||||
export const OidbGroupReactionSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
sequence: { field: 2, type: 'uint32' as const },
|
||||
code: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x6D8_1: Group file list ---
|
||||
|
||||
export const OidbGroupFileListReqSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
appId: { field: 2, type: 'uint32' as const },
|
||||
targetDirectory: { field: 3, type: 'string' as const },
|
||||
fileCount: { field: 5, type: 'uint32' as const },
|
||||
sortBy: { field: 9, type: 'uint32' as const },
|
||||
startIndex: { field: 13, type: 'uint32' as const },
|
||||
field17: { field: 17, type: 'uint32' as const },
|
||||
field18: { field: 18, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileViewReqSchema = {
|
||||
list: { field: 2, type: 'message' as const, schema: OidbGroupFileListReqSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileListFolderRespSchema = {
|
||||
folderId: { field: 1, type: 'string' as const },
|
||||
parentDirectoryId: { field: 2, type: 'string' as const },
|
||||
folderName: { field: 3, type: 'string' as const },
|
||||
createTime: { field: 4, type: 'uint32' as const },
|
||||
modifiedTime: { field: 5, type: 'uint32' as const },
|
||||
creatorUin: { field: 6, type: 'uint32' as const },
|
||||
creatorName: { field: 7, type: 'string' as const },
|
||||
totalFileCount: { field: 8, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileListFileRespSchema = {
|
||||
fileId: { field: 1, type: 'string' as const },
|
||||
fileName: { field: 2, type: 'string' as const },
|
||||
fileSize: { field: 3, type: 'uint64' as const },
|
||||
busId: { field: 4, type: 'uint32' as const },
|
||||
uploadedTime: { field: 6, type: 'uint32' as const },
|
||||
expireTime: { field: 7, type: 'uint32' as const },
|
||||
modifiedTime: { field: 8, type: 'uint32' as const },
|
||||
downloadedTimes: { field: 9, type: 'uint32' as const },
|
||||
uploaderName: { field: 14, type: 'string' as const },
|
||||
uploaderUin: { field: 15, type: 'uint32' as const },
|
||||
parentDirectory: { field: 16, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileListItemRespSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
folderInfo: { field: 2, type: 'message' as const, schema: OidbGroupFileListFolderRespSchema },
|
||||
fileInfo: { field: 3, type: 'message' as const, schema: OidbGroupFileListFileRespSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileListRespSchema = {
|
||||
retCode: { field: 1, type: 'uint32' as const },
|
||||
retMsg: { field: 2, type: 'string' as const },
|
||||
clientWording: { field: 3, type: 'string' as const },
|
||||
isEnd: { field: 4, type: 'bool' as const },
|
||||
items: { field: 5, type: 'repeated_message' as const, schema: OidbGroupFileListItemRespSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileViewRespSchema = {
|
||||
list: { field: 2, type: 'message' as const, schema: OidbGroupFileListRespSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x6D6_2 / 0x6D6_3: Group file url & delete ---
|
||||
|
||||
export const OidbGroupFileUploadReqSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
appId: { field: 2, type: 'uint32' as const },
|
||||
busId: { field: 3, type: 'uint32' as const },
|
||||
entrance: { field: 4, type: 'uint32' as const },
|
||||
targetDirectory: { field: 5, type: 'string' as const },
|
||||
fileName: { field: 6, type: 'string' as const },
|
||||
localDirectory: { field: 7, type: 'string' as const },
|
||||
fileSize: { field: 8, type: 'uint64' as const },
|
||||
fileSha1: { field: 9, type: 'bytes' as const },
|
||||
fileSha3: { field: 10, type: 'bytes' as const },
|
||||
fileMd5: { field: 11, type: 'bytes' as const },
|
||||
field15: { field: 15, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileDownloadReqSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
appId: { field: 2, type: 'uint32' as const },
|
||||
busId: { field: 3, type: 'uint32' as const },
|
||||
fileId: { field: 4, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileDeleteReqSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
busId: { field: 3, type: 'uint32' as const },
|
||||
fileId: { field: 5, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileMoveReqSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
appId: { field: 2, type: 'uint32' as const },
|
||||
busId: { field: 3, type: 'uint32' as const },
|
||||
fileId: { field: 4, type: 'string' as const },
|
||||
parentDirectory: { field: 5, type: 'string' as const },
|
||||
targetDirectory: { field: 6, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileReqSchema = {
|
||||
file: { field: 1, type: 'message' as const, schema: OidbGroupFileUploadReqSchema },
|
||||
download: { field: 3, type: 'message' as const, schema: OidbGroupFileDownloadReqSchema },
|
||||
delete: { field: 4, type: 'message' as const, schema: OidbGroupFileDeleteReqSchema },
|
||||
move: { field: 6, type: 'message' as const, schema: OidbGroupFileMoveReqSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileUploadRespSchema = {
|
||||
retCode: { field: 1, type: 'int32' as const },
|
||||
retMsg: { field: 2, type: 'string' as const },
|
||||
clientWording: { field: 3, type: 'string' as const },
|
||||
uploadIp: { field: 4, type: 'string' as const },
|
||||
serverDns: { field: 5, type: 'string' as const },
|
||||
busId: { field: 6, type: 'int32' as const },
|
||||
fileId: { field: 7, type: 'string' as const },
|
||||
checkKey: { field: 8, type: 'bytes' as const },
|
||||
fileKey: { field: 9, type: 'bytes' as const },
|
||||
boolFileExist: { field: 10, type: 'bool' as const },
|
||||
uploadPort: { field: 14, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileDownloadRespSchema = {
|
||||
retCode: { field: 1, type: 'uint32' as const },
|
||||
retMsg: { field: 2, type: 'string' as const },
|
||||
clientWording: { field: 3, type: 'string' as const },
|
||||
downloadIp: { field: 4, type: 'string' as const },
|
||||
downloadDns: { field: 5, type: 'string' as const },
|
||||
downloadUrl: { field: 6, type: 'bytes' as const },
|
||||
saveFileName: { field: 11, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileRetRespSchema = {
|
||||
retCode: { field: 1, type: 'uint32' as const },
|
||||
retMsg: { field: 2, type: 'string' as const },
|
||||
clientWording: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileRespSchema = {
|
||||
upload: { field: 1, type: 'message' as const, schema: OidbGroupFileUploadRespSchema },
|
||||
download: { field: 3, type: 'message' as const, schema: OidbGroupFileDownloadRespSchema },
|
||||
delete: { field: 4, type: 'message' as const, schema: OidbGroupFileRetRespSchema },
|
||||
move: { field: 6, type: 'message' as const, schema: OidbGroupFileRetRespSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x6D7_0 / 0x6D7_1 / 0x6D7_2: Group file folder ops ---
|
||||
|
||||
export const OidbGroupFileCreateFolderReqSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
rootDirectory: { field: 3, type: 'string' as const },
|
||||
folderName: { field: 4, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileDeleteFolderReqSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
folderId: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileRenameFolderReqSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
folderId: { field: 3, type: 'string' as const },
|
||||
newFolderName: { field: 4, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileFolderReqSchema = {
|
||||
create: { field: 1, type: 'message' as const, schema: OidbGroupFileCreateFolderReqSchema },
|
||||
delete: { field: 2, type: 'message' as const, schema: OidbGroupFileDeleteFolderReqSchema },
|
||||
rename: { field: 3, type: 'message' as const, schema: OidbGroupFileRenameFolderReqSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileFolderRetRespSchema = {
|
||||
retcode: { field: 1, type: 'uint32' as const },
|
||||
retMsg: { field: 2, type: 'string' as const },
|
||||
clientWording: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileFolderRespSchema = {
|
||||
create: { field: 1, type: 'message' as const, schema: OidbGroupFileFolderRetRespSchema },
|
||||
delete: { field: 2, type: 'message' as const, schema: OidbGroupFileFolderRetRespSchema },
|
||||
rename: { field: 3, type: 'message' as const, schema: OidbGroupFileFolderRetRespSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0xE37_1200: Private file download url ---
|
||||
|
||||
export const OidbPrivateFileDownloadReqBodySchema = {
|
||||
receiverUid: { field: 10, type: 'string' as const },
|
||||
fileUuid: { field: 20, type: 'string' as const },
|
||||
type: { field: 30, type: 'uint32' as const },
|
||||
fileHash: { field: 60, type: 'string' as const },
|
||||
t2: { field: 601, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbPrivateFileDownloadReqSchema = {
|
||||
subCommand: { field: 1, type: 'uint32' as const },
|
||||
field2: { field: 2, type: 'uint32' as const },
|
||||
body: { field: 14, type: 'message' as const, schema: OidbPrivateFileDownloadReqBodySchema },
|
||||
field101: { field: 101, type: 'uint32' as const },
|
||||
field102: { field: 102, type: 'uint32' as const },
|
||||
field200: { field: 200, type: 'uint32' as const },
|
||||
field99999: { field: 99999, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbPrivateFileDownloadRespResultSchema = {
|
||||
server: { field: 20, type: 'string' as const },
|
||||
port: { field: 40, type: 'uint32' as const },
|
||||
url: { field: 50, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbPrivateFileDownloadRespBodySchema = {
|
||||
state: { field: 20, type: 'string' as const },
|
||||
result: { field: 30, type: 'message' as const, schema: OidbPrivateFileDownloadRespResultSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbPrivateFileDownloadRespSchema = {
|
||||
body: { field: 14, type: 'message' as const, schema: OidbPrivateFileDownloadRespBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0xE37_1700: Private file upload ---
|
||||
|
||||
export const OidbPrivateFileUploadReqBodySchema = {
|
||||
senderUid: { field: 10, type: 'string' as const },
|
||||
receiverUid: { field: 20, type: 'string' as const },
|
||||
fileSize: { field: 30, type: 'uint32' as const },
|
||||
fileName: { field: 40, type: 'string' as const },
|
||||
md510MCheckSum:{ field: 50, type: 'bytes' as const },
|
||||
sha1CheckSum: { field: 60, type: 'bytes' as const },
|
||||
localPath: { field: 70, type: 'string' as const },
|
||||
md5CheckSum: { field: 110, type: 'bytes' as const },
|
||||
sha3CheckSum: { field: 120, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbPrivateFileUploadReqSchema = {
|
||||
command: { field: 1, type: 'uint32' as const },
|
||||
seq: { field: 2, type: 'int32' as const },
|
||||
upload: { field: 19, type: 'message' as const, schema: OidbPrivateFileUploadReqBodySchema },
|
||||
businessId: { field: 101, type: 'int32' as const },
|
||||
clientType: { field: 102, type: 'int32' as const },
|
||||
flagSupportMediaPlatform: { field: 200, type: 'int32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbPrivateFileUploadRespBodySchema = {
|
||||
retCode: { field: 10, type: 'int32' as const },
|
||||
retMsg: { field: 20, type: 'string' as const },
|
||||
uploadIp: { field: 60, type: 'string' as const },
|
||||
uploadPort: { field: 80, type: 'uint32' as const },
|
||||
uuid: { field: 90, type: 'string' as const },
|
||||
uploadKey: { field: 100, type: 'bytes' as const },
|
||||
boolFileExist: { field: 110, type: 'bool' as const },
|
||||
fileAddon: { field: 200, type: 'string' as const },
|
||||
mediaPlatformUploadKey: { field: 220, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbPrivateFileUploadRespSchema = {
|
||||
upload: { field: 19, type: 'message' as const, schema: OidbPrivateFileUploadRespBodySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- NTV2 Rich Media (0x9067_202): Download RKey ---
|
||||
|
||||
export const NTV2CommonHeadSchema = {
|
||||
requestId: { field: 1, type: 'uint32' as const },
|
||||
command: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2C2CUserInfoSchema = {
|
||||
accountType: { field: 1, type: 'uint32' as const },
|
||||
targetUid: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2GroupInfoSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2SceneInfoSchema = {
|
||||
requestType: { field: 101, type: 'uint32' as const },
|
||||
businessType: { field: 102, type: 'uint32' as const },
|
||||
sceneType: { field: 200, type: 'uint32' as const },
|
||||
c2c: { field: 201, type: 'message' as const, schema: NTV2C2CUserInfoSchema },
|
||||
group: { field: 202, type: 'message' as const, schema: NTV2GroupInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2ClientMetaSchema = {
|
||||
agentType: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2ReqHeadSchema = {
|
||||
common: { field: 1, type: 'message' as const, schema: NTV2CommonHeadSchema },
|
||||
scene: { field: 2, type: 'message' as const, schema: NTV2SceneInfoSchema },
|
||||
client: { field: 3, type: 'message' as const, schema: NTV2ClientMetaSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2DownloadRKeyReqSchema = {
|
||||
types: { field: 1, type: 'repeated_uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2FileTypeSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
picFormat: { field: 2, type: 'uint32' as const },
|
||||
videoFormat: { field: 3, type: 'uint32' as const },
|
||||
voiceFormat: { field: 4, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2FileInfoSchema = {
|
||||
fileSize: { field: 1, type: 'uint32' as const },
|
||||
fileHash: { field: 2, type: 'string' as const },
|
||||
fileSha1: { field: 3, type: 'string' as const },
|
||||
fileName: { field: 4, type: 'string' as const },
|
||||
type: { field: 5, type: 'message' as const, schema: NTV2FileTypeSchema },
|
||||
width: { field: 6, type: 'uint32' as const },
|
||||
height: { field: 7, type: 'uint32' as const },
|
||||
time: { field: 8, type: 'uint32' as const },
|
||||
original: { field: 9, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2IndexNodeSchema = {
|
||||
info: { field: 1, type: 'message' as const, schema: NTV2FileInfoSchema },
|
||||
fileUuid: { field: 2, type: 'string' as const },
|
||||
storeId: { field: 3, type: 'uint32' as const },
|
||||
uploadTime: { field: 4, type: 'uint32' as const },
|
||||
ttl: { field: 5, type: 'uint32' as const },
|
||||
subType: { field: 6, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2VideoDownloadExtSchema = {
|
||||
busiType: { field: 1, type: 'uint32' as const },
|
||||
sceneType: { field: 2, type: 'uint32' as const },
|
||||
subBusiType: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2DownloadExtSchema = {
|
||||
video: { field: 2, type: 'message' as const, schema: NTV2VideoDownloadExtSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2DownloadReqSchema = {
|
||||
node: { field: 1, type: 'message' as const, schema: NTV2IndexNodeSchema },
|
||||
download: { field: 2, type: 'message' as const, schema: NTV2DownloadExtSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2RichMediaReqSchema = {
|
||||
reqHead: { field: 1, type: 'message' as const, schema: NTV2ReqHeadSchema },
|
||||
download: { field: 3, type: 'message' as const, schema: NTV2DownloadReqSchema },
|
||||
downloadRkey: { field: 4, type: 'message' as const, schema: NTV2DownloadRKeyReqSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2RespHeadSchema = {
|
||||
common: { field: 1, type: 'message' as const, schema: NTV2CommonHeadSchema },
|
||||
retCode: { field: 2, type: 'uint32' as const },
|
||||
message: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2RKeyInfoSchema = {
|
||||
rkey: { field: 1, type: 'string' as const },
|
||||
rkeyTtlSec: { field: 2, type: 'uint64' as const },
|
||||
storeId: { field: 3, type: 'uint32' as const },
|
||||
rkeyCreateTime:{ field: 4, type: 'uint32' as const },
|
||||
type: { field: 5, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2DownloadRKeyRespSchema = {
|
||||
rkeys: { field: 1, type: 'repeated_message' as const, schema: NTV2RKeyInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2MediaDownloadInfoSchema = {
|
||||
domain: { field: 1, type: 'string' as const },
|
||||
urlPath: { field: 2, type: 'string' as const },
|
||||
httpsPort: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2MediaDownloadRespSchema = {
|
||||
rKeyParam: { field: 1, type: 'string' as const },
|
||||
rKeyTtlSecond: { field: 2, type: 'uint32' as const },
|
||||
info: { field: 3, type: 'message' as const, schema: NTV2MediaDownloadInfoSchema },
|
||||
rKeyCreateTime: { field: 4, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const NTV2RichMediaRespSchema = {
|
||||
respHead: { field: 1, type: 'message' as const, schema: NTV2RespHeadSchema },
|
||||
download: { field: 3, type: 'message' as const, schema: NTV2MediaDownloadRespSchema },
|
||||
downloadRkey:{ field: 4, type: 'message' as const, schema: NTV2DownloadRKeyRespSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0xB6E_2: Set friend remark ---
|
||||
|
||||
export const OidbSetFriendRemarkSchema = {
|
||||
targetUid: { field: 1, type: 'string' as const },
|
||||
remark: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x9082_2: Set group reaction (remove) — same schema as set ---
|
||||
// (0x9082_1 for add, 0x9082_2 for remove — both use OidbGroupReactionSchema)
|
||||
|
||||
// --- Group file count (0x6D8_3) ---
|
||||
|
||||
export const OidbGroupFileCountReqSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
appId: { field: 2, type: 'uint32' as const },
|
||||
busId: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileCountRespSchema = {
|
||||
fileCount: { field: 1, type: 'uint32' as const },
|
||||
maxCount: { field: 2, type: 'uint32' as const },
|
||||
isEnd: { field: 3, type: 'bool' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileCountViewReqSchema = {
|
||||
count: { field: 3, type: 'message' as const, schema: OidbGroupFileCountReqSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbGroupFileCountViewRespSchema = {
|
||||
count: { field: 3, type: 'message' as const, schema: OidbGroupFileCountRespSchema },
|
||||
} satisfies ProtoSchema;
|
||||
@@ -0,0 +1,161 @@
|
||||
// Proto schemas for OidbSvc service types.
|
||||
// Port of src/bridge/include/bridge/proto/oidb.h
|
||||
|
||||
import type { ProtoSchema } from '../../protobuf/decode';
|
||||
|
||||
// --- OidbSvcTrpcTcpBase wrapper ---
|
||||
|
||||
export const OidbPropertySchema = {
|
||||
key: { field: 1, type: 'string' as const },
|
||||
value: { field: 2, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// Factory for OidbSvcTrpcTcpBase<T>
|
||||
export function makeOidbBaseSchema(bodySchema: ProtoSchema): ProtoSchema {
|
||||
return {
|
||||
command: { field: 1, type: 'uint32' as const },
|
||||
subCommand: { field: 2, type: 'uint32' as const },
|
||||
errorCode: { field: 3, type: 'uint32' as const },
|
||||
body: { field: 4, type: 'message' as const, schema: bodySchema },
|
||||
errorMsg: { field: 5, type: 'string' as const },
|
||||
properties: { field: 11, type: 'repeated_message' as const, schema: OidbPropertySchema },
|
||||
reserved: { field: 12, type: 'int32' as const },
|
||||
};
|
||||
}
|
||||
|
||||
// --- Friend list (0xFD4_1) ---
|
||||
|
||||
export const OidbFriendPropertySchema = {
|
||||
code: { field: 1, type: 'uint32' as const },
|
||||
value: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbFriendLayer1Schema = {
|
||||
properties: { field: 2, type: 'repeated_message' as const, schema: OidbFriendPropertySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbFriendAdditionalSchema = {
|
||||
type: { field: 1, type: 'uint32' as const },
|
||||
layer1: { field: 2, type: 'message' as const, schema: OidbFriendLayer1Schema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbFriendSchema = {
|
||||
uid: { field: 1, type: 'string' as const },
|
||||
customGroup:{ field: 2, type: 'uint32' as const },
|
||||
uin: { field: 3, type: 'uint32' as const },
|
||||
additional: { field: 10001, type: 'repeated_message' as const, schema: OidbFriendAdditionalSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFD4_1ResponseUinSchema = {
|
||||
uin: { field: 1, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFD4_1ResponseSchema = {
|
||||
next: { field: 2, type: 'message' as const, schema: OidbSvcTrpcTcp0xFD4_1ResponseUinSchema },
|
||||
displayFriendCount: { field: 3, type: 'uint32' as const },
|
||||
timestamp: { field: 6, type: 'uint32' as const },
|
||||
selfUin: { field: 7, type: 'uint32' as const },
|
||||
friends: { field: 101, type: 'repeated_message' as const, schema: OidbFriendSchema },
|
||||
groups: { field: 102, type: 'repeated_message' as const, schema: OidbFriendPropertySchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Group list (0xFE5_2) ---
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE5_2MemberSchema = {
|
||||
uid: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE5_2GroupInfoSchema = {
|
||||
groupOwner: { field: 1, type: 'message' as const, schema: OidbSvcTrpcTcp0xFE5_2MemberSchema },
|
||||
createdTime: { field: 2, type: 'uint32' as const },
|
||||
memberMax: { field: 3, type: 'uint32' as const },
|
||||
memberCount: { field: 4, type: 'uint32' as const },
|
||||
groupName: { field: 5, type: 'string' as const },
|
||||
description: { field: 18, type: 'string' as const },
|
||||
question: { field: 19, type: 'string' as const },
|
||||
announcement: { field: 30, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE5_2CustomInfoSchema = {
|
||||
remark: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE5_2GroupSchema = {
|
||||
groupUin: { field: 3, type: 'uint32' as const },
|
||||
info: { field: 4, type: 'message' as const, schema: OidbSvcTrpcTcp0xFE5_2GroupInfoSchema },
|
||||
customInfo: { field: 5, type: 'message' as const, schema: OidbSvcTrpcTcp0xFE5_2CustomInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE5_2ResponseSchema = {
|
||||
groups: { field: 2, type: 'repeated_message' as const, schema: OidbSvcTrpcTcp0xFE5_2GroupSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Group member list (0xFE7_3) ---
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE7_3UinSchema = {
|
||||
uid: { field: 2, type: 'string' as const },
|
||||
uin: { field: 4, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE7_3CardSchema = {
|
||||
memberCard: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE7_3LevelSchema = {
|
||||
infos: { field: 1, type: 'repeated_uint32' as const },
|
||||
level: { field: 2, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE7_3MemberSchema = {
|
||||
uin: { field: 1, type: 'message' as const, schema: OidbSvcTrpcTcp0xFE7_3UinSchema },
|
||||
memberName: { field: 10, type: 'string' as const },
|
||||
specialTitle: { field: 17, type: 'string' as const },
|
||||
memberCard: { field: 11, type: 'message' as const, schema: OidbSvcTrpcTcp0xFE7_3CardSchema },
|
||||
level: { field: 12, type: 'message' as const, schema: OidbSvcTrpcTcp0xFE7_3LevelSchema },
|
||||
joinTimestamp: { field: 100, type: 'uint32' as const },
|
||||
lastMsgTimestamp: { field: 101, type: 'uint32' as const },
|
||||
shutUpTimestamp: { field: 102, type: 'uint32' as const },
|
||||
permission: { field: 107, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0xFE7_3ResponseSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
members: { field: 2, type: 'repeated_message' as const, schema: OidbSvcTrpcTcp0xFE7_3MemberSchema },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
memberChangeSeq: { field: 5, type: 'uint32' as const },
|
||||
memberCardChangeSeq:{ field: 6, type: 'uint32' as const },
|
||||
token: { field: 15, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- Group request (0x10C0) ---
|
||||
|
||||
export const OidbSvcTrpcTcp0x10C0ResponseUserSchema = {
|
||||
uid: { field: 1, type: 'string' as const },
|
||||
name: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0x10C0ResponseGroupSchema = {
|
||||
groupUin: { field: 1, type: 'uint32' as const },
|
||||
groupName: { field: 2, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0x10C0ResponseRequestSchema = {
|
||||
sequence: { field: 1, type: 'uint64' as const },
|
||||
eventType: { field: 2, type: 'uint32' as const },
|
||||
state: { field: 3, type: 'uint32' as const },
|
||||
group: { field: 4, type: 'message' as const, schema: OidbSvcTrpcTcp0x10C0ResponseGroupSchema },
|
||||
target: { field: 5, type: 'message' as const, schema: OidbSvcTrpcTcp0x10C0ResponseUserSchema },
|
||||
invitor: { field: 6, type: 'message' as const, schema: OidbSvcTrpcTcp0x10C0ResponseUserSchema },
|
||||
operatorUser: { field: 7, type: 'message' as const, schema: OidbSvcTrpcTcp0x10C0ResponseUserSchema },
|
||||
field9: { field: 9, type: 'string' as const },
|
||||
comment: { field: 10, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const OidbSvcTrpcTcp0x10C0ResponseSchema = {
|
||||
requests: { field: 1, type: 'repeated_message' as const, schema: OidbSvcTrpcTcp0x10C0ResponseRequestSchema },
|
||||
field2: { field: 2, type: 'uint64' as const },
|
||||
newLatestSeq: { field: 3, type: 'uint64' as const },
|
||||
field4: { field: 4, type: 'uint32' as const },
|
||||
field5: { field: 5, type: 'uint64' as const },
|
||||
field6: { field: 6, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
@@ -0,0 +1,205 @@
|
||||
// QQ info store — per-UIN state for friends, groups, member lookup.
|
||||
// Port of src/bridge/include/bridge/qq_info.h + src/bridge/src/qq_info.cpp
|
||||
|
||||
export interface UserProfileInfo {
|
||||
uin: number;
|
||||
uid: string;
|
||||
nickname: string;
|
||||
remark: string;
|
||||
qid: string;
|
||||
sex: string;
|
||||
age: number;
|
||||
sign: string;
|
||||
avatar: string;
|
||||
}
|
||||
|
||||
export interface FriendInfo {
|
||||
uin: number;
|
||||
uid: string;
|
||||
nickname: string;
|
||||
remark: string;
|
||||
}
|
||||
|
||||
export interface GroupMemberInfo {
|
||||
uin: number;
|
||||
uid: string;
|
||||
nickname: string;
|
||||
card: string;
|
||||
role: string; // 'owner' | 'admin' | 'member'
|
||||
level: number;
|
||||
title: string;
|
||||
joinTime: number;
|
||||
lastSentTime: number;
|
||||
shutUpTime: number;
|
||||
}
|
||||
|
||||
export interface QQGroupInfo {
|
||||
groupId: number;
|
||||
groupName: string;
|
||||
remark: string;
|
||||
memberCount: number;
|
||||
memberMax: number;
|
||||
members: Map<number, GroupMemberInfo>;
|
||||
}
|
||||
|
||||
export interface GroupRequestInfo {
|
||||
groupId: number;
|
||||
groupName: string;
|
||||
targetUid: string;
|
||||
targetUin: number;
|
||||
targetName: string;
|
||||
invitorUid: string;
|
||||
invitorUin: number;
|
||||
invitorName: string;
|
||||
operatorUid: string;
|
||||
operatorUin: number;
|
||||
operatorName: string;
|
||||
sequence: number;
|
||||
state: number;
|
||||
eventType: number;
|
||||
comment: string;
|
||||
filtered: boolean;
|
||||
}
|
||||
|
||||
export class QQInfo {
|
||||
private uin_: string;
|
||||
private nickname_ = '';
|
||||
private selfProfile_: UserProfileInfo | null = null;
|
||||
private userProfiles_ = new Map<number, UserProfileInfo>();
|
||||
private friends_: FriendInfo[] = [];
|
||||
private groups_ = new Map<number, QQGroupInfo>();
|
||||
|
||||
constructor(uin: string) {
|
||||
this.uin_ = uin;
|
||||
}
|
||||
|
||||
get uin(): string { return this.uin_; }
|
||||
|
||||
get nickname(): string { return this.nickname_; }
|
||||
set nickname(v: string) { this.nickname_ = v; }
|
||||
|
||||
// --- Self profile ---
|
||||
|
||||
setSelfProfile(info: UserProfileInfo): void { this.selfProfile_ = info; }
|
||||
get selfProfile(): UserProfileInfo | null { return this.selfProfile_; }
|
||||
get selfUid(): string | null { return this.selfProfile_?.uid ?? null; }
|
||||
|
||||
// --- User profiles ---
|
||||
|
||||
setUserProfile(info: UserProfileInfo): void {
|
||||
this.userProfiles_.set(info.uin, info);
|
||||
}
|
||||
|
||||
findUserProfile(uin: number): UserProfileInfo | null {
|
||||
return this.userProfiles_.get(uin) ?? null;
|
||||
}
|
||||
|
||||
// --- Friends ---
|
||||
|
||||
setFriends(friends: FriendInfo[]): void { this.friends_ = friends; }
|
||||
get friends(): FriendInfo[] { return this.friends_; }
|
||||
|
||||
findFriend(uin: number): FriendInfo | null {
|
||||
return this.friends_.find(f => f.uin === uin) ?? null;
|
||||
}
|
||||
|
||||
// --- Groups ---
|
||||
|
||||
setGroups(groups: QQGroupInfo[]): void {
|
||||
this.groups_.clear();
|
||||
for (const g of groups) {
|
||||
this.groups_.set(g.groupId, g);
|
||||
}
|
||||
}
|
||||
|
||||
get groups(): QQGroupInfo[] { return [...this.groups_.values()]; }
|
||||
|
||||
findGroup(groupId: number): QQGroupInfo | null {
|
||||
return this.groups_.get(groupId) ?? null;
|
||||
}
|
||||
|
||||
findGroupMember(groupId: number, uin: number): GroupMemberInfo | null {
|
||||
return this.groups_.get(groupId)?.members.get(uin) ?? null;
|
||||
}
|
||||
|
||||
setGroupMembers(groupId: number, members: GroupMemberInfo[]): void {
|
||||
const g = this.groups_.get(groupId);
|
||||
if (!g) return;
|
||||
g.members.clear();
|
||||
for (const m of members) {
|
||||
g.members.set(m.uin, m);
|
||||
}
|
||||
}
|
||||
|
||||
updateGroupMember(groupId: number, member: GroupMemberInfo): void {
|
||||
const g = this.groups_.get(groupId);
|
||||
if (!g) return;
|
||||
g.members.set(member.uin, member);
|
||||
}
|
||||
|
||||
// --- UID resolution ---
|
||||
|
||||
resolveUid(uid: string): number | null {
|
||||
// Check self
|
||||
if (this.selfProfile_?.uid === uid) {
|
||||
return this.selfProfile_.uin || parseInt(this.uin_, 10) || null;
|
||||
}
|
||||
// Check friends
|
||||
for (const f of this.friends_) {
|
||||
if (f.uid === uid) return f.uin;
|
||||
}
|
||||
// Check user profiles
|
||||
for (const [, p] of this.userProfiles_) {
|
||||
if (p.uid === uid) return p.uin;
|
||||
}
|
||||
// Check all group members
|
||||
for (const [, g] of this.groups_) {
|
||||
for (const [, m] of g.members) {
|
||||
if (m.uid === uid) return m.uin;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
resolveGroupMemberUid(groupId: number, uid: string): number | null {
|
||||
const g = this.groups_.get(groupId);
|
||||
if (!g) return null;
|
||||
for (const [, m] of g.members) {
|
||||
if (m.uid === uid) return m.uin;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// --- Reverse UID lookup (UIN → UID) ---
|
||||
|
||||
findUidByUin(uin: number): string | null {
|
||||
// Check self
|
||||
if (this.selfProfile_ && this.selfProfile_.uin === uin && this.selfProfile_.uid) {
|
||||
return this.selfProfile_.uid;
|
||||
}
|
||||
// Check friends
|
||||
for (const f of this.friends_) {
|
||||
if (f.uin === uin && f.uid) return f.uid;
|
||||
}
|
||||
// Check user profiles
|
||||
for (const [, p] of this.userProfiles_) {
|
||||
if (p.uin === uin && p.uid) return p.uid;
|
||||
}
|
||||
// Check all group members
|
||||
for (const [, g] of this.groups_) {
|
||||
for (const [, m] of g.members) {
|
||||
if (m.uin === uin && m.uid) return m.uid;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
findUidByUinInGroup(groupId: number, uin: number): string | null {
|
||||
const g = this.groups_.get(groupId);
|
||||
if (!g) return null;
|
||||
for (const [, m] of g.members) {
|
||||
if (m.uin === uin && m.uid) return m.uid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user