예제 #1
0
파일: Friends.cs 프로젝트: pengpercy/lphant
        private int m_FindFriend(uint ID, byte[] ClientHash, ushort Port)
        {
            //First: i try to locate Friend with UserHash
            if (ClientHash != null)
            {
                for (int n = 0; n != List.Count; n++)
                {
                    byte[] hashFriend = (byte[])((SFriend)List[n]).UserHash;
                    if (hashFriend != null)
                    {
                        if (CKernel.SameHash(ref ClientHash, ref hashFriend))
                        {
                            return(n);
                        }
                    }
                }
            }

            //If i did not locate Friend with UserHash, i try to locate Friend with IP&Port
            for (int n = 0; n != List.Count; n++)
            {
                if ((((SFriend)List[n]).ID == ID) && (((SFriend)List[n]).Port == Port))
                {
                    return(n);
                }
            }
            return(-1);
        }
예제 #2
0
 public CElement this[byte[] key]
 {
     get
     {
         try
         {
             CElement result = null;
             lock (m_FileList.SyncRoot)
             {
                 foreach (CElement element in m_FileList)
                 {
                     if (CKernel.SameHash(ref key, ref element.File.FileHash))
                     {
                         result = element;
                         break;
                     }
                 }
             }
             return(result);
         }
         catch
         {
             return(null);
         }
     }
 }
예제 #3
0
 private bool m_Contains(byte[] fileHash)
 {
     foreach (CElement element in m_FileList)
     {
         if (CKernel.SameHash(ref fileHash, ref element.File.FileHash))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #4
0
 public CSourceOld GetSourceOld(byte[] UserHash)
 {
     lock (m_ArrayList.SyncRoot)
     {
         foreach (CSourceOld sourceOld in m_ArrayList)
         {
             if (CKernel.SameHash(ref UserHash, ref sourceOld.UserHash))
             {
                 return(sourceOld);
             }
         }
     }
     return(null);
 }
예제 #5
0
 public void AddClientToFile(CClient client, byte[] FileHash)
 {
     if (client.DownFileHash == null)
     {
         client.DownFileHash = FileHash;
         CKernel.FilesList.AddSource(FileHash, ref client);
     }
     else
     {
         if (CKernel.SameHash(ref FileHash, ref client.DownFileHash))
         {
             CKernel.FilesList.AddSource(FileHash, ref client);
         }
         else
         {
             client.AddOtherDownloadFile(CKernel.HashToString(FileHash));
         }
     }
 }