Move the forwarding of raw 353 into an own function

This also contains some minor changes to the code. One of those is that we now
also handle namesx and uhnames for channels we don't know.
BTW: CIRCSock::ReadLine() is waaay too long.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1148 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2008-07-24 10:22:17 +00:00
parent 3106f3b90e
commit cd2fb1b1b5
2 changed files with 59 additions and 55 deletions

View File

@@ -328,62 +328,20 @@ void CIRCSock::ReadLine(const CString& sData) {
sRest.Trim();
// Todo: allow for non @+= server msgs
CChan* pChan = m_pUser->FindChan(sRest.Token(1));
if (!pChan) {
// If we don't know that channel, a client might have
// sent a /names on it's own -> forward it.
m_pUser->PutUser(sLine);
return;
}
CString sNicks = sRest.Token(2, true);
if (sNicks.Left(1) == ":") {
sNicks.LeftChomp();
}
pChan->AddNicks(sNicks);
// Get everything except the actual user list
CString sTmp = sLine.Token(0, false, " :") + " :";
vector<CClient*>& vClients = m_pUser->GetClients();
for (unsigned int a = 0; a < vClients.size(); a++) {
if ((!m_bNamesx || vClients[a]->HasNamesx())
&& (!m_bUHNames || vClients[a]->HasUHNames())) {
m_pUser->PutUser(sLine, vClients[a]);
} else {
unsigned int i = 0;
// This loop runs once for
// every nick on the channel
for (;;) {
sNick = sNicks.Token(i).Trim_n(" ");
if (sNick.empty())
break;
if (m_bNamesx && !vClients[a]->HasNamesx()
&& IsPermChar(sNick[0])) {
// Server has, client hasnt NAMESX,
// so we just use the first perm char
while (sNick.length() > 2
&& IsPermChar(sNick[1])) {
sNick = sNick[0] + sNick.substr(2);
}
}
// Server has, client hasnt UHNAMES,
// so we strip away ident and host.
if (m_bUHNames && !vClients[a]->HasUHNames()) {
sNick = sNick.Token(0, false, "!");
}
sTmp += sNick + " ";
i++;
}
// Strip away the spaces we inserted at the end
sTmp.Trim(" ");
m_pUser->PutUser(sTmp, vClients[a]);
// If we don't know that channel, some client might have
// requested a /names for it and we really should forward this.
if (pChan) {
CString sNicks = sRest.Token(2, true);
if (sNicks.Left(1) == ":") {
sNicks.LeftChomp();
}
pChan->AddNicks(sNicks);
}
// We forwarded it in the for loop above already
ForwardRaw353(sLine);
// We forwarded it already, so return
return;
}
case 366: { // end of names list
@@ -1036,6 +994,51 @@ void CIRCSock::ParseISupport(const CString& sLine) {
}
}
void CIRCSock::ForwardRaw353(const CString& sLine) const {
vector<CClient*>& vClients = m_pUser->GetClients();
CString sNicks = sLine.Token(5, true);
if (sNicks.Left(1) == ":")
sNicks.LeftChomp();
for (unsigned int a = 0; a < vClients.size(); a++) {
if ((!m_bNamesx || vClients[a]->HasNamesx()) && (!m_bUHNames || vClients[a]->HasUHNames())) {
// Client and server have both the same UHNames and Namesx stuff enabled
m_pUser->PutUser(sLine, vClients[a]);
} else {
// Get everything except the actual user list
CString sTmp = sLine.Token(0, false, " :") + " :";
unsigned int i = 0;
// This loop runs once for every nick on the channel
for (;;) {
CString sNick = sNicks.Token(i).Trim_n(" ");
if (sNick.empty())
break;
if (m_bNamesx && !vClients[a]->HasNamesx() && IsPermChar(sNick[0])) {
// Server has, client doesn't have NAMESX, so we just use the first perm char
size_t pos = sNick.find_first_not_of(GetPerms());
if (pos >= 2 && pos != CString::npos) {
sNick = sNick[0] + sNick.substr(pos);
}
}
if (m_bUHNames && !vClients[a]->HasUHNames()) {
// Server has, client hasnt UHNAMES,
// so we strip away ident and host.
sNick = sNick.Token(0, false, "!");
}
sTmp += sNick + " ";
i++;
}
// Strip away the spaces we inserted at the end
sTmp.TrimRight(" ");
m_pUser->PutUser(sTmp, vClients[a]);
}
}
}
unsigned char CIRCSock::GetPermFromMode(unsigned char uMode) const {
if (m_sPermModes.size() == m_sPerms.size()) {
for (unsigned int a = 0; a < m_sPermModes.size(); a++) {

View File

@@ -49,7 +49,6 @@ public:
void KeepNick(bool bForce = false);
void PutIRC(const CString& sLine);
void ParseISupport(const CString& sLine);
void ResetChans();
void Quit();
@@ -82,6 +81,8 @@ public:
// !Getters
private:
void SetNick(const CString& sNick);
void ParseISupport(const CString& sLine);
void ForwardRaw353(const CString& sLine) const;
protected:
bool m_bISpoofReleased;
bool m_bAuthed;