virtual EModRet OnUserCTCP(CString& sTarget, CString& sMessage) { if (sMessage.Equals("DCC ", false, 4)) { CString sType = sMessage.Token(1); CString sFile = sMessage.Token(2); unsigned long uLongIP = sMessage.Token(3).ToULong(); unsigned short uPort = sMessage.Token(4).ToUShort(); unsigned long uFileSize = sMessage.Token(5).ToULong(); CString sIP = GetLocalDCCIP(); if (!UseClientIP()) { uLongIP = CUtils::GetLongIP(m_pClient->GetRemoteIP()); } if (sType.Equals("CHAT")) { unsigned short uBNCPort = CDCCBounce::DCCRequest(sTarget, uLongIP, uPort, "", true, this, ""); if (uBNCPort) { PutIRC("PRIVMSG " + sTarget + " :\001DCC CHAT chat " + CString(CUtils::GetLongIP(sIP)) + " " + CString(uBNCPort) + "\001"); } } else if (sType.Equals("SEND")) { // DCC SEND readme.txt 403120438 5550 1104 unsigned short uBNCPort = CDCCBounce::DCCRequest(sTarget, uLongIP, uPort, sFile, false, this, ""); if (uBNCPort) { PutIRC("PRIVMSG " + sTarget + " :\001DCC SEND " + sFile + " " + CString(CUtils::GetLongIP(sIP)) + " " + CString(uBNCPort) + " " + CString(uFileSize) + "\001"); } } else if (sType.Equals("RESUME")) { // PRIVMSG user :DCC RESUME "znc.o" 58810 151552 unsigned short uResumePort = sMessage.Token(3).ToUShort(); set<CSocket*>::const_iterator it; for (it = BeginSockets(); it != EndSockets(); ++it) { CDCCBounce* pSock = (CDCCBounce*) *it; if (pSock->GetLocalPort() == uResumePort) { PutIRC("PRIVMSG " + sTarget + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetUserPort()) + " " + sMessage.Token(4) + "\001"); } } } else if (sType.Equals("ACCEPT")) { // Need to lookup the connection by port, filter the port, and forward to the user set<CSocket*>::const_iterator it; for (it = BeginSockets(); it != EndSockets(); ++it) { CDCCBounce* pSock = (CDCCBounce*) *it; if (pSock->GetUserPort() == sMessage.Token(3).ToUShort()) { PutIRC("PRIVMSG " + sTarget + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetLocalPort()) + " " + sMessage.Token(4) + "\001"); } } } return HALTCORE; } return CONTINUE; }
virtual EModRet OnPrivCTCP(CNick& Nick, CString& sMessage) { if (sMessage.Equals("DCC ", false, 4) && m_pUser->IsUserAttached()) { // DCC CHAT chat 2453612361 44592 CString sType = sMessage.Token(1); CString sFile = sMessage.Token(2); unsigned long uLongIP = sMessage.Token(3).ToULong(); unsigned short uPort = sMessage.Token(4).ToUShort(); unsigned long uFileSize = sMessage.Token(5).ToULong(); if (sType.Equals("CHAT")) { CNick FromNick(Nick.GetNickMask()); unsigned short uBNCPort = CDCCBounce::DCCRequest(FromNick.GetNick(), uLongIP, uPort, "", true, this, CUtils::GetIP(uLongIP)); if (uBNCPort) { CString sIP = GetLocalDCCIP(); m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + m_pUser->GetNick() + " :\001DCC CHAT chat " + CString(CUtils::GetLongIP(sIP)) + " " + CString(uBNCPort) + "\001"); } } else if (sType.Equals("SEND")) { // DCC SEND readme.txt 403120438 5550 1104 unsigned short uBNCPort = CDCCBounce::DCCRequest(Nick.GetNick(), uLongIP, uPort, sFile, false, this, CUtils::GetIP(uLongIP)); if (uBNCPort) { CString sIP = GetLocalDCCIP(); m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + m_pUser->GetNick() + " :\001DCC SEND " + sFile + " " + CString(CUtils::GetLongIP(sIP)) + " " + CString(uBNCPort) + " " + CString(uFileSize) + "\001"); } } else if (sType.Equals("RESUME")) { // Need to lookup the connection by port, filter the port, and forward to the user unsigned short uResumePort = sMessage.Token(3).ToUShort(); set<CSocket*>::const_iterator it; for (it = BeginSockets(); it != EndSockets(); ++it) { CDCCBounce* pSock = (CDCCBounce*) *it; if (pSock->GetLocalPort() == uResumePort) { m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + m_pClient->GetNick() + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetUserPort()) + " " + sMessage.Token(4) + "\001"); } } } else if (sType.Equals("ACCEPT")) { // Need to lookup the connection by port, filter the port, and forward to the user set<CSocket*>::const_iterator it; for (it = BeginSockets(); it != EndSockets(); ++it) { CDCCBounce* pSock = (CDCCBounce*) *it; if (pSock->GetUserPort() == sMessage.Token(3).ToUShort()) { m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + m_pClient->GetNick() + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetLocalPort()) + " " + sMessage.Token(4) + "\001"); } } } return HALTCORE; } return CONTINUE; }
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); } }
void ListDCCsCommand(const CString& sLine) { CTable Table; Table.AddColumn("Type"); Table.AddColumn("State"); Table.AddColumn("Speed"); Table.AddColumn("Nick"); Table.AddColumn("IP"); Table.AddColumn("File"); set<CSocket*>::const_iterator it; for (it = BeginSockets(); it != EndSockets(); ++it) { CDCCBounce* pSock = (CDCCBounce*) *it; CString sSockName = pSock->GetSockName(); if (!(pSock->IsRemote())) { Table.AddRow(); Table.SetCell("Nick", pSock->GetRemoteNick()); Table.SetCell("IP", pSock->GetRemoteIP()); if (pSock->IsChat()) { Table.SetCell("Type", "Chat"); } else { Table.SetCell("Type", "Xfer"); Table.SetCell("File", pSock->GetFileName()); } CString sState = "Waiting"; if ((pSock->IsConnected()) || (pSock->IsPeerConnected())) { sState = "Halfway"; if ((pSock->IsPeerConnected()) && (pSock->IsPeerConnected())) { sState = "Connected"; } } Table.SetCell("State", sState); } } if (PutModule(Table) == 0) { PutModule("You have no active DCCs."); } }
void ListTransfersCommand(const CString& sLine) { CTable Table; Table.AddColumn("Type"); Table.AddColumn("State"); Table.AddColumn("Speed"); Table.AddColumn("Nick"); Table.AddColumn("IP"); Table.AddColumn("File"); set<CSocket*>::const_iterator it; for (it = BeginSockets(); it != EndSockets(); ++it) { CDCCSock* pSock = (CDCCSock*) *it; Table.AddRow(); Table.SetCell("Nick", pSock->GetRemoteNick()); Table.SetCell("IP", pSock->GetRemoteIP()); Table.SetCell("File", pSock->GetFileName()); if (pSock->IsSend()) { Table.SetCell("Type", "Sending"); } else { Table.SetCell("Type", "Getting"); } if (pSock->GetType() == Csock::LISTENER) { Table.SetCell("State", "Waiting"); } else { Table.SetCell("State", CString::ToPercent(pSock->GetProgress())); Table.SetCell("Speed", CString((int)(pSock->GetAvgRead() / 1024.0)) + " KiB/s"); } } if (PutModule(Table) == 0) { PutModule("You have no active DCC transfers."); } }