Ejemplo n.º 1
0
 /// <summary>
 /// Type=102 群事件-群成员减少。
 /// </summary>
 /// <param name="subType">子类型,1/群员离开 2/群员被踢 3/自己(即登录号)被踢。</param>
 /// <param name="sendTime">发送时间(时间戳)。</param>
 /// <param name="fromGroup">来源群。</param>
 /// <param name="fromQQ">来源QQ。</param>
 /// <param name="beingOperateQQ">被操作QQ。</param>
 public override void GroupMemberDecrease(int subType, int sendTime, long fromGroup, long fromQQ, long beingOperateQQ)
 {
     // 处理群事件-群成员减少。
     if (fromGroup == GroupSet1)
     {
         if (subType == 1)
         {
             String a = XML.read(config_read.Event, "事件-群员退出");
             if (a != "")
             {
                 a = a.Replace("%player%", CQ.GetQQName(beingOperateQQ));
                 CQ.SendGroupMessage(fromGroup, a);
             }
         }
         if (subType == 2)
         {
             String a = XML.read(config_read.Event, "事件-踢出群员");
             if (a != "")
             {
                 a = a.Replace("%player%", CQ.GetQQName(beingOperateQQ));
                 CQ.SendGroupMessage(fromGroup, a);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Type=11 群文件上传事件。
 /// </summary>
 /// <param name="subType">子类型,目前固定为1。</param>
 /// <param name="sendTime">发送时间(时间戳)。</param>
 /// <param name="fromGroup">来源群号。</param>
 /// <param name="fromQQ">来源QQ。</param>
 /// <param name="file">上传文件信息。</param>
 public override void GroupUpload(int subType, int sendTime, long fromGroup, long fromQQ, string file)
 {
     // 处理群文件上传事件。
     if (fromGroup == GroupSet1)
     {
         string a = XML.read(config_read.Event, "事件-文件上传");
         if (a != "")
         {
             a = a.Replace("%player%", CQ.GetQQName(fromQQ));
             a = a.Replace("%file%", file);
             CQ.SendGroupMessage(fromGroup, a);
         }
     }
 }
Ejemplo n.º 3
0
 private static void Send(Socket socket, string data)
 {
     if (socket != null && data != null && !data.Equals(""))
     {
         byte[] bytes = null;
         if (XML.read(config_read.config, "编码") == "UTF-8")
         {
             bytes = Encoding.UTF8.GetBytes(data);
         }
         if (XML.read(config_read.config, "编码") == "ANSI(GBK)")
         {
             bytes = Encoding.Default.GetBytes(data);
         }
         socket.Send(bytes);
     }
 }
Ejemplo n.º 4
0
 private static void message(string read)
 {
     if (read.IndexOf("[群消息]") == 0)
     {
         var sb = new StringBuilder(read);
         sb.Replace("[群消息]", string.Empty);
         string x = sb.ToString();
         string z = use.get_string(x, "(", ")");
         if (XML.read(config_read.mute, z) != "true")
         {
             x = x.Replace("(" + z + ")", "");
             CQ.SendGroupMessage(Minecraft_QQ.GroupSet1, x);
             if (Minecraft_QQ.GroupSet2 != 0 && Minecraft_QQ.Group2_on == true)
             {
                 CQ.SendGroupMessage(Minecraft_QQ.GroupSet2, x);
             }
             if (Minecraft_QQ.GroupSet3 != 0 && Minecraft_QQ.Group3_on == true)
             {
                 CQ.SendGroupMessage(Minecraft_QQ.GroupSet3, x);
             }
         }
         Minecraft_QQ.Group = 0;
         return;
     }
     else if (Minecraft_QQ.Group == 1)
     {
         CQ.SendGroupMessage(Minecraft_QQ.GroupSet1, read);
         Minecraft_QQ.Group = 0;
         return;
     }
     else if (Minecraft_QQ.Group == 2)
     {
         CQ.SendGroupMessage(Minecraft_QQ.GroupSet2, read);
         Minecraft_QQ.Group = 0;
         return;
     }
     else if (Minecraft_QQ.Group == 3)
     {
         CQ.SendGroupMessage(Minecraft_QQ.GroupSet3, read);
         Minecraft_QQ.Group = 0;
         return;
     }
 }
Ejemplo n.º 5
0
 public static string get_at(string a)
 {
     for (; a.IndexOf("[CQ:at,qq=") != -1;)
     {
         string b = get_string(a, "=", "]");
         string c = get_string(a, "[", "]");
         string d;
         if (Minecraft_QQ.Mysql_mode == true)
         {
             string e = Mysql.mysql_search(Mysql.Mysql_player, b);
             if (e == null)
             {
                 d = b;
             }
             else
             {
                 d = e;
             }
         }
         else
         {
             string e = XML.read(config_read.player, b);
             if (e == null)
             {
                 d = b;
             }
             else
             {
                 d = e;
             }
         }
         a = a.Replace(c, "@" + d + "");
     }
     if (a.IndexOf("CQ:at,qq=all") != -1)
     {
         a.Replace("CQ:at,qq=all", "@全体人员");
     }
     a = a.Replace("[", "").Replace("]", "");
     return(a);
 }
Ejemplo n.º 6
0
        private static string Receive(Socket socket)
        {
            string data = "";

            byte[] bytes = null;
            int    len   = socket.Available;

            if (len > 0)
            {
                bytes = new byte[len];
                int receiveNumber = socket.Receive(bytes);

                if (XML.read(config_read.config, "编码") == "UTF-8")
                {
                    data = Encoding.UTF8.GetString(bytes, 0, receiveNumber);
                }
                if (XML.read(config_read.config, "编码") == "ANSI(GBK)")
                {
                    data = Encoding.Default.GetString(bytes, 0, receiveNumber);
                }
            }
            return(data);
        }
Ejemplo n.º 7
0
        public static bool mysql_start()
        {
            Mysql_IP       = XML.read(config_read.config, "Mysql地址");
            Mysql_Port     = XML.read(config_read.config, "Mysql端口");
            Mysql_User     = XML.read(config_read.config, "Mysql账户");
            Mysql_Password = XML.read(config_read.config, "Mysql密码");

            ConnectString = string.Format("SslMode=none;Server={0};Port={1};User ID={2};Password={3};Database=minecraft_qq;", Mysql_IP, Mysql_Port, Mysql_User, Mysql_Password);
            conn          = new MySqlConnection(ConnectString);

            if (mysql_add_table(Mysql_player) == false)
            {
                return(false);
            }
            if (mysql_add_table(Mysql_notid) == false)
            {
                return(false);
            }
            if (mysql_add_table(Mysql_mute) == false)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
        public static void read_config()
        {
            FormSettings frm = new FormSettings();

            if (Directory.Exists(path) == false)
            {
                Directory.CreateDirectory(path);
            }
            if (File.Exists(path + config) == false)
            {
                XML.write(config, "更新?", "false");
                XML.write(config, "IP", "127.0.0.1");
                XML.write(config, "Port", "25555");
                XML.write(config, "编码", "ANSI(GBK)");
                XML.write(config, "发送消息", "不!");
                XML.write(config, "发送文本", "%player%:%message%");
                XML.write(config, "维护模式", "关");
                XML.write(config, "Mysql地址", "127.0.0.1");
                XML.write(config, "Mysql端口", "3306");
                XML.write(config, "Mysql账户", "root");
                XML.write(config, "Mysql密码", "123456");
                XML.write(config, "Mysql启用", "关");
            }
            if (XML.read(config, "更新?") != "false")
            {
                XML.write(config, "更新?", "false");
                if (XML.read(config, "IP") == null)
                {
                    XML.write(config, "IP", "127.0.0.1");
                }
                if (XML.read(config, "Port") == null)
                {
                    XML.write(config, "Port", "25555");
                }
                if (XML.read(config, "编码") == null)
                {
                    XML.write(config, "编码", "ANSI(GBK)");
                }
                if (XML.read(config, "发送消息") == null)
                {
                    XML.write(config, "发送消息", "不!");
                }
                if (XML.read(config, "发送文本") == null)
                {
                    XML.write(config, "发送文本", "%player%:%message%");
                }
                if (XML.read(config, "维护模式") == null)
                {
                    XML.write(config, "维护模式", "关");
                }
                if (XML.read(config, "Mysql地址") == null)
                {
                    XML.write(config, "Mysql地址", "127.0.0.1");
                }
                if (XML.read(config, "Mysql端口") == null)
                {
                    XML.write(config, "Mysql端口", "3306");
                }
                if (XML.read(config, "Mysql账户") == null)
                {
                    XML.write(config, "Mysql账户", "root");
                }
                if (XML.read(config, "Mysql密码") == null)
                {
                    XML.write(config, "Mysql密码", "123456");
                }
                if (XML.read(config, "Mysql启用") == null)
                {
                    XML.write(config, "Mysql启用", "关");
                }
            }

            if (File.Exists(path + mute) == false)
            {
                XML.CreateFile(mute, 0);
            }

            if (File.Exists(path + admin) == false)
            {
                XML.write(admin, "发送给的人", null);
            }

            if (File.Exists(path + player) == false)
            {
                XML.CreateFile(player, 0);
            }

            if (File.Exists(path + Event) == false)
            {
                XML.write(Event, "更新?", "false");
                XML.write(Event, "事件-群员加入", "欢迎新人%player%,输入【%服务器菜单】获取更多帮助。");
                XML.write(Event, "事件-群员退出", "%player%退出了群");
                XML.write(Event, "事件-文件上传", "%player%上传了文件%file%");
                XML.write(Event, "事件-踢出群员", "%player%感受制裁吧!");
                XML.write(Event, "在线人数", "在线人数");
                XML.write(Event, "服务器状态", "服务器状态");
                XML.write(Event, "绑定文本", "绑定:");
                XML.write(Event, "发送文本", "服务器:");
                XML.write(Event, "禁言文本", "禁言:");
                XML.write(Event, "解禁文本", "解禁:");
                XML.write(Event, "查询玩家ID", "查询:");
                XML.write(Event, "修改玩家ID", "修改:");
                XML.write(Event, "维护文本", "服务器维护");
                XML.write(Event, "服务器维护文本", "服务器正在维护,请等待维护结束!");
                XML.write(Event, "机器人功能-重读配置文件", "重读文件");
                XML.write(Event, "机器人功能-内存回收", "内存回收");
                XML.write(Event, "启用群内绑定", "启用");
            }
            if (XML.read(Event, "更新?") != "false")
            {
                XML.write(Event, "更新?", "false");
                if (XML.read(Event, "事件-群员加入") == null)
                {
                    XML.write(Event, "事件-群员加入", "欢迎新人%player%,输入【%服务器菜单】获取更多帮助。");
                }
                if (XML.read(Event, "事件-群员退出") == null)
                {
                    XML.write(Event, "事件-群员退出", "%player%退出了群");
                }
                if (XML.read(Event, "事件-文件上传") == null)
                {
                    XML.write(Event, "事件-文件上传", "%player%上传了文件%file%");
                }
                if (XML.read(Event, "事件-踢出群员") == null)
                {
                    XML.write(Event, "事件-踢出群员", "%player%感受制裁吧!");
                }
                if (XML.read(Event, "在线人数") == null)
                {
                    XML.write(Event, "在线人数", "在线人数");
                }
                if (XML.read(Event, "服务器状态") == null)
                {
                    XML.write(Event, "服务器状态", "服务器状态");
                }
                if (XML.read(Event, "绑定文本") == null)
                {
                    XML.write(Event, "绑定文本", "绑定:");
                }
                if (XML.read(Event, "发送文本") == null)
                {
                    XML.write(Event, "发送文本", "服务器:");
                }
                if (XML.read(Event, "禁言文本") == null)
                {
                    XML.write(Event, "禁言文本", "禁言:");
                }
                if (XML.read(Event, "解禁文本") == null)
                {
                    XML.write(Event, "解禁文本", "解禁:");
                }
                if (XML.read(Event, "查询玩家ID") == null)
                {
                    XML.write(Event, "查询玩家ID", "查询:");
                }
                if (XML.read(Event, "修改玩家ID") == null)
                {
                    XML.write(Event, "修改玩家ID", "修改:");
                }
                if (XML.read(Event, "修改玩家ID") == null)
                {
                    XML.write(Event, "修改玩家ID", "修改:");
                }
                if (XML.read(Event, "维护文本") == null)
                {
                    XML.write(Event, "维护文本", "服务器维护");
                }
                if (XML.read(Event, "服务器维护文本") == null)
                {
                    XML.write(Event, "服务器维护文本", "服务器正在维护,请等待维护结束!");
                }
                if (XML.read(Event, "机器人功能-重读配置文件") == null)
                {
                    XML.write(Event, "机器人功能-重读配置文件", "重读文件");
                }
                if (XML.read(Event, "机器人功能-内存回收") == null)
                {
                    XML.write(Event, "机器人功能-内存回收", "内存回收");
                }
                if (XML.read(Event, "启用群内绑定") == null)
                {
                    XML.write(Event, "启用群内绑定", "启用");
                }
            }

            if (File.Exists(path + message) == false)
            {
                XML.write(message, "启用", "true");
                XML.write(message, "%服务器菜单", "服务器查询菜单:\r\n【" + XML.read(Event, "绑定文本") + "】可以绑定你的游戏ID。\r\n【在线人数】可以查询服务器在线人数。\r\n【服务器状态】可以查询服务器是否在运行。\r\n【" + XML.read(Event, "发送文本") + "内容】可以向服务器里发送消息。");
            }
            if (XML.read(message, "启用") == null)
            {
                XML.write(message, "启用", "true");
                if (XML.read(message, "%服务器菜单") == null)
                {
                    XML.write(message, "%服务器菜单", "服务器查询菜单:\r\n【" + XML.read(Event, "绑定文本") + "】可以绑定你的游戏ID。\r\n【在线人数】可以查询服务器在线人数。\r\n【服务器状态】可以查询服务器是否在运行。\r\n【" + XML.read(Event, "发送文本") + "内容】可以向服务器里发送消息。");
                }
            }

            string check = XML.read(config, "群号1");

            if (check == null)
            {
                MessageBox.Show("未设置群号,请设置"); frm.ShowDialog();
            }
            else
            {
                Minecraft_QQ.GroupSet1 = long.Parse(check);
            }
            Minecraft_QQ.ipaddress = XML.read(config, "IP");
            if (Minecraft_QQ.ipaddress == null)
            {
                MessageBox.Show("未设置IP,请设置"); frm.ShowDialog();
            }
            else
            {
                Minecraft_QQ.ipaddress = XML.read(config, "IP");
            }
            check = XML.read(config, "Port");
            if (check == null)
            {
                MessageBox.Show("未设置端口,请设置"); frm.ShowDialog();
            }
            else
            {
                Minecraft_QQ.Port = int.Parse(check);
            }

            CQ.SendGroupMessage(Minecraft_QQ.GroupSet1, "[Minecraft_QQ]正在启动");


            check = XML.read(config, "群号2");
            if (check != null)
            {
                Minecraft_QQ.GroupSet2 = long.Parse(check);
            }
            else
            {
                Minecraft_QQ.GroupSet2 = 0;
            }
            check = XML.read(config, "群号3");
            if (check != null)
            {
                Minecraft_QQ.GroupSet3 = long.Parse(check);
            }
            else
            {
                Minecraft_QQ.GroupSet3 = 0;
            }

            if (!File.Exists(path + logs.log))
            {
                File.WriteAllText(path + logs.log, "正在尝试创建文件" + Environment.NewLine);
            }

            if (XML.read(config, "维护模式") == "关")
            {
                Minecraft_QQ.server = true;
            }
            else
            {
                Minecraft_QQ.server = false;
            }

            if (XML.read(config, "群2发送消息") == "开")
            {
                Minecraft_QQ.Group2_on = true;
            }
            else
            {
                Minecraft_QQ.Group2_on = false;
            }
            if (XML.read(config, "群3发送消息") == "开")
            {
                Minecraft_QQ.Group3_on = true;
            }
            else
            {
                Minecraft_QQ.Group3_on = false;
            }

            if (XML.read(config, "Mysql启用") == "开")
            {
                CQ.SendGroupMessage(Minecraft_QQ.GroupSet1, "[Minecraft_QQ]正在链接Mysql");
                if (Mysql.mysql_start() == true)
                {
                    Minecraft_QQ.Mysql_mode = true;
                }
                else
                {
                    Minecraft_QQ.Mysql_mode = false;
                    MessageBox.Show("Mysql错误,请检查");
                }
                CQ.SendGroupMessage(Minecraft_QQ.GroupSet1, "[Minecraft_QQ]Mysql已连接");
            }
            else
            {
                Minecraft_QQ.Mysql_mode = false;
            }
            socket.Start_socket();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Type=21 私聊消息。
        /// </summary>
        /// <param name="subType">子类型,11/来自好友 1/来自在线状态 2/来自群 3/来自讨论组。</param>
        /// <param name="sendTime">发送时间(时间戳)。</param>
        /// <param name="fromQQ">来源QQ。</param>
        /// <param name="msg">消息内容。</param>
        /// <param name="font">字体。</param>
        public override void PrivateMessage(int subType, int sendTime, long fromQQ, string msg, int font)
        {
            // 处理私聊消息。
            logs.Log_write("私聊消息" + '[' + fromQQ.ToString() + "][" + CQ.GetQQName(fromQQ) + "]:" + msg);
            if (msg.IndexOf(XML.read(config_read.Event, "绑定文本")) == 0)
            {
                string player = null;
                if (Mysql_mode == true)
                {
                    player = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                }
                else
                {
                    player = XML.read(config_read.player, fromQQ.ToString());
                }
                if (player == null)
                {
                    string player_name = msg.Replace(XML.read(config_read.Event, "绑定文本"), "");
                    if (player_name == " " || player_name == "" || use.IsNatural_Number(player_name) == false)
                    {
                        CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "绑定失败,请检查你的ID");
                    }
                    else
                    {
                        player_name = player_name.Trim();
                        if (Mysql_mode == true)
                        {
                            if (Mysql.mysql_search(Mysql.Mysql_notid, player_name.ToLower()) == "notid")
                            {
                                CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "禁止绑定ID:" + player_name);
                                return;
                            }
                            Mysql.mysql_add(Mysql.Mysql_player, fromQQ.ToString(), player_name.ToString());
                        }
                        else
                        {
                            if (XML.read(config_read.notid, player_name.ToLower()) == "notid")
                            {
                                CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "禁止绑定ID:" + player_name);
                                return;
                            }
                            XML.write(config_read.player, fromQQ.ToString(), player_name);
                        }

                        CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "绑定ID:" + player_name + "成功!");

                        string qq_admin = XML.read(config_read.admin, "发送给的人");
                        if (qq_admin != null)
                        {
                            CQ.SendPrivateMessage(long.Parse(qq_admin), "玩家[" + CQ.GetQQName(fromQQ) + "]绑定了ID:[" + player_name + "]");
                        }
                    }
                }
                else
                {
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "你已经绑定ID了,请找腐竹更改");
                }
            }
            if (msg.IndexOf(XML.read(config_read.Event, "禁言文本")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                string player      = msg.Replace(XML.read(config_read.Event, "禁言文本"), "");
                string player_name = null;
                if (player.IndexOf("[CQ") != -1)
                {
                    player = use.get_string(player, "=", "]");
                    if (Mysql_mode == true)
                    {
                        player_name = Mysql.mysql_search(Mysql.Mysql_player, player);
                    }
                    else
                    {
                        player_name = XML.read(config_read.player, player);
                    }
                }
                else
                {
                    player_name = player;
                }
                player_name = player_name.Trim();
                if (player_name == null)
                {
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "该玩家未绑定ID");
                }
                else
                {
                    if (Mysql_mode == true)
                    {
                        Mysql.mysql_add(Mysql.Mysql_mute, player_name.ToLower(), "true");
                    }
                    else
                    {
                        XML.write(config_read.mute, player_name.ToLower(), "true");
                    }
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "已禁言:[" + player_name + "]");
                }
            }
            if (msg.IndexOf(XML.read(config_read.Event, "解禁文本")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                string player      = msg.Replace(XML.read(config_read.Event, "解禁文本"), "");
                string player_name = null;
                if (player.IndexOf("[CQ") != -1)
                {
                    player = use.get_string(player, "=", "]");
                    if (Mysql_mode == true)
                    {
                        player_name = Mysql.mysql_search(Mysql.Mysql_player, player);
                    }
                    else
                    {
                        player_name = XML.read(config_read.player, player);
                    }
                }
                else
                {
                    player_name = player;
                }
                player_name = player_name.Trim();
                if (player_name == null)
                {
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "该玩家未绑定ID");
                }
                else
                {
                    if (Mysql_mode == true)
                    {
                        Mysql.mysql_add(Mysql.Mysql_mute, player_name.ToLower(), "false");
                    }
                    else
                    {
                        XML.write(config_read.mute, player_name.ToLower(), "false");
                    }
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "已解禁:[" + player_name + "]");
                }
            }
            if (msg.IndexOf(XML.read(config_read.Event, "查询玩家ID")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                string player = msg.Replace(XML.read(config_read.Event, "查询玩家ID"), "");
                player = use.get_string(player, "=", "]");
                string player_name = null;
                if (Mysql_mode == true)
                {
                    player_name = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                }
                else
                {
                    player_name = XML.read(player, fromQQ.ToString());
                }
                CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "玩家ID:" + player_name);
            }
            if (msg.IndexOf(XML.read(config_read.Event, "修改玩家ID")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                string player      = msg.Replace(XML.read(config_read.Event, "修改玩家ID"), "");
                string player_name = player;
                player      = use.get_string(player, "=", "]");
                player_name = use.get_string(player_name, "]");
                player_name = player_name.Trim();
                if (Mysql_mode == true)
                {
                    XML.write(player, player, player_name);
                }
                else
                {
                    Mysql.mysql_add(Mysql.Mysql_player, player, player_name);
                }

                CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "已修改玩家[" + player + "]ID为:" + player_name);
            }
            if (msg == XML.read(config_read.Event, "维护文本") && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                if (XML.read(config_read.config, "维护模式") == "关")
                {
                    XML.write(config_read.config, "维护模式", "开");
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "服务器维护模式已开启");
                    server = false;
                    return;
                }
                else
                {
                    XML.write(config_read.config, "维护模式", "关");
                    CQ.SendPrivateMessage(fromQQ, CQ.CQCode_At(fromQQ) + "服务器维护模式已关闭");
                    server = true;
                    return;
                }
            }
            if (msg.IndexOf("打开菜单") == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                CQ.SendPrivateMessage(fromQQ, "已打开,请前往后台查看");
                OpenSettingForm();
            }
            if (msg == XML.read(config_read.Event, "机器人功能-重读配置文件") && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                CQ.SendPrivateMessage(fromQQ, "开始重读配置文件");
                config_read.read_config();
                CQ.SendPrivateMessage(fromQQ, "重读完成");
            }
            if (msg == XML.read(config_read.Event, "机器人功能-内存回收") && XML.read(config_read.admin, fromQQ.ToString()) != null)
            {
                try
                {
                    GC.Collect();
                    CQ.SendPrivateMessage(fromQQ, "内存回收完毕");
                }
                catch (Exception exception)
                { }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Type=2 群消息。
        /// </summary>
        /// <param name="subType">子类型,目前固定为1。</param>
        /// <param name="sendTime">发送时间(时间戳)。</param>
        /// <param name="fromGroup">来源群号。</param>
        /// <param name="fromQQ">来源QQ。</param>
        /// <param name="fromAnonymous">来源匿名者。</param>
        /// <param name="msg">消息内容。</param>
        /// <param name="font">字体。</param>
        public override void GroupMessage(int subType, int sendTime, long fromGroup, long fromQQ, string fromAnonymous, string msg, int font)
        {
            logs.Log_write('[' + fromGroup.ToString() + ']' + '[' + fromQQ.ToString() + "][" + CQ.GetQQName(fromQQ) + "]:" + msg);
            // 处理群消息。
            if (fromGroup == GroupSet1 || fromGroup == GroupSet2 || fromGroup == GroupSet3)
            {
                if (XML.read(config_read.message, msg) != "" && XML.read(config_read.message, "启用") == "true")
                {
                    CQ.SendGroupMessage(fromGroup, XML.read(config_read.message, msg));
                }
                if (XML.read(config_read.config, "发送消息") == "当然!")
                {
                    if (server == true && socket.ready == true)
                    {
                        if ((fromGroup == GroupSet2 && Group2_on == true) || (fromGroup == GroupSet3 && Group3_on == true) || fromGroup == GroupSet1)
                        {
                            string play_name = null;
                            if (Mysql_mode == true)
                            {
                                play_name = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                            }
                            else
                            {
                                play_name = XML.read(config_read.player, fromQQ.ToString());
                            }
                            if (play_name != null)
                            {
                                if (Mysql_mode == true)
                                {
                                    if (Mysql.mysql_search(Mysql.Mysql_mute, play_name.ToLower()) == "true")
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    if (XML.read(config_read.mute, play_name.ToLower()) == "true")
                                    {
                                        return;
                                    }
                                }
                                string send;
                                send = XML.read(config_read.config, "发送文本");
                                send = send.Replace("%player%", play_name);
                                msg  = use.remove_pic(msg);
                                if (msg == "")
                                {
                                    return;
                                }
                                msg  = use.get_at(msg);
                                send = send.Replace("%message%", use.remove_pic(msg));
                                socket.Send("群消息" + send, socket.MCserver);
                            }
                        }
                    }
                }
                else if (msg.IndexOf(XML.read(config_read.Event, "发送文本")) == 0 && XML.read(config_read.config, "发送消息") == "不!")
                {
                    if ((fromGroup == GroupSet2 && Group2_on == false) || (fromGroup == GroupSet3 && Group3_on == false))
                    {
                        CQ.SendGroupMessage(fromGroup, "该群没有开启聊天功能");
                    }
                    else if (server == true)
                    {
                        if (socket.ready == true)
                        {
                            string play_name = null;
                            if (Mysql_mode == true)
                            {
                                play_name = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                            }
                            else
                            {
                                play_name = XML.read(config_read.player, fromQQ.ToString());
                            }
                            if (play_name != null && play_name != "")
                            {
                                if (Mysql_mode == true)
                                {
                                    if (Mysql.mysql_search(Mysql.Mysql_mute, play_name.ToLower()) == "true")
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    if (XML.read(config_read.mute, play_name.ToLower()) == "true")
                                    {
                                        return;
                                    }
                                }
                                string send;
                                send = XML.read(config_read.config, "发送文本");
                                send = send.Replace("%player%", play_name);
                                msg  = msg.Replace(XML.read(config_read.Event, "发送文本"), "");
                                msg  = use.remove_pic(msg);
                                if (msg == "")
                                {
                                    return;
                                }
                                msg  = use.get_at(msg);
                                send = send.Replace("%message%", use.remove_pic(msg));
                                socket.Send("群消息" + send, socket.MCserver);
                            }
                            else
                            {
                                CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "检测到你没有绑定服务器ID,发送:" + XML.read(config_read.Event, "绑定文本") + "ID来绑定,如:" +
                                                    "\n" + XML.read(config_read.Event, "绑定文本") + "Color_yr");
                            }
                        }
                        else
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "发送失败,请稍后尝试");
                        }
                    }
                    else
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + XML.read(config_read.Event, "服务器维护文本"));
                    }
                }
                if (msg == XML.read(config_read.Event, "在线人数"))
                {
                    if (server == true)
                    {
                        if (socket.ready == true)
                        {
                            if (fromGroup == GroupSet1)
                            {
                                Group = 1;
                            }
                            else if (fromGroup == GroupSet2)
                            {
                                Group = 2;
                            }
                            else if (fromGroup == GroupSet3)
                            {
                                Group = 3;
                            }
                            socket.Send("在线人数", socket.MCserver);
                        }
                        else
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "发送失败,请稍后尝试");
                        }
                    }
                    else
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + XML.read(config_read.Event, "服务器维护文本"));
                    }
                }
                if (msg == XML.read(config_read.Event, "服务器状态"))
                {
                    if (server == true)
                    {
                        if (socket.ready == true)
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "查询中,如果没有回复,则证明服务器未开启");
                            if (fromGroup == GroupSet1)
                            {
                                Group = 1;
                            }
                            else if (fromGroup == GroupSet2)
                            {
                                Group = 2;
                            }
                            else if (fromGroup == GroupSet3)
                            {
                                Group = 3;
                            }
                            socket.Send("服务器状态", socket.MCserver);
                        }
                        else
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "发送失败,请稍后尝试");
                        }
                    }
                    else
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + XML.read(config_read.Event, "服务器维护文本"));
                    }
                }
                if (msg.IndexOf(XML.read(config_read.Event, "绑定文本")) == 0)
                {
                    string player = null;
                    if (Mysql_mode == true)
                    {
                        player = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                    }
                    else
                    {
                        player = XML.read(config_read.player, fromQQ.ToString());
                    }
                    if (player == null)
                    {
                        string player_name = msg.Replace(XML.read(config_read.Event, "绑定文本"), "");
                        if (player_name == " " || player_name == "" || use.IsNatural_Number(player_name) == false)
                        {
                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "绑定失败,请检查你的ID");
                        }
                        else
                        {
                            player_name = player_name.Trim();
                            if (Mysql_mode == true)
                            {
                                if (Mysql.mysql_search(Mysql.Mysql_notid, player_name.ToLower()) == "notid")
                                {
                                    CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "禁止绑定ID:" + player_name);
                                    return;
                                }
                                Mysql.mysql_add(Mysql.Mysql_player, fromQQ.ToString(), player_name);
                            }
                            else
                            {
                                if (XML.read(config_read.notid, player_name.ToLower()) == "notid")
                                {
                                    CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "禁止绑定ID:" + player_name);
                                    return;
                                }
                                XML.write(config_read.player, fromQQ.ToString(), player_name);
                            }

                            CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "绑定ID:" + player_name + "成功!");

                            string qq_admin = XML.read(config_read.admin, "发送给的人");
                            if (qq_admin != null)
                            {
                                CQ.SendPrivateMessage(long.Parse(qq_admin), "玩家[" + CQ.GetQQName(fromQQ) + "]绑定了ID:[" + player_name + "]");
                            }
                        }
                    }
                    else
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "你已经绑定ID了,请找腐竹更改");
                    }
                }
                if (msg.IndexOf(XML.read(config_read.Event, "禁言文本")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    string player      = msg.Replace(XML.read(config_read.Event, "禁言文本"), "");
                    string player_name = null;
                    if (player.IndexOf("[CQ") != -1)
                    {
                        player = use.get_string(player, "=", "]");
                        if (Mysql_mode == true)
                        {
                            player_name = Mysql.mysql_search(Mysql.Mysql_player, player);
                        }
                        else
                        {
                            player_name = XML.read(config_read.player, player);
                        }
                    }
                    else
                    {
                        player_name = player;
                    }
                    if (player_name == null)
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "ID无效");
                    }
                    else
                    {
                        if (Mysql_mode == true)
                        {
                            Mysql.mysql_add(Mysql.Mysql_mute, player_name.ToLower(), "true");
                        }
                        else
                        {
                            XML.write(config_read.mute, player_name.ToLower(), "true");
                        }
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "已禁言:[" + player_name + "]");
                    }
                }
                if (msg.IndexOf(XML.read(config_read.Event, "解禁文本")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    string player      = msg.Replace(XML.read(config_read.Event, "解禁文本"), "");
                    string player_name = null;
                    if (player.IndexOf("[CQ") != -1)
                    {
                        player = use.get_string(player, "=", "]");
                        if (Mysql_mode == true)
                        {
                            player_name = Mysql.mysql_search(Mysql.Mysql_player, player);
                        }
                        else
                        {
                            player_name = XML.read(config_read.player, player);
                        }
                    }
                    else
                    {
                        player_name = player;
                    }
                    if (player_name == null)
                    {
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "ID无效");
                    }
                    else
                    {
                        if (Mysql_mode == true)
                        {
                            Mysql.mysql_add(Mysql.Mysql_mute, player_name.ToLower(), "false");
                        }
                        else
                        {
                            XML.write(config_read.mute, player_name.ToLower(), "false");
                        }
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "已解禁:[" + player_name + "]");
                    }
                }
                if (msg.IndexOf(XML.read(config_read.Event, "查询玩家ID")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    string player = msg.Replace(XML.read(config_read.Event, "查询玩家ID"), "");
                    player = use.get_string(player, "=", "]");
                    string player_name = null;
                    if (Mysql_mode == true)
                    {
                        player_name = Mysql.mysql_search(Mysql.Mysql_player, fromQQ.ToString());
                    }
                    else
                    {
                        player_name = XML.read(player, fromQQ.ToString());
                    }
                    CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "玩家ID:" + player_name);
                }
                if (msg.IndexOf(XML.read(config_read.Event, "修改玩家ID")) == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    string player      = msg.Replace(XML.read(config_read.Event, "修改玩家ID"), "");
                    string player_name = player;
                    player      = use.get_string(player, "=", "]");
                    player_name = use.get_string(player_name, "]");
                    player_name = player_name.Trim();
                    if (Mysql_mode == true)
                    {
                        Mysql.mysql_add(Mysql.Mysql_player, player, player_name);
                    }
                    else
                    {
                        XML.write(player, player, player_name);
                    }

                    CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "已修改玩家[" + player + "]ID为:" + player_name);
                }
                if (msg == XML.read(config_read.Event, "维护文本") && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    if (XML.read(config_read.config, "维护模式") == "关")
                    {
                        XML.write(config_read.config, "维护模式", "开");
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "服务器维护模式已开启");
                        server = false;
                        return;
                    }
                    else
                    {
                        XML.write(config_read.config, "维护模式", "关");
                        CQ.SendGroupMessage(fromGroup, CQ.CQCode_At(fromQQ) + "服务器维护模式已关闭");
                        server = true;
                        return;
                    }
                }
                if (msg.IndexOf("打开菜单") == 0 && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    CQ.SendGroupMessage(fromGroup, "已打开,请前往后台查看");
                    OpenSettingForm();
                }
                if (msg == XML.read(config_read.Event, "机器人功能-重读配置文件") && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    CQ.SendGroupMessage(fromGroup, "开始重读配置文件");
                    config_read.read_config();
                    CQ.SendGroupMessage(fromGroup, "重读完成");
                }
                if (msg == XML.read(config_read.Event, "机器人功能-内存回收") && XML.read(config_read.admin, fromQQ.ToString()) != null)
                {
                    try
                    {
                        GC.Collect();
                        CQ.SendGroupMessage(fromGroup, "内存回收完毕");
                    }
                    catch (Exception exception)
                    { }
                }
            }
        }
Ejemplo n.º 11
0
        private void FormSettings_Load(object sender, EventArgs e)
        {
            textBox1.Text = XML.read(config_read.config, "群号1");
            textBox3.Text = XML.read(config_read.config, "群号2");
            textBox6.Text = XML.read(config_read.config, "群号3");

            textBox4.Text = XML.read(config_read.config, "IP");
            textBox5.Text = XML.read(config_read.config, "Port");

            textBox11.Text = XML.read(config_read.admin, "发送给的人");

            textBox7.Text  = XML.read(config_read.config, "Mysql地址");
            textBox8.Text  = XML.read(config_read.config, "Mysql端口");
            textBox9.Text  = XML.read(config_read.config, "Mysql账户");
            textBox10.Text = XML.read(config_read.config, "Mysql密码");

            if (Minecraft_QQ.Mysql_mode == true)
            {
                checkBox3.Checked = true;
            }

            if (XML.read(config_read.config, "编码") == "UTF-8")
            {
                radioButton1.Checked = true;
                radioButton2.Checked = false;
            }
            else if (XML.read(config_read.config, "编码") == "ANSI(GBK)")
            {
                radioButton1.Checked = false;
                radioButton2.Checked = true;
            }
            if (XML.read(config_read.config, "发送消息") == "当然!")
            {
                checkBox1.Checked = true;
            }
            else if (XML.read(config_read.config, "发送消息") == "不!")
            {
                checkBox1.Checked = false;
            }
            if (XML.read(config_read.config, "维护模式") == "关")
            {
                checkBox2.Checked = false;
                checkBox2.Text    = "服务器维护模式:关";
            }
            else if (XML.read(config_read.config, "维护模式") == "开")
            {
                checkBox2.Checked = true;
                checkBox2.Text    = "服务器维护模式:开";
            }
            if (XML.read(config_read.config, "群2发送消息") == "开")
            {
                checkBox4.Checked = true;
            }
            else
            {
                checkBox4.Checked = false;
            }
            if (XML.read(config_read.config, "群3发送消息") == "开")
            {
                checkBox5.Checked = true;
            }
            else
            {
                checkBox5.Checked = false;
            }
        }