Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();

            this._notify = new NotifyManager(this);



            this.Title += System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + "                    当前模式:" + (CQ.ProxyType == CQP.Framework.CQProxyType.UDP ? "UDP" : "NavitaCLR");
            this.lsApps.ItemsSource = CQAppContainer.GetInstance().Apps;



            CQLogger.GetInstance().NewLogWrite += CQLogger_NewLogWrite;

            try
            {
                if (CQ.ProxyType == CQProxyType.UDP)
                {
                    CQUDPProxy.GetInstance().Start();
                    this.btnPortSetting.Visibility = System.Windows.Visibility.Visible;

                    string folder = Path.Combine(CQ.GetCQAppFolder(), "app");
                    folder = Path.Combine(folder, "cc.flexlive.cqeproxy");


                    string ipAddress = "127.0.0.1";
                    int    port      = 18139;

                    if (Directory.Exists(folder))
                    {
                        string iniFile = Path.Combine(folder, "cc.flexlive.cqeproxy.ini");

                        if (File.Exists(iniFile))
                        {
                            ipAddress = IniFileHelper.GetStringValue(iniFile, "代理配置", "服务器地址", "127.0.0.1");
                            string strPort = IniFileHelper.GetStringValue(iniFile, "代理配置", "服务器端口", "18139");
                            port = Convert.ToInt32(strPort);
                        }
                    }

                    this.Title = this.Title + ":" + port.ToString();
                }

                LogManager.GetInstance().AddLog(String.Format("[{0}] [#][系统] CSharp代理启动成功,请手动给挂机QQ发送条信息激活酷Q端代理功能。", DateTime.Now));

                if (CQAppContainer.GetInstance().Apps.Count > 0)
                {
                    LogManager.GetInstance().AddLog(String.Format("[{0}] [#][系统] 成功加载{1}个应用。", DateTime.Now, CQAppContainer.GetInstance().Apps.Count));
                }
                else
                {
                    LogManager.GetInstance().AddLog(String.Format("[{0}] [%][异常] 没有加载到应用,你可以使用测试功能测试发送消息。", DateTime.Now));
                }
            }
            catch
            {
                LogManager.GetInstance().AddLog(String.Format("[{0}] [%][异常] CSharp代理启动失败,18139端口被占用,请检查。", DateTime.Now));
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        public void Start()
        {
            //初始化插件容器。
            CQAppContainer.GetInstance();

            string ipAddress = "127.0.0.1";
            int    port      = 18139;

            string folder = Path.Combine(CQ.GetCQAppFolder(), "app");

            folder = Path.Combine(folder, "cc.flexlive.cqeproxy");

            if (Directory.Exists(folder))
            {
                string iniFile = Path.Combine(folder, "cc.flexlive.cqeproxy.ini");

                if (File.Exists(iniFile))
                {
                    ipAddress = IniFileHelper.GetStringValue(iniFile, "代理配置", "服务器地址", "127.0.0.1");
                    string strPort = IniFileHelper.GetStringValue(iniFile, "代理配置", "服务器端口", "18139");
                    port = Convert.ToInt32(strPort);
                }
            }

            IPAddress ip         = IPAddress.Parse(ipAddress);
            int       listenPort = port;

            IPEndPoint listenIPEndPoint = new IPEndPoint(ip, listenPort);

            //定义网络类型,数据连接类型和网络协议UDP
            this.mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            //绑定网络地址
            this.mySocket.Bind(listenIPEndPoint);

            //得到客户机IP
            int        clientPort = 18131;
            IPEndPoint ipep       = new IPEndPoint(ip, clientPort);

            RemotePoint = (EndPoint)(ipep);

            //启动一个新的线程,执行方法this.ReceiveHandle,
            //以便在一个独立的进程中执行数据接收的操作
            RunningFlag = true;
            Thread thread = new Thread(new ThreadStart(this.ReceiveMessage));

            thread.IsBackground = true;
            thread.Start();
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        public void Start()
        {
            //初始化插件容器。
            CQAppContainer.GetInstance();

            string ipAddress = "127.0.0.1";
            int    port      = 18139;

            string folder = Path.Combine(CQ.GetCQAppFolder(), "app");

            folder = Path.Combine(folder, "cc.flexlive.cqeproxy");

            if (Directory.Exists(folder))
            {
                string iniFile = Path.Combine(folder, "cc.flexlive.cqeproxy.ini");

                if (File.Exists(iniFile))
                {
                    ipAddress = IniFileHelper.GetStringValue(iniFile, "代理配置", "服务器地址", "127.0.0.1");
                    string strPort = IniFileHelper.GetStringValue(iniFile, "代理配置", "服务器端口", "18139");
                    port = Convert.ToInt32(strPort);
                }
            }

            IPAddress ip         = IPAddress.Parse(ipAddress);
            int       listenPort = port;

            IPEndPoint listenIPEndPoint = new IPEndPoint(ip, listenPort);

            //定义网络类型,数据连接类型和网络协议UDP
            this.mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            //绑定网络地址
            this.mySocket.Bind(listenIPEndPoint);

            //得到客户机IP
            int        clientPort = 18131;
            IPEndPoint ipep       = new IPEndPoint(ip, clientPort);

            RemotePoint = (EndPoint)(ipep);

            //启动一个新的线程,执行方法this.ReceiveHandle,
            //以便在一个独立的进程中执行数据接收的操作
            RunningFlag = true;
            Thread thread = new Thread(new ThreadStart(this.ReceiveMessage));

            thread.IsBackground = true;
            thread.Start();


            HttpListener httpListener = new HttpListener();

            httpListener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
            httpListener.Prefixes.Add("http://localhost:3147/");
            httpListener.Start();
            new Thread(new ThreadStart(delegate
            {
                while (true)
                {
                    HttpListenerContext httpListenerContext = httpListener.GetContext();
                    httpListenerContext.Response.StatusCode = 200;
                    String uri = httpListenerContext.Request.Url.LocalPath;
                    if (!uri.Equals("/ssAPI/jabber.ashx"))
                    {
                        continue;
                    }
                    try
                    {
                        long groupId = long.Parse(httpListenerContext.Request.QueryString["groupId"]);
                        String msg   = httpListenerContext.Request.QueryString["msg"];
                        if (msg == null || msg.Equals(""))
                        {
                            continue;
                        }
                        CQ.SendGroupMessage(groupId, msg);
                        using (StreamWriter writer = new StreamWriter(httpListenerContext.Response.OutputStream))
                        {
                            writer.WriteLine("OK");
                        }
                    }
                    catch (Exception ex)
                    {
                        using (StreamWriter writer = new StreamWriter(httpListenerContext.Response.OutputStream))
                        {
                            writer.WriteLine("ERROR:" + ex.Message);
                        }
                    }
                }
            })).Start();
        }