1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
use jcers::JcePut;

use crate::command::common::PbToBytes;
use crate::pb;
use crate::protocol::packet::Packet;

impl super::super::super::Engine {
    // ProfileService.Pb.ReqSystemMsgNew.Group
    pub fn build_system_msg_new_group_packet(&self, suspicious: bool) -> Packet {
        let req = pb::structmsg::ReqSystemMsgNew {
            msg_num: 100,
            version: 1000,
            checktype: 3,
            flag: Some(pb::structmsg::FlagInfo {
                grp_msg_kick_admin: 1,
                grp_msg_hidden_grp: 1,
                grp_msg_wording_down: 1,
                grp_msg_get_official_account: 1,
                grp_msg_get_pay_in_group: 1,
                frd_msg_discuss2_many_chat: 1,
                grp_msg_not_allow_join_grp_invite_not_frd: 1,
                frd_msg_need_waiting_msg: 1,
                frd_msg_uint32_need_all_unread_msg: 1,
                grp_msg_need_auto_admin_wording: 1,
                grp_msg_get_transfer_group_msg_flag: 1,
                grp_msg_get_quit_pay_group_msg_flag: 1,
                grp_msg_support_invite_auto_join: 1,
                grp_msg_mask_invite_auto_join: 1,
                grp_msg_get_disbanded_by_admin: 1,
                grp_msg_get_c2c_invite_join_group: 1,
                ..Default::default()
            }),
            friend_msg_type_flag: 1,
            req_msg_type: if suspicious { 2 } else { 1 },
            ..Default::default()
        };
        let payload = req.to_bytes();
        self.uni_packet("ProfileService.Pb.ReqSystemMsgNew.Group", payload)
    }

    // ProfileService.Pb.ReqSystemMsgNew.Friend
    pub fn build_system_msg_new_friend_packet(&self) -> Packet {
        let req = pb::structmsg::ReqSystemMsgNew {
            msg_num: 20,
            version: 1000,
            checktype: 2,
            flag: Some(pb::structmsg::FlagInfo {
                frd_msg_discuss2_many_chat: 1,
                frd_msg_get_busi_card: 1,
                frd_msg_need_waiting_msg: 1,
                frd_msg_uint32_need_all_unread_msg: 1,
                grp_msg_mask_invite_auto_join: 1,
                ..Default::default()
            }),
            friend_msg_type_flag: 1,
            ..Default::default()
        };
        let payload = req.to_bytes();
        self.uni_packet("ProfileService.Pb.ReqSystemMsgNew.Friend", payload)
    }

    // ProfileService.Pb.ReqSystemMsgAction.Group
    #[allow(clippy::too_many_arguments)]
    pub fn build_system_msg_group_action_packet(
        &self,
        msg_seq: i64,
        req_uin: i64,
        group_code: i64,
        msg_type: i32,
        is_invite: bool,
        accept: bool,
        block: bool,
        reason: String,
    ) -> Packet {
        let req = pb::structmsg::ReqSystemMsgAction {
            msg_type,
            msg_seq,
            req_uin,
            sub_type: 1,
            src_id: 3,
            sub_src_id: if is_invite { 10016 } else { 31 },
            group_msg_type: if is_invite { 2 } else { 1 },
            action_info: Some(pb::structmsg::SystemMsgActionInfo {
                r#type: if accept { 11 } else { 12 },
                group_code,
                blacklist: block,
                msg: reason,
                sig: vec![],
                ..Default::default()
            }),
            language: 1000,
        };
        let payload = req.to_bytes();
        self.uni_packet("ProfileService.Pb.ReqSystemMsgAction.Group", payload)
    }

    // ProfileService.Pb.ReqSystemMsgAction.Friend
    pub fn build_system_msg_friend_action_packet(
        &self,
        req_id: i64,
        req_uin: i64,
        accept: bool,
    ) -> Packet {
        let req = pb::structmsg::ReqSystemMsgAction {
            msg_type: 1,
            msg_seq: req_id,
            req_uin,
            sub_type: 1,
            src_id: 6,
            sub_src_id: 7,
            action_info: Some(pb::structmsg::SystemMsgActionInfo {
                r#type: if accept { 2 } else { 3 },
                blacklist: false,
                add_frd_sn_info: Some(pb::structmsg::AddFrdSnInfo::default()),
                ..Default::default()
            }),
            ..Default::default()
        };
        let payload = req.to_bytes();
        self.uni_packet("ProfileService.Pb.ReqSystemMsgAction.Friend", payload)
    }

    // ProfileService.GroupMngReq
    pub fn build_quit_group_packet(&self, group_code: i64) -> Packet {
        let mut jce_mut = jcers::JceMut::new();
        jce_mut.put_i32(2, 0);
        jce_mut.put_i64(self.uin(), 1);
        jce_mut.put_bytes(
            bytes::Bytes::from({
                let mut v = Vec::with_capacity(8);
                v.extend((self.uin() as u32).to_be_bytes());
                v.extend(group_code.to_be_bytes());
                v
            }),
            2,
        );
        let buf = crate::jce::RequestDataVersion3 {
            map: [(
                "GroupMngReq".to_owned(),
                crate::command::common::pack_uni_request_data(&jce_mut.freeze()),
            )]
            .into(),
        };
        let pkt = crate::jce::RequestPacket {
            i_version: 3,
            i_request_id: self.next_packet_seq(),
            s_servant_name: "KQQ.ProfileService.ProfileServantObj".to_owned(),
            s_func_name: "GroupMngReq".to_owned(),
            s_buffer: buf.freeze(),
            ..Default::default()
        };
        self.uni_packet("ProfileService.GroupMngReq", pkt.freeze())
    }

    pub fn build_get_rich_sig_request_packet(&self, user_ids: Vec<i64>) -> Packet {
        let payload = crate::jce::GetRichSigReq {
            req_rich_infos: user_ids
                .into_iter()
                .map(|id| crate::jce::ReqRichInfo {
                    uin: id,
                    dw_time: 0,
                })
                .collect(),
            check_update: false,
            show_date_sig: false,
            get_large_tlv: true,
        };
        let buf = crate::jce::RequestDataVersion3 {
            map: [(
                "GetRichSigReq".to_owned(),
                crate::command::common::pack_uni_request_data(&payload.freeze()),
            )]
            .into(),
        };
        let pkt = crate::jce::RequestPacket {
            i_version: 3,
            i_request_id: self.next_packet_seq(),
            s_servant_name: "KQQ.ProfileService.ProfileServantObj".to_owned(),
            s_func_name: "GetRichSig".to_owned(),
            s_buffer: buf.freeze(),
            ..Default::default()
        };
        self.uni_packet("ProfileService.GetRichSig", pkt.freeze())
    }
}