Beispiel #1
0
        public PassiveSearch()
        {
            UpdateBase = new FlowLib.Events.FmdcEventHandler(PassiveSearch_UpdateBase);

            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol    = "Auto";

            Hub hubConnection = new Hub(settings, this);

            hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);
            hubConnection.Connect();

            // Wait 5 seconds (We should really listen on ConnectionStatusChange instead.
            System.Threading.Thread.Sleep(5 * 1000);

            // Send Search
            SearchInfo searchInfo = new SearchInfo();

            searchInfo.Set(SearchInfo.SEARCH, "Ubuntu");

            UpdateBase(this, new FlowLib.Events.FmdcEventArgs(Actions.Search, searchInfo));
        }
Beispiel #2
0
        void hubConnection_Update(object sender, FlowLib.Events.FmdcEventArgs e)
        {
            Hub hub = sender as Hub;

            if (hub == null)
            {
                return;
            }
            switch (e.Action)
            {
            case Actions.SearchResult:
                if (e.Data is SearchResultInfo)
                {
                    SearchResultInfo srInfo = (SearchResultInfo)e.Data;
                    // This is if we want to enable auto adding of sources to a downloaditem.
                    //FlowLib.Managers.DownloadManager dm = new FlowLib.Managers.DownloadManager();
                    //DownloadItem tmpDownloadItem = new DownloadItem(srInfo.Info);
                    //// Do downloadItem exist?
                    //if (dm.ContainsDownload(tmpDownloadItem))
                    //{
                    //    // Add Source to the existing downloaditem. Note that we first check if it exist.
                    //    dm.AddDownload(tmpDownloadItem, srInfo.Source);
                    //}
                }
                break;

            case Actions.UserOnline:
                bool hasMe = (hub.GetUserById(hub.Me.ID) != null);
                if (!sentRequest && hasMe)
                {
                    // Send Search
                    SearchInfo searchInfo = new SearchInfo();
                    searchInfo.Set(SearchInfo.SEARCH, "Ubuntu");
                    //searchInfo.Set(SearchInfo.SIZE, "1000");
                    //searchInfo.Set(SearchInfo.SIZETYPE, "1");
                    UpdateBase(this, new FlowLib.Events.FmdcEventArgs(Actions.Search, searchInfo));
                    sentRequest = true;
                }
                break;
            }
        }
Beispiel #3
0
        public PassiveSearch()
        {
            UpdateBase = new FlowLib.Events.FmdcEventHandler(PassiveSearch_UpdateBase);

            HubSetting settings = new HubSetting();
            settings.Address = "127.0.0.1";
            settings.Port = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol = "Auto";

            Hub hubConnection = new Hub(settings,this);
            hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange);
            hubConnection.Connect();

            // Wait 5 seconds (We should really listen on ConnectionStatusChange instead.
            System.Threading.Thread.Sleep(5 * 1000);

            // Send Search
            SearchInfo searchInfo = new SearchInfo();
            searchInfo.Set(SearchInfo.SEARCH, "Ubuntu");

            UpdateBase(this, new FlowLib.Events.FmdcEventArgs(Actions.Search, searchInfo));
        }
Beispiel #4
0
        public Search(Hub hub, string raw)
            : base(hub, raw)
        {
            int searchPos = 0;

            #region Get From
            int pos1 = 0, pos2 = 0;
            if (Utils.StringOperations.Find(raw, "Hub:", " ", ref pos1, ref pos2))
            {
                searchPos = pos2;
                pos1     += 4;
                pos2     -= 1;
                from      = raw.Substring(pos1, pos2 - pos1);
            }
            else if (((pos1 = 0) == 0) && Utils.StringOperations.Find(raw, "$Search ", " ", ref pos1, ref pos2))
            {
                searchPos = pos2;
                pos1     += 8;
                pos2     -= 1;
                string[] tmp = raw.Substring(pos1, pos2 - pos1).Split(':');
                if (tmp.Length == 2)
                {
                    System.Net.IPAddress ip = null;
                    int port = -1;
                    try
                    {
                        ip = System.Net.IPAddress.Parse(tmp[0]);
                    }
                    catch { }
                    try
                    {
                        port = int.Parse(tmp[1]);
                        if (port < 0 || port > 65535)
                        {
                            port = 0;
                        }
                    }
                    catch { }

                    if (ip != null)
                    {
                        address = new System.Net.IPEndPoint(ip, port);
                    }
                }
            }
            #endregion
            #region Search Info
            if (searchPos != 0)
            {
                info = new SearchInfo();
                string[] sections = raw.Substring(searchPos).Split('?');
                if (sections.Length == 5)
                {
                    #region Size Info
                    info.Set(SearchInfo.SIZETYPE, "0");
                    if (sections[0] == "T")
                    {
                        info.Set(SearchInfo.SIZETYPE, (sections[1] == "F" ? "1" : "2"));
                    }
                    long size = 0;
                    try
                    {
                        size = long.Parse(sections[2]);
                    }
                    catch { size = 0; }
                    info.Set(SearchInfo.SIZE, size.ToString());
                    #endregion
                    #region Extention
                    string ext = string.Empty;
                    System.Text.StringBuilder sb = new System.Text.StringBuilder(7);
                    switch (sections[3])
                    {
                    case "2":           // Audio
                        sb.Append("mp3 ");
                        sb.Append("mp2 ");
                        sb.Append("wav ");
                        sb.Append("au ");
                        sb.Append("rm ");
                        sb.Append("mid ");
                        sb.Append("sm");
                        break;

                    case "3":           // Compressed
                        sb.Append("zip ");
                        sb.Append("arj ");
                        sb.Append("rar ");
                        sb.Append("lzh ");
                        sb.Append("gz ");
                        sb.Append("z ");
                        sb.Append("arc ");
                        sb.Append("pak");
                        break;

                    case "4":           // Documents
                        sb.Append("doc ");
                        sb.Append("txt ");
                        sb.Append("wri ");
                        sb.Append("pdf ");
                        sb.Append("ps ");
                        sb.Append("tex");
                        break;

                    case "5":           // Executables
                        sb.Append("exe ");
                        sb.Append("pm ");
                        sb.Append("bat ");
                        sb.Append("com");
                        break;

                    case "6":           // Pictures
                        sb.Append("gif ");
                        sb.Append("jpg ");
                        sb.Append("jpeg ");
                        sb.Append("bmp ");
                        sb.Append("pcx ");
                        sb.Append("png ");
                        sb.Append("wmf ");
                        sb.Append("psd");
                        break;

                    case "7":           // Videos
                        sb.Append("mpg ");
                        sb.Append("mpeg ");
                        sb.Append("avi ");
                        sb.Append("asf ");
                        sb.Append("mov");
                        break;

                    case "8":           // Folders
                        sb.Append("$0");
                        info.Set(SearchInfo.TYPE, "1");
                        break;

                    case "9":           // TTH Search
                        sb.Append("$1");
                        info.Set(SearchInfo.TYPE, "2");
                        break;
                    }
                    info.Set(SearchInfo.EXTENTION, sb.ToString());
                    #endregion
                    #region Search String
                    if (sections[4].StartsWith("TTH:"))
                    {
                        info.Set(SearchInfo.SEARCH, sections[4].Substring(4));
                    }
                    else
                    {
                        info.Set(SearchInfo.SEARCH, sections[4]);
                    }
                    #endregion
                    valid = true;
                }
            }
            #endregion
        }
Beispiel #5
0
        public Search(Hub hub, string raw)
            : base(hub, raw)
        {
            bool validAddress = false;

            int searchPos = 0;
            #region Get From
            int pos1 =0, pos2 = 0;
            if (Utils.StringOperations.Find(raw, "Hub:", " ", ref pos1, ref pos2))
            {
                searchPos = pos2;
                pos1 += 4;
                pos2 -= 1;
                from = raw.Substring(pos1, pos2 - pos1);

                validAddress = true;
            }
            else if (((pos1=0) == 0) && Utils.StringOperations.Find(raw, "$Search ", " ", ref pos1, ref pos2))
            {
                searchPos = pos2;
                pos1 += 8;
                pos2 -= 1;
                string[] tmp = raw.Substring(pos1, pos2 - pos1).Split(':');
                if (tmp.Length == 2)
                {
                    System.Net.IPAddress ip = null;
                    int port = -1;
                    try
                    {
                        ip = System.Net.IPAddress.Parse(tmp[0]);
                    }
                    catch { }

                    int.TryParse(tmp[1], out port);
                    //if (port < 	 || port > System.Net.IPEndPoint.MaxPort)
                    //    port = -1;

                    if (ip != null && (System.Net.IPEndPoint.MinPort <= port &&  port <= System.Net.IPEndPoint.MaxPort))
                    {
                        address = new System.Net.IPEndPoint(ip, port);
                        validAddress = true;
                    }
                }
            }
            #endregion
            #region Search Info
            if (searchPos != 0)
            {
                info = new SearchInfo();
                string[] sections = raw.Substring(searchPos).Split('?');
                if (sections.Length == 5)
                {
                    #region Size Info
                    info.Set(SearchInfo.SIZETYPE, "0");
                    if (sections[0] == "T")
                    {
                        info.Set(SearchInfo.SIZETYPE, (sections[1] == "F" ? "1" : "2"));
                    }
                    long size = 0;
                    try
                    {
                        size = long.Parse(sections[2]);
                    }
                    catch { size = 0; }
                    info.Set(SearchInfo.SIZE, size.ToString());
                    #endregion
                    #region Extention
                    string ext = string.Empty;
                    System.Text.StringBuilder sb = new System.Text.StringBuilder(7);
                    switch (sections[3])
                    {
                        case "2":       // Audio
                            sb.Append("mp3 ");
                            sb.Append("mp2 ");
                            sb.Append("wav ");
                            sb.Append("au ");
                            sb.Append("rm ");
                            sb.Append("mid ");
                            sb.Append("sm");
                            break;
                        case "3":       // Compressed
                            sb.Append("zip ");
                            sb.Append("arj ");
                            sb.Append("rar ");
                            sb.Append("lzh ");
                            sb.Append("gz ");
                            sb.Append("z ");
                            sb.Append("arc ");
                            sb.Append("pak");
                            break;
                        case "4":       // Documents
                            sb.Append("doc ");
                            sb.Append("txt ");
                            sb.Append("wri ");
                            sb.Append("pdf ");
                            sb.Append("ps ");
                            sb.Append("tex");
                            break;
                        case "5":       // Executables
                            sb.Append("exe ");
                            sb.Append("pm ");
                            sb.Append("bat ");
                            sb.Append("com");
                            break;
                        case "6":       // Pictures
                            sb.Append("gif ");
                            sb.Append("jpg ");
                            sb.Append("jpeg ");
                            sb.Append("bmp ");
                            sb.Append("pcx ");
                            sb.Append("png ");
                            sb.Append("wmf ");
                            sb.Append("psd");
                            break;
                        case "7":       // Videos
                            sb.Append("mpg ");
                            sb.Append("mpeg ");
                            sb.Append("avi ");
                            sb.Append("asf ");
                            sb.Append("mov");
                            break;
                        case "8":       // Folders
                            sb.Append("$0");
                            info.Set(SearchInfo.TYPE, "1");
                            break;
                        case "9":       // TTH Search
                            sb.Append("$1");
                            info.Set(SearchInfo.TYPE, "2");
                            break;
                    }
                    info.Set(SearchInfo.EXTENTION, sb.ToString());
                    #endregion
                    #region Search String
                    if (sections[4].StartsWith("TTH:"))
                        info.Set(SearchInfo.SEARCH, sections[4].Substring(4));
                    else
                        info.Set(SearchInfo.SEARCH, sections[4]);
                    #endregion

                    // A search is only valid if it has a valid Adress
                    if (validAddress)
                    {
                        valid = true;
                    }
                }
            }
            #endregion
        }
Beispiel #6
0
 void hubConnection_Update(object sender, FlowLib.Events.FmdcEventArgs e)
 {
     Hub hub = sender as Hub;
     if (hub == null)
         return;
     switch (e.Action)
     {
         case Actions.SearchResult:
             if (e.Data is SearchResultInfo)
             {
                 SearchResultInfo srInfo = (SearchResultInfo)e.Data;
                 // This is if we want to enable auto adding of sources to a downloaditem.
                 //FlowLib.Managers.DownloadManager dm = new FlowLib.Managers.DownloadManager();
                 //DownloadItem tmpDownloadItem = new DownloadItem(srInfo.Info);
                 //// Do downloadItem exist?
                 //if (dm.ContainsDownload(tmpDownloadItem))
                 //{
                 //    // Add Source to the existing downloaditem. Note that we first check if it exist.
                 //    dm.AddDownload(tmpDownloadItem, srInfo.Source);
                 //}
             }
             break;
         case Actions.UserOnline:
             bool hasMe = (hub.GetUserById(hub.Me.ID) != null);
             if (!sentRequest && hasMe)
             {
                 // Send Search
                 SearchInfo searchInfo = new SearchInfo();
                 searchInfo.Set(SearchInfo.SEARCH, "Ubuntu");
                 //searchInfo.Set(SearchInfo.SIZE, "1000");
                 //searchInfo.Set(SearchInfo.SIZETYPE, "1");
                 UpdateBase(this, new FlowLib.Events.FmdcEventArgs(Actions.Search, searchInfo));
                 sentRequest = true;
             }
             break;
     }
 }
        public SCH(IConnection con, string raw)
            : base(con, raw)
        {
            // BSCH NRQF TRUDHPNB4BUIQV2LAI4HDWRL3KLJTUSXCTAMJHNII TOauto
            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 "AN":
                    //TODO : We should make it possible to have more then 1 AN.
                    if (info.ContainsKey(SearchInfo.SEARCH))
                    {
                        value = value + " " + info.Get(SearchInfo.SEARCH);
                    }
                    info.Set(SearchInfo.SEARCH, value);
                    valid = true;
                    break;

                case "NO":
                    //TODO : We should make it possible to have more then 1 AN.
                    info.Set(SearchInfo.NOSEARCH, value);
                    break;

                case "EX":
                    if (info.ContainsKey(SearchInfo.EXTENTION))
                    {
                        value = value + " " + info.Get(SearchInfo.EXTENTION);
                    }
                    info.Set(SearchInfo.EXTENTION, value);
                    break;

                case "LE":
                    info.Set(SearchInfo.SIZETYPE, "2");
                    try
                    {
                        info.Set(SearchInfo.SIZE, long.Parse(value).ToString());
                    }
                    catch { }
                    break;

                case "GE":
                    info.Set(SearchInfo.SIZETYPE, "1");
                    try
                    {
                        info.Set(SearchInfo.SIZE, long.Parse(value).ToString());
                    }
                    catch { }
                    break;

                case "EQ":
                    info.Set(SearchInfo.SIZETYPE, "3");
                    try
                    {
                        info.Set(SearchInfo.SIZE, long.Parse(value).ToString());
                    }
                    catch { }
                    break;

                case "TO":
                    info.Set(SearchInfo.TOKEN, value);
                    break;

                case "TY":
                    switch (value)
                    {
                    case "1":           // File
                        break;

                    case "2":           // Directory
                        info.Set(SearchInfo.TYPE, "1");
                        break;

                    default:
                        break;
                    }
                    break;

                case "TR":
                    info.Set(SearchInfo.SEARCH, value);
                    info.Set(SearchInfo.TYPE, "2");
                    valid = true;
                    break;
                }
            }
        }
Beispiel #8
0
        public void ActOnInMessage(IConMessage conMsg)
        {
            StrMessage message = (StrMessage)conMsg;
            #region INF
            if (message is INF)
            {
                INF inf = (INF)message;
                if (hub != null && inf.Type.Equals("I"))
                {
                    if (hub.RegMode < 0)
                        hub.RegMode = 0;
                    UpdateInf();
                    Info = inf.UserInfo;
                    if (hub != null && Info.Description == null)
                        Update(con, new FmdcEventArgs(Actions.Name, new Containers.HubName(Info.DisplayName)));
                    else if (hub != null)
                        Update(con, new FmdcEventArgs(Actions.Name, new Containers.HubName(Info.DisplayName, Info.Description)));
                }
                else if (trans != null && inf.Type.Equals("C"))
                {
                    string token = null;
                    // CINF IDE3VACJVAXNOQLGRFQS7D5HYH4A6GLZDO3LJ33HQ TO2718662518
                    if (trans.Me != null && trans.Me.ContainsKey("TO"))
                        token = trans.Me.Get("TO");
                    else if (inf.UserInfo.ContainsKey("TO"))
                        token = inf.UserInfo.Get("TO");

                    TransferRequest req = new TransferRequest(token, null, inf.UserInfo);
                    FmdcEventArgs eArgs = new FmdcEventArgs(0, req);
                    RequestTransfer(trans, eArgs);
                    req = eArgs.Data as TransferRequest;
                    if (!eArgs.Handled || req == null)
                    {
                        // Can't see user/connection on my allow list
                        trans.Disconnect("No match for Request");
                        return;
                    }
                    if (!((req.User.ContainsKey(UserInfo.CID) && inf.UserInfo.ContainsKey(UserInfo.CID)) && req.User.Get(UserInfo.CID).Equals(inf.UserInfo.Get(UserInfo.CID))))
                    {
                        // For some reason user is trying to tell us it is a diffrent user. We dont like that.
                        FmdcEventArgs e = new FmdcEventArgs((int)TransferErrors.USERID_MISMATCH);
                        Error(trans, e);
                        if (!e.Handled)
                        {
                            trans.Disconnect("User Id Mismatch");
                            return;
                        }
                    }
                    if (trans.Me == null)
                        trans.Me = req.Me;
                    trans.User = req.User;
                    info = trans.User;
                    trans.Share = req.Share;
                    trans.Source = req.Source;
                    download = req.Download;

                    con.Send(new INF(con, trans.Me));
                    if (download)
                    {
                        EnsureCurrentSegmentCancelation();
                        // Request new segment from user. IF we have found one. ELSE disconnect.
                        if (GetSegment(true))
                        {
                            OnDownload();
                        }
                        else
                            trans.Disconnect("All content downloaded");
                    }
                }
                else if (hub != null)
                {
                    User usr = null;
                    if ((usr = hub.GetUserById(inf.Id)) == null)
                    {
                        if (inf.UserInfo.Mode == ConnectionTypes.Unknown)
                        {
                            inf.UserInfo.Mode = ConnectionTypes.Passive;
                        }
                        Update(con, new FmdcEventArgs(Actions.UserOnline, inf.UserInfo));
                    }
                    else
                    {
                        usr.UserInfo = inf.UserInfo;
                        Update(con, new FmdcEventArgs(Actions.UserInfoChange, usr.UserInfo));
                    }
                    // This is so we update our own reg/op hub count.
                    if (string.Equals(hub.Me.ID,inf.Id))
                    {
                        // Should we be marked with key?
                        bool regmodeChanged = false;
                        if (hub.RegMode < 2)
                        {
                            if (((UserInfo.ACCOUNT_FLAG_OPERATOR & inf.UserInfo.Account) == UserInfo.ACCOUNT_FLAG_OPERATOR))
                            {
                                hub.RegMode = 2;
                                regmodeChanged = true;
                            }
                            else if (((UserInfo.ACCOUNT_FLAG_SUPERUSER & inf.UserInfo.Account) == UserInfo.ACCOUNT_FLAG_SUPERUSER))
                            {
                                hub.RegMode = 2;
                                regmodeChanged = true;
                            }
                            else if (((UserInfo.ACCOUNT_FLAG_HUBOWNER & inf.UserInfo.Account) == UserInfo.ACCOUNT_FLAG_HUBOWNER))
                            {
                                hub.RegMode = 2;
                                regmodeChanged = true;
                            }
                        }
                        // Should we be marked as reg?
                        if (hub.RegMode < 1)
                        {
                            if (((UserInfo.ACCOUNT_FLAG_REGISTERED & inf.UserInfo.Account) == UserInfo.ACCOUNT_FLAG_REGISTERED))
                            {
                                hub.RegMode = 1;
                                regmodeChanged = true;
                            }

                        }
                        if (regmodeChanged)
                            UpdateInf();

                        IsReady = true;
                    }
                }
            }
            #endregion
            #region MSG
            else if (message is MSG && hub != null)
            {
                MSG msg = (MSG)message;
                if (msg.PmGroup == null)
                {
                    MainMessage main = new MainMessage(msg.From, msg.Content);
                    Update(con, new FmdcEventArgs(Actions.MainMessage, main));
                }
                else
                {
                    PrivateMessage pm = new PrivateMessage(msg.To, msg.From, msg.Content, msg.PmGroup);
                    Update(con, new FmdcEventArgs(Actions.PrivateMessage, pm));
                }
            }
            #endregion
            #region SID
            else if (message is SID && hub != null)
            {
                SID sid = (SID)message;
                hub.Me.Set(UserInfo.SID, sid.Id);
            }
            #endregion
            #region STA
            else if (message is STA)
            {
                STA sta = (STA)message;
                if (hub != null)
                {
                    MainMessage main = new MainMessage(info.ID, sta.Content);
                    Update(con, new FmdcEventArgs(Actions.MainMessage, main));
                }
            }
            #endregion
            #region GPA
            else if (message is GPA)
            {
                GPA gpa = (GPA)message;
                this.gpaString = gpa.RandomData;
                if (trans != null)
                {
                    Update(con, new FmdcEventArgs(Actions.Password, null));
                }
                if (hub != null && hub.HubSetting.Password.Length == 0)
                {
                    Update(con, new FmdcEventArgs(Actions.Password, null));
                }
                else
                    hub.Send(new PAS(hub, gpa.RandomData, hub.HubSetting.Password));
            }
            #endregion
            #region QUI
            else if (message is QUI && hub != null)
            {
                QUI qui = (QUI)message;
                User usr = null;
                if ((usr = hub.GetUserById(qui.Id)) != null)
                {
                    Update(con, new FmdcEventArgs(Actions.UserOffline, usr.UserInfo));
                    if (usr.ID == hub.Me.ID)
                    {
                        // TODO : Banning and redirect handling
                        hub.Disconnect();
                        // Redirect
                        if (!string.IsNullOrEmpty(qui.Address))
                            Update(con, new FmdcEventArgs(Actions.Redirect, new RedirectInfo(qui.Address, qui.Message, qui.DisconnectedBy)));
                        // Banned
                        else
                        {
                            if (qui.Time != -1)
                                // Sets reconnect attempt to infinite
                                hub.KeepAliveInterval = 0;
                            else
                                hub.KeepAliveInterval = qui.Time;
                            Update(con, new FmdcEventArgs(Actions.Banned, new BannedInfo(qui.Time, qui.Message, qui.DisconnectedBy)));
                        }
                    }
                }
            }
            #endregion
            #region SUP
            else if (message is SUP)
            {
                if (trans != null && !hasSentSUP)
                {
                    con.Send(new SUP(con));
                }
                supports = (SUP)message;
                // TODO : We should really care about what hub support.
                if (!supports.BASE && !supports.TIGR)
                {
                    // We will just simply disconnect if hub doesnt support this right now
                    con.Disconnect("Connection doesnt support BASE or BAS0");
                }
            #if !COMPACT_FRAMEWORK
                // Encrypted transfers
                if (supports.ADCS)
                {
                    if (
                        (hub != null && hub.Me.ContainsKey(UserInfo.SECURE)) ||
                        (trans != null && trans.Me.ContainsKey(UserInfo.SECURE))
                        )
                    {
                        con.SecureProtocol = SecureProtocols.TLS;
                    }
                }
            #endif
            }
            #endregion
            #region RES
            else if (message is RES)
            {
                RES res = (RES)message;
                SearchResultInfo srinfo = new SearchResultInfo(res.Info, res.Id, res.Token);
                if (hub != null)
                    Update(con, new FmdcEventArgs(Actions.SearchResult, srinfo));
            }
            #endregion
            #region SCH
            else if (message is SCH)
            {
                SCH sch = (SCH)message;
                UserInfo usr = null;
                if (hub != null)
                {
                    User u = hub.GetUserById(sch.Id);
                    if (u != null)
                        usr = u.UserInfo;
                }
                else if (trans != null)
                    usr = trans.User;

                SendRES(sch.Info, usr);
            }
            #endregion
            #region CTM
            else if (message is CTM && hub != null)
            {
                CTM ctm = (CTM)message;

                // We really hate buggy hubsofts. Only reason we will get this message is because hubsoft dont know diffrent between E and D messages.
                if (ctm.Id == hub.Me.ID)
                    return;

                User usr = null;
                string addr = null;

                // Do we support same protocol?
                double version = 0.0;
                if (ctm.Protocol != null && (ctm.Protocol.StartsWith("ADC/") || ctm.Protocol.StartsWith("ADCS/")))
                {
                    try
                    {
                        version = double.Parse(ctm.Protocol.Substring( ctm.Protocol.IndexOf("/") +1), CultureInfo.GetCultureInfo("en-GB").NumberFormat);
                    }
                    catch { }
                }
                if (version > 1.0)
                {
                    hub.Send(new STA(hub, ctm.Id, hub.Me.ID, "241", "Protocol is not supported. I only support ADC 1.0/ADCS 0.10 and prior", "TO" + ctm.Token + " PR" + ctm.Protocol));
                    return;
                }

                if ((usr = hub.GetUserById(ctm.Id)) != null && usr.UserInfo.ContainsKey(UserInfo.IP))
                {
                    addr = usr.UserInfo.Get(UserInfo.IP);
                    Transfer trans = new Transfer(addr, ctm.Port);
                    trans.Share = hub.Share;
                    // We are doing this because we want to filter out PID and so on.
                    User me = hub.GetUserById(hub.Me.ID);
                    trans.Me = new UserInfo(me.UserInfo);
                    trans.Protocol = new AdcProtocol(trans);
            #if !COMPACT_FRAMEWORK
                    if (ctm.Secure)
                        trans.SecureProtocol = SecureProtocols.TLS;
            #endif

                    // Support for prior versions of adc then 1.0
                    string token = ctm.Token;
                    if (version < 1.0 && ctm.Token.StartsWith("TO"))
                        token = ctm.Token.Substring(2);
                    trans.Me.Set("TO", token);

                    Update(con, new FmdcEventArgs(Actions.TransferRequest, new TransferRequest(token, hub, usr.UserInfo,false)));
                    Update(con, new FmdcEventArgs(Actions.TransferStarted, trans));
                }
            }
            #endregion
            #region RCM
            else if (message is RCM && hub != null)
            {
                RCM rcm = (RCM)message;

                // We really hate buggy hubsofts. Only reason we will get this message is because hubsoft dont know diffrent between E and D messages.
                if (rcm.Id == hub.Me.ID)
                    return;

               if (hub.Me.Mode != FlowLib.Enums.ConnectionTypes.Passive && hub.Share != null)
                {
                    User usr = null;
                    if ((usr = hub.GetUserById(rcm.Id)) != null)
                    {
                        // Do we support same protocol?
                        double version = 0.0;
                        if (rcm.Protocol != null && (rcm.Protocol.StartsWith("ADC/") || rcm.Protocol.StartsWith("ADCS/")))
                        {
                            try
                            {
                                version = double.Parse(rcm.Protocol.Substring(rcm.Protocol.IndexOf("/") + 1), CultureInfo.GetCultureInfo("en-GB").NumberFormat);
                            }
                            catch { }
                            if (version <= 1.0)
                            {
                                // Support for prior versions of adc then 1.0
                                string token = rcm.Token;
                                if (version < 1.0 && rcm.Token.StartsWith("TO"))
                                    token = rcm.Token.Substring(2);

                                Update(con, new FmdcEventArgs(Actions.TransferRequest, new TransferRequest(token, hub, usr.UserInfo, false)));

                                if (rcm.Secure && hub.Me.ContainsKey(UserInfo.SECURE))
                                    hub.Send(new CTM(hub, rcm.Id, rcm.IDTwo, rcm.Protocol, int.Parse(0 + hub.Me.Get(UserInfo.SECURE)), token));
                                else
                                    hub.Send(new CTM(hub, rcm.Id, rcm.IDTwo, rcm.Protocol, hub.Share.Port, token));
                            }
                            else
                            {
                                hub.Send(new STA(hub, rcm.Id, hub.Me.ID, "241", "Protocol is not supported. I only support ADC 1.0 and prior", "TO" + rcm.Token + " PR" + rcm.Protocol));
                                return;
                            }
                        }
                    }
                }
                else
                {
                    // TODO : we should probably return a STA message.
                }
            }
            #endregion
            #region GFI
            else if (message is GFI && this.trans != null)
            {
                GFI gfi = (GFI)message;
                if (gfi.Identifier != null)
                {
                    trans.Content = new ContentInfo();
                    switch (gfi.ContentType)
                    {
                        case "file":        // Requesting file
                            // This is because we have support for old DC++ client and mods like (DCDM who has ASCII encoding)
                            if (gfi.Identifier.Equals("files.xml.bz2"))
                            {
                                trans.Content.Set(ContentInfo.FILELIST, Utils.FileLists.BaseFilelist.XMLBZ);
                                trans.Content.Set(ContentInfo.VIRTUAL, System.Text.Encoding.UTF8.WebName + gfi.Identifier);
                            }
                            else if (gfi.Identifier.StartsWith("TTH/"))
                            {
                                trans.Content.Set(ContentInfo.TTH, gfi.Identifier.Substring(4));
                            }
                            else
                            {
                                trans.Content.Set(ContentInfo.VIRTUAL, gfi.Identifier);
                            }
                            break;
                        case "list":        // TODO : We dont care about what subdirectoy user whats list for
                            trans.Content.Set(ContentInfo.FILELIST, Utils.FileLists.BaseFilelist.XML);
                            trans.Content.Set(ContentInfo.VIRTUAL, System.Text.Encoding.UTF8.WebName + "files.xml");
                            break;
                        default:            // We are not supporting type. Disconnect
                            con.Send(new STA(con, "251", "Type not known:" + gfi.ContentType, null));
                            con.Disconnect();
                            return;
                    }
                    SearchInfo si = new SearchInfo();
                    if (trans.Content.ContainsKey(ContentInfo.TTH))
                        si.Set(SearchInfo.TYPE, trans.Content.Get(ContentInfo.TTH));
                    si.Set(SearchInfo.SEARCH, trans.Content.Get(ContentInfo.VIRTUAL));
                    SendRES(si, trans.User);
                }
            }
            #endregion
            #region GET
            else if (message is GET && this.trans != null)
            {
                GET get = (GET)message;
                // If we are supposed to download and other client tries to download. Disconnect.
                if (trans != null && this.download)
                {
                    trans.Disconnect();
                    return;
                }
                bool firstTime = true;

                if (get.Identifier != null)
                {
                    trans.Content = new ContentInfo();
                    switch (get.ContentType)
                    {
                        case "file":        // Requesting file
                            // This is because we have support for old DC++ client and mods like (DCDM who has ASCII encoding)
                            if (get.Identifier.Equals("files.xml.bz2"))
                            {
                                trans.Content.Set(ContentInfo.FILELIST, Utils.FileLists.BaseFilelist.XMLBZ);
                                trans.Content.Set(ContentInfo.VIRTUAL, System.Text.Encoding.UTF8.WebName + get.Identifier);
                            }
                            else if (get.Identifier.StartsWith("TTH/"))
                            {
                                trans.Content.Set(ContentInfo.TTH, get.Identifier.Substring(4));
                            }
                            else
                            {
                                trans.Content.Set(ContentInfo.VIRTUAL, get.Identifier);
                            }
                            break;
                        case "list":        // TODO : We dont care about what subdirectoy user whats list for
                            trans.Content.Set(ContentInfo.FILELIST, Utils.FileLists.BaseFilelist.XML);
                            trans.Content.Set(ContentInfo.VIRTUAL, System.Text.Encoding.UTF8.WebName + "files.xml");
                            break;
                        case "tthl":
                            // TTH/DQSGG2MYKKLXX4N2P7TBPKSC5HVBO3ISYZPLMWA
                            if (get.Identifier.StartsWith("TTH/"))
                            {
                                trans.Content.Set(ContentInfo.TTH, get.Identifier.Substring(4));

                                ContentInfo tmp = trans.Content;
                                if (con.Share != null && con.Share.ContainsContent(ref tmp) && tmp.ContainsKey(ContentInfo.TTHL))
                                {
                                    byte[] bytes = Utils.Convert.Base32.Decode(tmp.Get(ContentInfo.TTHL));
            #if !COMPACT_FRAMEWORK
                                    trans.CurrentSegment = new SegmentInfo(-1, 0, bytes.LongLength);
            #else
                                    trans.CurrentSegment = new SegmentInfo(-1, 0, bytes.Length);
            #endif

                                    con.Send(new SND(trans, get.ContentType, get.Identifier, new SegmentInfo(-1, trans.CurrentSegment.Start, trans.CurrentSegment.Length)));
                                    // Send content to user
                                    System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
                                    ms.Flush();
                                    bytes = ms.ToArray();
                                    con.Send(new BinaryMessage(con, bytes, bytes.Length));
                                    System.Console.WriteLine("TTH Leaves:" + FlowLib.Utils.Convert.Base32.Encode(bytes));
                                    firstTime = true;
                                }
                            }
                            if (!firstTime)
                            {
                                // We should not get here if file is in share.
                                con.Send(new STA(con, "251", "File not available", null));
                                con.Disconnect();
                            }
                            return;
                        default:            // We are not supporting type. Disconnect
                            con.Send(new STA(con, "251", "Type not known:" + get.ContentType, null));
                            con.Disconnect();
                            return;
                    }
                    trans.CurrentSegment = get.SegmentInfo;
                    byte[] bytesToSend = null;
                    try
                    {
                        // TODO : ZLib compression here doesnt work as we want. It takes much memory and much cpu
                        //Util.Compression.ZLib zlib = null;
                        //if (adcget.ZL1)
                        //    zlib = new Fmdc.Util.Compression.ZLib();
                        while (connectionStatus != TcpConnection.Disconnected && (bytesToSend = GetContent(System.Text.Encoding.UTF8, trans.CurrentSegment.Position, trans.CurrentSegment.Length - trans.CurrentSegment.Position)) != null)
                        {
                            if (firstTime)
                            {
                                con.Send(new SND(trans, get.ContentType, get.Identifier, new SegmentInfo(-1, get.SegmentInfo.Start, trans.CurrentSegment.Length)));
                                firstTime = false;
                            }

                            trans.CurrentSegment.Position += bytesToSend.Length;
                            // We want to compress content with ZLib
                            //if (zlib != null)
                            //{
                            //    zlib.Compress2(bytesToSend);
                            //    bytesToSend = zlib.Read();
                            //}
                            con.Send(new BinaryMessage(trans, bytesToSend, bytesToSend.Length));
                            bytesToSend = null;

                        }

                        // If we compressing data with zlib. We need to send ending bytes too.
                        //if (zlib != null && connectionStatus != Connection.Disconnected)
                        //    trans.Send(new ConMessage(trans, zlib.close()));
                    }
                    catch (System.Exception e) { System.Console.WriteLine("ERROR:" + e); }
                }
                trans.CurrentSegment = new SegmentInfo(-1);
                trans.Content = null;
                if (firstTime)
                {
                    // We should not get here if file is in share.
                    con.Send(new STA(con, "251", "File not available", null));
                    con.Disconnect();
                }
            }
            #endregion
            #region SND
            else if (message is SND)
            {
                SND snd = (SND)message;
                if (!trans.Content.Get(ContentInfo.REQUEST).Equals(snd.Identifier))
                {
                    trans.Disconnect("I want my bytes..");
                    return;
                }
                if (trans.DownloadItem.ContentInfo.Size == -1)
                {
                    trans.DownloadItem.ContentInfo.Size = snd.SegmentInfo.Length;
                    trans.DownloadItem.SegmentSize = snd.SegmentInfo.Length;
                    EnsureCurrentSegmentCancelation();
                    GetSegment(false);
                }
                else if (trans.CurrentSegment != null && trans.CurrentSegment.Length != snd.SegmentInfo.Length)
                {
                    trans.Disconnect("Why would i want to get a diffrent length of bytes then i asked for?");
                    return;
                }
                this.IsRawData = true;
                trans.ShouldBlockOnSend = true;
            }
            #endregion
        }