Exemplo n.º 1
0
        void client_ClientDiscon(ConClient client, string message)
        {
            try
            {
                this.BeginInvoke(new EventHandler((a, b) =>
                {
                    this.richTextBox1.AppendText(client.Host + ":" + client.Port + "-" + client.Key + " ->" + message + "\r\n");
                }));

                if (client.UserToken != null)
                {
                    UserInfo user = client.UserToken as UserInfo;

                    if (user != null)
                    {
                        UserList.Remove(user);
                        UpdateUserListView();
                    }

                    client.UserToken = null;
                }

                if (!client.IsProxy)
                {
                    client.Sock.Close();
                }
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
        void client_ClientConnToMe(ConClient client)
        {
            if (UserList == null)
            {
                UserList = new List <UserInfo>();
            }

            UserInfo user = new UserInfo();

            user.Client      = client;
            user.MainClient  = MClient;
            user.Stream      = new ZYSocket.share.ZYNetRingBufferPoolV2(1073741824);
            client.UserToken = user;

            UserList.Add(user);
            UpdateUserListView();

            this.BeginInvoke(new EventHandler((a, b) =>
            {
                this.richTextBox1.AppendText(client.Host + ":" + client.Port + "-" + client.Key + " 连接");
            }));
        }
Exemplo n.º 3
0
 static void client_ClientDataIn(ConClient client, byte[] data)
 {
     Console.WriteLine(Encoding.UTF8.GetString(data));
 }
Exemplo n.º 4
0
 static void client_ClientConnToMe(ConClient client)
 {
     Console.WriteLine(client.Host + ":" + client.Port + "-" + client.Key + " 连接");
 }
Exemplo n.º 5
0
 static void client_ClientDiscon(ConClient client, string message)
 {
     Console.WriteLine(client.Host + ":" + client.Port + "-" + client.Key + " ->" + message);
 }
Exemplo n.º 6
0
        void client_ClientDataIn(string key, ConClient client, byte[] data)
        {
            try
            {
                UserInfo user = client.UserToken as UserInfo;

                if (user == null && client.IsProxy)
                {
                    if (UserList == null)
                    {
                        UserList = new List <UserInfo>();
                    }

                    user             = new UserInfo();
                    user.Client      = client;
                    user.MainClient  = MClient;
                    user.Stream      = new ZYSocket.share.ZYNetRingBufferPoolV2(1073741824);
                    client.UserToken = user;

                    UserList.Add(user);
                    UpdateUserListView();

                    this.BeginInvoke(new EventHandler((a, b) =>
                    {
                        this.richTextBox1.AppendText(client.Host + ":" + client.Port + "-" + client.Key + " 连接");
                    }));
                }



                if (user != null)
                {
                    user.Stream.Write(data);

                    byte[] datax;
                    while (user.Stream.Read(out datax))
                    {
                        if (user.IsSuccess)
                        {
                            DataOn(user, datax);
                        }
                        else
                        {
                            SuccessData(user, datax);
                        }
                    }
                }
                else
                {
                    if (!client.IsProxy)
                    {
                        client.Sock.Close();
                    }
                }
            }
            catch (Exception er)
            {
                this.BeginInvoke(new EventHandler((a, b) =>
                {
                    this.richTextBox1.AppendText(er.ToString() + "\r\n");
                }));
            }
        }
Exemplo n.º 7
0
 void client_ClientDataIn(string key, ConClient client, byte[] data)
 {
     SetViewText("Revc:" + Encoding.UTF8.GetString(data));
 }
Exemplo n.º 8
0
 void client_ClientConnToMe(ConClient client)
 {
     SetViewText(client.Host + ":" + client.Port + "-" + client.Key + " 连接");
 }
Exemplo n.º 9
0
 void client_ClientDiscon(ConClient client, string message)
 {
     SetViewText(client.Host + ":" + client.Port + "-" + client.Key + " ->" + message);
 }
Exemplo n.º 10
0
        private async Task ws(HttpConnection p)
        {
            var wss = new WebSocketServer(p);

            wss.AddToManaged();
            if (!(await wss.HandleRequestAsync(false).CAF()).IsConnected)
            {
                return;
            }
            if (!no_passwd)
            {
                var realPasswd = passwd;
                var aesEnabled = false;
                if (p.ParseUrlQstr()["encryption"] == "1")
                {
                    wss.ApplyAesStreamFilter(GetMD5FromString(realPasswd));
                    await wss.StartVerify(true).CAF();
                }
                int chances = 3;
                while (true)
                {
                    await wss.SendStringAsync("passwd:\r\n");

                    var passwd = await wss.RecvString();

                    if (passwd == null)
                    {
                        return;
                    }
                    if (!aesEnabled && passwd == "__AesStreamFilter__")
                    {
                        wss.ApplyAesStreamFilter(GetMD5FromString(realPasswd));
                        await wss.StartVerify(false);

                        continue;
                    }
                    if (passwd == realPasswd)
                    {
                        break;
                    }
                    else
                    {
                        Logger.warning($"{(passwd.Length == 0 ? "empty" : "wrong")} passwd from {p.myStream}");
                        if (--chances <= 0)
                        {
                            await wss.SendStringAsync("session end.\r\n");

                            return;
                        }
                    }
                }
                await wss.SendStringAsync("success.\r\n");
            }
            else
            {
                await wss.SendStringAsync("success (no passwd).\r\n");
            }

            var concli = new ConClient(wss);

            new Thread(() => {
                try {
                    consoleHub.SessionSelectLoop(concli);
                } catch (Exception e) { }
            })
            {
                IsBackground = true, Name = "consolewsSession"
            }.Start();

            await wss.RecvLoopAsync().CAF();
        }