controlpanel: $user and $network (#847)

IMHO these placeholder names are the most obvious choice and easiest
to remember. For old-timers and to retain compatibility, $me is still
supported. For the advanced users there's also $net for convenience.
This commit is contained in:
J-P Nurmi
2015-02-28 01:10:58 +01:00
parent a1165cfcca
commit 21c93c1658
+32 -32
View File
@@ -140,11 +140,11 @@ class CAdminMod : public CModule {
}
if (sCmdFilter.empty())
PutModule("You can use $me as the user name for modifying your own user.");
PutModule("You can use $user as the user name and $network as the network name for modifying your own user and network.");
}
CUser* FindUser(const CString& sUsername) {
if (sUsername.Equals("$me"))
if (sUsername.Equals("$me") || sUsername.Equals("$user"))
return GetUser();
CUser *pUser = CZNC::Get().FindUser(sUsername);
if (!pUser) {
@@ -158,6 +158,21 @@ class CAdminMod : public CModule {
return pUser;
}
CIRCNetwork* FindNetwork(CUser* pUser, const CString& sNetwork) {
if (sNetwork.Equals("$net") || sNetwork.Equals("$network")) {
if (pUser != GetUser()) {
PutModule("Error: You cannot use " + sNetwork + " to modify other users!");
return nullptr;
}
return CModule::GetNetwork();
}
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
if (!pNetwork) {
PutModule("Error: [" + pUser->GetUserName() + "] does not have a network named [" + sNetwork + "].");
}
return pNetwork;
}
void Get(const CString& sLine) {
const CString sVar = sLine.Token(1).AsLower();
CString sUsername = sLine.Token(2, true);
@@ -450,9 +465,8 @@ class CAdminMod : public CModule {
return;
}
pNetwork = pUser->FindNetwork(sNetwork);
pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork && !sNetwork.empty()) {
PutModule("Network [" + sNetwork + "] not found.");
return;
}
}
@@ -509,9 +523,8 @@ class CAdminMod : public CModule {
return;
}
pNetwork = pUser->FindNetwork(sNetwork);
pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork && !sNetwork.empty()) {
PutModule("Network [" + sNetwork + "] not found.");
return;
}
}
@@ -603,9 +616,8 @@ class CAdminMod : public CModule {
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("Error: [" + sUsername + "] does not have a network named [" + sNetwork + "].");
return;
}
@@ -635,9 +647,8 @@ class CAdminMod : public CModule {
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("Error: [" + sUsername + "] does not have a network named [" + sNetwork + "].");
return;
}
@@ -673,9 +684,8 @@ class CAdminMod : public CModule {
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("[" + sUsername + "] does not have a network named [" + sNetwork + "]");
return;
}
@@ -737,9 +747,8 @@ class CAdminMod : public CModule {
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("[" + sUsername + "] does not have a network named [" + sNetwork + "]");
return;
}
@@ -994,10 +1003,8 @@ class CAdminMod : public CModule {
return;
}
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("[" + pUser->GetUserName() + "] does not have a network with the name [" + sNetwork + "]");
return;
}
@@ -1066,9 +1073,8 @@ class CAdminMod : public CModule {
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("[" + sUsername + "] does not have a network with the name [" + sNetwork + "]");
return;
}
@@ -1094,9 +1100,8 @@ class CAdminMod : public CModule {
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("[" + sUsername + "] does not have a network with the name [" + sNetwork + "]");
return;
}
@@ -1121,9 +1126,8 @@ class CAdminMod : public CModule {
return;
}
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("[" + sUserName + "] does not have a network with the name [" + sNetwork + "]");
return;
}
@@ -1158,9 +1162,8 @@ class CAdminMod : public CModule {
return;
}
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("[" + sUserName + "] does not have a network with the name [" + sNetwork + "]");
return;
}
@@ -1303,9 +1306,8 @@ class CAdminMod : public CModule {
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("Network not found");
return;
}
@@ -1361,9 +1363,8 @@ class CAdminMod : public CModule {
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("Network not found");
return;
}
@@ -1417,9 +1418,8 @@ class CAdminMod : public CModule {
if (!pUser)
return;
CIRCNetwork* pNetwork = pUser->FindNetwork(sNetwork);
CIRCNetwork* pNetwork = FindNetwork(pUser, sNetwork);
if (!pNetwork) {
PutModule("Network not found");
return;
}
@@ -1433,7 +1433,7 @@ public:
AddCommand("Get", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::Get),
"<variable> [username]", "Prints the variable's value for the given or current user");
AddCommand("Set", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::Set),
"<variable> <username> <value>", "Sets the variable's value for the given user (use $me for the current user)");
"<variable> <username> <value>", "Sets the variable's value for the given user");
AddCommand("GetNetwork", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::GetNetwork),
"<variable> [username] [network]", "Prints the variable's value for the given network");
AddCommand("SetNetwork", static_cast<CModCommand::ModCmdFunc>(&CAdminMod::SetNetwork),