mirror of
https://github.com/znc/znc.git
synced 2026-06-21 18:45:18 +02:00
Modules: use public API
Avoid accessing protected member variables directly, so there's a chance of cleaning up the module API later.
This commit is contained in:
+37
-37
@@ -165,13 +165,13 @@ class CAdminMod : public CModule {
|
||||
|
||||
CUser* FindUser(const CString& sUsername) {
|
||||
if (sUsername.Equals("$me"))
|
||||
return m_pUser;
|
||||
return GetUser();
|
||||
CUser *pUser = CZNC::Get().FindUser(sUsername);
|
||||
if (!pUser) {
|
||||
PutModule("Error: User [" + sUsername + "] not found.");
|
||||
return NULL;
|
||||
}
|
||||
if (pUser != m_pUser && !m_pUser->IsAdmin()) {
|
||||
if (pUser != GetUser() && !GetUser()->IsAdmin()) {
|
||||
PutModule("Error: You need to have admin rights to modify other users!");
|
||||
return NULL;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
if (sUsername.empty()) {
|
||||
pUser = m_pUser;
|
||||
pUser = GetUser();
|
||||
} else {
|
||||
pUser = FindUser(sUsername);
|
||||
}
|
||||
@@ -286,14 +286,14 @@ class CAdminMod : public CModule {
|
||||
PutModule("RealName = " + sValue);
|
||||
}
|
||||
else if (sVar == "bindhost") {
|
||||
if(!pUser->DenySetBindHost() || m_pUser->IsAdmin()) {
|
||||
if (sValue.Equals(m_pUser->GetBindHost())) {
|
||||
if(!pUser->DenySetBindHost() || GetUser()->IsAdmin()) {
|
||||
if (sValue.Equals(GetUser()->GetBindHost())) {
|
||||
PutModule("This bind host is already set!");
|
||||
return;
|
||||
}
|
||||
|
||||
const VCString& vsHosts = CZNC::Get().GetBindHosts();
|
||||
if (!m_pUser->IsAdmin() && !vsHosts.empty()) {
|
||||
if (!GetUser()->IsAdmin() && !vsHosts.empty()) {
|
||||
VCString::const_iterator it;
|
||||
bool bFound = false;
|
||||
|
||||
@@ -305,7 +305,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
if (!bFound) {
|
||||
PutModule("You may not use this bind host. See /msg " + m_pUser->GetStatusPrefix() + "status ListBindHosts for a list");
|
||||
PutModule("You may not use this bind host. See /msg " + GetUser()->GetStatusPrefix() + "status ListBindHosts for a list");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -322,7 +322,7 @@ class CAdminMod : public CModule {
|
||||
PutModule("MultiClients = " + CString(b));
|
||||
}
|
||||
else if (sVar == "denyloadmod") {
|
||||
if(m_pUser->IsAdmin()) {
|
||||
if(GetUser()->IsAdmin()) {
|
||||
bool b = sValue.ToBool();
|
||||
pUser->SetDenyLoadMod(b);
|
||||
PutModule("DenyLoadMod = " + CString(b));
|
||||
@@ -331,7 +331,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
}
|
||||
else if (sVar == "denysetbindhost") {
|
||||
if(m_pUser->IsAdmin()) {
|
||||
if(GetUser()->IsAdmin()) {
|
||||
bool b = sValue.ToBool();
|
||||
pUser->SetDenySetBindHost(b);
|
||||
PutModule("DenySetBindHost = " + CString(b));
|
||||
@@ -350,7 +350,7 @@ class CAdminMod : public CModule {
|
||||
else if (sVar == "buffercount") {
|
||||
unsigned int i = sValue.ToUInt();
|
||||
// Admins don't have to honour the buffer limit
|
||||
if (pUser->SetBufferCount(i, m_pUser->IsAdmin())) {
|
||||
if (pUser->SetBufferCount(i, GetUser()->IsAdmin())) {
|
||||
PutModule("BufferCount = " + sValue);
|
||||
} else {
|
||||
PutModule("Setting failed, limit is " +
|
||||
@@ -384,7 +384,7 @@ class CAdminMod : public CModule {
|
||||
PutModule("MaxJoins = " + CString(pUser->MaxJoins()));
|
||||
}
|
||||
else if (sVar == "maxnetworks") {
|
||||
if(m_pUser->IsAdmin()) {
|
||||
if(GetUser()->IsAdmin()) {
|
||||
unsigned int i = sValue.ToUInt();
|
||||
pUser->SetMaxNetworks(i);
|
||||
PutModule("MaxNetworks = " + sValue);
|
||||
@@ -407,7 +407,7 @@ class CAdminMod : public CModule {
|
||||
PutModule("Timezone = " + pUser->GetTimezone());
|
||||
}
|
||||
else if (sVar == "admin") {
|
||||
if(m_pUser->IsAdmin() && pUser != m_pUser) {
|
||||
if(GetUser()->IsAdmin() && pUser != GetUser()) {
|
||||
bool b = sValue.ToBool();
|
||||
pUser->SetAdmin(b);
|
||||
PutModule("Admin = " + CString(pUser->IsAdmin()));
|
||||
@@ -430,7 +430,7 @@ class CAdminMod : public CModule {
|
||||
PutModule("TimestampFormat = " + sValue);
|
||||
}
|
||||
else if (sVar == "dccbindhost") {
|
||||
if(!pUser->DenySetBindHost() || m_pUser->IsAdmin()) {
|
||||
if(!pUser->DenySetBindHost() || GetUser()->IsAdmin()) {
|
||||
pUser->SetDCCBindHost(sValue);
|
||||
PutModule("DCCBindHost = " + sValue);
|
||||
} else {
|
||||
@@ -464,8 +464,8 @@ class CAdminMod : public CModule {
|
||||
CIRCNetwork *pNetwork = NULL;
|
||||
|
||||
if (sUsername.empty()) {
|
||||
pUser = m_pUser;
|
||||
pNetwork = m_pNetwork;
|
||||
pUser = GetUser();
|
||||
pNetwork = CModule::GetNetwork();
|
||||
} else {
|
||||
pUser = FindUser(sUsername);
|
||||
if (!pUser) {
|
||||
@@ -519,8 +519,8 @@ class CAdminMod : public CModule {
|
||||
CIRCNetwork *pNetwork = NULL;
|
||||
|
||||
if (sUsername.empty()) {
|
||||
pUser = m_pUser;
|
||||
pNetwork = m_pNetwork;
|
||||
pUser = GetUser();
|
||||
pNetwork = CModule::GetNetwork();
|
||||
} else {
|
||||
pUser = FindUser(sUsername);
|
||||
if (!pUser) {
|
||||
@@ -552,14 +552,14 @@ class CAdminMod : public CModule {
|
||||
pNetwork->SetRealName(sValue);
|
||||
PutModule("RealName = " + pNetwork->GetRealName());
|
||||
} else if (sVar.Equals("bindhost")) {
|
||||
if(!pUser->DenySetBindHost() || m_pUser->IsAdmin()) {
|
||||
if(!pUser->DenySetBindHost() || GetUser()->IsAdmin()) {
|
||||
if (sValue.Equals(pNetwork->GetBindHost())) {
|
||||
PutModule("This bind host is already set!");
|
||||
return;
|
||||
}
|
||||
|
||||
const VCString& vsHosts = CZNC::Get().GetBindHosts();
|
||||
if (!m_pUser->IsAdmin() && !vsHosts.empty()) {
|
||||
if (!GetUser()->IsAdmin() && !vsHosts.empty()) {
|
||||
VCString::const_iterator it;
|
||||
bool bFound = false;
|
||||
|
||||
@@ -571,7 +571,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
if (!bFound) {
|
||||
PutModule("You may not use this bind host. See /msg " + m_pUser->GetStatusPrefix() + "status ListBindHosts for a list");
|
||||
PutModule("You may not use this bind host. See /msg " + GetUser()->GetStatusPrefix() + "status ListBindHosts for a list");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -761,7 +761,7 @@ class CAdminMod : public CModule {
|
||||
} else if (sVar == "buffer") {
|
||||
unsigned int i = sValue.ToUInt();
|
||||
// Admins don't have to honour the buffer limit
|
||||
if (pChan->SetBufferCount(i, m_pUser->IsAdmin())) {
|
||||
if (pChan->SetBufferCount(i, GetUser()->IsAdmin())) {
|
||||
PutModule(pChan->GetName() + ": Buffer = " + sValue);
|
||||
} else {
|
||||
PutModule("Setting failed, limit is " +
|
||||
@@ -800,7 +800,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
void ListUsers(const CString&) {
|
||||
if (!m_pUser->IsAdmin())
|
||||
if (!GetUser()->IsAdmin())
|
||||
return;
|
||||
|
||||
const map<CString, CUser*>& msUsers = CZNC::Get().GetUserMap();
|
||||
@@ -831,7 +831,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
void AddUser(const CString& sLine) {
|
||||
if (!m_pUser->IsAdmin()) {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Error: You need to have admin rights to add new users!");
|
||||
return;
|
||||
}
|
||||
@@ -865,7 +865,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
void DelUser(const CString& sLine) {
|
||||
if (!m_pUser->IsAdmin()) {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Error: You need to have admin rights to delete users!");
|
||||
return;
|
||||
}
|
||||
@@ -883,7 +883,7 @@ class CAdminMod : public CModule {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pUser == m_pUser) {
|
||||
if (pUser == GetUser()) {
|
||||
PutModule("Error: You can't delete yourself!");
|
||||
return;
|
||||
}
|
||||
@@ -899,7 +899,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
void CloneUser(const CString& sLine) {
|
||||
if (!m_pUser->IsAdmin()) {
|
||||
if (!GetUser()->IsAdmin()) {
|
||||
PutModule("Error: You need to have admin rights to add new users!");
|
||||
return;
|
||||
}
|
||||
@@ -941,7 +941,7 @@ class CAdminMod : public CModule {
|
||||
void AddNetwork(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sNetwork = sLine.Token(2);
|
||||
CUser *pUser = m_pUser;
|
||||
CUser *pUser = GetUser();
|
||||
|
||||
if (sNetwork.empty()) {
|
||||
sNetwork = sUser;
|
||||
@@ -958,7 +958,7 @@ class CAdminMod : public CModule {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_pUser->IsAdmin() && !pUser->HasSpaceForNewNetwork()) {
|
||||
if (!GetUser()->IsAdmin() && !pUser->HasSpaceForNewNetwork()) {
|
||||
PutStatus("Network number limit reached. Ask an admin to increase the limit for you, or delete unneeded networks using /znc DelNetwork <name>");
|
||||
return;
|
||||
}
|
||||
@@ -979,7 +979,7 @@ class CAdminMod : public CModule {
|
||||
void DelNetwork(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CString sNetwork = sLine.Token(2);
|
||||
CUser *pUser = m_pUser;
|
||||
CUser *pUser = GetUser();
|
||||
|
||||
if (sNetwork.empty()) {
|
||||
sNetwork = sUser;
|
||||
@@ -1002,8 +1002,8 @@ class CAdminMod : public CModule {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pNetwork == m_pNetwork) {
|
||||
PutModule("The currently active network can be deleted via " + m_pUser->GetStatusPrefix() + "status");
|
||||
if (pNetwork == CModule::GetNetwork()) {
|
||||
PutModule("The currently active network can be deleted via " + GetUser()->GetStatusPrefix() + "status");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1016,7 +1016,7 @@ class CAdminMod : public CModule {
|
||||
|
||||
void ListNetworks(const CString& sLine) {
|
||||
CString sUser = sLine.Token(1);
|
||||
CUser *pUser = m_pUser;
|
||||
CUser *pUser = GetUser();
|
||||
|
||||
if (!sUser.empty()) {
|
||||
pUser = FindUser(sUser);
|
||||
@@ -1145,7 +1145,7 @@ class CAdminMod : public CModule {
|
||||
CString sUserName = sLine.Token(1, true);
|
||||
|
||||
if (sUserName.empty()) {
|
||||
sUserName = m_pUser->GetUserName();
|
||||
sUserName = GetUser()->GetUserName();
|
||||
}
|
||||
CUser* pUser = FindUser(sUserName);
|
||||
if (!pUser)
|
||||
@@ -1177,7 +1177,7 @@ class CAdminMod : public CModule {
|
||||
if (sCTCPRequest.empty()) {
|
||||
sCTCPRequest = sUserName;
|
||||
sCTCPReply = sLine.Token(2, true);
|
||||
sUserName = m_pUser->GetUserName();
|
||||
sUserName = GetUser()->GetUserName();
|
||||
}
|
||||
if (sCTCPRequest.empty()) {
|
||||
PutModule("Usage: AddCTCP [user] [request] [reply]");
|
||||
@@ -1202,7 +1202,7 @@ class CAdminMod : public CModule {
|
||||
|
||||
if (sCTCPRequest.empty()) {
|
||||
sCTCPRequest = sUserName;
|
||||
sUserName = m_pUser->GetUserName();
|
||||
sUserName = GetUser()->GetUserName();
|
||||
}
|
||||
CUser* pUser = FindUser(sUserName);
|
||||
if (!pUser)
|
||||
@@ -1220,7 +1220,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
void LoadModuleFor(CModules& Modules, const CString& sModName, const CString& sArgs, CModInfo::EModuleType eType, CUser* pUser, CIRCNetwork* pNetwork) {
|
||||
if (pUser->DenyLoadMod() && !m_pUser->IsAdmin()) {
|
||||
if (pUser->DenyLoadMod() && !GetUser()->IsAdmin()) {
|
||||
PutModule("Loading modules has been disabled.");
|
||||
return;
|
||||
}
|
||||
@@ -1286,7 +1286,7 @@ class CAdminMod : public CModule {
|
||||
}
|
||||
|
||||
void UnLoadModuleFor(CModules& Modules, const CString& sModName, CUser* pUser) {
|
||||
if (pUser->DenyLoadMod() && !m_pUser->IsAdmin()) {
|
||||
if (pUser->DenyLoadMod() && !GetUser()->IsAdmin()) {
|
||||
PutModule("Loading modules has been disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user