Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: znc/znc
base: 4d4e6a6
...
head fork: znc/znc
compare: 4b1e714
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 22, 2011
@kylef kylef Clean up CClient::ReadLine 523deaf
@kylef kylef Set default TrimPrefix to ":"
Use TrimPrefix instead of if prefix then chomp, saving quite a lot of
duplicated code
4b1e714
Showing with 37 additions and 100 deletions.
  1. +20 −50 Client.cpp
  2. +15 −48 IRCSock.cpp
  3. +2 −2 ZNCString.h
View
70 Client.cpp
@@ -90,14 +90,11 @@ void CClient::ReadLine(const CString& sData) {
sCommand = sLine.Token(0);
}
- if (sCommand.Equals("PASS")) {
- if (!IsAttached()) {
+ if (!IsAttached()) { // The following commands happen before authentication with ZNC
+ if (sCommand.Equals("PASS")) {
m_bGotPass = true;
- CString sAuthLine = sLine.Token(1, true);
- if (sAuthLine.Left(1) == ":") {
- sAuthLine.LeftChomp();
- }
+ CString sAuthLine = sLine.Token(1, true).TrimPrefix_n();
// [user[/network]:]password
if (sAuthLine.find(":") == CString::npos) {
@@ -115,22 +112,15 @@ void CClient::ReadLine(const CString& sData) {
AuthUser();
return; // Don't forward this msg. ZNC has already registered us.
- }
- } else if (sCommand.Equals("NICK")) {
- CString sNick = sLine.Token(1);
- if (sNick.Left(1) == ":") {
- sNick.LeftChomp();
- }
+ } else if (sCommand.Equals("NICK")) {
+ CString sNick = sLine.Token(1).TrimPrefix_n();
- if (!IsAttached()) {
m_sNick = sNick;
m_bGotNick = true;
AuthUser();
return; // Don't forward this msg. ZNC will handle nick changes until auth is complete
- }
- } else if (sCommand.Equals("USER")) {
- if (!IsAttached()) {
+ } else if (sCommand.Equals("USER")) {
// user[/network]
CString sAuthLine = sLine.Token(1);
@@ -150,7 +140,9 @@ void CClient::ReadLine(const CString& sData) {
return; // Don't forward this msg. ZNC has already registered us.
}
- } else if (sCommand.Equals("CAP")) {
+ }
+
+ if (sCommand.Equals("CAP")) {
HandleCap(sLine);
// Don't let the client talk to the server directly about CAP,
@@ -215,11 +207,7 @@ void CClient::ReadLine(const CString& sData) {
return; // If the server understands it, we already enabled namesx / uhnames
} else if (sCommand.Equals("NOTICE")) {
CString sTarget = sLine.Token(1);
- CString sMsg = sLine.Token(2, true);
-
- if (sMsg.Left(1) == ":") {
- sMsg.LeftChomp();
- }
+ CString sMsg = sLine.Token(2, true).TrimPrefix_n();
if (sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) {
if (!sTarget.Equals("status")) {
@@ -273,11 +261,7 @@ void CClient::ReadLine(const CString& sData) {
}
} else if (sCommand.Equals("PRIVMSG")) {
CString sTarget = sLine.Token(1);
- CString sMsg = sLine.Token(2, true);
-
- if (sMsg.Left(1) == ":") {
- sMsg.LeftChomp();
- }
+ CString sMsg = sLine.Token(2, true).TrimPrefix_n();
if (sMsg.WildCmp("\001*\001")) {
CString sCTCP = sMsg;
@@ -397,13 +381,9 @@ void CClient::ReadLine(const CString& sData) {
PutStatusNotice("Detached from [" + sChan + "]");
return;
} else if (sCommand.Equals("JOIN")) {
- CString sChans = sLine.Token(1);
+ CString sChans = sLine.Token(1).TrimPrefix_n();
CString sKey = sLine.Token(2);
- if (sChans.Left(1) == ":") {
- sChans.LeftChomp();
- }
-
VCString vChans;
sChans.Split(",", vChans, false);
sChans.clear();
@@ -433,16 +413,8 @@ void CClient::ReadLine(const CString& sData) {
sLine += " " + sKey;
}
} else if (sCommand.Equals("PART")) {
- CString sChan = sLine.Token(1);
- CString sMessage = sLine.Token(2, true);
-
- if (sChan.Left(1) == ":") {
- // I hate those broken clients, I hate them so much, I really hate them...
- sChan.LeftChomp();
- }
- if (sMessage.Left(1) == ":") {
- sMessage.LeftChomp();
- }
+ CString sChan = sLine.Token(1).TrimPrefix_n();
+ CString sMessage = sLine.Token(2, true).TrimPrefix_n();
NETWORKMODULECALL(OnUserPart(sChan, sMessage), m_pUser, m_pNetwork, this, return);
@@ -461,27 +433,25 @@ void CClient::ReadLine(const CString& sData) {
}
} else if (sCommand.Equals("TOPIC")) {
CString sChan = sLine.Token(1);
- CString sTopic = sLine.Token(2, true);
+ CString sTopic = sLine.Token(2, true).TrimPrefix_n();
if (!sTopic.empty()) {
- if (sTopic.Left(1) == ":")
- sTopic.LeftChomp();
NETWORKMODULECALL(OnUserTopic(sChan, sTopic), m_pUser, m_pNetwork, this, return);
sLine = "TOPIC " + sChan + " :" + sTopic;
} else {
NETWORKMODULECALL(OnUserTopicRequest(sChan), m_pUser, m_pNetwork, this, return);
}
- } else if (m_pNetwork && sCommand.Equals("MODE")) {
+ } else if (sCommand.Equals("MODE")) {
CString sTarget = sLine.Token(1);
CString sModes = sLine.Token(2, true);
- if (m_pNetwork->IsChan(sTarget)) {
- CChan *pChan = m_pNetwork->FindChan(sTarget);
-
+ if (m_pNetwork->IsChan(sTarget) && sModes.empty()) {
// If we are on that channel and already received a
// /mode reply from the server, we can answer this
// request ourself.
- if (pChan && pChan->IsOn() && sModes.empty() && !pChan->GetModeString().empty()) {
+
+ CChan *pChan = m_pNetwork->FindChan(sTarget);
+ if (pChan && pChan->IsOn() && !pChan->GetModeString().empty()) {
PutClient(":" + m_pNetwork->GetIRCServer() + " 324 " + GetNick() + " " + sTarget + " " + pChan->GetModeString());
if (pChan->GetCreationDate() > 0) {
PutClient(":" + m_pNetwork->GetIRCServer() + " 329 " + GetNick() + " " + sTarget + " " + CString(pChan->GetCreationDate()));
View
63 IRCSock.cpp
@@ -105,11 +105,7 @@ void CIRCSock::ReadLine(const CString& sData) {
} else if (sLine.Equals("ERROR ", false, 6)) {
//ERROR :Closing Link: nick[24.24.24.24] (Excess Flood)
CString sError(sLine.substr(6));
-
- if (sError.Left(1) == ":") {
- sError.LeftChomp();
- }
-
+ sError.TrimPrefix();
m_pNetwork->PutStatus("Error from Server [" + sError + "]");
return;
}
@@ -117,7 +113,7 @@ void CIRCSock::ReadLine(const CString& sData) {
CString sCmd = sLine.Token(1);
if ((sCmd.length() == 3) && (isdigit(sCmd[0])) && (isdigit(sCmd[1])) && (isdigit(sCmd[2]))) {
- CString sServer = sLine.Token(0); sServer.LeftChomp();
+ CString sServer = sLine.Token(0).LeftChomp_n();
unsigned int uRaw = sCmd.ToUInt();
CString sNick = sLine.Token(2);
CString sRest = sLine.Token(3, true);
@@ -166,7 +162,7 @@ void CIRCSock::ReadLine(const CString& sData) {
case 10: { // :irc.server.com 010 nick <hostname> <port> :<info>
CString sHost = sRest.Token(0);
CString sPort = sRest.Token(1);
- CString sInfo = sRest.Token(2, true).TrimPrefix_n(":");
+ CString sInfo = sRest.Token(2, true).TrimPrefix_n();
m_pNetwork->PutStatus("Server [" + m_pNetwork->GetCurrentServer()->GetString(false) +
"] redirects us to [" + sHost + ":" + sPort + "] with reason [" + sInfo + "]");
m_pNetwork->PutStatus("Perhaps you want to add it as a new server.");
@@ -278,11 +274,7 @@ void CIRCSock::ReadLine(const CString& sData) {
// 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();
- }
-
+ CString sNicks = sRest.Token(2, true).TrimPrefix_n();
pChan->AddNicks(sNicks);
}
@@ -363,18 +355,14 @@ void CIRCSock::ReadLine(const CString& sData) {
}
}
} else {
- CNick Nick(sLine.Token(0).LeftChomp_n());
+ CNick Nick(sLine.Token(0).TrimPrefix_n());
sCmd = sLine.Token(1);
CString sRest = sLine.Token(2, true);
if (sCmd.Equals("NICK")) {
- CString sNewNick = sRest;
+ CString sNewNick = sRest.TrimPrefix_n();
bool bIsVisible = false;
- if (sNewNick.Left(1) == ":") {
- sNewNick.LeftChomp();
- }
-
vector<CChan*> vFoundChans;
const vector<CChan*>& vChans = m_pNetwork->GetChans();
@@ -403,13 +391,9 @@ void CIRCSock::ReadLine(const CString& sData) {
return;
}
} else if (sCmd.Equals("QUIT")) {
- CString sMessage = sRest;
+ CString sMessage = sRest.TrimPrefix_n();
bool bIsVisible = false;
- if (sMessage.Left(1) == ":") {
- sMessage.LeftChomp();
- }
-
// :nick!ident@host.com QUIT :message
if (Nick.GetNick().Equals(GetNick())) {
@@ -441,11 +425,7 @@ void CIRCSock::ReadLine(const CString& sData) {
return;
}
} else if (sCmd.Equals("JOIN")) {
- CString sChan = sRest.Token(0);
- if (sChan.Left(1) == ":") {
- sChan.LeftChomp();
- }
-
+ CString sChan = sRest.Token(0).TrimPrefix_n();
CChan* pChan;
// Todo: use nick compare function
@@ -470,11 +450,8 @@ void CIRCSock::ReadLine(const CString& sData) {
}
}
} else if (sCmd.Equals("PART")) {
- CString sChan = sRest.Token(0);
- if (sChan.Left(1) == ":") {
- sChan.LeftChomp();
- }
- CString sMsg = sRest.Token(1, true).TrimPrefix_n(":");
+ CString sChan = sRest.Token(0).TrimPrefix_n();
+ CString sMsg = sRest.Token(1, true).TrimPrefix_n();
CChan* pChan = m_pNetwork->FindChan(sChan);
bool bDetached = false;
@@ -621,11 +598,7 @@ void CIRCSock::ReadLine(const CString& sData) {
} else if (sCmd.Equals("PRIVMSG")) {
// :nick!ident@host.com PRIVMSG #chan :Message
CString sTarget = sRest.Token(0);
- CString sMsg = sRest.Token(1, true);
-
- if (sMsg.Left(1) == ":") {
- sMsg.LeftChomp();
- }
+ CString sMsg = sRest.Token(1, true).TrimPrefix_n();
if (sMsg.WildCmp("\001*\001")) {
sMsg.LeftChomp();
@@ -659,11 +632,7 @@ void CIRCSock::ReadLine(const CString& sData) {
}
} else if (sCmd.Equals("WALLOPS")) {
// :blub!dummy@rox-8DBEFE92 WALLOPS :this is a test
- CString sMsg = sRest.Token(0, true);
-
- if (sMsg.Left(1) == ":") {
- sMsg.LeftChomp();
- }
+ CString sMsg = sRest.Token(0, true).TrimPrefix_n();
if (!m_pNetwork->IsUserAttached()) {
m_pNetwork->AddQueryBuffer(":" + Nick.GetNickMask() + " WALLOPS ", ":" + m_pNetwork->GetUser()->AddTimestamp(sMsg), false);
@@ -689,9 +658,9 @@ void CIRCSock::ReadLine(const CString& sData) {
// of this reply.
CString sArgs;
if (sRest.Token(2) == "*") {
- sArgs = sRest.Token(3, true).TrimPrefix_n(":");
+ sArgs = sRest.Token(3, true).TrimPrefix_n();
} else {
- sArgs = sRest.Token(2, true).TrimPrefix_n(":");
+ sArgs = sRest.Token(2, true).TrimPrefix_n();
}
if (sSubCmd == "LS") {
@@ -1074,9 +1043,7 @@ void CIRCSock::ForwardRaw353(const CString& sLine) const {
}
void CIRCSock::ForwardRaw353(const CString& sLine, CClient* pClient) const {
- CString sNicks = sLine.Token(5, true);
- if (sNicks.Left(1) == ":")
- sNicks.LeftChomp();
+ CString sNicks = sLine.Token(5, true).TrimPrefix_n();
if ((!m_bNamesx || pClient->HasNamesx()) && (!m_bUHNames || pClient->HasUHNames())) {
// Client and server have both the same UHNames and Namesx stuff enabled
View
4 ZNCString.h
@@ -413,7 +413,7 @@ class CString : public string {
* @param sPrefix The prefix that should be removed.
* @return True if this string was modified.
*/
- bool TrimPrefix(const CString& sPrefix);
+ bool TrimPrefix(const CString& sPrefix = ":");
/** Trim a given suffix.
* @param sSuffix The suffix that should be removed.
* @return True if this string was modified.
@@ -423,7 +423,7 @@ class CString : public string {
* @param sPrefix The prefix that should be removed.
* @return A copy of this string without the prefix.
*/
- CString TrimPrefix_n(const CString& sPrefix) const;
+ CString TrimPrefix_n(const CString& sPrefix = ":") const;
/** Trim a given suffix.
* @param sSuffix The suffix that should be removed.
* @return A copy of this string without the prefix.

No commit comments for this range

Something went wrong with that request. Please try again.