///// <summary>
        ///// QQ群列表
        ///// </summary>
        //public List<ClusterInfo> ClusterList { get; set; }
        protected override void ParseBody(ByteBuffer buf)
        {
            #if DEBUG
            Client.LogManager.Log(ToString() + " Decoded Data:" + Utils.Util.ToHex(buf.ToByteArray()));
            #endif

            ReplyCode = buf.GetChar();//00 9C
            buf.GetInt();//00 00 00 00
            NextPos = buf.GetUShort();
            Finished = !(ReplyCode == 0x038A && NextPos > 0);
            //this.ClusterList = new List<ClusterInfo>();
            //this.QQFriendList = new List<QQFriend>();
            this.QQList = new List<QQBasicInfo>();
            while (buf.Position + 2 < buf.Length)
            {
                int number = buf.GetInt();
                QQType type =(QQType) buf.Get();
                byte gid = buf.Get();

                QQBasicInfo qq = new QQBasicInfo(number, type, ((int)gid) / 4);
                //qq.UIN = number;
                //qq.GroupId = ((int)gid) / 4;
                //qq.Type = (QQType)type;
                this.QQList.Add(qq);
                //if (type == 0x04)
                //{
                //    ClusterInfo ci = new ClusterInfo();
                //    ci.ClusterId =(uint) number;//群内部号码
                //    this.ClusterList.Add(ci);
                //}
                //else if (type == 0x01)
                //{
                //    QQFriend friend = new QQFriend();

                //    friend.QQ = number;
                //    friend.GroupId = ((int)gid)/4;
                //    this.QQFriendList.Add(friend);
                //}
                //else
                //{
                //    Client.LogManager.Log("unknown type: type=0x"+type.ToString("X2")+" number="+number.ToString() +" gid=0x"+gid.ToString("X2"));
                //}

            }
        }
Example #2
0
        private static void ParseCommand(string s)
        {
            string[] args = s.Split(new char[] { ' ', '\t' },StringSplitOptions.RemoveEmptyEntries);
            if (args.Length > 0)
            {
                switch (args[0].ToLower())
                {
                    case "t":
                    case "to":
                        if (args.Length > 2)
                            {
                                int qqnum =0;
                                int.TryParse(args[1], out qqnum);
                                //if (Client.QQUser.Friends.ContainsKey(qqnum))
                               // {
                                    SendMsg(qqnum, args[2]);
                                    //Echo("two parm");
                               // }
                               // else if (Client.QQUser.ClusterList.ContainsKey(qqnum))
                               // {
                               //     SendMsg(qqnum, args[2]);
                               // }
                               // else
                               // {
                               //     Echo("未找到该QQ好友!请使用?获取帮助");
                               // }
                            }//此处需要增加直接发送消息的方法

                        else
                            ChatToQQ(args[1]);
                        break;
                    case "tq":
                    case "toqun":
                        //if (args.Length > 2)
                        //{
                        //    int qqqnum = 0;
                        //    int.TryParse(args[1], out qqqnum);
                            //if (Client.QQUser.ClusterList.ContainsKey(qqqnum))
                           // {
                           //     SendMsg(qqqnum, args[2]);
                                //Echo("two parm");
                            //}
                           // else
                           //     {
                           //         Echo("未找到该QQ群!");
                           //     }
                        // }
                        //else
                        //    ChatToQQ(args[1]);
                        try
                        {
                            int.Parse(args[1]);
                        }
                        catch (Exception)
                        {
                            Echo("发送消息失败,请输入正确的群号码!");
                            return;
                        }
                        if (args.Length > 1)
                        {
                            if (args.Length <= 2)
                            {
                                Echo("程序指令出错!请检查!");
                                return;
                            }
                            int num3 = 0;
                            if (!int.TryParse(args[1], out num3))
                            {
                                return;
                            }
                            if (!Client.QQUser.ClusterList.ContainsKey(num3))
                            {
                                Echo("未找到该群号码!");
                                return;
                            }
                            int num4 = 2;
                            string str2 = "";
                            while (num4 < args.Length)
                            {
                                str2 = str2 + args[num4] + " ";
                                num4++;
                            }
                            TQQ = Client.QQUser.ClusterList[num3].QQBasicInfo;
                            SendMsg(TQQ, str2);
                            TQQ = null;
                        }

                       break;
                    case "l":
                    case "list":
                    case "view":
                        List();
                        break;
                    case "o":
                    case "ol":
                    case "onlines":
                    case "listonlines":
                        OnLineList();
                        break;
                    case "add":
                    case "+":
                    case "a"://应该不要吧
                        int q = 0;
                        try
                        {
                            q=int.Parse(args[1]);
                        }
                        catch(Exception e)
                        {
                            Echo("添加失败,请输入正确的QQ号码!"+e);
                            break;
                        }
                        if (args.Length > 2)
                        {
                            Client.FriendManager.SendAddFriendAuth(q, args[2]);
                            Echo("添加好友:" + q.ToString() + ",附加消息" + args[2]);
                        }
                        else
                        {
                            Client.FriendManager.AddFriend(q);
                            Echo("添加好友:" + q.ToString() );
                        }
                        FriendAction();
                        break;
                    case "sign":

                        if (args.Length < 2 || args.Length>2)
                        {

                            Echo("参数错误");
                        }
                        else
                         {

                             Echo(args[1]);
                            if (args[1]=="''")
                                //
                            {//删除签名
                                Client.PrivateManager.DeleteSignature();
                            }
                            else
                            {//修改签名

                                Client.PrivateManager.ModifySignature(utf2gbk(args[1]));
                                //if (PM.ModifySignatureSuccessed == true)
                                //    Echo("success");
                            }
                        }
                        break;
                    case "v":
                    case "vibration":
                        if (args.Length > 1)
                        {
                            int qqnum = 0;
                            if (int.TryParse(args[1], out qqnum))
                            {
                                if (Client.QQUser.Friends.ContainsKey(qqnum))
                                {
                                    int t = 1;
                                    if (args.Length > 2)
                                        int.TryParse(args[2], out t);
                                    for (int i = 0; i < t; i++)
                                    {
                                        Client.MessageManager.SendVibration(qqnum);
                                        Echo(string.Format("你给 {1}[{0}] 发送振动", qqnum, Client.QQUser.Friends[qqnum].Nick));
                                        Thread.Sleep(10000);//休眠 防止发送过快
                                    }

                                }
                                else
                                    Echo("未找到该QQ好友!");
                            }
                            else
                            {
                                Echo("QQ号错误,命令格式为: -v 123456");
                            }
                        }
                        else
                        {
                            if (TQQ != null)
                            {
                                Client.MessageManager.SendVibration(TQQ.QQ);
                                Echo(string.Format("你给 {1}[{0}] 发送振动", TQQ, Client.QQUser.Friends[TQQ.QQ].Nick));
                            }
                        }
                        break;

                    case "h":
                    case "help":
                    case "?":
                        HelpMessage();
                        break;
                    case "c":
                    case "cls":
                        Console.Clear();
                        break;

                }

            }
        }
Example #3
0
        /// <summary>
        /// 和谁聊天
        /// </summary>
        /// <param name="args"></param>
        private static void ChatToQQ(string To)
        {
            int qqnum = 0;
            if (int.TryParse(To, out qqnum))
            {
                if (Client.QQUser.Friends.ContainsKey(qqnum))
                {
                    TQQ = Client.QQUser.QQList[qqnum];
                    Echo("你将和 " + TQQ.QQ.ToString() + "[" + Client.QQUser.Friends[TQQ.QQ].Nick + "] 聊天。");

                }
                else if (Client.QQUser.ClusterList.ContainsKey(qqnum))
                {
                    TQQ = Client.QQUser.ClusterList[qqnum].QQBasicInfo;
                    Echo("你将在群 " + TQQ.QQ.ToString() + "[" + Client.QQUser.ClusterList[TQQ.QQ].Name + "] 中聊天。");
                }
                else
                {
                    Echo("输入的QQ号错误,当前好友列表中没有该好友!请使用/view命令查看好友列表");
                }

            }
            else
            {
                //var q=from fi in Client.QQUser.Friends.Values where  fi.
                List<QQFriend> fl = new List<QQFriend>();
                foreach (QQFriend  Friend in Client.QQUser.Friends.Values)
                {
                    if (Friend.Nick != null && Friend.Nick.Contains(To))
                    {
                        fl.Add(Friend);
                    }
                }
                if (fl.Count == 0)
                {
                    Echo("好友列表中没有该好友!请使用/view命令查看好友列表");
                }
                else if (fl.Count == 1)
                {
                    TQQ = fl[0].QQBasicInfo;
                    Echo("你将和 " + TQQ.QQ.ToString() + "[" + Client.QQUser.Friends[TQQ.QQ].Nick + "] 聊天。");
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("共找到 " + fl.Count.ToString() + " 位好友,请使用-To QQ号命令从下面选择一位好友");
                    sb.AppendLine(string.Format("{0,-12}{1,-20}\t{2,-5}\t{3,-5}\t{4,-5}\t{5,5}", "好友", "昵称", "头像", "年龄", "性别", "状态"));
                    foreach (QQFriend Friend in fl)
                    {
                        sb.AppendLine(string.Format("{0,-12}{1,-20}\t{2,7}\t{3,7}\t{4,7}\t{5,7}", Friend.QQ, Friend.Nick, Friend.Header.ToString(), Friend.Age, Friend.Gender, Friend.FriendStatus.Status.ToString()));
                    }
                    Echo(sb.ToString());
                }
            }
        }
Example #4
0
        private static void getsleep(object source, ElapsedEventArgs e)
        {
            get();
            if (getcode != "")
            {
                string[] strArray = Regex.Split(getcode, "\n");
                string str2 = strArray[0];
                int qq = strArray.Length > 2?int.Parse(strArray[1]):0;
                int index = 2;
                string msg = "";
                if (strArray.Length > 2)
                {
                    while (index < strArray.Length)
                    {
                        msg = msg + strArray[index] + " ";
                        index++;
                    }
                }
                switch (str2)
                {
                    case "-4":
                        {

                            Echo("签名!");
                            return;
                        }
                    case "-1":
                        {

                            Echo("连接接口服务器失败!请检查配置文件!");
                            return;
                        }
                    case "0":
                        {
                            int key = qq;
                            if (Client.QQUser.Friends.ContainsKey(key))
                            {
                                TQQ = Client.QQUser.QQList[key];
                                SendMsg(TQQ, msg);
                                TQQ = null;
                                return;
                            }
                            else
                            {
                                Echo("未能在好友列表中找到该QQ号码!");
                                return;
                            }
                        }
                    case "2":
                        {
                            int num4 = qq;
                            if (Client.QQUser.ClusterList.ContainsKey(num4))
                            {
                                TQQ = Client.QQUser.ClusterList[num4].QQBasicInfo;
                                SendMsg(TQQ, msg);
                                TQQ = null;
                                return;
                            }
                            else
                            {
                                Echo("未找到该群号码!");
                                return;
                            }
                        }
                    case "3":
                        Client.LoginManager.Logout();
                        Console.WriteLine();
                        Console.WriteLine("退出成功");
                        Thread.Sleep(0x7d0);
                        Client.LoginStatus = LoginStatus.Logout;
                        StartLogin();
                        AddEvents();
                        startmessage();
                        return;

                    case "4":
                        Process.Start("update.bat");
                        return;

                    case "5":
                        {
                            int num5 = qq;
                            if (Client.QQUser.Friends.ContainsKey(num5))
                            {
                                Client.MessageManager.SendVibration(num5);
                                Echo(string.Format("你给 {1}[{0}] 发送振动", num5, Client.QQUser.Friends[num5].Nick));
                                return;
                            }
                            else
                            {
                                Echo("未能在好友列表中找到该QQ号码!");
                                return;
                            }
                        }
                    case "on":
                        Program.AutoReply = "start";
                        SendMsg(qq, msg);
                        Echo("接口已开启自动回复功能!");
                        return;

                    case "off":
                        Program.AutoReply = "sleep";
                        SendMsg(qq, msg);
                        Echo("接口已关闭自动回复功能!");
                        return;

                    case "qunon":
                        Program.qunAutoReply = "start";
                        Client.ClusterManager.SendClusterIM(qq, msg);
                        Echo("接口开启闭群自动回复功能!");
                        return;

                    case "qunoff":
                        Program.qunAutoReply = "sleep";
                        Client.ClusterManager.SendClusterIM(qq, msg);
                        Echo("接口已关闭群自动回复功能!");
                        break;
                }
            }
        }
Example #5
0
        /// <summary>
        /// 重载SendMsg
        /// </summary>
        private static void SendMsg(QQBasicInfo TQQ, string msg)
        {
            switch (TQQ.Type)
                {
                    case QQType.QQ:
                        if (Client.QQUser.Friends.ContainsKey(TQQ.QQ))
                        {
                            Client.MessageManager.SendIM(TQQ.QQ, msg);
                            Echo(string.Format(DateTime.Now.ToShortTimeString() + ",你对 {0}[{1}] 说:\n\t{2}", TQQ.QQ, Client.QQUser.Friends[TQQ.QQ].Nick, msg));
                        }
                        else
                        {
                            Echo(" 该号码不存在,请首先使用-l命令查询好友信息");
                        }
                        break;
                    case QQType.Cluster:
                        if (Client.QQUser.ClusterList.ContainsKey(TQQ.QQ))
                        {
                            Client.ClusterManager.SendClusterIM(TQQ.QQ, msg);
                            Echo(string.Format(DateTime.Now.ToShortTimeString() + "你在群 {0}[{1}] 里说:\n\t{2}", Client.QQUser.ClusterList[TQQ.QQ].ExternalId, Client.QQUser.ClusterList[TQQ.QQ].Name, msg));
                        }
                        else
                        {
                            Echo(" 该群不存在,请首先使用-l命令查询群信息");
                        }
                        break;

                }
        }