public bool AddClient(CClient client) { if (client.DownFileChunks == null) { return(false); } CSourceOld source = GetSourceOld(client.UserHash); if (source == null) { CSourceOld sourceOld = new CSourceOld(client); m_ArrayList.Add(sourceOld); return(true); } else { source.DeletedTime = DateTime.Now; } return(false); }
/// <summary> /// Process incomming eDonkey packet. /// </summary> /// <param name="packet">Packet which need to be processed.</param> protected virtual void ProcessDonkeyPacket(ref byte[] packet) { try { switch ((Protocol.ClientCommand)m_DonkeyHeader.Command) { case Protocol.ClientCommand.Hello: if (m_Client == null) { CReceiveHello HelloPacket = new CReceiveHello(false, new MemoryStream(packet)); m_Client = CKernel.ClientsList.GetClient(HelloPacket.UserID, HelloPacket.UserPort, HelloPacket.ServerIP, HelloPacket.Hash); if (m_Client == null) { m_Client = new CClient(this); CKernel.ClientsList.AddClient(m_Client); } else { if ((m_Client.connection != null) && (m_Client.connection.Connected) && (m_Client.connection != this)) { m_Client.connection.CloseConnection(); Debug.WriteLine("Client conexion!=null"); } m_Client.connection = this; } } CClient cant = m_Client; CConnection conant = m_Client.connection; bool NeedExtendRequest = !m_Client.ProcessHello(false, packet); if ((NeedExtendRequest) && (m_Client.EmuleProtocol) && (CKernel.Preferences.GetBool("UseEmuleProtocol"))) { m_Client.SendEmuleHello(false); } m_Client.ResponseHello(); break; case Protocol.ClientCommand.FileRequest: m_Client.ProcessFileRequest(packet); break; case Protocol.ClientCommand.HelloAnswer: m_Client.ProcessHello(true, packet); break; case Protocol.ClientCommand.SetRequestFileID: m_Client.ProcessRequestFileID(packet); break; case Protocol.ClientCommand.FileRequestAnswer: m_Client.ProcessFileInfo(packet); break; case Protocol.ClientCommand.FileState: m_Client.ProcessChunksStatus(packet, false /*tcp*/); break; case Protocol.ClientCommand.HashSetAnswer: m_Client.ProcessHashSet(packet); break; case Protocol.ClientCommand.HashSetRequest: m_Client.SendHashSet(); break; case Protocol.ClientCommand.AcceptUploadRequest: if (m_Client.DownloadState == Protocol.DownloadState.OnQueue) { m_Client.RequestBlocks(); } else { if (m_Client.DownFileHash != null) { // CLog.Log(Constants.Log.Verbose,"Trying to resume download {2}: {0},hashdescarga=null? {1}",m_Client.DownloadState,(m_Client.DownFileHash==null),m_Client.UserName); m_Client.RequestBlocks(); } else { if (m_Client.UpFileHash != null) { #if DEBUG CLog.Log(Constants.Log.Verbose, "Recovering source to download " + m_Client.UserName); #endif m_Client.DownFileHash = m_Client.UpFileHash; m_Client.RequestBlocks(); } else { CSourceOld sourceRecovered = CKernel.SourcesOld.GetSourceOld(m_Client.UserHash); if (sourceRecovered != null) { m_Client.DownFileHash = sourceRecovered.FileHash; m_Client.DownFileChunks = sourceRecovered.FileChunks; m_Client.RequestBlocks(); #if DEBUG CLog.Log(Constants.Log.Verbose, "RECOVERED SOURCE from sources cache " + m_Client.UserName); #endif } #if DEBUG else { CLog.Log(Constants.Log.Verbose, "download lost: {0}", m_Client.UserName); } #endif } } } break; case Protocol.ClientCommand.OutOfPartRequest: m_Client.ProcessOutOfParts(); break; case Protocol.ClientCommand.StartUploadRequest: m_Client.ProcessStartUploadRequest(packet); break; case Protocol.ClientCommand.RequestParts: m_Client.ProcessRequestParts(packet); break; case Protocol.ClientCommand.EndOfDownload: case Protocol.ClientCommand.CancelTransfer: m_Client.CancelUploadTransfer(false); break; case Protocol.ClientCommand.SendingPart: m_Client.ReceiveBlock(packet); break; case Protocol.ClientCommand.QueueRank: m_Client.ProcessQR(packet); break; case Protocol.ClientCommand.FileRequestAnswerNoFile: m_Client.FileNotFound(packet); break; case Protocol.ClientCommand.ChangeClientID: m_Client.ProcessIDChange(packet); break; case Protocol.ClientCommand.ChangeSlot: break; case Protocol.ClientCommand.AskSharedFiles: Constants.AllowViewShared allow = (Constants.AllowViewShared)CKernel.Preferences.GetEnum("AllowViewShared", Constants.AllowViewShared.Nobody); if (allow == Constants.AllowViewShared.All) { m_Client.ProcessSharedListRequest(); } if ((allow == Constants.AllowViewShared.All) && (m_Client.IsFriend)) { m_Client.ProcessSharedListRequest(); } break; case Protocol.ClientCommand.AskSharedFilesAnswer: m_Client.ProcessSharedListResponse(packet); break; case Protocol.ClientCommand.Message: m_Client.ProcessChatMessage(packet); break; case Protocol.ClientCommand.CrumbSetResponse: m_Client.ProcessCrumbSetResponse(packet); break; default: CLog.Log(Constants.Log.Verbose, "CLI_UNK_DONK_TCP_PACKET", m_DonkeyHeader.Command); break; } } catch (Exception e) { Debug.WriteLine(e.ToString()); #if DEBUG if (m_DonkeyHeader != null) { CLog.Log(Constants.Log.Verbose, "CLI_PAQ_DONK_ERROR", m_DonkeyHeader.Command); } #endif } packet = null; return; }