From 619436736b3b0da715f264d59f643ac6aa228d5b Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Wed, 4 Jul 2012 03:30:00 +0100 Subject: [PATCH] *admin: Add {Get,Set}Network command --- modules/admin.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/modules/admin.cpp b/modules/admin.cpp index 3c012742..bcea356f 100644 --- a/modules/admin.cpp +++ b/modules/admin.cpp @@ -73,6 +73,25 @@ class CAdminMod : public CModule { } PutModule(VarTable); + PutModule("The following variables are available when using the SetNetwork/GetNetwork commands:"); + + CTable NVarTable; + NVarTable.AddColumn("Variable"); + NVarTable.AddColumn("Type"); + static const char* nvars[][2] = { + {"Nick", str}, + {"Altnick", str}, + {"Ident", str}, + {"RealName", str}, + }; + for (unsigned int i = 0; i != ARRAY_SIZE(nvars); ++i) { + NVarTable.AddRow(); + NVarTable.SetCell("Variable", nvars[i][0]); + NVarTable.SetCell("Type", nvars[i][1]); + } + PutModule(NVarTable); + + PutModule("The following variables are available when using the SetChan/GetChan commands:"); CTable CVarTable; CVarTable.AddColumn("Variable"); @@ -322,6 +341,95 @@ class CAdminMod : public CModule { PutModule("Error: Unknown variable"); } + void GetNetwork(const CString& sLine) { + const CString sVar = sLine.Token(1).AsLower(); + const CString sUsername = sLine.Token(2); + const CString sNetwork = sLine.Token(3); + + CUser *pUser = NULL; + CIRCNetwork *pNetwork = NULL; + + if (sUsername.empty()) { + pUser = m_pUser; + pNetwork = m_pNetwork; + } else { + pUser = GetUser(sUsername); + if (!pUser) { + return; + } + + pNetwork = pUser->FindNetwork(sNetwork); + if (!pNetwork && !sNetwork.empty()) { + PutModule("Network not found."); + return; + } + } + + if (!pNetwork) { + PutModule("Usage: GetNetwork "); + return; + } + + if (sVar.Equals("nick")) { + PutModule("Nick = " + pNetwork->GetNick()); + } else if (sVar.Equals("altnick")) { + PutModule("AltNick = " + pNetwork->GetAltNick()); + } else if (sVar.Equals("ident")) { + PutModule("Ident = " + pNetwork->GetIdent()); + } else if (sVar.Equals("realname")) { + PutModule("RealName = " + pNetwork->GetRealName()); + } else { + PutModule("Error: Unknown variable"); + } + } + + void SetNetwork(const CString& sLine) { + const CString sVar = sLine.Token(1).AsLower(); + const CString sUsername = sLine.Token(2); + const CString sNetwork = sLine.Token(3); + const CString sValue = sLine.Token(4, true); + + CUser *pUser = NULL; + CIRCNetwork *pNetwork = NULL; + + if (sUsername.empty()) { + pUser = m_pUser; + pNetwork = m_pNetwork; + } else { + pUser = GetUser(sUsername); + if (!pUser) { + return; + } + + pNetwork = pUser->FindNetwork(sNetwork); + if (!pNetwork && !sNetwork.empty()) { + PutModule("Network not found."); + return; + } + } + + if (!pNetwork) { + PutModule("Usage: SetNetwork "); + return; + } + + if (sVar.Equals("nick")) { + pNetwork->SetNick(sValue); + PutModule("Nick = " + pNetwork->GetNick()); + } else if (sVar.Equals("altnick")) { + pNetwork->SetAltNick(sValue); + PutModule("AltNick = " + pNetwork->GetAltNick()); + } else if (sVar.Equals("ident")) { + pNetwork->SetIdent(sValue); + PutModule("Ident = " + pNetwork->GetIdent()); + } else if (sVar.Equals("realname")) { + pNetwork->SetRealName(sValue); + PutModule("RealName = " + pNetwork->GetRealName()); + } else { + PutModule("Error: Unknown variable"); + } + } + void GetChan(const CString& sLine) { const CString sVar = sLine.Token(1).AsLower(); CString sUsername = sLine.Token(2); @@ -951,6 +1059,10 @@ public: "variable [username]", "Prints the variable's value for the given or current user"); AddCommand("Set", static_cast(&CAdminMod::Set), "variable username value", "Sets the variable's value for the given user (use $me for the current user)"); + AddCommand("GetNetwork", static_cast(&CAdminMod::GetNetwork), + "variable [username network]", "Prints the variable's value for the given network"); + AddCommand("SetNetwork", static_cast(&CAdminMod::SetNetwork), + "variable username network value", "Sets the variable's value for the given network"); AddCommand("GetChan", static_cast(&CAdminMod::GetChan), "variable [username] network chan", "Prints the variable's value for the given channel"); AddCommand("SetChan", static_cast(&CAdminMod::SetChan),