Skip to content
Browse files

Add OnJoining module hook.

This patch adds an OnJoining module hook that allows a module to allow
or disallow joining any given channel.
  • Loading branch information...
1 parent 5d001cd commit db0e0995e2b8e81a5a29548ddd718a58d4166b69 @ahf ahf committed May 29, 2014
View
6 include/znc/Modules.h
@@ -567,6 +567,11 @@ class CModule {
* @param sMessage The kick message.
*/
virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage);
+ /** This module hook is called just before ZNC tries to join an IRC channel.
+ * @param Chan The channel which is about to get joined.
+ * @return See CModule::EModRet.
+ */
+ virtual EModRet OnJoining(CChan& Channel);
/** Called when a nick joins a channel.
* @param Nick The nick who joined.
* @param Channel The channel which was joined.
@@ -1112,6 +1117,7 @@ class CModules : public std::vector<CModule*> {
bool OnQuit(const CNick& Nick, const CString& sMessage, const std::vector<CChan*>& vChans);
bool OnNick(const CNick& Nick, const CString& sNewNick, const std::vector<CChan*>& vChans);
bool OnKick(const CNick& Nick, const CString& sOpNick, CChan& Channel, const CString& sMessage);
+ bool OnJoining(CChan& Channel);
bool OnJoin(const CNick& Nick, CChan& Channel);
bool OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage);
bool OnInvite(const CNick& Nick, const CString& sChan);
View
1 modules/modperl/functions.in
@@ -28,6 +28,7 @@ void OnModCTCP(const CString& sMessage)
void OnQuit(const CNick& Nick, const CString& sMessage, const vector<CChan*>& vChans)
void OnNick(const CNick& Nick, const CString& sNewNick, const vector<CChan*>& vChans)
void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage)
+EModRet OnJoining(CChan& Channel)
void OnJoin(const CNick& Nick, CChan& Channel)
void OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage)
EModRet OnChanBufferStarting(CChan& Chan, CClient& Client)
View
1 modules/modperl/module.h
@@ -68,6 +68,7 @@ class CPerlModule : public CModule {
virtual void OnQuit(const CNick& Nick, const CString& sMessage, const std::vector<CChan*>& vChans);
virtual void OnNick(const CNick& Nick, const CString& sNewNick, const std::vector<CChan*>& vChans);
virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage);
+ virtual EModRet OnJoining(CChan& Channel);
virtual void OnJoin(const CNick& Nick, CChan& Channel);
virtual void OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage);
virtual EModRet OnChanBufferStarting(CChan& Chan, CClient& Client);
View
1 modules/modperl/startup.pl
@@ -337,6 +337,7 @@ sub module_types {
sub OnQuit {}
sub OnNick {}
sub OnKick {}
+sub OnJoining {}
sub OnJoin {}
sub OnPart {}
sub OnChanBufferStarting {}
View
1 modules/modpython/functions.in
@@ -28,6 +28,7 @@ void OnModCTCP(const CString& sMessage)
void OnQuit(const CNick& Nick, const CString& sMessage, const vector<CChan*>& vChans)
void OnNick(const CNick& Nick, const CString& sNewNick, const vector<CChan*>& vChans)
void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage)
+EModRet OnJoining(CChan& Channel)
void OnJoin(const CNick& Nick, CChan& Channel)
void OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage)
EModRet OnChanBufferStarting(CChan& Chan, CClient& Client)
View
1 modules/modpython/module.h
@@ -84,6 +84,7 @@ class CPyModule : public CModule {
virtual void OnQuit(const CNick& Nick, const CString& sMessage, const std::vector<CChan*>& vChans);
virtual void OnNick(const CNick& Nick, const CString& sNewNick, const std::vector<CChan*>& vChans);
virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage);
+ virtual EModRet OnJoining(CChan& Channel);
virtual void OnJoin(const CNick& Nick, CChan& Channel);
virtual void OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage);
virtual EModRet OnChanBufferStarting(CChan& Chan, CClient& Client);
View
3 modules/modpython/znc.py
@@ -281,6 +281,9 @@ def OnNick(self, Nick, sNewNick, vChans):
def OnKick(self, OpNick, sKickedNick, Channel, sMessage):
pass
+ def OnJoining(self, Channel):
+ pass
+
def OnJoin(self, Nick, Channel):
pass
View
6 src/IRCNetwork.cpp
@@ -762,6 +762,12 @@ void CIRCNetwork::JoinChans(set<CChan*>& sChans) {
}
bool CIRCNetwork::JoinChan(CChan* pChan) {
+ bool bReturn = false;
+ NETWORKMODULECALL(OnJoining(*pChan), m_pUser, this, NULL, &bReturn);
+
+ if (bReturn)
+ return false;
+
if (m_pUser->JoinTries() != 0 && pChan->GetJoinTries() >= m_pUser->JoinTries()) {
PutStatus("The channel " + pChan->GetName() + " could not be joined, disabling it.");
pChan->Disable();
View
2 src/Modules.cpp
@@ -589,6 +589,7 @@ void CModule::OnUnknownModCommand(const CString& sLine) {
void CModule::OnQuit(const CNick& Nick, const CString& sMessage, const vector<CChan*>& vChans) {}
void CModule::OnNick(const CNick& Nick, const CString& sNewNick, const vector<CChan*>& vChans) {}
void CModule::OnKick(const CNick& Nick, const CString& sKickedNick, CChan& Channel, const CString& sMessage) {}
+CModule::EModRet CModule::OnJoining(CChan& Channel) { return CONTINUE; }
void CModule::OnJoin(const CNick& Nick, CChan& Channel) {}
void CModule::OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage) {}
CModule::EModRet CModule::OnInvite(const CNick& Nick, const CString& sChan) { return CONTINUE; }
@@ -775,6 +776,7 @@ bool CModules::OnUserTopicRequest(CString& sChannel) { MODHALTCHK(OnUserTopicReq
bool CModules::OnQuit(const CNick& Nick, const CString& sMessage, const vector<CChan*>& vChans) { MODUNLOADCHK(OnQuit(Nick, sMessage, vChans)); return false; }
bool CModules::OnNick(const CNick& Nick, const CString& sNewNick, const vector<CChan*>& vChans) { MODUNLOADCHK(OnNick(Nick, sNewNick, vChans)); return false; }
bool CModules::OnKick(const CNick& Nick, const CString& sKickedNick, CChan& Channel, const CString& sMessage) { MODUNLOADCHK(OnKick(Nick, sKickedNick, Channel, sMessage)); return false; }
+bool CModules::OnJoining(CChan& Channel) { MODHALTCHK(OnJoining(Channel)); }
bool CModules::OnJoin(const CNick& Nick, CChan& Channel) { MODUNLOADCHK(OnJoin(Nick, Channel)); return false; }
bool CModules::OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage) { MODUNLOADCHK(OnPart(Nick, Channel, sMessage)); return false; }
bool CModules::OnInvite(const CNick& Nick, const CString& sChan) { MODHALTCHK(OnInvite(Nick, sChan)); }

0 comments on commit db0e099

Please sign in to comment.
Something went wrong with that request. Please try again.