Permalink
Browse files

Fix chansaver's channel keys by adding other OnMode() hooks

  • Loading branch information...
1 parent 40536fb commit 618d9c58a4ec24d515f5c82d6d5e47afa8902a3b @DarthGandalf DarthGandalf committed Feb 15, 2014
View
@@ -471,7 +471,7 @@ class CModule {
virtual EModRet OnBroadcast(CString& sMessage);
/** This module hook is called when a user mode on a channel changes.
- * @param OpNick The nick who sent the mode change.
+ * @param pOpNick The nick who sent the mode change, or NULL if set by server.
* @param Nick The nick whose channel mode changes.
* @param Channel The channel on which the user mode is changed.
* @param uMode The mode character that is changed, e.g. '@' for op.
@@ -481,31 +481,38 @@ class CModule {
* @see CIRCSock::GetModeType() for converting uMode into a mode (e.g.
* 'o' for op).
*/
+ virtual void OnChanPermission(const CNick* pOpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange);
virtual void OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange);
/** Called when a nick is opped on a channel */
+ virtual void OnOp(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
virtual void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
/** Called when a nick is deopped on a channel */
+ virtual void OnDeop(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
virtual void OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
/** Called when a nick is voiced on a channel */
+ virtual void OnVoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
virtual void OnVoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
/** Called when a nick is devoiced on a channel */
+ virtual void OnDevoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
virtual void OnDevoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
/** Called on an individual channel mode change.
- * @param OpNick The nick who changes the channel mode.
+ * @param pOpNick The nick who changes the channel mode, or NULL if set by server.
* @param Channel The channel whose mode is changed.
* @param uMode The mode character that is changed.
* @param sArg The argument to the mode character, if any.
* @param bAdded True if this mode is added ("+"), else false.
* @param bNoChange True if this mode was already effective before.
*/
+ virtual void OnMode(const CNick* pOpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange);
virtual void OnMode(const CNick& OpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange);
/** Called on any channel mode change. This is called before the more
* detailed mode hooks like e.g. OnOp() and OnMode().
- * @param OpNick The nick who changes the channel mode.
+ * @param pOpNick The nick who changes the channel mode, or NULL if set by server.
* @param Channel The channel whose mode is changed.
* @param sModes The raw mode change, e.g. "+s-io".
* @param sArgs All arguments to the mode change from sModes.
*/
+ virtual void OnRawMode(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
virtual void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
/** Called on any raw IRC line received from the <em>IRC server</em>.
@@ -1066,12 +1073,19 @@ class CModules : public std::vector<CModule*> {
bool OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName);
bool OnBroadcast(CString& sMessage);
+ bool OnChanPermission(const CNick* pOpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange);
bool OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange);
+ bool OnOp(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
bool OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ bool OnDeop(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
bool OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ bool OnVoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
bool OnVoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ bool OnDevoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
bool OnDevoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ bool OnRawMode(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
bool OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
+ bool OnMode(const CNick* pOpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange);
bool OnMode(const CNick& OpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange);
bool OnRaw(CString& sLine);
View
@@ -210,7 +210,7 @@ class CAutoOpMod : public CModule {
return HALTCORE;
}
- virtual void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) {
+ virtual void OnOp(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange) {
if (Nick.GetNick() == m_pNetwork->GetIRCNick().GetNick()) {
const map<CString,CNick>& msNicks = Channel.GetNicks();
View
@@ -33,8 +33,9 @@ class CBuffExtras : public CModule {
Channel.AddBuffer(":" + GetModNick() + "!" + GetModName() + "@znc.in PRIVMSG " + _NAMEDFMT(Channel.GetName()) + " :{text}", sMessage);
}
- virtual void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs) {
- AddBuffer(Channel, OpNick.GetNickMask() + " set mode: " + sModes + " " + sArgs);
+ virtual void OnRawMode(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs) {
+ const CString sNickMask = pOpNick ? pOpNick->GetNickMask() : "Server";
+ AddBuffer(Channel, sNickMask + " set mode: " + sModes + " " + sArgs);
}
virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage) {
View
@@ -54,7 +54,7 @@ class CChanSaverMod : public CModule {
return CONTINUE;
}
- virtual void OnMode(const CNick& OpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange) {
+ virtual void OnMode(const CNick* pOpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange) {
// This is called when we join (ZNC requests the channel modes
// on join) *and* when someone changes the channel keys.
// We ignore channel key "*" because of some broken nets.
View
@@ -40,7 +40,7 @@ class CLogMod: public CModule {
virtual void OnIRCDisconnected();
virtual EModRet OnBroadcast(CString& sMessage);
- virtual void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
+ virtual void OnRawMode(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage);
virtual void OnQuit(const CNick& Nick, const CString& sMessage, const vector<CChan*>& vChans);
virtual void OnJoin(const CNick& Nick, CChan& Channel);
@@ -195,9 +195,10 @@ CModule::EModRet CLogMod::OnBroadcast(CString& sMessage)
return CONTINUE;
}
-void CLogMod::OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs)
+void CLogMod::OnRawMode(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs)
{
- PutLog("*** " + OpNick.GetNick() + " sets mode: " + sModes + " " + sArgs, Channel);
+ const CString sNick = pOpNick ? pOpNick->GetNick() : "Server";
+ PutLog("*** " + sNick + " sets mode: " + sModes + " " + sArgs, Channel);
}
void CLogMod::OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage)
@@ -13,13 +13,13 @@ EModRet OnIRCConnecting(CIRCSock *pIRCSock)
void OnIRCConnectionError(CIRCSock *pIRCSock)
EModRet OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName)
EModRet OnBroadcast(CString& sMessage)
-void OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange)
-void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
-void OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
-void OnVoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
-void OnDevoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
-void OnMode(const CNick& OpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange)
-void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs)
+void OnChanPermission(const CNick* pOpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange)
+void OnOp(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
+void OnDeop(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
+void OnVoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
+void OnDevoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
+void OnMode(const CNick* pOpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange)
+void OnRawMode(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs)
EModRet OnRaw(CString& sLine)
EModRet OnStatusCommand(CString& sCommand)
void OnModCommand(const CString& sCommand)
View
@@ -53,13 +53,13 @@ class CPerlModule : public CModule {
virtual void OnIRCConnectionError(CIRCSock *pIRCSock);
virtual EModRet OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName);
virtual EModRet OnBroadcast(CString& sMessage);
- virtual void OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange);
- virtual void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
- virtual void OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
- virtual void OnVoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
- virtual void OnDevoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
- virtual void OnMode(const CNick& OpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange);
- virtual void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
+ virtual void OnChanPermission(const CNick* pOpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange);
+ virtual void OnOp(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ virtual void OnDeop(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ virtual void OnVoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ virtual void OnDevoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ virtual void OnMode(const CNick* pOpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange);
+ virtual void OnRawMode(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
virtual EModRet OnRaw(CString& sLine);
virtual EModRet OnStatusCommand(CString& sCommand);
virtual void OnModCommand(const CString& sCommand);
@@ -13,13 +13,13 @@ EModRet OnIRCConnecting(CIRCSock *pIRCSock)
void OnIRCConnectionError(CIRCSock *pIRCSock)
EModRet OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName)
EModRet OnBroadcast(CString& sMessage)
-void OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange)
-void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
-void OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
-void OnVoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
-void OnDevoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
-void OnMode(const CNick& OpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange)
-void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs)
+void OnChanPermission(const CNick* pOpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange)
+void OnOp(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
+void OnDeop(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
+void OnVoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
+void OnDevoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange)
+void OnMode(const CNick* pOpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange)
+void OnRawMode(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs)
EModRet OnRaw(CString& sLine)
EModRet OnStatusCommand(CString& sCommand)
void OnModCommand(const CString& sCommand)
View
@@ -69,13 +69,13 @@ class CPyModule : public CModule {
virtual void OnIRCConnectionError(CIRCSock *pIRCSock);
virtual EModRet OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName);
virtual EModRet OnBroadcast(CString& sMessage);
- virtual void OnChanPermission(const CNick& OpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange);
- virtual void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
- virtual void OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
- virtual void OnVoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
- virtual void OnDevoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
- virtual void OnMode(const CNick& OpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange);
- virtual void OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
+ virtual void OnChanPermission(const CNick* pOpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange);
+ virtual void OnOp(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ virtual void OnDeop(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ virtual void OnVoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ virtual void OnDevoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
+ virtual void OnMode(const CNick* pOpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange);
+ virtual void OnRawMode(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
virtual EModRet OnRaw(CString& sLine);
virtual EModRet OnStatusCommand(CString& sCommand);
virtual void OnModCommand(const CString& sCommand);
View
@@ -232,13 +232,13 @@ class CQModule : public CModule {
HandleNeed(Channel, "ov");
}
- virtual void OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) {
- if (m_bRequestPerms && IsSelf(Nick) && !IsSelf(OpNick))
+ virtual void OnDeop(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange) {
+ if (m_bRequestPerms && IsSelf(Nick) && (!pOpNick || !IsSelf(*pOpNick)))
HandleNeed(Channel, "o");
}
- virtual void OnDevoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) {
- if (m_bRequestPerms && IsSelf(Nick) && !IsSelf(OpNick))
+ virtual void OnDevoice(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange) {
+ if (m_bRequestPerms && IsSelf(Nick) && (!pOpNick || !IsSelf(*pOpNick)))
HandleNeed(Channel, "v");
}
View
@@ -263,9 +263,7 @@ void CChan::ModeChange(const CString& sModes, const CNick* pOpNick) {
pOpNick = OpNick;
}
- if (pOpNick) {
- NETWORKMODULECALL(OnRawMode(*pOpNick, *this, sModeArg, sArgs), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
- }
+ NETWORKMODULECALL(OnRawMode(pOpNick, *this, sModeArg, sArgs), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
for (unsigned int a = 0; a < sModeArg.size(); a++) {
const unsigned char& uMode = sModeArg[a];
@@ -297,21 +295,19 @@ void CChan::ModeChange(const CString& sModes, const CNick* pOpNick) {
}
}
- if (uMode && pOpNick) {
- NETWORKMODULECALL(OnChanPermission(*pOpNick, *pNick, *this, uMode, bAdd, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
-
- if (uMode == CChan::M_Op) {
- if (bAdd) {
- NETWORKMODULECALL(OnOp(*pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
- } else {
- NETWORKMODULECALL(OnDeop(*pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
- }
- } else if (uMode == CChan::M_Voice) {
- if (bAdd) {
- NETWORKMODULECALL(OnVoice(*pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
- } else {
- NETWORKMODULECALL(OnDevoice(*pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
- }
+ NETWORKMODULECALL(OnChanPermission(pOpNick, *pNick, *this, uMode, bAdd, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
+
+ if (uMode == CChan::M_Op) {
+ if (bAdd) {
+ NETWORKMODULECALL(OnOp(pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
+ } else {
+ NETWORKMODULECALL(OnDeop(pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
+ }
+ } else if (uMode == CChan::M_Voice) {
+ if (bAdd) {
+ NETWORKMODULECALL(OnVoice(pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
+ } else {
+ NETWORKMODULECALL(OnDevoice(pOpNick, *pNick, *this, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
}
}
}
@@ -338,17 +334,15 @@ void CChan::ModeChange(const CString& sModes, const CNick* pOpNick) {
break;
}
- if (pOpNick) {
- bool bNoChange;
- if (bList) {
- bNoChange = false;
- } else if (bAdd) {
- bNoChange = HasMode(uMode) && GetModeArg(uMode) == sArg;
- } else {
- bNoChange = !HasMode(uMode);
- }
- NETWORKMODULECALL(OnMode(*pOpNick, *this, uMode, sArg, bAdd, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
+ bool bNoChange;
+ if (bList) {
+ bNoChange = false;
+ } else if (bAdd) {
+ bNoChange = HasMode(uMode) && GetModeArg(uMode) == sArg;
+ } else {
+ bNoChange = !HasMode(uMode);
}
+ NETWORKMODULECALL(OnMode(pOpNick, *this, uMode, sArg, bAdd, bNoChange), m_pNetwork->GetUser(), m_pNetwork, NULL, NOTHING);
if (!bList) {
(bAdd) ? AddMode(uMode, sArg) : RemMode(uMode);
Oops, something went wrong.

0 comments on commit 618d9c5

Please sign in to comment.