Added global module functionality

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@348 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-05-22 00:47:36 +00:00
parent 41b5ea4398
commit 3dde793e62
10 changed files with 313 additions and 138 deletions

56
znc.cpp
View File

@@ -14,6 +14,7 @@
#endif
CZNC::CZNC() {
m_pModules = new CGlobalModules(this);
m_uListenPort = 0;
m_bISpoofLocked = false;
m_sISpoofFormat = "global { reply \"%\" }";
@@ -21,6 +22,8 @@ CZNC::CZNC() {
CZNC::~CZNC() {
#ifdef _MODULES
delete m_pModules;
for (map<CString,CUser*>::iterator a = m_msUsers.begin(); a != m_msUsers.end(); a++) {
a->second->GetModules().UnloadAll();
}
@@ -43,6 +46,10 @@ CString CZNC::GetTag(bool bIncludeVersion) {
}
bool CZNC::OnBoot() {
if (!GetModules().OnBoot()) {
return false;
}
for (map<CString,CUser*>::iterator it = m_msUsers.begin(); it != m_msUsers.end(); it++) {
if (!it->second->OnBoot()) {
return false;
@@ -534,6 +541,7 @@ bool CZNC::ParseConfig(const CString& sConfig) {
}
pUser = new CUser(sValue, this);
CUtils::PrintMessage("Loading user [" + sValue + "]");
bAutoCycle = true;
if (!sStatusPrefix.empty()) {
@@ -671,6 +679,9 @@ bool CZNC::ParseConfig(const CString& sConfig) {
try {
bool bModRet = pUser->GetModules().LoadModule(sModName, sArgs, pUser, sModRet);
CUtils::PrintStatus(bModRet, (bModRet) ? "" : sModRet);
if (!bModRet) {
return false;
}
} catch (CException e) {
CUtils::PrintStatus(false, sModRet);
return false;
@@ -742,6 +753,27 @@ bool CZNC::ParseConfig(const CString& sConfig) {
CUtils::PrintStatus(true);
continue;
} else if (sName.CaseCmp("LoadModule") == 0) {
CString sModName = sValue.Token(0);
CUtils::PrintAction("Loading Global Module [" + sModName + "]");
#ifdef _MODULES
CString sModRet;
CString sArgs = sValue.Token(1, true);
try {
bool bModRet = GetModules().LoadModule(sModName, sArgs, NULL, sModRet);
CUtils::PrintStatus(bModRet, (bModRet) ? "" : sModRet);
if (!bModRet) {
return false;
}
} catch (CException e) {
CUtils::PrintStatus(false, sModRet);
return false;
}
#else
CUtils::PrintStatus(false, "Modules are not enabled.");
#endif
continue;
} else if (sName.CaseCmp("ISpoofFormat") == 0) {
m_sISpoofFormat = sValue;
@@ -781,3 +813,27 @@ bool CZNC::ParseConfig(const CString& sConfig) {
return true;
}
CString CZNC::FindModPath(const CString& sModule) const {
CString sModPath = GetCurPath() + "/modules/" + sModule;
sModPath += (sModule.find(".") == CString::npos) ? ".so" : "";
if (!CFile::Exists(sModPath)) {
DEBUG_ONLY(cout << "[" << sModPath << "] Not found..." << endl);
sModPath = GetModPath() + "/" + sModule;
sModPath += (sModule.find(".") == CString::npos) ? ".so" : "";
if (!CFile::Exists(sModPath)) {
DEBUG_ONLY(cout << "[" << sModPath << "] Not found..." << endl);
sModPath = _MODDIR_ + CString("/") + sModule;
sModPath += (sModule.find(".") == CString::npos) ? ".so" : "";
if (!CFile::Exists(sModPath)) {
DEBUG_ONLY(cout << "[" << sModPath << "] Not found... giving up!" << endl);
return "";
}
}
}
return sModPath;
}