Skip to content

Commit

Permalink
Migrate dcc bouncing to its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Jun 1, 2011
1 parent 0b360c0 commit 8f508cb
Show file tree
Hide file tree
Showing 13 changed files with 482 additions and 529 deletions.
97 changes: 6 additions & 91 deletions Client.cpp
Expand Up @@ -8,7 +8,6 @@

#include "Client.h"
#include "Chan.h"
#include "DCCBounce.h"
#include "FileUtils.h"
#include "IRCSock.h"
#include "User.h"
Expand Down Expand Up @@ -315,14 +314,6 @@ void CClient::ReadLine(const CString& sData) {
return;
}

// No idea what this is supposed to do, but it doesn't seem to
// make sense. Comment this out and wait for complaints.
#if 0
if (sMsg.WildCmp("DCC * (*)")) {
sMsg = "DCC " + sLine.Token(3) + " (" + ((GetIRCSock()) ? GetIRCSock()->GetLocalIP() : GetLocalIP()) + ")";
}
#endif

if (sMsg.WildCmp("\001*\001")) {
CString sCTCP = sMsg;
sCTCP.LeftChomp();
Expand Down Expand Up @@ -377,95 +368,19 @@ void CClient::ReadLine(const CString& sData) {
sCTCP.LeftChomp();
sCTCP.RightChomp();

if (sCTCP.Equals("DCC ", false, 4) && m_pUser->BounceDCCs()) {
CString sType = sCTCP.Token(1);
CString sFile = sCTCP.Token(2);
unsigned long uLongIP = sCTCP.Token(3).ToULong();
unsigned short uPort = sCTCP.Token(4).ToUShort();
unsigned long uFileSize = sCTCP.Token(5).ToULong();
CString sIP = m_pUser->GetLocalDCCIP();

if (!m_pUser->UseClientIP()) {
uLongIP = CUtils::GetLongIP(GetRemoteIP());
}

if (sType.Equals("CHAT")) {
if (!sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) {
unsigned short uBNCPort = CDCCBounce::DCCRequest(sTarget, uLongIP, uPort, "", true, m_pUser, "");
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

if (sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) {
if (sTarget.Equals("status")) {
CString sPath = m_pUser->GetDLPath();
if (!CFile::Exists(sPath)) {
PutStatus("Could not create [" + sPath + "] directory.");
return;
} else if (!CFile::IsDir(sPath)) {
PutStatus("Error: [" + sPath + "] is not a directory.");
return;
}

CString sAbsolutePath = CDir::CheckPathPrefix(sPath, sFile);

if (sAbsolutePath.empty()) {
PutStatus("Illegal path.");
return;
}

m_pUser->GetFile(GetNick(), CUtils::GetIP(uLongIP), uPort, sAbsolutePath, uFileSize);
}
} else {
unsigned short uBNCPort = CDCCBounce::DCCRequest(sTarget, uLongIP, uPort, sFile, false, m_pUser, "");
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
if (sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) {
if (sCTCP.Equals("DCC RESUME ", false, 11)) {
CString sFile = sCTCP.Token(2);
unsigned short uResumePort = sCTCP.Token(3).ToUShort();
unsigned long uResumeSize = sCTCP.Token(4).ToULong();

// Need to lookup the connection by port, filter the port, and forward to the user
CString sStatusPrefix = m_pUser->GetStatusPrefix();
if (sTarget.Equals(sStatusPrefix, false, sStatusPrefix.length())) {
if (m_pUser->ResumeFile(uResumePort, uResumeSize)) {
PutClient(":" + sTarget + "!znc@znc.in PRIVMSG " + GetNick() + " :\001DCC ACCEPT " + sFile + " " + CString(uResumePort) + " " + CString(uResumeSize) + "\001");
} else {
PutStatus("DCC -> [" + GetNick() + "][" + sFile + "] Unable to find send to initiate resume.");
}
if (m_pUser->ResumeFile(uResumePort, uResumeSize)) {
PutClient(":" + sTarget + "!znc@znc.in PRIVMSG " + GetNick() + " :\001DCC ACCEPT " + sFile + " " + CString(uResumePort) + " " + CString(uResumeSize) + "\001");
} else {
CDCCBounce* pSock = (CDCCBounce*) CZNC::Get().GetManager().FindSockByLocalPort(uResumePort);
if (pSock && pSock->GetSockName().Equals("DCC::", false, 5)) {
PutIRC("PRIVMSG " + sTarget + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetUserPort()) + " " + sCTCP.Token(4) + "\001");
}
}
} else if (sType.Equals("ACCEPT")) {
CString sStatusPrefix = m_pUser->GetStatusPrefix();
if (!sTarget.Equals(sStatusPrefix, false, sStatusPrefix.length())) {
// Need to lookup the connection by port, filter the port, and forward to the user
CSockManager& Manager = CZNC::Get().GetManager();

for (unsigned int a = 0; a < Manager.size(); a++) {
CDCCBounce* pSock = (CDCCBounce*) Manager[a];

if (pSock && pSock->GetSockName().Equals("DCC::", false, 5)) {
if (pSock->GetUserPort() == sCTCP.Token(3).ToUShort()) {
PutIRC("PRIVMSG " + sTarget + " :\001DCC " + sType + " " + sFile + " " + CString(pSock->GetLocalPort()) + " " + sCTCP.Token(4) + "\001");
}
}
}
PutStatus("DCC -> [" + GetNick() + "][" + sFile + "] Unable to find send to initiate resume.");
}
}

return;
}

if (sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) {
if (sTarget.Equals("status")) {
StatusCTCP(sCTCP);
} else {
Expand Down
42 changes: 0 additions & 42 deletions ClientCommand.cpp
Expand Up @@ -8,7 +8,6 @@

#include "Client.h"
#include "Chan.h"
#include "DCCBounce.h"
#include "DCCSock.h"
#include "FileUtils.h"
#include "IRCSock.h"
Expand Down Expand Up @@ -522,14 +521,6 @@ void CClient::UserCommand(CString& sLine) {
CString sSockName = Manager[a]->GetSockName();

if (sSockName.TrimPrefix("DCC::")) {
if (sSockName.Equals("XFER::REMOTE::", false, 14)) {
continue;
}

if (sSockName.Equals("CHAT::REMOTE::", false, 14)) {
continue;
}

if (sSockName.Equals("SEND", false, 4)) {
CDCCSock* pSock = (CDCCSock*) Manager[a];

Expand Down Expand Up @@ -559,39 +550,6 @@ void CClient::UserCommand(CString& sLine) {
Table.SetCell("Nick", pSock->GetRemoteNick());
Table.SetCell("IP", pSock->GetRemoteIP());
Table.SetCell("File", pSock->GetFileName());
} else if (sSockName.Equals("XFER::LOCAL", false, 11)) {
CDCCBounce* pSock = (CDCCBounce*) Manager[a];

CString sState = "Waiting";
if ((pSock->IsConnected()) || (pSock->IsPeerConnected())) {
sState = "Halfway";
if ((pSock->IsPeerConnected()) && (pSock->IsPeerConnected())) {
sState = "Connected";
}
}

Table.AddRow();
Table.SetCell("Type", "Xfer");
Table.SetCell("State", sState);
Table.SetCell("Nick", pSock->GetRemoteNick());
Table.SetCell("IP", pSock->GetRemoteIP());
Table.SetCell("File", pSock->GetFileName());
} else if (sSockName.Equals("CHAT::LOCAL", false, 11)) {
CDCCBounce* pSock = (CDCCBounce*) Manager[a];

CString sState = "Waiting";
if ((pSock->IsConnected()) || (pSock->IsPeerConnected())) {
sState = "Halfway";
if ((pSock->IsPeerConnected()) && (pSock->IsPeerConnected())) {
sState = "Connected";
}
}

Table.AddRow();
Table.SetCell("Type", "Chat");
Table.SetCell("State", sState);
Table.SetCell("Nick", pSock->GetRemoteNick());
Table.SetCell("IP", pSock->GetRemoteIP());
}
}
}
Expand Down

0 comments on commit 8f508cb

Please sign in to comment.