diff --git a/Modules.cpp b/Modules.cpp index 6346ee1b..8fc88d61 100644 --- a/Modules.cpp +++ b/Modules.cpp @@ -10,6 +10,38 @@ #define _MODDIR_ "/usr/share/znc" #endif +#define MODUNLOADCHK(func) \ + for (unsigned int a = 0; a < size(); a++) { \ + try { \ + (*this)[a]->func; \ + } catch (CModule::EModException e) { \ + if (e == CModule::UNLOAD) { \ + UnloadModule((*this)[a]->GetModName()); \ + } \ + } \ + } \ + +#define MODHALTCHK(func) \ + bool bHaltCore = false; \ + for (unsigned int a = 0; a < size(); a++) { \ + try { \ + CModule::EModRet e = (*this)[a]->func; \ + if (e == CModule::HALTMODS) { \ + break; \ + } else if (e == CModule::HALTCORE) { \ + bHaltCore = true; \ + } else if (e == CModule::HALT) { \ + bHaltCore = true; \ + break; \ + } \ + } catch (CModule::EModException e) { \ + if (e == CModule::UNLOAD) { \ + UnloadModule((*this)[a]->GetModName()); \ + } \ + } \ + } \ + return bHaltCore; + /////////////////// Timer /////////////////// CTimer::CTimer(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription) : CCron() { SetName(sLabel); @@ -45,50 +77,57 @@ CModule::~CModule() { while (m_vTimers.size()) { RemTimer(m_vTimers[0]->GetName()); } + SaveRegistry(); } -bool CModule::LoadRegistry() -{ +void CModule::Unload() { throw UNLOAD; } + +bool CModule::LoadRegistry() { CString sRegistryDir = m_pUser->GetDataPath() + "/" + m_sModName; - CUtils::MakeDir( sRegistryDir ); - return( ( m_mssRegistry.ReadFromDisk( sRegistryDir + "/" + m_pUser->GetUserName() + "-registry.txt", 0600 ) == MCString::MCS_SUCCESS ) ); + CUtils::MakeDir(sRegistryDir); + + return (m_mssRegistry.ReadFromDisk(sRegistryDir + "/" + m_pUser->GetUserName() + "-registry.txt", 0600) == MCString::MCS_SUCCESS); } -bool CModule::SaveRegistry() -{ +bool CModule::SaveRegistry() { CString sRegistryDir = m_pUser->GetDataPath() + "/" + m_sModName; - CUtils::MakeDir( sRegistryDir ); - return( ( m_mssRegistry.WriteToDisk( sRegistryDir + "/" + m_pUser->GetUserName() + "-registry.txt", 0600 ) == MCString::MCS_SUCCESS ) ); + CUtils::MakeDir(sRegistryDir); + + return (m_mssRegistry.WriteToDisk(sRegistryDir + "/" + m_pUser->GetUserName() + "-registry.txt", 0600) == MCString::MCS_SUCCESS); } -bool CModule::SetNV( const CString & sName, const CString & sValue, bool bWriteToDisk ) -{ +bool CModule::SetNV(const CString & sName, const CString & sValue, bool bWriteToDisk) { m_mssRegistry[sName] = sValue; - if ( bWriteToDisk ) - return( SaveRegistry() ); + if (bWriteToDisk) { + return SaveRegistry(); + } - return( true ); + return true; } -CString CModule::GetNV( const CString & sName ) -{ - MCString::iterator it = m_mssRegistry.find( sName ); - if ( it != m_mssRegistry.end() ) - return( it->second ); - return( "" ); +CString CModule::GetNV(const CString & sName) { + MCString::iterator it = m_mssRegistry.find(sName); + + if (it != m_mssRegistry.end()) { + return it->second; + } + + return ""; } -bool CModule::DelNV( const CString & sName, bool bWriteToDisk ) -{ +bool CModule::DelNV(const CString & sName, bool bWriteToDisk) { MCString::iterator it = m_mssRegistry.find( sName ); - if ( it != m_mssRegistry.end() ) - m_mssRegistry.erase( it ); - if ( bWriteToDisk ) - return( SaveRegistry() ); + if (it != m_mssRegistry.end()) { + m_mssRegistry.erase(it); + } - return( true ); + if (bWriteToDisk) { + return SaveRegistry(); + } + + return true; } bool CModule::AddTimer(CTimer* pTimer) { @@ -102,12 +141,11 @@ bool CModule::AddTimer(CTimer* pTimer) { return true; } -bool CModule::AddTimer(FPTimer_t pFBCallback, const CString& sLabel, u_int uInterval, - u_int uCycles, const CString& sDescription ) -{ - CFPTimer *pTimer = new CFPTimer( this, uInterval, uCycles, sLabel, sDescription ); - pTimer->SetFPCallback( pFBCallback ); - return( AddTimer( pTimer ) ); +bool CModule::AddTimer(FPTimer_t pFBCallback, const CString& sLabel, u_int uInterval, u_int uCycles, const CString& sDescription) { + CFPTimer *pTimer = new CFPTimer(this, uInterval, uCycles, sLabel, sDescription); + pTimer->SetFPCallback(pFBCallback); + + return AddTimer(pTimer); } bool CModule::RemTimer(const CString& sLabel) { @@ -191,7 +229,7 @@ void CModule::OnUserDetached() {} void CModule::OnIRCDisconnected() {} void CModule::OnIRCConnected() {} -bool CModule::OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) { return false; } +CModule::EModRet CModule::OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) { return CONTINUE; } void CModule::OnChanPermission(const CNick& OpNick, const CNick& Nick, const CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange) {} void CModule::OnOp(const CNick& OpNick, const CNick& Nick, const CChan& Channel, bool bNoChange) {} @@ -200,10 +238,10 @@ void CModule::OnVoice(const CNick& OpNick, const CNick& Nick, const CChan& Chann void CModule::OnDevoice(const CNick& OpNick, const CNick& Nick, const CChan& Channel, bool bNoChange) {} void CModule::OnRawMode(const CNick& OpNick, const CChan& Channel, const CString& sModes, const CString& sArgs) {} -bool CModule::OnUserRaw(CString& sLine) { return false; } -bool CModule::OnRaw(CString& sLine) { return false; } +CModule::EModRet CModule::OnUserRaw(CString& sLine) { return CONTINUE; } +CModule::EModRet CModule::OnRaw(CString& sLine) { return CONTINUE; } -bool CModule::OnStatusCommand(const CString& sCommand) { return false; } +CModule::EModRet CModule::OnStatusCommand(const CString& sCommand) { return CONTINUE; } void CModule::OnModCommand(const CString& sCommand) {} void CModule::OnModNotice(const CString& sMessage) {} void CModule::OnModCTCP(const CString& sMessage) {} @@ -214,17 +252,17 @@ void CModule::OnKick(const CNick& Nick, const CString& sKickedNick, const CChan& void CModule::OnJoin(const CNick& Nick, const CChan& Channel) {} void CModule::OnPart(const CNick& Nick, const CChan& Channel) {} -bool CModule::OnUserCTCPReply(const CNick& Nick, CString& sMessage) { return false; } -bool CModule::OnCTCPReply(const CNick& Nick, CString& sMessage) { return false; } -bool CModule::OnUserCTCP(const CString& sTarget, CString& sMessage) { return false; } -bool CModule::OnPrivCTCP(const CNick& Nick, CString& sMessage) { return false; } -bool CModule::OnChanCTCP(const CNick& Nick, const CChan& Channel, CString& sMessage) { return false; } -bool CModule::OnUserMsg(const CString& sTarget, CString& sMessage) { return false; } -bool CModule::OnPrivMsg(const CNick& Nick, CString& sMessage) { return false; } -bool CModule::OnChanMsg(const CNick& Nick, const CChan& Channel, CString& sMessage) { return false; } -bool CModule::OnUserNotice(const CString& sTarget, CString& sMessage) { return false; } -bool CModule::OnPrivNotice(const CNick& Nick, CString& sMessage) { return false; } -bool CModule::OnChanNotice(const CNick& Nick, const CChan& Channel, CString& sMessage) { return false; } +CModule::EModRet CModule::OnUserCTCPReply(const CNick& Nick, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnCTCPReply(const CNick& Nick, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnUserCTCP(const CString& sTarget, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnPrivCTCP(const CNick& Nick, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnChanCTCP(const CNick& Nick, const CChan& Channel, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnUserMsg(const CString& sTarget, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnPrivMsg(const CNick& Nick, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnChanMsg(const CNick& Nick, const CChan& Channel, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnUserNotice(const CString& sTarget, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnPrivNotice(const CNick& Nick, CString& sMessage) { return CONTINUE; } +CModule::EModRet CModule::OnChanNotice(const CNick& Nick, const CChan& Channel, CString& sMessage) { return CONTINUE; } void* CModule::GetDLL() { return m_pDLL; } bool CModule::PutIRC(const CString& sLine) { @@ -254,12 +292,6 @@ void CModules::UnloadAll() { } } -void CModules::OnIRCConnected() { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnIRCConnected(); - } -} - bool CModules::OnLoad(const CString& sArgs) { for (unsigned int a = 0; a < size(); a++) { if (!(*this)[a]->OnLoad(sArgs)) { @@ -280,256 +312,136 @@ bool CModules::OnBoot() { return true; } +void CModules::OnIRCConnected() { + MODUNLOADCHK(OnIRCConnected()); +} + void CModules::OnUserAttached() { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnUserAttached(); - } + MODUNLOADCHK(OnUserAttached()); } void CModules::OnUserDetached() { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnUserDetached(); - } + MODUNLOADCHK(OnUserDetached()); } void CModules::OnIRCDisconnected() { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnIRCDisconnected(); - } + MODUNLOADCHK(OnIRCDisconnected()); } bool CModules::OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnDCCUserSend(RemoteNick, uLongIP, uPort, sFile, uFileSize)) { - return true; - } - } - - return false; + MODHALTCHK(OnDCCUserSend(RemoteNick, uLongIP, uPort, sFile, uFileSize)); } void CModules::OnChanPermission(const CNick& OpNick, const CNick& Nick, const CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnChanPermission(OpNick, Nick, Channel, uMode, bAdded, bNoChange); - } + MODUNLOADCHK(OnChanPermission(OpNick, Nick, Channel, uMode, bAdded, bNoChange)); } void CModules::OnOp(const CNick& OpNick, const CNick& Nick, const CChan& Channel, bool bNoChange) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnOp(OpNick, Nick, Channel, bNoChange); - } + MODUNLOADCHK(OnOp(OpNick, Nick, Channel, bNoChange)); } void CModules::OnDeop(const CNick& OpNick, const CNick& Nick, const CChan& Channel, bool bNoChange) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnDeop(OpNick, Nick, Channel, bNoChange); - } + MODUNLOADCHK(OnDeop(OpNick, Nick, Channel, bNoChange)); } void CModules::OnVoice(const CNick& OpNick, const CNick& Nick, const CChan& Channel, bool bNoChange) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnVoice(OpNick, Nick, Channel, bNoChange); - } + MODUNLOADCHK(OnVoice(OpNick, Nick, Channel, bNoChange)); } void CModules::OnDevoice(const CNick& OpNick, const CNick& Nick, const CChan& Channel, bool bNoChange) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnDevoice(OpNick, Nick, Channel, bNoChange); - } + MODUNLOADCHK(OnDevoice(OpNick, Nick, Channel, bNoChange)); } void CModules::OnRawMode(const CNick& OpNick, const CChan& Channel, const CString& sModes, const CString& sArgs) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnRawMode(OpNick, Channel, sModes, sArgs); - } + MODUNLOADCHK(OnRawMode(OpNick, Channel, sModes, sArgs)); } bool CModules::OnRaw(CString& sLine) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnRaw(sLine)) { - return true; - } - } - - return false; + MODHALTCHK(OnRaw(sLine)); } bool CModules::OnUserRaw(CString& sLine) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnUserRaw(sLine)) { - return true; - } - } - - return false; + MODHALTCHK(OnUserRaw(sLine)); } void CModules::OnQuit(const CNick& Nick, const CString& sMessage, const vector& vChans) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnQuit(Nick, sMessage, vChans); - } + MODUNLOADCHK(OnQuit(Nick, sMessage, vChans)); } void CModules::OnNick(const CNick& Nick, const CString& sNewNick, const vector& vChans) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnNick(Nick, sNewNick, vChans); - } + MODUNLOADCHK(OnNick(Nick, sNewNick, vChans)); } void CModules::OnKick(const CNick& Nick, const CString& sKickedNick, const CChan& Channel, const CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnKick(Nick, sKickedNick, Channel, sMessage); - } + MODUNLOADCHK(OnKick(Nick, sKickedNick, Channel, sMessage)); } void CModules::OnJoin(const CNick& Nick, const CChan& Channel) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnJoin(Nick, Channel); - } + MODUNLOADCHK(OnJoin(Nick, Channel)); } void CModules::OnPart(const CNick& Nick, const CChan& Channel) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnPart(Nick, Channel); - } + MODUNLOADCHK(OnPart(Nick, Channel)); } bool CModules::OnUserCTCP(const CString& sTarget, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnUserCTCP(sTarget, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnUserCTCP(sTarget, sMessage)); } bool CModules::OnUserCTCPReply(const CNick& Nick, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnUserCTCPReply(Nick, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnUserCTCPReply(Nick, sMessage)); } bool CModules::OnCTCPReply(const CNick& Nick, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnCTCPReply(Nick, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnCTCPReply(Nick, sMessage)); } bool CModules::OnPrivCTCP(const CNick& Nick, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnPrivCTCP(Nick, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnPrivCTCP(Nick, sMessage)); } bool CModules::OnChanCTCP(const CNick& Nick, const CChan& Channel, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnChanCTCP(Nick, Channel, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnChanCTCP(Nick, Channel, sMessage)); } bool CModules::OnUserMsg(const CString& sTarget, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnUserMsg(sTarget, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnUserMsg(sTarget, sMessage)); } bool CModules::OnPrivMsg(const CNick& Nick, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnPrivMsg(Nick, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnPrivMsg(Nick, sMessage)); } bool CModules::OnChanMsg(const CNick& Nick, const CChan& Channel, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnChanMsg(Nick, Channel, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnChanMsg(Nick, Channel, sMessage)); } bool CModules::OnUserNotice(const CString& sTarget, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnUserNotice(sTarget, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnUserNotice(sTarget, sMessage)); } bool CModules::OnPrivNotice(const CNick& Nick, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnPrivNotice(Nick, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnPrivNotice(Nick, sMessage)); } bool CModules::OnChanNotice(const CNick& Nick, const CChan& Channel, CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnChanNotice(Nick, Channel, sMessage)) { - return true; - } - } - - return false; + MODHALTCHK(OnChanNotice(Nick, Channel, sMessage)); } bool CModules::OnStatusCommand(const CString& sCommand) { - for (unsigned int a = 0; a < size(); a++) { - if ((*this)[a]->OnStatusCommand(sCommand)) { - return true; - } - } - - return false; + MODHALTCHK(OnStatusCommand(sCommand)); } void CModules::OnModCommand(const CString& sCommand) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnModCommand(sCommand); - } + MODUNLOADCHK(OnModCommand(sCommand)); } void CModules::OnModNotice(const CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnModNotice(sMessage); - } + MODUNLOADCHK(OnModNotice(sMessage)); } void CModules::OnModCTCP(const CString& sMessage) { - for (unsigned int a = 0; a < size(); a++) { - (*this)[a]->OnModCTCP(sMessage); - } + MODUNLOADCHK(OnModCTCP(sMessage)); } CModule* CModules::FindModule(const CString& sModule) { @@ -572,13 +484,11 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p DEBUG_ONLY(cout << "[" << sModPath << "] Not found..." << endl); sModPath = pUser->GetModPath() + "/" + sModule + ".so"; - if (!CFile::Exists(sModPath)) - { + if (!CFile::Exists(sModPath)) { DEBUG_ONLY(cout << "[" << sModPath << "] Not found..." << endl); sModPath = _MODDIR_ + CString("/") + sModule + ".so"; - if (!CFile::Exists(sModPath)) - { + if (!CFile::Exists(sModPath)) { DEBUG_ONLY(cout << "[" << sModPath << "] Not found... giving up!" << endl); sRetMsg = "Unable to find module [" + sModule + "]"; return false; @@ -632,6 +542,11 @@ bool CModules::LoadModule(const CString& sModule, const CString& sArgs, CUser* p #endif // !_MODULES } +bool CModules::UnloadModule(const CString& sModule) { + CString s; + return UnloadModule(sModule, s); +} + bool CModules::UnloadModule(const CString& sModule, CString& sRetMsg) { #ifndef _MODULES sRetMsg = "Unable to unload module [" + sModule + "] module support was not enabled."; diff --git a/Modules.h b/Modules.h index 93cf6a86..315fc477 100644 --- a/Modules.h +++ b/Modules.h @@ -96,6 +96,18 @@ public: CModule(void* pDLL, CUser* pUser, const CString& sModName); virtual ~CModule(); + typedef enum { + CONTINUE = 1, + HALT = 2, + HALTMODS = 3, + HALTCORE = 4 + } EModRet; + + typedef enum { + UNLOAD + } EModException; + + void Unload(); virtual CString GetDescription(); virtual bool OnLoad(const CString& sArgs); @@ -105,7 +117,7 @@ public: virtual void OnIRCDisconnected(); virtual void OnIRCConnected(); - virtual bool OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize); + virtual EModRet OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize); virtual void OnChanPermission(const CNick& OpNick, const CNick& Nick, const CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange); virtual void OnOp(const CNick& OpNick, const CNick& Nick, const CChan& Channel, bool bNoChange); @@ -114,10 +126,10 @@ public: virtual void OnDevoice(const CNick& OpNick, const CNick& Nick, const CChan& Channel, bool bNoChange); virtual void OnRawMode(const CNick& OpNick, const CChan& Channel, const CString& sModes, const CString& sArgs); - virtual bool OnUserRaw(CString& sLine); - virtual bool OnRaw(CString& sLine); + virtual EModRet OnUserRaw(CString& sLine); + virtual EModRet OnRaw(CString& sLine); - virtual bool OnStatusCommand(const CString& sCommand); + virtual EModRet OnStatusCommand(const CString& sCommand); virtual void OnModCommand(const CString& sCommand); virtual void OnModNotice(const CString& sMessage); virtual void OnModCTCP(const CString& sMessage); @@ -128,17 +140,17 @@ public: virtual void OnJoin(const CNick& Nick, const CChan& Channel); virtual void OnPart(const CNick& Nick, const CChan& Channel); - virtual bool OnUserCTCPReply(const CNick& Nick, CString& sMessage); - virtual bool OnCTCPReply(const CNick& Nick, CString& sMessage); - virtual bool OnUserCTCP(const CString& sTarget, CString& sMessage); - virtual bool OnPrivCTCP(const CNick& Nick, CString& sMessage); - virtual bool OnChanCTCP(const CNick& Nick, const CChan& Channel, CString& sMessage); - virtual bool OnUserMsg(const CString& sTarget, CString& sMessage); - virtual bool OnPrivMsg(const CNick& Nick, CString& sMessage); - virtual bool OnChanMsg(const CNick& Nick, const CChan& Channel, CString& sMessage); - virtual bool OnUserNotice(const CString& sTarget, CString& sMessage); - virtual bool OnPrivNotice(const CNick& Nick, CString& sMessage); - virtual bool OnChanNotice(const CNick& Nick, const CChan& Channel, CString& sMessage); + virtual EModRet OnUserCTCPReply(const CNick& Nick, CString& sMessage); + virtual EModRet OnCTCPReply(const CNick& Nick, CString& sMessage); + virtual EModRet OnUserCTCP(const CString& sTarget, CString& sMessage); + virtual EModRet OnPrivCTCP(const CNick& Nick, CString& sMessage); + virtual EModRet OnChanCTCP(const CNick& Nick, const CChan& Channel, CString& sMessage); + virtual EModRet OnUserMsg(const CString& sTarget, CString& sMessage); + virtual EModRet OnPrivMsg(const CNick& Nick, CString& sMessage); + virtual EModRet OnChanMsg(const CNick& Nick, const CChan& Channel, CString& sMessage); + virtual EModRet OnUserNotice(const CString& sTarget, CString& sMessage); + virtual EModRet OnPrivNotice(const CNick& Nick, CString& sMessage); + virtual EModRet OnChanNotice(const CNick& Nick, const CChan& Channel, CString& sMessage); void * GetDLL(); static double GetVersion() { return VERSION; } @@ -188,8 +200,8 @@ public: void UnloadAll(); - virtual bool OnLoad(const CString& sArgs); - virtual bool OnBoot(); + virtual bool OnLoad(const CString& sArgs); // Return false to abort + virtual bool OnBoot(); // Return false to abort virtual void OnUserAttached(); virtual void OnUserDetached(); virtual void OnIRCDisconnected(); @@ -232,6 +244,7 @@ public: CModule* FindModule(const CString& sModule); bool LoadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg); + bool UnloadModule(const CString& sModule); bool UnloadModule(const CString& sModule, CString& sRetMsg); bool ReloadModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg); diff --git a/modules/away.cpp b/modules/away.cpp index 2bb597f7..64772a08 100644 --- a/modules/away.cpp +++ b/modules/away.cpp @@ -20,6 +20,9 @@ * * * $Log$ + * Revision 1.13 2005/05/15 08:27:27 prozacx + * Changed return value from bool to EModRet on most hooks + * * Revision 1.12 2005/05/08 06:42:01 prozacx * Moved CUtils::ToString() into CString class * @@ -349,28 +352,28 @@ public: m_sReason = ""; } - virtual bool OnPrivMsg(const CNick& Nick, CString& sMessage) + virtual EModRet OnPrivMsg(const CNick& Nick, CString& sMessage) { if ( m_bIsAway ) AddMessage( time( NULL ), Nick, sMessage ); - return( false ); + return( CONTINUE ); } - virtual bool OnUserNotice(const CString& sTarget, CString& sMessage) + virtual EModRet OnUserNotice(const CString& sTarget, CString& sMessage) { Ping(); if( m_bIsAway ) Back(); - return( false ); + return( CONTINUE ); } - virtual bool OnUserMsg(const CString& sTarget, CString& sMessage) + virtual EModRet OnUserMsg(const CString& sTarget, CString& sMessage) { Ping(); if( m_bIsAway ) Back(); - return( false ); + return( CONTINUE ); } time_t GetTimeStamp() const { return( m_iLastSentData ); } diff --git a/modules/raw.cpp b/modules/raw.cpp index cede80db..32d033f5 100644 --- a/modules/raw.cpp +++ b/modules/raw.cpp @@ -13,14 +13,14 @@ public: return "View all of the raw traffic."; } - virtual bool OnRaw(CString& sLine) { + virtual EModRet OnRaw(CString& sLine) { PutModule("IRC -> [" + sLine + "]"); - return false; + return CONTINUE; } - virtual bool OnUserRaw(CString& sLine) { + virtual EModRet OnUserRaw(CString& sLine) { PutModule("YOU -> [" + sLine + "]"); - return false; + return CONTINUE; } }; diff --git a/modules/sample.cpp b/modules/sample.cpp index 9ad6fc0a..567c49dd 100644 --- a/modules/sample.cpp +++ b/modules/sample.cpp @@ -74,14 +74,14 @@ public: PutModule("* " + OpNick.GetNick() + " sets mode: " + sModes + " " + sArgs + " (" + Channel.GetName() + ")"); } - virtual bool OnRaw(CString& sLine) { + virtual EModRet OnRaw(CString& sLine) { // PutModule("OnRaw() [" + sLine + "]"); - return false; + return CONTINUE; } - virtual bool OnUserRaw(CString& sLine) { + virtual EModRet OnUserRaw(CString& sLine) { // PutModule("UserRaw() [" + sLine + "]"); - return false; + return CONTINUE; } virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, const CChan& Channel, const CString& sMessage) { @@ -104,82 +104,84 @@ public: PutModule("* " + OldNick.GetNick() + " is now known as " + sNewNick); } - virtual bool OnUserCTCPReply(const CNick& Nick, CString& sMessage) { + virtual EModRet OnUserCTCPReply(const CNick& Nick, CString& sMessage) { PutModule("[" + Nick.GetNick() + "] userctcpreply [" + sMessage + "]"); sMessage = "\037" + sMessage + "\037"; - return false; + return CONTINUE; } - virtual bool OnCTCPReply(const CNick& Nick, CString& sMessage) { + virtual EModRet OnCTCPReply(const CNick& Nick, CString& sMessage) { PutModule("[" + Nick.GetNick() + "] ctcpreply [" + sMessage + "]"); - return false; + return CONTINUE; } - virtual bool OnUserCTCP(const CString& sTarget, CString& sMessage) { + virtual EModRet OnUserCTCP(const CString& sTarget, CString& sMessage) { PutModule("[" + sTarget + "] userctcp [" + sMessage + "]"); - return false; + return CONTINUE; } - virtual bool OnPrivCTCP(const CNick& Nick, CString& sMessage) { + virtual EModRet OnPrivCTCP(const CNick& Nick, CString& sMessage) { PutModule("[" + Nick.GetNick() + "] privctcp [" + sMessage + "]"); sMessage = "\002" + sMessage + "\002"; - return false; + return CONTINUE; } - virtual bool OnChanCTCP(const CNick& Nick, const CChan& Channel, CString& sMessage) { + virtual EModRet OnChanCTCP(const CNick& Nick, const CChan& Channel, CString& sMessage) { PutModule("[" + Nick.GetNick() + "] chanctcp [" + sMessage + "] to [" + Channel.GetName() + "]"); sMessage = "\00311,5 " + sMessage + " \003"; - return false; + return CONTINUE; } - virtual bool OnUserNotice(const CString& sTarget, CString& sMessage) { + virtual EModRet OnUserNotice(const CString& sTarget, CString& sMessage) { PutModule("[" + sTarget + "] usernotice [" + sMessage + "]"); sMessage = "\037" + sMessage + "\037"; - return false; + return CONTINUE; } - virtual bool OnPrivNotice(const CNick& Nick, CString& sMessage) { + virtual EModRet OnPrivNotice(const CNick& Nick, CString& sMessage) { PutModule("[" + Nick.GetNick() + "] privnotice [" + sMessage + "]"); sMessage = "\002" + sMessage + "\002"; - return false; + return CONTINUE; } - virtual bool OnChanNotice(const CNick& Nick, const CChan& Channel, CString& sMessage) { + virtual EModRet OnChanNotice(const CNick& Nick, const CChan& Channel, CString& sMessage) { PutModule("[" + Nick.GetNick() + "] channotice [" + sMessage + "] to [" + Channel.GetName() + "]"); sMessage = "\00311,5 " + sMessage + " \003"; - return false; + return CONTINUE; } - virtual bool OnUserMsg(const CString& sTarget, CString& sMessage) { + virtual EModRet OnUserMsg(const CString& sTarget, CString& sMessage) { PutModule("[" + sTarget + "] usermsg [" + sMessage + "]"); sMessage = "\0034" + sMessage + "\003"; - return false; + return CONTINUE; } - virtual bool OnPrivMsg(const CNick& Nick, CString& sMessage) { + virtual EModRet OnPrivMsg(const CNick& Nick, CString& sMessage) { PutModule("[" + Nick.GetNick() + "] privmsg [" + sMessage + "]"); sMessage = "\002" + sMessage + "\002"; - return false; + return CONTINUE; } - virtual bool OnChanMsg(const CNick& Nick, const CChan& Channel, CString& sMessage) { + virtual EModRet OnChanMsg(const CNick& Nick, const CChan& Channel, CString& sMessage) { if (sMessage == "!ping") { PutIRC("PRIVMSG " + Channel.GetName() + " :PONG?"); } sMessage = "x " + sMessage + " x"; - return false; + PutModule(sMessage); + + return HALTCORE; } virtual void OnModCommand(const CString& sCommand) { @@ -188,13 +190,13 @@ public: } } - virtual bool OnStatusCommand(const CString& sCommand) { + virtual EModRet OnStatusCommand(const CString& sCommand) { if (strcasecmp(sCommand.c_str(), "SAMPLE") == 0) { PutModule("Hi, I'm your friendly sample module."); - return true; + return HALT; } - return false; + return CONTINUE; } }; diff --git a/modules/schat.cpp b/modules/schat.cpp index 87b0fa86..6861f030 100644 --- a/modules/schat.cpp +++ b/modules/schat.cpp @@ -16,6 +16,9 @@ * Author: imaginos * * $Log$ + * Revision 1.13 2005/05/15 08:27:27 prozacx + * Changed return value from bool to EModRet on most hooks + * * Revision 1.12 2005/05/08 06:42:02 prozacx * Moved CUtils::ToString() into CString class * @@ -213,22 +216,22 @@ public: return ( "Secure cross platform (:P) chat system" ); } - virtual bool OnUserRaw( CString & sLine ) + virtual EModRet OnUserRaw( CString & sLine ) { if ( strncasecmp( sLine.c_str(), "schat ", 6 ) == 0 ) { OnModCommand( "chat " + sLine.substr( 6, CString::npos ) ); - return( true ); + return( HALT ); } else if ( strcasecmp( sLine.c_str(), "schat" ) == 0 ) { PutModule( "SChat User Area ..." ); OnModCommand( "help" ); - return( true ); + return( HALT ); } - return( false ); + return( CONTINUE ); } virtual void OnModCommand( const CString& sCommand ) { @@ -423,7 +426,7 @@ public: PutModule( "Unknown command [" + sCom + "] [" + sArgs + "]" ); } - virtual bool OnPrivCTCP( const CNick& Nick, CString& sMessage ) + virtual EModRet OnPrivCTCP( const CNick& Nick, CString& sMessage ) { if ( strncasecmp( sMessage.c_str(), "DCC SCHAT ", 10 ) == 0 ) { @@ -441,11 +444,11 @@ public: CRemMarkerJob *p = new CRemMarkerJob( this, 60, 1, "Remove (s)" + Nick.GetNick(), "Removes this nicks entry for waiting DCC." ); p->SetNick( "(s)" + Nick.GetNick() ); AddTimer( p ); - return( true ); + return( HALT ); } } - return( false ); + return( CONTINUE ); } void AcceptSDCC( const CString & sNick, u_long iIP, u_short iPort ) @@ -457,7 +460,7 @@ public: m_pManager->Connect( CUtils::GetIP( iIP ), iPort, sSockName, 60, true, m_pUser->GetLocalIP(), p ); RemTimer( "Remove " + sNick ); // delete any associated timer to this nick } - virtual bool OnUserMsg( const CString& sTarget, CString& sMessage ) + virtual EModRet OnUserMsg( const CString& sTarget, CString& sMessage ) { if ( strncmp( sTarget.c_str(), "(s)", 3 ) == 0 ) { @@ -474,15 +477,15 @@ public: AcceptSDCC( sTarget, it->second.first, it->second.second ); m_siiWaitingChats.erase( it ); - return( true ); + return( HALT ); } PutModule( "No such SCHAT to [" + sTarget + "]" ); } else p->Write( sMessage + "\n" ); - return( true ); + return( HALT ); } - return( false ); + return( CONTINUE ); } virtual void RemoveMarker( const CString & sNick ) diff --git a/modules/shell.cpp b/modules/shell.cpp index 125c8462..c837f666 100644 --- a/modules/shell.cpp +++ b/modules/shell.cpp @@ -154,25 +154,25 @@ public: } } - virtual bool OnStatusCommand(const CString& sCommand) { + virtual EModRet OnStatusCommand(const CString& sCommand) { if (strcasecmp(sCommand.c_str(), "SHELL") == 0) { PutShell("-- ZNC Shell Service --"); - return true; + return HALT; } - return false; + return CONTINUE; } - virtual bool OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) { + virtual EModRet OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize) { if (strcasecmp(RemoteNick.GetNick().c_str(), CString(GetModNick()).c_str()) == 0) { CString sLocalFile = CUtils::ChangeDir(m_sPath, sFile, m_pUser->GetHomePath()); m_pUser->GetFile(m_pUser->GetCurNick(), CUtils::GetIP(uLongIP), uPort, sLocalFile, uFileSize, GetModName()); - return true; + return HALT; } - return false; + return CONTINUE; } void PutShell(const CString& sLine) { diff --git a/modules/watch.cpp b/modules/watch.cpp index 6d52c783..8435fac4 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -177,13 +177,13 @@ public: m_Buffer.Clear(); } - virtual bool OnUserRaw(CString& sLine) { + virtual EModRet OnUserRaw(CString& sLine) { if (strncasecmp(sLine.c_str(), "WATCH ", 6) == 0) { Watch(sLine.Token(1), sLine.Token(2), sLine.Token(3, true), true); - return true; + return HALT; } - return false; + return CONTINUE; } virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, const CChan& Channel, const CString& sMessage) { @@ -206,39 +206,39 @@ public: Process(OldNick, "* " + OldNick.GetNick() + " is now known as " + sNewNick, ""); } - virtual bool OnCTCPReply(const CNick& Nick, CString& sMessage) { + virtual EModRet OnCTCPReply(const CNick& Nick, CString& sMessage) { Process(Nick, "* CTCP: " + Nick.GetNick() + " reply [" + sMessage + "]", "priv"); - return false; + return CONTINUE; } - virtual bool OnPrivCTCP(const CNick& Nick, CString& sMessage) { + virtual EModRet OnPrivCTCP(const CNick& Nick, CString& sMessage) { Process(Nick, "* CTCP: " + Nick.GetNick() + " [" + sMessage + "]", "priv"); - return false; + return CONTINUE; } - virtual bool OnChanCTCP(const CNick& Nick, const CChan& Channel, CString& sMessage) { + virtual EModRet OnChanCTCP(const CNick& Nick, const CChan& Channel, CString& sMessage) { Process(Nick, "* CTCP: " + Nick.GetNick() + " [" + sMessage + "] to [" + Channel.GetName() + "]", Channel.GetName()); - return false; + return CONTINUE; } - virtual bool OnPrivNotice(const CNick& Nick, CString& sMessage) { + virtual EModRet OnPrivNotice(const CNick& Nick, CString& sMessage) { Process(Nick, "-" + Nick.GetNick() + "- " + sMessage, "priv"); - return false; + return CONTINUE; } - virtual bool OnChanNotice(const CNick& Nick, const CChan& Channel, CString& sMessage) { + virtual EModRet OnChanNotice(const CNick& Nick, const CChan& Channel, CString& sMessage) { Process(Nick, "-" + Nick.GetNick() + ":" + Channel.GetName() + "- " + sMessage, Channel.GetName()); - return false; + return CONTINUE; } - virtual bool OnPrivMsg(const CNick& Nick, CString& sMessage) { + virtual EModRet OnPrivMsg(const CNick& Nick, CString& sMessage) { Process(Nick, "<" + Nick.GetNick() + "> " + sMessage, "priv"); - return false; + return CONTINUE; } - virtual bool OnChanMsg(const CNick& Nick, const CChan& Channel, CString& sMessage) { + virtual EModRet OnChanMsg(const CNick& Nick, const CChan& Channel, CString& sMessage) { Process(Nick, "<" + Nick.GetNick() + ":" + Channel.GetName() + "> " + sMessage, Channel.GetName()); - return false; + return CONTINUE; } virtual void OnModCommand(const CString& sCommand) {