From a533066dc675ffa004379032e707630263d4b842 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 16 Feb 2011 12:53:06 +0100 Subject: [PATCH] Call modules for /MODE done by not-in-channel nicks When ChanServ ops someone in a channel without joining first, znc didn't call modules for this event, because it couldn't figure out a CNick* instance to use Instead, the module hooks are now executed with a temporary CNick instance which is created by CIRCSock anyway. Big thanks to Robby for reporting this and helping me test it! Signed-off-by: Uli Schlachter --- Chan.cpp | 12 ++++++++++-- Chan.h | 2 +- IRCSock.cpp | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Chan.cpp b/Chan.cpp index b04b5c92..f0867aa3 100644 --- a/Chan.cpp +++ b/Chan.cpp @@ -220,12 +220,20 @@ void CChan::OnWho(const CString& sNick, const CString& sIdent, const CString& sH } } -void CChan::ModeChange(const CString& sModes, const CString& sOpNick) { +void CChan::ModeChange(const CString& sModes, const CNick* pOpNick) { CString sModeArg = sModes.Token(0); CString sArgs = sModes.Token(1, true); bool bAdd = true; - CNick* pOpNick = FindNick(sOpNick); + /* Try to find a CNick* from this channel so that pOpNick->HasPerm() + * works as expected. */ + if (pOpNick) { + CNick* OpNick = FindNick(pOpNick->GetNick()); + /* If nothing was found, use the original pOpNick, else use the + * CNick* from FindNick() */ + if (OpNick) + pOpNick = OpNick; + } if (pOpNick) { MODULECALL(OnRawMode(*pOpNick, *this, sModeArg, sArgs), m_pUser, NULL, NOTHING); diff --git a/Chan.h b/Chan.h index 3586c223..e781ddba 100644 --- a/Chan.h +++ b/Chan.h @@ -66,7 +66,7 @@ public: // Modes void SetModes(const CString& s); - void ModeChange(const CString& sModes, const CString& sNick = ""); + void ModeChange(const CString& sModes, const CNick* OpNick = NULL); bool AddMode(unsigned char uMode, const CString& sArg); bool RemMode(unsigned char uMode); CString GetModeString() const; diff --git a/IRCSock.cpp b/IRCSock.cpp index 8db0a4c1..871e5071 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -500,7 +500,7 @@ void CIRCSock::ReadLine(const CString& sData) { CChan* pChan = m_pUser->FindChan(sTarget); if (pChan) { - pChan->ModeChange(sModes, Nick.GetNick()); + pChan->ModeChange(sModes, &Nick); if (pChan->IsDetached()) { return;