Exemplo n.º 1
0
        public static void SendFriendMessage(long id, List <string> message)
        {
            var data = BuildPack.Build(new SendFriendMessagePack {
                id = id, message = message
            }, 54);

            QueueSend.Add(data);
        }
Exemplo n.º 2
0
        public static void CallEvent(long eventid, int dofun, List <object> arg)
        {
            var data = BuildPack.Build(new EventCallPack {
                eventid = eventid, dofun = dofun, arg = arg
            }, 59);

            QueueSend.Add(data);
        }
Exemplo n.º 3
0
        public static void SendGroupPrivateMessage(long id, long fid, List <string> message)
        {
            var data = BuildPack.Build(new SendGroupPrivateMessagePack {
                id = id, fid = fid, message = message
            }, 53);

            QueueSend.Add(data);
        }
Exemplo n.º 4
0
        public static void SendFriendImage(long id, string img)
        {
            var data = BuildPack.Build(new SendFriendImagePack {
                id = id, img = img
            }, 63);

            QueueSend.Add(data);
        }
Exemplo n.º 5
0
        public static void SendGroupPrivateImage(long id, long fid, string img)
        {
            var data = BuildPack.Build(new SendGroupPrivateImagePack {
                id = id, fid = fid, img = img
            }, 62);

            QueueSend.Add(data);
        }
Exemplo n.º 6
0
        public static void SendGroupMessage(long id, string message)
        {
            var data = BuildPack.Build(new SendGroupMessagePack {
                id = id, message = message
            }, 52);

            QueueSend.Add(data);
        }
Exemplo n.º 7
0
        public static void SendGroupImageFile(long qq, long id, string file)
        {
            var data = BuildPack.Build(new LoadFileSendToGroupImagePack {
                qq = qq, id = id, file = file,
            }, 75);

            QueueSend.Add(data);
        }
Exemplo n.º 8
0
        public static void SendGroupMessage(long qq, long id, List <string> message)
        {
            var data = BuildPack.Build(new SendGroupMessagePack {
                qq = qq, id = id, message = message
            }, 52);

            QueueSend.Add(data);
        }
Exemplo n.º 9
0
        public static void SendGroupSound(long id, string sound)
        {
            var data = BuildPack.BuildSound(id, sound, 74);

            QueueSend.Add(data);
        }
Exemplo n.º 10
0
        public static void SendFriendImage(long id, string img)
        {
            var data = BuildPack.BuildImage(id, 0, img, 63);

            QueueSend.Add(data);
        }
Exemplo n.º 11
0
        public static void SendGroupPrivateImage(long id, long fid, string img)
        {
            var data = BuildPack.BuildImage(id, fid, img, 62);

            QueueSend.Add(data);
        }
Exemplo n.º 12
0
        public static void Start()
        {
            QueueRead = new ConcurrentBag <RobotTask>();
            QueueSend = new ConcurrentBag <byte[]>();
            DoThread  = new Thread(() =>
            {
                RobotTask task;
                while (IsRun)
                {
                    try
                    {
                        if (QueueRead.TryTake(out task))
                        {
                            switch (task.index)
                            {
                            case 28:
                                var pack5 = JsonConvert.DeserializeObject <GroupMessagePostSendEventPack>(task.data);
                                if (pack5.res && pack5.message[pack5.message.Count - 1] == "3秒后撤回")
                                {
                                    Task.Run(() =>
                                    {
                                        Thread.Sleep(2900);
                                        string id = Utils.GetString(pack5.message[0], "source:", ",");
                                        var data  = BuildPack.Build(new ReCallMessage {
                                            id = long.Parse(id)
                                        }, 71);
                                        QueueSend.Add(data);
                                    });
                                }
                                break;

                            case 46:
                                var pack3 = JsonConvert.DeserializeObject <NewFriendRequestEventPack>(task.data);
                                Console.WriteLine("id = " + pack3.id);
                                Console.WriteLine("fid = " + pack3.fid);
                                Console.WriteLine("name = " + pack3.name);
                                Console.WriteLine("message = " + pack3.message);
                                Console.WriteLine("eventid = " + pack3.eventid);
                                Console.WriteLine();
                                CallEvent(pack3.eventid, 0, null);
                                break;

                            case 49:
                                var pack = JsonConvert.DeserializeObject <GroupMessageEventPack>(task.data);
                                Console.WriteLine("id = " + pack.id);
                                Console.WriteLine("fid = " + pack.fid);
                                Console.WriteLine("name = " + pack.name);
                                Console.WriteLine("message = ");
                                foreach (var item in pack.message)
                                {
                                    Console.WriteLine(item);
                                }
                                Console.WriteLine();
                                if (pack.message[pack.message.Count - 1] == "撤回")
                                {
                                    string id = Utils.GetString(pack.message[0], "source:", ",");
                                    var data  = BuildPack.Build(new ReCallMessage {
                                        id = long.Parse(id)
                                    }, 71);
                                    QueueSend.Add(data);
                                }
                                else if (pack.message[pack.message.Count - 1] == "回复")
                                {
                                    string id = Utils.GetString(pack.message[0], "source:", ",");
                                    var list2 = new List <string>()
                                    {
                                        "quote:" + id
                                    };
                                    list2.Add("回复消息");
                                    SendGroupMessage(pack.id, list2);
                                }
                                else if (pack.message[pack.message.Count - 1] == "撤回自己")
                                {
                                    var list2 = new List <string>()
                                    {
                                        "3秒后撤回"
                                    };
                                    SendGroupMessage(pack.id, list2);
                                }
                                break;

                            case 50:
                                var pack1 = JsonConvert.DeserializeObject <TempMessageEventPack>(task.data);
                                Console.WriteLine("id = " + pack1.id);
                                Console.WriteLine("fid = " + pack1.fid);
                                Console.WriteLine("name = " + pack1.name);
                                Console.WriteLine("message = ");
                                foreach (var item in pack1.message)
                                {
                                    Console.WriteLine(item);
                                }
                                Console.WriteLine();
                                var list = new List <string>()
                                {
                                    pack1.name
                                };
                                list.AddRange(pack1.message);
                                SendGroupPrivateMessage(pack1.id, pack1.fid, list);
                                break;

                            case 51:
                                var pack2 = JsonConvert.DeserializeObject <FriendMessageEventPack>(task.data);
                                Console.WriteLine("id = " + pack2.id);
                                Console.WriteLine("time = " + pack2.time);
                                Console.WriteLine("name = " + pack2.name);
                                Console.WriteLine("message = ");
                                foreach (var item in pack2.message)
                                {
                                    Console.WriteLine(item);
                                }
                                Console.WriteLine();
                                var list1 = new List <string>()
                                {
                                    pack2.name
                                };
                                list1.AddRange(pack2.message);
                                SendFriendMessage(pack2.id, list1);
                                break;
                            }
                        }
                        Thread.Sleep(10);
                    }
                    catch (Exception e)
                    {
                        ServerMain.LogError(e);
                    }
                }
            });

            ReadThread = new Thread(() =>
            {
                while (!IsRun)
                {
                    Thread.Sleep(100);
                }
                DoThread.Start();
                byte[] Send;
                int time = 0;
                while (IsRun)
                {
                    try
                    {
                        if (!IsConnect)
                        {
                            ReConnect();
                        }
                        else if (Socket.Available > 0)
                        {
                            var data = new byte[Socket.Available];
                            Socket.Receive(data);
                            var type = data[data.Length - 1];
                            data[data.Length - 1] = 0;
                            QueueRead.Add(new RobotTask
                            {
                                index = type,
                                data  = Encoding.UTF8.GetString(data)
                            });
                        }
                        else if (time >= 20)
                        {
                            time = 0;
                            if (Socket.Poll(1000, SelectMode.SelectRead))
                            {
                                ServerMain.LogOut("机器人连接中断");
                                IsConnect = false;
                            }
                        }
                        else if (QueueSend.TryTake(out Send))
                        {
                            Socket.Send(Send);
                        }
                        time++;
                        Thread.Sleep(50);
                    }
                    catch (Exception e)
                    {
                        ServerMain.LogError("机器人连接失败");
                        ServerMain.LogError(e);
                        IsConnect = false;
                        ServerMain.LogError("机器人20秒后重连");
                        Thread.Sleep(20000);
                        ServerMain.LogError("机器人重连中");
                    }
                }
            });
            ReadThread.Start();
            IsRun = true;
            ReadTest();
        }
Exemplo n.º 13
0
        public static void SendGroupImage(long qq, long id, string img)
        {
            var data = BuildPack.BuildImage(qq, id, 0, img, 61);

            QueueSend.Add(data);
        }