Exemplo n.º 1
0
        public bool AddSource(CClient source)
        {
            bool notMaxSources;

            notMaxSources = (((m_Element.File != null) && (m_ArrayList.Count < m_Element.File.MaxSources)) ||
                             (RemoveNoNeededSource()));
            if ((notMaxSources) &&
                (!m_ArrayList.Contains(source)) &&
                ((source.UserID != CKernel.Preferences.GetUInt("ID")) ||
                 (source.Port != CKernel.Preferences.GetUShort("TCPPort"))))
            {
                //this is an additional check to avoid duplicated sources
                //is it really needed, does it solve the problem at 100% ?
                CClient existingSource = CKernel.GetClient(m_ArrayList, source.UserID, source.Port, source.ServerIP, source.UserHash);
                if (existingSource != null)
                {
#if DEBUG
                    //CLog.Log(Types.Constants.Log.Verbose,"Duplicated source detected: "+ source.UserName + "-" + source.UserID.ToString() + "-" + m_ArrayList.Contains(source).ToString());
#endif
                    //attach the client to the existing one
                    source = existingSource;
                    return(false);
                }
                //

                m_ArrayList.Add(source);

                CKernel.NewSource(source, CKernel.HashToString(source.DownFileHash));

                return(true);
            }
            else
            {
                CKernel.ClientsList.IsClientNeeded(source);
            }
            return(false);
        }