コード例 #1
0
        private HandleResult Service_OnAccept(TcpServer sender, IntPtr connId, IntPtr pClient)
        {
            strPwd = INIOperation.ReadString("Info", "Password");
            var data = Encoding.Default.GetBytes("欢迎连接\r\n请输入密码:");

            this.Send(connId, data, data.Length);
            this.SetExtra(connId, "");
            return(HandleResult.Ok);
        }
コード例 #2
0
 HandleResult Service_OnPrepareListen(TcpServer sender, IntPtr soListen)
 {
     isAccess = INIOperation.ReadString("Info", "ServiceName") == this.Name;
     if (isAccess)
     {
         strKey = INIOperation.ReadString("Info", "AccessKey");
         INIOperation.WriteString("IPList", null, null);
     }
     else
     {
         forwardIp   = ConfigurationManager.AppSettings[this.Name + "_ForwardIP"];
         forwardPort = ushort.Parse(ConfigurationManager.AppSettings[this.Name + "_ForwardPort"]);
     }
     return(HandleResult.Ignore);
 }
コード例 #3
0
        HandleResult Service_OnAccept(TcpServer sender, IntPtr connId, IntPtr pClient)
        {
            string ip   = "";
            ushort port = 0;

            this.GetRemoteAddress(connId, ref ip, ref port);
            if (isAccess)
            {
                var key     = Guid.NewGuid().ToString();
                var keyData = Encoding.Default.GetBytes(Encrypt.AESEncrypt(key, strKey) + "\r\n");
                this.Send(connId, keyData, keyData.Length);
                this.SetExtra(connId, new ExtraData()
                {
                    Key = key, IP = ip
                });
                return(HandleResult.Ignore);
            }
            if (!bool.Parse(INIOperation.ReadString("IPList", ip, "false")))
            {
                this.Disconnect(connId);
                this.Log(string.Format("[{0}]连接失败:IP={1}", this.Name, ip));
                return(HandleResult.Ignore);
            }
            var aId = IntPtr.Zero;

            if (agent.Connect(forwardIp, forwardPort, ref aId))
            {
                this.SetExtra(connId, aId);
                agent.SetExtra(aId, connId);
            }
            else
            {
                this.Disconnect(connId);
            }
            return(HandleResult.Ignore);
        }