bool SendFile(const CString& sRemoteNick, const CString& sFileName) { CString sFullPath = CDir::ChangeDir(GetSavePath(), sFileName, CZNC::Get().GetHomePath()); CDCCSock* pSock = new CDCCSock(this, sRemoteNick, sFullPath); CFile* pFile = pSock->OpenFile(false); if (!pFile) { delete pSock; return false; } CString sLocalDCCIP = GetUser()->GetLocalDCCIP(); unsigned short uPort = CZNC::Get().GetManager().ListenRand( "DCC::LISTEN::" + sRemoteNick, sLocalDCCIP, false, SOMAXCONN, pSock, 120); if (GetUser()->GetNick().Equals(sRemoteNick)) { PutUser(":*[email protected] PRIVMSG " + sRemoteNick + " :\001DCC SEND " + pFile->GetShortName() + " " + CString(CUtils::GetLongIP(sLocalDCCIP)) + " " + CString(uPort) + " " + CString(pFile->GetSize()) + "\001"); } else { PutIRC("PRIVMSG " + sRemoteNick + " :\001DCC SEND " + pFile->GetShortName() + " " + CString(CUtils::GetLongIP(sLocalDCCIP)) + " " + CString(uPort) + " " + CString(pFile->GetSize()) + "\001"); } PutModule(t_f("Attempting to send [{1}] to [{2}].")( pFile->GetShortName(), sRemoteNick)); return true; }
bool GetFile(const CString& sRemoteNick, const CString& sRemoteIP, unsigned short uRemotePort, const CString& sFileName, unsigned long uFileSize) { if (CFile::Exists(sFileName)) { PutModule(t_f("Receiving [{1}] from [{2}]: File already exists.")( sFileName, sRemoteNick)); return false; } CDCCSock* pSock = new CDCCSock(this, sRemoteNick, sRemoteIP, uRemotePort, sFileName, uFileSize); if (!pSock->OpenFile()) { delete pSock; return false; } CZNC::Get().GetManager().Connect(sRemoteIP, uRemotePort, "DCC::GET::" + sRemoteNick, 60, false, GetUser()->GetLocalDCCIP(), pSock); PutModule( t_f("Attempting to connect to [{1} {2}] in order to download [{3}] " "from [{4}].")(sRemoteIP, uRemotePort, sFileName, sRemoteNick)); return true; }
virtual void OnModCTCP(const CString& sMessage) { if (sMessage.Equals("DCC RESUME ", false, 11)) { CString sFile = sMessage.Token(2); unsigned short uResumePort = sMessage.Token(3).ToUShort(); unsigned long uResumeSize = sMessage.Token(4).ToULong(); set<CSocket*>::const_iterator it; for (it = BeginSockets(); it != EndSockets(); ++it) { CDCCSock* pSock = (CDCCSock*) *it; if (pSock->GetLocalPort() == uResumePort) { if (pSock->Seek(uResumeSize)) { PutModule("DCC -> [" + pSock->GetRemoteNick() + "][" + pSock->GetFileName() + "] - Attempting to resume from file position [" + CString(uResumeSize) + "]"); PutUser(":*[email protected] PRIVMSG " + m_pUser->GetNick() + " :\001DCC ACCEPT " + sFile + " " + CString(uResumePort) + " " + CString(uResumeSize) + "\001"); } else { PutModule("DCC -> [" + m_pUser->GetNick() + "][" + sFile + "] Unable to find send to initiate resume."); } } } } else if (sMessage.Equals("DCC SEND ", false, 9)) { CString sLocalFile = CDir::CheckPathPrefix(GetSavePath(), sMessage.Token(2)); if (sLocalFile.empty()) { PutModule("Bad DCC file: " + sMessage.Token(2)); } unsigned long uLongIP = sMessage.Token(3).ToULong(); unsigned short uPort = sMessage.Token(4).ToUShort(); unsigned long uFileSize = sMessage.Token(5).ToULong(); GetFile(m_pUser->GetCurNick(), CUtils::GetIP(uLongIP), uPort, sLocalFile, uFileSize); } }
Csock* CDCCSock::GetSockObj(const CString& sHost, unsigned short uPort) { Close(); CDCCSock* pSock = new CDCCSock(m_pModule, m_sRemoteNick, m_sLocalFile, m_uFileSize, m_pFile); pSock->SetSockName("DCC::SEND::" + m_sRemoteNick); pSock->SetTimeout(120); pSock->SetFileName(m_sFileName); pSock->SetFileOffset(m_uBytesSoFar); m_bNoDelFile = true; return pSock; }
bool GetFile(const CString& sRemoteNick, const CString& sRemoteIP, unsigned short uRemotePort, const CString& sFileName, unsigned long uFileSize) { if (CFile::Exists(sFileName)) { PutModule("DCC <- [" + sRemoteNick + "][" + sFileName + "] - File already exists."); return false; } CDCCSock* pSock = new CDCCSock(this, sRemoteNick, sRemoteIP, uRemotePort, sFileName, uFileSize); if (!pSock->OpenFile()) { delete pSock; return false; } CZNC::Get().GetManager().Connect(sRemoteIP, uRemotePort, "DCC::GET::" + sRemoteNick, 60, false, m_pUser->GetLocalDCCIP(), pSock); PutModule("DCC <- [" + sRemoteNick + "][" + sFileName + "] - Attempting to connect to [" + sRemoteIP + "]"); return true; }
void OnModCTCP(const CString& sMessage) override { if (sMessage.StartsWith("DCC RESUME ")) { CString sFile = sMessage.Token(2); unsigned short uResumePort = sMessage.Token(3).ToUShort(); unsigned long uResumeSize = sMessage.Token(4).ToULong(); set<CSocket*>::const_iterator it; for (it = BeginSockets(); it != EndSockets(); ++it) { CDCCSock* pSock = (CDCCSock*)*it; if (pSock->GetLocalPort() == uResumePort) { if (pSock->Seek(uResumeSize)) { PutModule( t_f("Attempting to resume send from position {1} " "of file [{2}] for [{3}]")( uResumeSize, pSock->GetFileName(), pSock->GetRemoteNick())); PutUser(":*[email protected] PRIVMSG " + GetUser()->GetNick() + " :\001DCC ACCEPT " + sFile + " " + CString(uResumePort) + " " + CString(uResumeSize) + "\001"); } else { PutModule(t_f( "Couldn't resume file [{1}] for [{2}]: not sending " "anything.")(sFile, GetUser()->GetNick())); } } } } else if (sMessage.StartsWith("DCC SEND ")) { CString sLocalFile = CDir::CheckPathPrefix(GetSavePath(), sMessage.Token(2)); if (sLocalFile.empty()) { PutModule(t_f("Bad DCC file: {1}")(sMessage.Token(2))); } unsigned long uLongIP = sMessage.Token(3).ToULong(); unsigned short uPort = sMessage.Token(4).ToUShort(); unsigned long uFileSize = sMessage.Token(5).ToULong(); GetFile(GetClient()->GetNick(), CUtils::GetIP(uLongIP), uPort, sLocalFile, uFileSize); } }
bool CUser::SendFile(const CString& sRemoteNick, const CString& sFileName, const CString& sModuleName) { CString sFullPath = CDir::ChangeDir(GetDLPath(), sFileName, CZNC::Get().GetHomePath()); CDCCSock* pSock = new CDCCSock(this, sRemoteNick, sFullPath, sModuleName); CFile* pFile = pSock->OpenFile(false); if (!pFile) { delete pSock; return false; } unsigned short uPort = CZNC::Get().GetManager().ListenRand("DCC::LISTEN::" + sRemoteNick, GetLocalDCCIP(), false, SOMAXCONN, pSock, 120); if (GetNick().Equals(sRemoteNick)) { PutUser(":" + GetStatusPrefix() + "[email protected] PRIVMSG " + sRemoteNick + " :\001DCC SEND " + pFile->GetShortName() + " " + CString(CUtils::GetLongIP(GetLocalDCCIP())) + " " + CString(uPort) + " " + CString(pFile->GetSize()) + "\001"); } else { PutIRC("PRIVMSG " + sRemoteNick + " :\001DCC SEND " + pFile->GetShortName() + " " + CString(CUtils::GetLongIP(GetLocalDCCIP())) + " " + CString(uPort) + " " + CString(pFile->GetSize()) + "\001"); } PutModule(sModuleName, "DCC -> [" + sRemoteNick + "][" + pFile->GetShortName() + "] - Attempting Send."); return true; }
void ListTransfersCommand(const CString& sLine) { CTable Table; Table.AddColumn(t_s("Type", "list")); Table.AddColumn(t_s("State", "list")); Table.AddColumn(t_s("Speed", "list")); Table.AddColumn(t_s("Nick", "list")); Table.AddColumn(t_s("IP", "list")); Table.AddColumn(t_s("File", "list")); set<CSocket*>::const_iterator it; for (it = BeginSockets(); it != EndSockets(); ++it) { CDCCSock* pSock = (CDCCSock*)*it; Table.AddRow(); Table.SetCell(t_s("Nick", "list"), pSock->GetRemoteNick()); Table.SetCell(t_s("IP", "list"), pSock->GetRemoteIP()); Table.SetCell(t_s("File", "list"), pSock->GetFileName()); if (pSock->IsSend()) { Table.SetCell(t_s("Type", "list"), t_s("Sending", "list-type")); } else { Table.SetCell(t_s("Type", "list"), t_s("Getting", "list-type")); } if (pSock->GetType() == Csock::LISTENER) { Table.SetCell(t_s("State", "list"), t_s("Waiting", "list-state")); } else { Table.SetCell(t_s("State", "list"), CString::ToPercent(pSock->GetProgress())); Table.SetCell(t_s("Speed", "list"), t_f("{1} KiB/s")(static_cast<int>( pSock->GetAvgRead() / 1024.0))); } } if (PutModule(Table) == 0) { PutModule(t_s("You have no active DCC transfers.")); } }
bool CUser::ResumeFile(unsigned short uPort, unsigned long uFileSize) { CSockManager& Manager = CZNC::Get().GetManager(); for (unsigned int a = 0; a < Manager.size(); a++) { if (Manager[a]->GetSockName().Equals("DCC::LISTEN::", false, 13)) { CDCCSock* pSock = (CDCCSock*) Manager[a]; if (pSock->GetLocalPort() == uPort) { if (pSock->Seek(uFileSize)) { PutModule(pSock->GetModuleName(), "DCC -> [" + pSock->GetRemoteNick() + "][" + pSock->GetFileName() + "] - Attempting to resume from file position [" + CString(uFileSize) + "]"); return true; } else { return false; } } } } return false; }