示例#1
0
        private static bool ConvertStrToGroupMembersList(string source, ref List <CQGroupMemberInfo> lsGm)
        {
            Unpack u = new Unpack();

            if (source == string.Empty)
            {
                return(false);
            }
            var data = Convert.FromBase64String(source);

            if (data == null || data.Length < 10)
            {
                return(false);
            }
            u.SetData(data);
            var count = u.GetInt();

            for (int i = 0; i < count; i++)
            {
                if (u.Len() <= 0)
                {
                    return(false);
                }
                CQGroupMemberInfo gm = new CQGroupMemberInfo();
                if (!ConvertAnsiHexToGroupMembers(u.GetToken(), ref gm))
                {
                    return(false);
                }
                lsGm.Add(gm);
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// 转换_ansihex到群成员信息
        /// </summary>
        /// <param name="source">源字节集</param>
        /// <param name="gm">群成员</param>
        /// <returns></returns>
        private static bool ConvertAnsiHexToGroupMembers(byte[] source, ref CQGroupMemberInfo gm)
        {
            if (source == null || source.Length < 40)
            {
                return(false);
            }
            Unpack u = new Unpack();

            u.SetData(source);
            gm.GroupId                 = u.GetLong();
            gm.Number                  = u.GetLong();
            gm.NickName                = u.GetLenStr();
            gm.InGroupName             = u.GetLenStr();
            gm.Gender                  = u.GetInt() == 0 ? "男" : "女";
            gm.Age                     = u.GetInt();
            gm.Area                    = u.GetLenStr();
            gm.JoinTime                = new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime().AddSeconds(u.GetInt());
            gm.LastSpeakingTime        = new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime().AddSeconds(u.GetInt());
            gm.Level                   = u.GetLenStr();
            gm.Authority               = u.GetInt().ToString();
            gm.HasBadRecord            = (u.GetInt() == 1);
            gm.Title                   = u.GetLenStr();
            gm.TitleExpirationTime     = u.GetInt();
            gm.IsInGroupNameModifiable = (u.GetInt() == 1);
            return(true);
        }
示例#3
0
        /// <summary>
        /// 取群成员信息
        /// </summary>
        /// <param name="groupId">群号</param>
        /// <param name="qq">QQ号</param>
        /// <param name="nocache">取缓存</param>
        /// <returns></returns>
        public static CQGroupMemberInfo GetGroupMemberInfo(long groupId, long qq, bool nocache = false)
        {
            try {
                lock (_syncRoot) {
                    nLogger.Info(string.Format("[↑][帐号] 取群成员信息"));
                    var data = CQUDPProxy.GetInstance().GetStringMessage(
                        string.Format("GroupMemberInfo {0} {1} {2}", groupId, qq, nocache ? 0 : 1)
                        );

                    var memberBytes      = Convert.FromBase64String(data);
                    var info             = new CQGroupMemberInfo();
                    var groupNumberBytes = new byte[8];

                    Array.Copy(memberBytes, 0, groupNumberBytes, 0, 8);
                    Array.Reverse(groupNumberBytes);
                    info.GroupId = BitConverter.ToInt64(groupNumberBytes, 0);

                    var qqNumberBytes = new byte[8];
                    Array.Copy(memberBytes, 8, qqNumberBytes, 0, 8);
                    Array.Reverse(qqNumberBytes);
                    info.Number = BitConverter.ToInt64(qqNumberBytes, 0);

                    var nameLengthBytes = new byte[2];
                    Array.Copy(memberBytes, 16, nameLengthBytes, 0, 2);
                    Array.Reverse(nameLengthBytes);
                    var nameLength = BitConverter.ToInt16(nameLengthBytes, 0);

                    var nameBytes = new byte[nameLength];
                    Array.Copy(memberBytes, 18, nameBytes, 0, nameLength);
                    info.NickName = Encoding.Default.GetString(nameBytes);

                    var cardLengthBytes = new byte[2];
                    Array.Copy(memberBytes, 18 + nameLength, cardLengthBytes, 0, 2);
                    Array.Reverse(cardLengthBytes);
                    var cardLength = BitConverter.ToInt16(cardLengthBytes, 0);

                    var cardBytes = new byte[cardLength];
                    Array.Copy(memberBytes, 20 + nameLength, cardBytes, 0, cardLength);
                    info.InGroupName = Encoding.Default.GetString(cardBytes);

                    var genderBytes = new byte[4];
                    Array.Copy(memberBytes, 20 + nameLength + cardLength, genderBytes, 0, 4);
                    Array.Reverse(genderBytes);
                    info.Gender = BitConverter.ToInt32(genderBytes, 0) == 0 ? "男" : " 女";

                    var ageBytes = new byte[4];
                    Array.Copy(memberBytes, 24 + nameLength + cardLength, ageBytes, 0, 4);
                    Array.Reverse(ageBytes);
                    info.Age = BitConverter.ToInt32(ageBytes, 0);

                    var areaLengthBytes = new byte[2];
                    Array.Copy(memberBytes, 28 + nameLength + cardLength, areaLengthBytes, 0, 2);
                    Array.Reverse(areaLengthBytes);
                    var areaLength = BitConverter.ToInt16(areaLengthBytes, 0);

                    var areaBytes = new byte[areaLength];
                    Array.Copy(memberBytes, 30 + nameLength + cardLength, areaBytes, 0, areaLength);
                    info.Area = Encoding.Default.GetString(areaBytes);

                    var addGroupTimesBytes = new byte[4];
                    Array.Copy(memberBytes, 30 + nameLength + cardLength + areaLength, addGroupTimesBytes, 0, 4);
                    Array.Reverse(addGroupTimesBytes);
                    info.JoinTime = new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime().AddSeconds(BitConverter.ToInt32(addGroupTimesBytes, 0));

                    var lastSpeakTimesBytes = new byte[4];
                    Array.Copy(memberBytes, 34 + nameLength + cardLength + areaLength, lastSpeakTimesBytes, 0, 4);
                    Array.Reverse(lastSpeakTimesBytes);
                    info.LastSpeakingTime = new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime().AddSeconds(BitConverter.ToInt32(lastSpeakTimesBytes, 0));

                    var levelNameLengthBytes = new byte[2];
                    Array.Copy(memberBytes, 38 + nameLength + cardLength + areaLength, levelNameLengthBytes, 0, 2);
                    Array.Reverse(levelNameLengthBytes);
                    var levelNameLength = BitConverter.ToInt16(levelNameLengthBytes, 0);

                    var levelNameBytes = new byte[levelNameLength];
                    Array.Copy(memberBytes, 40 + nameLength + cardLength + areaLength, levelNameBytes, 0, levelNameLength);
                    info.Level = Encoding.Default.GetString(levelNameBytes);

                    var authorBytes = new byte[4];
                    Array.Copy(memberBytes, 40 + nameLength + cardLength + areaLength + levelNameLength, authorBytes, 0, 4);
                    Array.Reverse(authorBytes);
                    var authority = BitConverter.ToInt32(authorBytes, 0);
                    info.Authority = authority.ToString();

                    var badBytes = new byte[4];
                    Array.Copy(memberBytes, 44 + nameLength + cardLength + areaLength + levelNameLength, badBytes, 0, 4);
                    Array.Reverse(badBytes);
                    info.HasBadRecord = BitConverter.ToInt32(badBytes, 0) == 1;

                    var titleLengthBytes = new byte[2];
                    Array.Copy(memberBytes, 48 + nameLength + cardLength + areaLength + levelNameLength, titleLengthBytes, 0,
                               2);
                    Array.Reverse(titleLengthBytes);
                    var titleLength = BitConverter.ToInt16(titleLengthBytes, 0);

                    var titleBytes = new byte[titleLength];
                    Array.Copy(memberBytes, 50 + nameLength + cardLength + areaLength + levelNameLength, titleBytes, 0,
                               titleLength);
                    info.Title = Encoding.Default.GetString(titleBytes);

                    var titleExpireBytes = new byte[4];
                    Array.Copy(memberBytes, 50 + nameLength + cardLength + areaLength + levelNameLength + titleLength,
                               titleExpireBytes, 0, 4);
                    Array.Reverse(titleExpireBytes);
                    info.TitleExpirationTime = BitConverter.ToInt32(titleExpireBytes, 0);

                    var modifyCardBytes = new byte[4];
                    Array.Copy(memberBytes, 54 + nameLength + cardLength + areaLength + levelNameLength + titleLength,
                               titleExpireBytes, 0, 4);
                    Array.Reverse(titleExpireBytes);
                    info.CanModifyInGroupName = BitConverter.ToInt32(modifyCardBytes, 0) == 1;

                    nLogger.Info(string.Format("[↓][帐号] 群成员: 昵称:{0} QQ:{1} 所属群:", info.NickName, info.Number, info.GroupId));
                    return(info);
                }
            } catch (Exception e) {
                nLogger.Error(e, string.Format("[X][帐号] 异常: {0}", e.Message));
                return(null);
            }
        }