Permalink
Browse files

Admin: Add functions for listing/adding/removing CTCP replies

Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information...
1 parent c1bb18b commit 3f0e200073ed73a07c9c9c706e9bd047ebe90f85 @psychon psychon committed Feb 18, 2011
Showing with 73 additions and 1 deletion.
  1. +73 −1 modules/admin.cpp
View
74 modules/admin.cpp
@@ -49,7 +49,10 @@ class CAdminMod : public CModule {
{"Disconnect", "username", "Disconnects the user from their IRC server"},
{"LoadModule", "username modulename", "Loads a Module for a user"},
{"UnLoadModule", "username modulename", "Removes a Module of a user"},
- {"ListMods", "username", "Get the list of modules for a user"}
+ {"ListMods", "username", "Get the list of modules for a user"},
+ {"ListCTCPs", "username", "List the configured CTCP replies"},
+ {"AddCTCP", "username ctcp [reply]", "Configure a new CTCP reply"},
+ {"DelCTCP", "username ctcp", "Remove a CTCP reply"}
};
for (unsigned int i = 0; i != ARRAY_SIZE(help); ++i) {
CmdTable.AddRow();
@@ -674,6 +677,72 @@ class CAdminMod : public CModule {
PutModule("Closed user's IRC connection.");
}
+ void ListCTCP(const CString& sLine) {
+ CString sUsername = sLine.Token(1);
+
+ CUser* pUser = GetUser(sUsername);
+ if (!pUser)
+ return;
+
+ const MCString& msCTCPReplies = pUser->GetCTCPReplies();
+ CTable Table;
+ Table.AddColumn("Request");
+ Table.AddColumn("Reply");
+ for (MCString::const_iterator it = msCTCPReplies.begin(); it != msCTCPReplies.end(); it++) {
+ Table.AddRow();
+ Table.SetCell("Request", it->first);
+ Table.SetCell("Reply", it->second);
+ }
+
+ if (Table.empty()) {
+ PutModule("No CTCP replies for user [" + pUser->GetUserName() + "] configured!");
+ } else {
+ PutModule("CTCP replies for user [" + pUser->GetUserName() + "]:");
+ PutModule(Table);
+ }
+ }
+
+ void AddCTCP(const CString& sLine) {
+ CString sUsername = sLine.Token(1);
+ CString sCTCPRequest = sLine.Token(2);
+ CString sCTCPReply = sLine.Token(3, true);
+
+ if (sCTCPRequest.empty()) {
+ PutModule("Usage: AddCTCP [user] [request] [reply]");
+ PutModule("This will cause ZNC to reply to the CTCP instead of forwarding it to clients.");
+ PutModule("An empty reply will cause the CTCP request to be blocked.");
+ return;
+ }
+
+ CUser* pUser = GetUser(sUsername);
+ if (!pUser)
+ return;
+
+ if (pUser->AddCTCPReply(sCTCPRequest, sCTCPReply))
+ PutModule("Added!");
+ else
+ PutModule("Error!");
+ }
+
+ void DelCTCP(const CString& sLine) {
+ CString sUsername = sLine.Token(1);
+ CString sCTCPRequest = sLine.Token(2);
+
+ CUser* pUser = GetUser(sUsername);
+ if (!pUser)
+ return;
+
+ if (sCTCPRequest.empty()) {
+ PutModule("Usage: DelCTCP [user] [request]");
+ return;
+ }
+
+ if (pUser->DelCTCPReply(sCTCPRequest))
+ PutModule("Successfully removed [" + sCTCPRequest + "]");
+ else
+ PutModule("Error: [" + sCTCPRequest + "] not found!");
+ }
+
void LoadModuleForUser(const CString& sLine) {
CString sUsername = sLine.Token(1);
CString sModName = sLine.Token(2);
@@ -790,6 +859,9 @@ class CAdminMod : public CModule {
fnmap_["loadmodule"] = &CAdminMod::LoadModuleForUser;
fnmap_["unloadmodule"] = &CAdminMod::UnLoadModuleForUser;
fnmap_["listmods"] = &CAdminMod::ListModuleForUser;
+ fnmap_["listctcps"] = &CAdminMod::ListCTCP;
+ fnmap_["addctcp"] = &CAdminMod::AddCTCP;
+ fnmap_["delctcp"] = &CAdminMod::DelCTCP;
}
virtual ~CAdminMod() {}

0 comments on commit 3f0e200

Please sign in to comment.