public bool ProcessHello(bool response,byte[] packet) { #if VERBOSE CKernel.LogClient.AddLog("ProcessHello, Response:"+response.ToString(),m_ID); #endif CReceiveHello helloPacket=new CReceiveHello(response,new MemoryStream(packet)); packet=null; m_UserHash=helloPacket.Hash; if (m_Software==(byte)Protocol.Client.Unknown) { m_Software=helloPacket.software; m_VersionMinor=helloPacket.Version; } if (helloPacket.software==(byte)Protocol.Client.eMule) m_EmuleProtocol=true; #if VERBOSE if ((m_ID!=0)&&(m_ID!=helloPacket.UserID)) CKernel.LogClient.AddLog("Older ID:"+Convert.ToString(m_ID)+",new:"+Convert.ToString(helloPacket.UserID),m_ID); #endif if ((helloPacket.UserID==0)||(helloPacket.UserID>Protocol.LowIDLimit)) { // probablemente no está conectado a un servidor y no sabe su ip pública // o es un idalto su id será la de su conexión if (connection!=null) m_ID=connection.IP; else m_ID=helloPacket.UserID; } else { //is a low id m_ID=helloPacket.UserID; } if ((m_ID!=0)&&(m_ID!=helloPacket.UserID)) Debug.WriteLine("OldUserID:"+Convert.ToString(m_ID)+",new:"+Convert.ToString(helloPacket.UserID)); m_Port=helloPacket.UserPort; m_UserName=helloPacket.UserName; m_supportsHorde=helloPacket.SupportsHorde; if (helloPacket.ExtendedInfoComplete) { //all the extended info is here we dont need a emule info packet emule v0.42+ m_Software=helloPacket.IDClientCompatible; m_UDPPort=helloPacket.PortUDP; m_SourceExchangeVersion=helloPacket.VersionSourceExchange; m_VersionMinor=(uint)helloPacket.VersioneMuleMinor; m_VersionMajor=(uint)helloPacket.VersioneMuleMajor; m_VersionRevision=(uint)helloPacket.VersioneMuleRevision; m_EmuleProtocol=true; m_VersionUDP=helloPacket.VersionUDP; m_VersionComments=helloPacket.VersionComments; m_VersionCompression=helloPacket.VersionCompression; m_VersionExtendedRequest=helloPacket.VersionExtendedRequests; m_AllowViewSharedFiles=helloPacket.AllowViewSharedFiles; m_PartnerAllowed=helloPacket.PartnerAllowed; m_SupportsPartner=helloPacket.SupportsPartner; } #if VERBOSE CKernel.LogClient.AddLog("User:"******"UpdateServerListFromClient"))) CKernel.ServersList.Add(m_ServerIP,m_ServerPort); #if DEBUG if (m_DownloadState==Protocol.DownloadState.WaitCallBack) { #if VERBOSE CKernel.LogClient.AddLog("ProcessHello-Responsed callback",m_ID); #endif m_UserName="******"+m_UserName; } #endif if (response) { m_OnConnetionReady(); } return helloPacket.ExtendedInfoComplete; }
/// <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(); } 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; }