示例#1
0
        /// <summary>
        /// Tries to connect to hub.
        /// </summary>
        public override void Connect()
        {
            // RegMode changed to default
            RegMode = -1;
            if (Protocol == null)
            {
                // Setting right Command Seperator.
                switch (HubSetting.Protocol)
                {
                case "Nmdc":         // NMDC
                    Protocol = new HubNmdcProtocol(this);
                    break;

                case "Zpoc":
                    Protocol = new HubZpocProtocol(this);
                    break;

                case "":            // Auto Detect
                case "Auto":        // Auto Detect
                case "Adc":         // ADC
                    Protocol = new AdcProtocol(this);
                    break;

#if !COMPACT_FRAMEWORK
// Security
                case "AdcSecure":
                    Protocol       = new AdcProtocol(this);
                    SecureProtocol = FlowLib.Enums.SecureProtocols.TLS;
                    break;

                case "NmdcSecure":
                    Protocol       = new HubNmdcProtocol(this);
                    SecureProtocol = FlowLib.Enums.SecureProtocols.TLS;
                    break;
#endif
                default:
                    FmdcEventArgs e = new FmdcEventArgs(0);
                    UnknownProtocolId(this, e);
                    if (e.Handled && e.Data is IProtocolHub)
                    {
                        Protocol = (IProtocolHub)e.Data;
                    }
                    else
                    {
                        throw new System.InvalidOperationException("Protocol is not beeing set. Protocol name is not a inbuilt protocol and has not been handled by plugin");
                    }
                    break;
                }
            }
            worker = new Thread(new ThreadStart(base.Connect));
            worker.IsBackground = true;
            worker.Start();
        }
示例#2
0
        public STA(IConnection con, string raw)
            : base(con, raw)
        {
            if (param == null)
            {
                return;
            }
            if (param.Count >= 2 && param[0].Length == 3)
            {
                severity = param[0].Substring(0, 1);
                code     = param[0].Substring(1);
                content  = AdcProtocol.ConvertIncomming(param[1]);
                valid    = true;
            }

            for (int i = 2; i < param.Count; i++)
            {
                if (param[i].Length < 2)
                {
                    continue;
                }
                string key   = param[i].Substring(0, 2);
                string value = param[i].Substring(2);
                switch (key)
                {
                case "FC":
                    pfc = value;
                    break;

                case "TL":
                    ptl = value;
                    break;

                case "FL":
                    pfl = value;
                    break;

                case "TO":
                    pto = value;
                    break;

                case "PR":
                    ppr = value;
                    break;

                case "IP":
                    pip = value;
                    break;
                }
            }
        }
示例#3
0
        public RES(IConnection con, string raw)
            : base(con, raw)
        {
            info = new ContentInfo();
            foreach (string var in param)
            {
                if (var.Length < 2)
                {
                    continue;
                }
                string key   = var.Substring(0, 2);
                string value = var.Substring(2);
                switch (key)
                {
                case "FN":
                    info.Set(ContentInfo.VIRTUAL, AdcProtocol.ConvertIncomming(value));
                    valid = true;
                    break;

                case "SI":
                    try
                    {
                        info.Size = long.Parse(value);
                    }
                    catch { }
                    break;

                case "SL":
                    try
                    {
                        slots = long.Parse(value);
                    }
                    catch { }
                    break;

                case "TO":
                    token = value;
                    break;

                case "TR":
                    info.Set(ContentInfo.TTH, value);
                    break;

                default:
                    // We dont know this value but to allow developer to support this anyway we will store it.
                    info.Set(key, value);
                    break;
                }
            }
        }
示例#4
0
        public RES(IConnection con, ContentInfo info, string token, UserInfo usr)
            : base(con, null)
        {
            this.info = info;

            if (
                usr.ContainsKey(UserInfo.UDPPORT) &&
                usr.ContainsKey("SU") &&
                usr.ContainsKey(UserInfo.IP) &&
                (usr.Get("SU").Contains("UDP4") || usr.Get("SU").Contains("UDP6"))
                )
            {
                type = "U";
                int    port = -1;
                string addr = usr.Get(UserInfo.IP);
                try
                {
                    port = int.Parse(usr.Get(UserInfo.UDPPORT));
                    if (port < 0 || port > 65535)
                    {
                        port = 0;
                    }
                    address = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(addr), port);
                }
                catch { }
            }
            else if (con is Hub)
            {
                type = "D";
            }
            else
            {
                type = "C";
            }

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (info.ContainsKey(ContentInfo.VIRTUAL))
            {
                sb.Append(" FN" + AdcProtocol.ConvertOutgoing(info.Get(ContentInfo.VIRTUAL)));
            }
            sb.Append(" SI" + info.Size.ToString());
            if (!string.IsNullOrEmpty(token))
            {
                sb.Append(" TO" + token);
            }
            // TODO : Add Slots handling
            Raw = string.Format("{0}RES{1}\n", type, sb.ToString());
        }
示例#5
0
        /// <summary>
        /// Constructor for recieving
        /// </summary>
        /// <param name="hub"></param>
        /// <param name="raw"></param>
        public MSG(IConnection con, string raw)
            : base(con, raw)
        {
            //I: IMSG Have\sa\snice\sday,\sand\sbehave\s;)
            //B: BMSG SHJV PIP
            //D: DMSG SHJV SH5B PIIP!! PMSHJV
            if (param == null)
            {
                return;
            }
            if (param.Count >= 1)
            {
                from    = id;
                to      = idtwo;
                content = param[0];
            }
            // Param
            for (int i = 1; i < param.Count; i++)
            {
                if (param[i].Length < 2)
                {
                    continue;
                }
                string key   = param[i].Substring(0, 2);
                string value = param[i].Substring(2);
                switch (key)
                {
                case "PM":
                    pmgroup = value;
                    break;

                case "ME":
                    me = value.Equals("1");
                    break;
                }
            }

            // Replacing stuff
            if (content != null)
            {
                content = AdcProtocol.ConvertIncomming(content);
                valid   = true;
            }
        }
示例#6
0
 public STA(IConnection con, string userId, string meId, string code, string description, string param)
     : base(con, null)
 {
     if (param != null)
     {
         param = " " + param;
     }
     else
     {
         param = string.Empty;
     }
     if (!string.IsNullOrEmpty(userId))
     {
         Raw = string.Format("DSTA {0} {1} {2} {3}{4}\n", meId, userId, code, AdcProtocol.ConvertOutgoing(description), param);
     }
     else
     {
         Raw = string.Format("CSTA {0} {1}{2}\n", code, AdcProtocol.ConvertOutgoing(description), param);
     }
 }
示例#7
0
 /// <summary>
 /// Constructor for sending Private messages
 /// </summary>
 /// <param name="hub"></param>
 /// <param name="me"></param>
 /// <param name="content"></param>
 /// <param name="to"></param>
 /// <param name="group"></param>
 public MSG(IConnection con, UserInfo usr, bool me, string content, string to, string group)
     : base(con, null)
 {
     this.to      = to;
     this.pmgroup = group;
     this.me      = me;
     this.content = content;
     if (usr.ContainsKey(UserInfo.SID))
     {
         this.from = usr.Get(UserInfo.SID);
     }
     if (this.to == null || this.pmgroup == null)
     {
         if (this.pmgroup != null)
         {
             this.to = this.pmgroup;
         }
     }
     // DMSG SHJV SH5B PIIP!! PMSHJV
     //Raw = "DMSG " + this.from + " " + this.to + " " + AdcProtocol.ConvertOutgoing(this.content) + (this.me ? " ME1" : "") + " PM"+((this.pmgroup != null) ? (this.pmgroup) : this.from) + "\n";
     Raw = "EMSG " + this.from + " " + this.to + " " + AdcProtocol.ConvertOutgoing(this.content) + (this.me ? " ME1" : "") + " PM" + ((this.pmgroup != null) ? (this.pmgroup) : this.from) + "\n";
 }
示例#8
0
        // Receiving
        public INF(IConnection con, string raw)
            : base(con, raw)
        {
            if (param == null)
            {
                return;
            }
            info.TagInfo.GenerateTag = true;
            info.Set(UserInfo.SID, id);

            if (typeValid)
            {
                valid = true;
            }

            // IINF is from hub. all other should be from user =)
            // NIDCDev\sPublic HU1 HI1 DEThe\spublic\sDirect\sConnect\sdevelopment\shub VEADCH++\sv2.0.0-Release
            // TUOD SF0 SL1 SS0 SUTCP4,UDP4 DEPASIV HN4 HO0 HR0 I489.38.33.162 U41090 IDARJQDWZKC4MMC7PLQNOYSPHVI7V62QPS4IRF5KA [email protected] US104857600 VE++\s0.698 NI[RO][B][QUICK-NET]LIVIU
            for (int i = 0; i < param.Count; i++)
            {
                if (param[i].Length < 2)
                {
                    continue;
                }
                string key   = param[i].Substring(0, 2);
                string value = param[i].Substring(2);
                switch (key)
                {
                case "ID":
                    info.Set(UserInfo.CID, value);
                    break;

                case "I4":
                    info.Set(UserInfo.IP, value);
                    break;

                case "I6":
                    info.Set(UserInfo.IP, value);
                    break;

                case "U4":
                    info.Set(UserInfo.UDPPORT, value);
                    break;

                case "U6":
                    info.Set(UserInfo.UDPPORT, value);
                    break;

                case "SS":
                    info.Share = value;
                    break;

                //case "SF":
                //    break;
                //case "US":
                //    break;
                //case "DS":
                //    break;
                case "SL":
                    try
                    {
                        info.TagInfo.Slots = int.Parse(value);
                    }
                    catch (System.Exception)
                    {
                        info.TagInfo.Slots = 0;
                    }
                    break;

                //case "AS":
                //    break;
                //case "AM":
                //    break;
                case "EM":
                    info.Email = AdcProtocol.ConvertIncomming(value);
                    break;

                case "HN":
                    try
                    {
                        info.TagInfo.Normal = int.Parse(value);
                    }
                    catch (System.Exception)
                    {
                        info.TagInfo.Normal = 0;
                    }
                    break;

                case "HR":
                    try
                    {
                        info.TagInfo.Regged = int.Parse(value);
                    }
                    catch (System.Exception)
                    {
                        info.TagInfo.Regged = 0;
                    }
                    break;

                case "HO":
                    try
                    {
                        info.TagInfo.OP = int.Parse(value);
                    }
                    catch (System.Exception)
                    {
                        info.TagInfo.OP = 0;
                    }
                    break;

                case "TO":
                    token = value;
                    info.Set(key, value);
                    break;

                case "OP":          // Before ADC 1.0
                    info.IsOperator = (value == "1");
                    break;

                //case "AW":
                //    break;
                //case "BO":
                //    break;
                //case "HI":
                //    break;
                //case "HU":
                //    break;
                //case "SU":
                //    break;
                case "NI":
                    info.DisplayName = AdcProtocol.ConvertIncomming(value);
                    break;

                case "VE":
                    info.TagInfo.Version = AdcProtocol.ConvertIncomming(value);
                    break;

                case "DE":
                    info.Description = AdcProtocol.ConvertIncomming(value);
                    break;

                case "CT":
                    try
                    {
                        info.Account = int.Parse(value);
                    }
                    catch { }
                    break;

                case "SU":
                    info.Set(key, value);
                    string[] supports = value.Split(',');
                    foreach (string sup in supports)
                    {
                        switch (sup)
                        {
                        case "ADC0":
                            info.Set(UserInfo.SECURE, "");
                            break;
                        }
                    }
                    break;

                default:
                    // We will add all unhandled fields to user. This is because developer may know how to handle it even if we dont.
                    info.Set(key, value);
                    break;
                }
            }
        }
示例#9
0
 /// <summary>
 /// Constructor for sending Main Chat messages
 /// </summary>
 /// <param name="hub"></param>
 /// <param name="me"></param>
 /// <param name="content"></param>
 public MSG(IConnection con, UserInfo usr, bool me, string content)
     : this(con, usr, me, content, null, null)
 {
     // BMSG SHJV PIP
     Raw = "BMSG " + this.from + " " + AdcProtocol.ConvertOutgoing(this.content) + (this.me ? " ME1" : "") + "\n";
 }
示例#10
0
        public SCH(IConnection con, SearchInfo info, string userId)
            : base(con, null)
        {
            this.info = info;
            // BSCH NRQF TRUDHPNB4BUIQV2LAI4HDWRL3KLJTUSXCTAMJHNII TOauto
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            #region EX
            if (info.ContainsKey(SearchInfo.EXTENTION))
            {
                string[] ext = info.Get(SearchInfo.EXTENTION).Split(' ');
                foreach (string extention in ext)
                {
                    sb.Append(" EX" + AdcProtocol.ConvertOutgoing(extention));
                }
            }
            #endregion
            #region TY
            if (info.ContainsKey(SearchInfo.TYPE))
            {
                switch (info.Get(SearchInfo.TYPE))
                {
                case "0":
                    sb.Append(" TY" + AdcProtocol.ConvertOutgoing("1")); break;

                case "1":
                    sb.Append(" TY" + AdcProtocol.ConvertOutgoing("2")); break;

                case "2":
                    sb.Append(" AN" + info.Get(SearchInfo.SEARCH)); break;
                }
            }
            #endregion
            #region AN
            if (info.ContainsKey(SearchInfo.SEARCH) && info.ContainsKey(SearchInfo.TYPE))
            {
                sb.Append(" AN" + AdcProtocol.ConvertOutgoing(info.Get(SearchInfo.SEARCH)));
            }
            #endregion
            #region NO
            if (info.ContainsKey(SearchInfo.NOSEARCH))
            {
                sb.Append(" NO" + AdcProtocol.ConvertOutgoing(info.Get(SearchInfo.NOSEARCH)));
            }
            #endregion
            #region TO
            if (info.ContainsKey(SearchInfo.TOKEN))
            {
                sb.Append(" TO" + AdcProtocol.ConvertOutgoing(info.Get(SearchInfo.TOKEN)));
            }
            #endregion
            #region Size Type
            if (info.ContainsKey(SearchInfo.SIZETYPE))
            {
                string size = info.Get(SearchInfo.SIZE);
                switch (info.Get(SearchInfo.SIZETYPE))
                {
                case "1":
                    sb.Append(" GE" + size);
                    break;

                case "2":
                    sb.Append(" LE" + size);
                    break;

                case "3":
                    sb.Append(" EQ" + size);
                    break;
                }
            }
            #endregion
            Raw = string.Format("BSCH {0}{1}\n", userId, sb.ToString());
        }
示例#11
0
        private void CreateRaw()
        {
            if (info == null)
            {
                return;
            }
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (con is Transfer)
            {
                sb.Append("CINF");
                sb.Append(" ID" + info.Get(UserInfo.CID));
                if (info.ContainsKey("TO"))
                {
                    sb.Append(" TO" + info.Get("TO"));
                }
            }
            else
            {
                sb.Append("BINF " + info.Get(UserInfo.SID));
                // Do PID exist? If not. Create PID and CID
                FlowLib.Utils.Hash.Tiger tiger = new FlowLib.Utils.Hash.Tiger();
                byte[] data = null;
                if (!info.ContainsKey(UserInfo.PID))
                {
                    data = tiger.ComputeHash(System.Text.Encoding.UTF8.GetBytes("FlowLib" + System.DateTime.Now.Ticks.ToString()));
                    info.Set(UserInfo.PID, FlowLib.Utils.Convert.Base32.Encode(data));
                }
                // Make CID from PID. This will always be done.
                data = tiger.ComputeHash(FlowLib.Utils.Convert.Base32.Decode(info.Get(UserInfo.PID)));
                info.Set(UserInfo.CID, FlowLib.Utils.Convert.Base32.Encode(data));

                sb.Append(" ID" + info.Get(UserInfo.CID));
                sb.Append(" PD" + info.Get(UserInfo.PID));
                sb.Append(" DE" + AdcProtocol.ConvertOutgoing(info.Description));

                sb.Append(" HN" + info.TagInfo.Normal.ToString());
                sb.Append(" HO" + info.TagInfo.OP.ToString());
                sb.Append(" HR" + info.TagInfo.Regged.ToString());
                sb.Append(" NI" + AdcProtocol.ConvertOutgoing(info.DisplayName));
                sb.Append(" SL" + info.TagInfo.Slots);                              // Upload Slots Open
                sb.Append(" SF" + (con.Share != null ? con.Share.HashedCount : 0)); // Shared Files
                sb.Append(" SS" + (con.Share != null ? con.Share.HashedSize : 0));  // Share Size in bytes
                if (con.Share != null)
                {
                    System.Text.StringBuilder support = new System.Text.StringBuilder();
                    switch (info.TagInfo.Mode)
                    {
                    case FlowLib.Enums.ConnectionTypes.Direct:
                    case FlowLib.Enums.ConnectionTypes.UPnP:
                    case FlowLib.Enums.ConnectionTypes.Forward:
                        string ip = info.Get(UserInfo.IP);
                        if (string.IsNullOrEmpty(ip) || ip.Contains("."))
                        {
                            if (string.IsNullOrEmpty(ip))
                            {
                                sb.Append(" I40.0.0.0");
                            }
                            else
                            {
                                sb.Append(" I4" + ip);
                            }
                            support.Append("TCP4,");        // Support
                            support.Append("UDP4,");        // Support
                            sb.Append(" U4" + con.Share.Port.ToString());
                        }
                        else
                        {
                            sb.Append(" I6" + ip);
                            support.Append("TCP6,");        // Support
                            support.Append("UDP6,");        // Support
                            sb.Append(" U6" + con.Share.Port.ToString());
                        }
                        break;
                    }

                    support.Append("BZIP,");         // Support
                    if (info.ContainsKey(UserInfo.SECURE))
                    {
                        support.Append("ADC0,");           // Support
                    }
                    sb.Append(" SU" + support.ToString()); // Support
                }
                sb.Append(" VE" + AdcProtocol.ConvertOutgoing(info.TagInfo.Version));
            }
            sb.Append("\n");
            Raw = sb.ToString();
        }