Add clang-format configuration.

For now, it uses tabs like before, to make the diff easier to read/check.
One of following commits will switch it to spaces.
This commit is contained in:
Alexey Sokolov
2015-12-06 22:36:35 +00:00
parent 02f8749a8b
commit 33b0627d75
132 changed files with 12743 additions and 8904 deletions
+191 -137
View File
@@ -26,7 +26,9 @@ using std::set;
using std::vector;
using std::map;
#define IRCSOCKMODULECALL(macFUNC, macEXITER) NETWORKMODULECALL(macFUNC, m_pNetwork->GetUser(), m_pNetwork, nullptr, macEXITER)
#define IRCSOCKMODULECALL(macFUNC, macEXITER) \
NETWORKMODULECALL(macFUNC, m_pNetwork->GetUser(), m_pNetwork, nullptr, \
macEXITER)
// These are used in OnGeneralCTCP()
const time_t CIRCSock::m_uCTCPFloodTime = 5;
const unsigned int CIRCSock::m_uCTCPFloodCount = 5;
@@ -37,19 +39,20 @@ const unsigned int CIRCSock::m_uCTCPFloodCount = 5;
static const double FLOOD_MINIMAL_RATE = 0.3;
class CIRCFloodTimer : public CCron {
CIRCSock* m_pSock;
public:
CIRCFloodTimer(CIRCSock* pSock) : m_pSock(pSock) {
StartMaxCycles(m_pSock->m_fFloodRate, 0);
}
CIRCFloodTimer(const CIRCFloodTimer&) = delete;
CIRCFloodTimer& operator=(const CIRCFloodTimer&) = delete;
void RunJob() override {
if (m_pSock->m_iSendsAllowed < m_pSock->m_uFloodBurst) {
m_pSock->m_iSendsAllowed++;
}
m_pSock->TrySend();
CIRCSock* m_pSock;
public:
CIRCFloodTimer(CIRCSock* pSock) : m_pSock(pSock) {
StartMaxCycles(m_pSock->m_fFloodRate, 0);
}
CIRCFloodTimer(const CIRCFloodTimer&) = delete;
CIRCFloodTimer& operator=(const CIRCFloodTimer&) = delete;
void RunJob() override {
if (m_pSock->m_iSendsAllowed < m_pSock->m_uFloodBurst) {
m_pSock->m_iSendsAllowed++;
}
m_pSock->TrySend();
}
};
bool CIRCSock::IsFloodProtected(double fRate) {
@@ -57,35 +60,34 @@ bool CIRCSock::IsFloodProtected(double fRate) {
}
CIRCSock::CIRCSock(CIRCNetwork* pNetwork)
: CIRCSocket(),
m_bAuthed(false),
m_bNamesx(false),
m_bUHNames(false),
m_bAwayNotify(false),
m_bAccountNotify(false),
m_bExtendedJoin(false),
m_bServerTime(false),
m_sPerms("*!@%+"),
m_sPermModes("qaohv"),
m_scUserModes(),
m_mueChanModes(),
m_pNetwork(pNetwork),
m_Nick(),
m_sPass(""),
m_msChans(),
m_uMaxNickLen(9),
m_uCapPaused(0),
m_ssAcceptedCaps(),
m_ssPendingCaps(),
m_lastCTCP(0),
m_uNumCTCP(0),
m_mISupport(),
m_vsSendQueue(),
m_iSendsAllowed(pNetwork->GetFloodBurst()),
m_uFloodBurst(pNetwork->GetFloodBurst()),
m_fFloodRate(pNetwork->GetFloodRate()),
m_bFloodProtection(IsFloodProtected(pNetwork->GetFloodRate()))
{
: CIRCSocket(),
m_bAuthed(false),
m_bNamesx(false),
m_bUHNames(false),
m_bAwayNotify(false),
m_bAccountNotify(false),
m_bExtendedJoin(false),
m_bServerTime(false),
m_sPerms("*!@%+"),
m_sPermModes("qaohv"),
m_scUserModes(),
m_mueChanModes(),
m_pNetwork(pNetwork),
m_Nick(),
m_sPass(""),
m_msChans(),
m_uMaxNickLen(9),
m_uCapPaused(0),
m_ssAcceptedCaps(),
m_ssPendingCaps(),
m_lastCTCP(0),
m_uNumCTCP(0),
m_mISupport(),
m_vsSendQueue(),
m_iSendsAllowed(pNetwork->GetFloodBurst()),
m_uFloodBurst(pNetwork->GetFloodBurst()),
m_fFloodRate(pNetwork->GetFloodRate()),
m_bFloodProtection(IsFloodProtected(pNetwork->GetFloodRate())) {
EnableReadLine();
m_Nick.SetIdent(m_pNetwork->GetIdent());
m_Nick.SetHost(m_pNetwork->GetBindHost());
@@ -104,7 +106,8 @@ CIRCSock::CIRCSock(CIRCNetwork* pNetwork)
pNetwork->SetIRCSocket(this);
// RFC says a line can have 512 chars max + 512 chars for message tags, but we don't care ;)
// RFC says a line can have 512 chars max + 512 chars for message tags, but
// we don't care ;)
SetMaxBufferThreshold(2048);
if (m_bFloodProtection) {
AddCron(new CIRCFloodTimer(this));
@@ -151,7 +154,8 @@ void CIRCSock::ReadLine(const CString& sData) {
sLine.TrimRight("\n\r");
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/" << m_pNetwork->GetName() << ") IRC -> ZNC [" << sLine << "]");
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/"
<< m_pNetwork->GetName() << ") IRC -> ZNC [" << sLine << "]");
bool bReturn = false;
IRCSOCKMODULECALL(OnRaw(sLine), &bReturn);
@@ -245,9 +249,7 @@ void CIRCSock::SendNextCap() {
}
}
void CIRCSock::PauseCap() {
++m_uCapPaused;
}
void CIRCSock::PauseCap() { ++m_uCapPaused; }
void CIRCSock::ResumeCap() {
--m_uCapPaused;
@@ -295,7 +297,8 @@ bool CIRCSock::OnActionMessage(CActionMessage& Message) {
IRCSOCKMODULECALL(OnPrivActionMessage(Message), &bResult);
if (bResult) return true;
if (!m_pNetwork->IsUserOnline() || !m_pNetwork->GetUser()->AutoClearQueryBuffer()) {
if (!m_pNetwork->IsUserOnline() ||
!m_pNetwork->GetUser()->AutoClearQueryBuffer()) {
const CNick& Nick = Message.GetNick();
CQuery* pQuery = m_pNetwork->AddQuery(Nick.GetNick());
if (pQuery) {
@@ -317,7 +320,8 @@ bool CIRCSock::OnActionMessage(CActionMessage& Message) {
IRCSOCKMODULECALL(OnChanActionMessage(Message), &bResult);
if (bResult) return true;
if (!pChan->AutoClearChanBuffer() || !m_pNetwork->IsUserOnline() || pChan->IsDetached()) {
if (!pChan->AutoClearChanBuffer() || !m_pNetwork->IsUserOnline() ||
pChan->IsDetached()) {
CActionMessage Format;
Format.Clone(Message);
Format.SetNick(_NAMEDFMT(Message.GetNick().GetNickMask()));
@@ -363,13 +367,14 @@ bool CIRCSock::OnCapabilityMessage(CMessage& Message) {
}
std::map<CString, std::function<void(bool bVal)>> mSupportedCaps = {
{"multi-prefix", [this](bool bVal) { m_bNamesx = bVal; }},
{"userhost-in-names", [this](bool bVal) { m_bUHNames = bVal; }},
{"away-notify", [this](bool bVal) { m_bAwayNotify = bVal; }},
{"account-notify", [this](bool bVal) { m_bAccountNotify = bVal; }},
{"extended-join", [this](bool bVal) { m_bExtendedJoin = bVal; }},
{"server-time", [this](bool bVal) { m_bServerTime = bVal; }},
{"znc.in/server-time-iso", [this](bool bVal) { m_bServerTime = bVal; }},
{"multi-prefix", [this](bool bVal) { m_bNamesx = bVal; }},
{"userhost-in-names", [this](bool bVal) { m_bUHNames = bVal; }},
{"away-notify", [this](bool bVal) { m_bAwayNotify = bVal; }},
{"account-notify", [this](bool bVal) { m_bAccountNotify = bVal; }},
{"extended-join", [this](bool bVal) { m_bExtendedJoin = bVal; }},
{"server-time", [this](bool bVal) { m_bServerTime = bVal; }},
{"znc.in/server-time-iso",
[this](bool bVal) { m_bServerTime = bVal; }},
};
if (sSubCmd == "LS") {
@@ -452,8 +457,7 @@ bool CIRCSock::OnCTCPMessage(CCTCPMessage& Message) {
if (!sReply.empty()) {
time_t now = time(nullptr);
// If the last CTCP is older than m_uCTCPFloodTime, reset the counter
if (m_lastCTCP + m_uCTCPFloodTime < now)
m_uNumCTCP = 0;
if (m_lastCTCP + m_uCTCPFloodTime < now) m_uNumCTCP = 0;
m_lastCTCP = now;
// If we are over the limit, don't reply to this CTCP
if (m_uNumCTCP >= m_uCTCPFloodCount) {
@@ -462,7 +466,8 @@ bool CIRCSock::OnCTCPMessage(CCTCPMessage& Message) {
}
m_uNumCTCP++;
PutIRC("NOTICE " + Nick.GetNick() + " :\001" + sQuery + " " + sReply + "\001");
PutIRC("NOTICE " + Nick.GetNick() + " :\001" + sQuery + " " + sReply +
"\001");
return true;
}
@@ -470,7 +475,7 @@ bool CIRCSock::OnCTCPMessage(CCTCPMessage& Message) {
}
bool CIRCSock::OnErrorMessage(CMessage& Message) {
//ERROR :Closing Link: nick[24.24.24.24] (Excess Flood)
// ERROR :Closing Link: nick[24.24.24.24] (Excess Flood)
CString sError = Message.GetParam(0);
m_pNetwork->PutStatus("Error from Server [" + sError + "]");
return true;
@@ -478,7 +483,8 @@ bool CIRCSock::OnErrorMessage(CMessage& Message) {
bool CIRCSock::OnInviteMessage(CMessage& Message) {
bool bResult = false;
IRCSOCKMODULECALL(OnInvite(Message.GetNick(), Message.GetParam(1)), &bResult);
IRCSOCKMODULECALL(OnInvite(Message.GetNick(), Message.GetParam(1)),
&bResult);
return bResult;
}
@@ -551,9 +557,10 @@ bool CIRCSock::OnModeMessage(CModeMessage& Message) {
} else if (sTarget == m_Nick.GetNick()) {
CString sModeArg = sModes.Token(0);
bool bAdd = true;
/* no module call defined (yet?)
MODULECALL(OnRawUserMode(*pOpNick, *this, sModeArg, sArgs), m_pNetwork->GetUser(), nullptr, );
*/
/* no module call defined (yet?)
MODULECALL(OnRawUserMode(*pOpNick, *this, sModeArg, sArgs),
m_pNetwork->GetUser(), nullptr, );
*/
for (unsigned int a = 0; a < sModeArg.size(); a++) {
const unsigned char& uMode = sModeArg[a];
@@ -630,7 +637,8 @@ bool CIRCSock::OnNoticeMessage(CNoticeMessage& Message) {
IRCSOCKMODULECALL(OnChanNoticeMessage(Message), &bResult);
if (bResult) return true;
if (!pChan->AutoClearChanBuffer() || !m_pNetwork->IsUserOnline() || pChan->IsDetached()) {
if (!pChan->AutoClearChanBuffer() || !m_pNetwork->IsUserOnline() ||
pChan->IsDetached()) {
CNoticeMessage Format;
Format.Clone(Message);
Format.SetNick(_NAMEDFMT(Message.GetNick().GetNickMask()));
@@ -666,16 +674,21 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
if (bResult) return true;
switch (uRaw) {
case 1: { // :irc.server.com 001 nick :Welcome to the Internet Relay Network nick
case 1: { // :irc.server.com 001 nick :Welcome to the Internet Relay
// Network nick
if (m_bAuthed && sServer == "irc.znc.in") {
// m_bAuthed == true => we already received another 001 => we might be in a traffic loop
m_pNetwork->PutStatus("ZNC seems to be connected to itself, disconnecting...");
// m_bAuthed == true => we already received another 001 => we
// might be in a traffic loop
m_pNetwork->PutStatus(
"ZNC seems to be connected to itself, disconnecting...");
Quit();
return true;
}
m_pNetwork->SetIRCServer(sServer);
SetTimeout(CIRCNetwork::NO_TRAFFIC_TIMEOUT, TMO_READ); // Now that we are connected, let nature take its course
SetTimeout(CIRCNetwork::NO_TRAFFIC_TIMEOUT,
TMO_READ); // Now that we are connected, let nature take
// its course
PutIRC("WHO " + sNick);
m_bAuthed = true;
@@ -687,8 +700,11 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
CString sClientNick = pClient->GetNick(false);
if (!sClientNick.Equals(sNick)) {
// If they connected with a nick that doesn't match the one we got on irc, then we need to update them
pClient->PutClient(":" + sClientNick + "!" + m_Nick.GetIdent() + "@" + m_Nick.GetHost() + " NICK :" + sNick);
// If they connected with a nick that doesn't match the one
// we got on irc, then we need to update them
pClient->PutClient(":" + sClientNick + "!" +
m_Nick.GetIdent() + "@" +
m_Nick.GetHost() + " NICK :" + sNick);
}
}
@@ -707,13 +723,16 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
ParseISupport(Message);
m_pNetwork->UpdateExactRawBuffer(BufferMessage(Message));
break;
case 10: { // :irc.server.com 010 nick <hostname> <port> :<info>
case 10: { // :irc.server.com 010 nick <hostname> <port> :<info>
CString sHost = Message.GetParam(1);
CString sPort = Message.GetParam(2);
CString sInfo = Message.GetParam(3);
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.");
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.");
// Don't send server redirects to the client
return true;
}
@@ -754,8 +773,7 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
return true;
}
}
}
break;
} break;
case 329: {
// :irc.server.com 329 nick #chan 1234567890
CChan* pChan = m_pNetwork->FindChan(Message.GetParam(1));
@@ -775,8 +793,7 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
return true;
}
}
}
break;
} break;
case 331: {
// :irc.server.com 331 yournick #chan :No topic is set.
CChan* pChan = m_pNetwork->FindChan(Message.GetParam(1));
@@ -823,7 +840,8 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
break;
}
case 352: { // WHO
// :irc.yourserver.com 352 yournick #chan ident theirhost.com irc.theirserver.com theirnick H :0 Real Name
// :irc.yourserver.com 352 yournick #chan ident theirhost.com
// irc.theirserver.com theirnick H :0 Real Name
sNick = Message.GetParam(5);
CString sChan = Message.GetParam(1);
CString sIdent = Message.GetParam(2);
@@ -877,7 +895,8 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
CString sModes = pChan->GetDefaultModes();
if (sModes.empty()) {
sModes = m_pNetwork->GetUser()->GetDefaultChanModes();
sModes =
m_pNetwork->GetUser()->GetDefaultChanModes();
}
if (!sModes.empty()) {
@@ -905,12 +924,15 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
}
break;
case 437:
// :irc.server.net 437 * badnick :Nick/channel is temporarily unavailable
// :irc.server.net 437 mynick badnick :Nick/channel is temporarily unavailable
// :irc.server.net 437 mynick badnick :Cannot change nickname while banned on channel
if (m_pNetwork->IsChan(Message.GetParam(1)) || sNick != "*")
break;
case 432: // :irc.server.com 432 * nick :Erroneous Nickname: Illegal characters
// :irc.server.net 437 * badnick :Nick/channel is temporarily
// unavailable
// :irc.server.net 437 mynick badnick :Nick/channel is temporarily
// unavailable
// :irc.server.net 437 mynick badnick :Cannot change nickname while
// banned on channel
if (m_pNetwork->IsChan(Message.GetParam(1)) || sNick != "*") break;
case 432: // :irc.server.com 432 * nick :Erroneous Nickname: Illegal
// characters
case 433: {
CString sBadNick = Message.GetParam(1);
@@ -922,12 +944,14 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
}
case 451:
// :irc.server.com 451 CAP :You have not registered
// Servers that dont support CAP will give us this error, dont send it to the client
if (sNick.Equals("CAP"))
return true;
// Servers that dont support CAP will give us this error, dont send
// it to the client
if (sNick.Equals("CAP")) return true;
case 470: {
// :irc.unreal.net 470 mynick [Link] #chan1 has become full, so you are automatically being transferred to the linked channel #chan2
// :mccaffrey.freenode.net 470 mynick #electronics ##electronics :Forwarding to another channel
// :irc.unreal.net 470 mynick [Link] #chan1 has become full, so you
// are automatically being transferred to the linked channel #chan2
// :mccaffrey.freenode.net 470 mynick #electronics ##electronics
// :Forwarding to another channel
// freenode style numeric
CChan* pChan = m_pNetwork->FindChan(Message.GetParam(1));
@@ -937,14 +961,17 @@ bool CIRCSock::OnNumericMessage(CNumericMessage& Message) {
}
if (pChan) {
pChan->Disable();
m_pNetwork->PutStatus("Channel [" + pChan->GetName() + "] is linked to "
"another channel and was thus disabled.");
m_pNetwork->PutStatus("Channel [" + pChan->GetName() +
"] is linked to "
"another channel and was thus disabled.");
}
break;
}
case 670:
// :hydra.sector5d.org 670 kylef :STARTTLS successful, go ahead with TLS handshake
// 670 is a response to `STARTTLS` telling the client to switch to TLS
// :hydra.sector5d.org 670 kylef :STARTTLS successful, go ahead with
// TLS handshake
// 670 is a response to `STARTTLS` telling the client to switch to
// TLS
if (!GetSSL()) {
StartTLS();
@@ -968,8 +995,7 @@ bool CIRCSock::OnPartMessage(CPartMessage& Message) {
Message.SetChan(pChan);
IRCSOCKMODULECALL(OnPartMessage(Message), NOTHING);
if (pChan->IsDetached())
bDetached = true;
if (pChan->IsDetached()) bDetached = true;
}
if (Nick.NickEquals(GetNick())) {
@@ -1036,7 +1062,8 @@ bool CIRCSock::OnTextMessage(CTextMessage& Message) {
IRCSOCKMODULECALL(OnPrivMessage(Message), &bResult);
if (bResult) return true;
if (!m_pNetwork->IsUserOnline() || !m_pNetwork->GetUser()->AutoClearQueryBuffer()) {
if (!m_pNetwork->IsUserOnline() ||
!m_pNetwork->GetUser()->AutoClearQueryBuffer()) {
const CNick& Nick = Message.GetNick();
CQuery* pQuery = m_pNetwork->AddQuery(Nick.GetNick());
if (pQuery) {
@@ -1056,7 +1083,8 @@ bool CIRCSock::OnTextMessage(CTextMessage& Message) {
IRCSOCKMODULECALL(OnChanMessage(Message), &bResult);
if (bResult) return true;
if (!pChan->AutoClearChanBuffer() || !m_pNetwork->IsUserOnline() || pChan->IsDetached()) {
if (!pChan->AutoClearChanBuffer() || !m_pNetwork->IsUserOnline() ||
pChan->IsDetached()) {
CTextMessage Format;
Format.Clone(Message);
Format.SetNick(_NAMEDFMT(Message.GetNick().GetNickMask()));
@@ -1081,7 +1109,7 @@ bool CIRCSock::OnTopicMessage(CTopicMessage& Message) {
if (bReturn) return true;
pChan->SetTopicOwner(Nick.GetNick());
pChan->SetTopicDate((unsigned long) time(nullptr));
pChan->SetTopicDate((unsigned long)time(nullptr));
pChan->SetTopic(Message.GetTopic());
}
@@ -1102,18 +1130,24 @@ bool CIRCSock::OnWallopsMessage(CMessage& Message) {
}
void CIRCSock::PutIRC(const CString& sLine) {
// Only print if the line won't get sent immediately (same condition as in TrySend()!)
// Only print if the line won't get sent immediately (same condition as in
// TrySend()!)
if (m_bFloodProtection && m_iSendsAllowed <= 0) {
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/" << m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine << "] (queued)");
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/"
<< m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine
<< "] (queued)");
}
m_vsSendQueue.push_back(sLine);
TrySend();
}
void CIRCSock::PutIRCQuick(const CString& sLine) {
// Only print if the line won't get sent immediately (same condition as in TrySend()!)
// Only print if the line won't get sent immediately (same condition as in
// TrySend()!)
if (m_bFloodProtection && m_iSendsAllowed <= 0) {
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/" << m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine << "] (queued to front)");
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/"
<< m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine
<< "] (queued to front)");
}
m_vsSendQueue.push_front(sLine);
TrySend();
@@ -1121,13 +1155,17 @@ void CIRCSock::PutIRCQuick(const CString& sLine) {
void CIRCSock::TrySend() {
// This condition must be the same as in PutIRC() and PutIRCQuick()!
while (!m_vsSendQueue.empty() && (!m_bFloodProtection || m_iSendsAllowed > 0)) {
while (!m_vsSendQueue.empty() &&
(!m_bFloodProtection || m_iSendsAllowed > 0)) {
m_iSendsAllowed--;
bool bSkip = false;
CString& sLine = m_vsSendQueue.front();
IRCSOCKMODULECALL(OnSendToIRC(sLine), &bSkip);
if (!bSkip) {;
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/" << m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine << "]");
if (!bSkip) {
;
DEBUG("(" << m_pNetwork->GetUser()->GetUserName() << "/"
<< m_pNetwork->GetName() << ") ZNC -> IRC [" << sLine
<< "]");
Write(sLine + "\r\n");
}
m_vsSendQueue.pop_front();
@@ -1148,7 +1186,8 @@ void CIRCSock::Connected() {
CString sRealName = m_pNetwork->GetRealName();
bool bReturn = false;
IRCSOCKMODULECALL(OnIRCRegistration(sPass, sNick, sIdent, sRealName), &bReturn);
IRCSOCKMODULECALL(OnIRCRegistration(sPass, sNick, sIdent, sRealName),
&bReturn);
if (bReturn) return;
PutIRC("CAP LS");
@@ -1158,7 +1197,8 @@ void CIRCSock::Connected() {
}
PutIRC("NICK " + sNick);
PutIRC("USER " + sIdent + " \"" + sIdent + "\" \"" + sIdent + "\" :" + sRealName);
PutIRC("USER " + sIdent + " \"" + sIdent + "\" \"" + sIdent + "\" :" +
sRealName);
// SendAltNick() needs this
m_Nick.SetNick(sNick);
@@ -1168,8 +1208,9 @@ void CIRCSock::Disconnected() {
IRCSOCKMODULECALL(OnIRCDisconnected(), NOTHING);
DEBUG(GetSockName() << " == Disconnected()");
if (!m_pNetwork->GetUser()->IsBeingDeleted() && m_pNetwork->GetIRCConnectEnabled() &&
m_pNetwork->GetServers().size() != 0) {
if (!m_pNetwork->GetUser()->IsBeingDeleted() &&
m_pNetwork->GetIRCConnectEnabled() &&
m_pNetwork->GetServers().size() != 0) {
m_pNetwork->PutStatus("Disconnected from IRC. Reconnecting...");
}
m_pNetwork->ClearRawBuffer();
@@ -1177,9 +1218,11 @@ void CIRCSock::Disconnected() {
CString sPrefix = m_pNetwork->GetUser()->GetStatusPrefix();
for (CChan* pChan : m_pNetwork->GetChans()) {
if(pChan->IsOn()) {
m_pNetwork->PutUser(":" + sPrefix + "status!znc@znc.in KICK " + pChan->GetName() + " " + GetNick()
+ " :You have been disconnected from the IRC server");
if (pChan->IsOn()) {
m_pNetwork->PutUser(
":" + sPrefix + "status!znc@znc.in KICK " + pChan->GetName() +
" " + GetNick() +
" :You have been disconnected from the IRC server");
}
}
@@ -1193,7 +1236,9 @@ void CIRCSock::Disconnected() {
sUserMode += cMode;
}
if (!sUserMode.empty()) {
m_pNetwork->PutUser(":" + m_pNetwork->GetIRCNick().GetNickMask() + " MODE " + m_pNetwork->GetIRCNick().GetNick() + " :-" + sUserMode);
m_pNetwork->PutUser(":" + m_pNetwork->GetIRCNick().GetNickMask() +
" MODE " + m_pNetwork->GetIRCNick().GetNick() +
" :-" + sUserMode);
}
// also clear the user modes in our space:
@@ -1203,13 +1248,14 @@ void CIRCSock::Disconnected() {
void CIRCSock::SockError(int iErrno, const CString& sDescription) {
CString sError = sDescription;
DEBUG(GetSockName() << " == SockError(" << iErrno << " "
<< sError << ")");
DEBUG(GetSockName() << " == SockError(" << iErrno << " " << sError << ")");
if (!m_pNetwork->GetUser()->IsBeingDeleted()) {
if (GetConState() != CST_OK) {
m_pNetwork->PutStatus("Cannot connect to IRC (" + sError + "). Retrying...");
m_pNetwork->PutStatus("Cannot connect to IRC (" + sError +
"). Retrying...");
} else {
m_pNetwork->PutStatus("Disconnected from IRC (" + sError + "). Reconnecting...");
m_pNetwork->PutStatus("Disconnected from IRC (" + sError +
"). Reconnecting...");
}
#ifdef HAVE_LIBSSL
if (iErrno == errnoBadSSLCert) {
@@ -1227,15 +1273,21 @@ void CIRCSock::SockError(int iErrno, const CString& sDescription) {
VCString vsCert;
sCert.Split("\n", vsCert);
for (const CString& s : vsCert) {
// It shouldn't contain any bad characters, but let's be safe...
// It shouldn't contain any bad characters, but let's be
// safe...
m_pNetwork->PutStatus("|" + s.Escape_n(CString::EDEBUG));
}
CString sSHA1;
if (GetPeerFingerprint(sSHA1))
m_pNetwork->PutStatus("SHA1: " + sSHA1.Escape_n(CString::EHEXCOLON, CString::EHEXCOLON));
m_pNetwork->PutStatus(
"SHA1: " +
sSHA1.Escape_n(CString::EHEXCOLON, CString::EHEXCOLON));
CString sSHA256 = GetSSLPeerFingerprint();
m_pNetwork->PutStatus("SHA-256: " + sSHA256);
m_pNetwork->PutStatus("If you trust this certificate, do /znc AddTrustedServerFingerprint " + sSHA256);
m_pNetwork->PutStatus(
"If you trust this certificate, do /znc "
"AddTrustedServerFingerprint " +
sSHA256);
}
}
#endif
@@ -1313,25 +1365,24 @@ void CIRCSock::ParseISupport(const CMessage& Message) {
CString sModes = sValue.Token(a, false, ",");
for (unsigned int b = 0; b < sModes.size(); b++) {
m_mueChanModes[sModes[b]] = (EChanModeArgs) a;
m_mueChanModes[sModes[b]] = (EChanModeArgs)a;
}
}
}
} else if (sName.Equals("NAMESX")) {
if (m_bNamesx)
continue;
if (m_bNamesx) continue;
m_bNamesx = true;
PutIRC("PROTOCTL NAMESX");
} else if (sName.Equals("UHNAMES")) {
if (m_bUHNames)
continue;
if (m_bUHNames) continue;
m_bUHNames = true;
PutIRC("PROTOCTL UHNAMES");
}
}
}
CString CIRCSock::GetISupport(const CString& sKey, const CString& sDefault) const {
CString CIRCSock::GetISupport(const CString& sKey,
const CString& sDefault) const {
MCString::const_iterator i = m_mISupport.find(sKey.AsUpper());
if (i == m_mISupport.end()) {
return sDefault;
@@ -1352,7 +1403,7 @@ void CIRCSock::SendAltNick(const CString& sBadNick) {
unsigned int uMax = m_uMaxNickLen;
const CString& sConfNick = m_pNetwork->GetNick();
const CString& sAltNick = m_pNetwork->GetAltNick();
const CString& sAltNick = m_pNetwork->GetAltNick();
CString sNewNick = sConfNick.Left(uMax - 1);
if (sLastNick.Equals(sConfNick)) {
@@ -1363,11 +1414,14 @@ void CIRCSock::SendAltNick(const CString& sBadNick) {
}
} else if (sLastNick.Equals(sAltNick) && !sAltNick.Equals(sNewNick + "-")) {
sNewNick += "-";
} else if (sLastNick.Equals(sNewNick + "-") && !sAltNick.Equals(sNewNick + "|")) {
} else if (sLastNick.Equals(sNewNick + "-") &&
!sAltNick.Equals(sNewNick + "|")) {
sNewNick += "|";
} else if (sLastNick.Equals(sNewNick + "|") && !sAltNick.Equals(sNewNick + "^")) {
} else if (sLastNick.Equals(sNewNick + "|") &&
!sAltNick.Equals(sNewNick + "^")) {
sNewNick += "^";
} else if (sLastNick.Equals(sNewNick + "^") && !sAltNick.Equals(sNewNick + "a")) {
} else if (sLastNick.Equals(sNewNick + "^") &&
!sAltNick.Equals(sNewNick + "a")) {
sNewNick += "a";
} else {
char cLetter = 0;
@@ -1385,9 +1439,9 @@ void CIRCSock::SendAltNick(const CString& sBadNick) {
return;
}
sNewNick = sConfNick.Left(uMax -1) + ++cLetter;
sNewNick = sConfNick.Left(uMax - 1) + ++cLetter;
if (sNewNick.Equals(sAltNick))
sNewNick = sConfNick.Left(uMax -1) + ++cLetter;
sNewNick = sConfNick.Left(uMax - 1) + ++cLetter;
}
PutIRC("NICK " + sNewNick);
m_Nick.SetNick(sNewNick);
@@ -1406,7 +1460,8 @@ unsigned char CIRCSock::GetPermFromMode(unsigned char uMode) const {
}
CIRCSock::EChanModeArgs CIRCSock::GetModeType(unsigned char uMode) const {
map<unsigned char, EChanModeArgs>::const_iterator it = m_mueChanModes.find(uMode);
map<unsigned char, EChanModeArgs>::const_iterator it =
m_mueChanModes.find(uMode);
if (it == m_mueChanModes.end()) {
return NoArg;
@@ -1420,4 +1475,3 @@ void CIRCSock::ResetChans() {
it.second->Reset();
}
}