From 3a16fe54c1344dd09b4a1a01c20bd1e8d6b7ae38 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 1 Mar 2011 20:31:35 -0700 Subject: [PATCH 1/2] Redo commands for send_raw modules. Also, use the new CModCommand stuff. --- modules/extra/send_raw.cpp | 68 ++++++++++++++++++-------- modules/extra/send_raw/tmpl/index.tmpl | 8 +-- 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/modules/extra/send_raw.cpp b/modules/extra/send_raw.cpp index 299786a2..d15eea2f 100644 --- a/modules/extra/send_raw.cpp +++ b/modules/extra/send_raw.cpp @@ -10,9 +10,30 @@ #include "znc.h" class CSendRaw_Mod: public CModule { -public: - MODCONSTRUCTOR(CSendRaw_Mod) {} + void SendClient(const CString& sLine) { + CUser *pUser = CZNC::Get().FindUser(sLine.Token(1)); + + if (pUser) { + pUser->PutUser(sLine.Token(2, true)); + PutModule("Sent [" + sLine.Token(2, true) + "] to " + pUser->GetUserName()); + } else { + PutModule("User [" + sLine.Token(1) + "] not found"); + } + } + + void SendServer(const CString& sLine) { + CUser *pUser = CZNC::Get().FindUser(sLine.Token(1)); + + if (pUser) { + pUser->PutIRC(sLine.Token(2, true)); + PutModule("Sent [" + sLine.Token(2, true) + "] to IRC Server of " + pUser->GetUserName()); + } else { + PutModule("User [" + sLine.Token(1) + "] not found"); + } + } + +public: virtual ~CSendRaw_Mod() { } @@ -32,18 +53,19 @@ public: if (sPageName == "index") { if (WebSock.IsPost()) { CUser *pUser = CZNC::Get().FindUser(WebSock.GetParam("user")); - bool bOutgoing = WebSock.GetParam("direction") == "out"; + bool bToServer = WebSock.GetParam("send_to") == "server"; const CString sLine = WebSock.GetParam("line"); if (!pUser) { - Tmpl["user"] = WebSock.GetParam("user"); - Tmpl[bOutgoing ? "direction_out" : "direction_in"] = "true"; - Tmpl["line"] = sLine; WebSock.GetSession()->AddError("User not found"); return true; } - if (bOutgoing) { + Tmpl["user"] = pUser->GetUserName(); + Tmpl[bToServer ? "to_server" : "to_client"] = "true"; + Tmpl["line"] = sLine; + + if (bToServer) { pUser->PutIRC(sLine); } else { pUser->PutUser(sLine); @@ -64,30 +86,36 @@ public: return false; } - virtual void OnModCommand(const CString& sLine) { + /* This is here for backwards compatibility. We used to accept commands in this format: + [] */ + virtual void OnUnknownModCommand(const CString& sLine) { const CString sUser = sLine.Token(0); const CString sDirection = sLine.Token(1); CUser *pUser = CZNC::Get().FindUser(sUser); if (!pUser) { - PutModule("User not found"); - PutModule("The expected format is: [] "); - PutModule("Out (default): The line will be sent to the user's IRC server"); - PutModule("In: The line will be sent to the user's IRC client"); + /* Since the user doesn't exist we'll adopt the default action of this method */ + PutModule("Unknown command!"); return; } - if (!sDirection.CaseCmp("in")) { - pUser->PutUser(sLine.Token(2, true)); - } else if (!sDirection.CaseCmp("out")) { - pUser->PutIRC(sLine.Token(2, true)); + if (sDirection.Equals("IN")) { + SendClient("Client " + sUser + " " + sLine.Token(2, true)); + } else if (sDirection.Equals("OUT")) { + SendServer("Server " + sUser + " " + sLine.Token(2, true)); } else { - /* The user did not supply a direction, let's send the line out. - We do this to preserve backwards compatibility. */ - pUser->PutIRC(sLine.Token(1, true)); + /* No direction given -- assume it's out for compatibility */ + SendServer("Server " + sUser + " " + sLine.Token(1, true)); } + } - PutModule("done"); + MODCONSTRUCTOR(CSendRaw_Mod) { + AddHelpCommand(); + AddCommand("Client", static_cast(&CSendRaw_Mod::SendClient), + "[user] [data to send]", "The data will be sent to the user's IRC client(s)"); + AddCommand("Server", static_cast(&CSendRaw_Mod::SendServer), + "[user] [data to send]", "The data will be sent to the IRC server the user is connected to"); + } }; diff --git a/modules/extra/send_raw/tmpl/index.tmpl b/modules/extra/send_raw/tmpl/index.tmpl index f36f8533..088e1aa9 100644 --- a/modules/extra/send_raw/tmpl/index.tmpl +++ b/modules/extra/send_raw/tmpl/index.tmpl @@ -18,11 +18,11 @@
-
Direction:
+
Send to:
- + +
From 98d8e5e37e3ec3ebfbfb47c4316ee63b2a6db9f1 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Wed, 8 Jun 2011 04:04:08 +0100 Subject: [PATCH 2/2] CUser: remove some non-existant methods from the headers These include: - SendFile - GetFile - ResumeFile Which were removed when DCC was moved out of the core --- User.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/User.h b/User.h index aa8b7e97..e61ca75d 100644 --- a/User.h +++ b/User.h @@ -121,9 +121,6 @@ public: CString AddTimestamp(const CString& sStr) const; CString& AddTimestamp(const CString& sStr, CString& sRet) const; - bool SendFile(const CString& sRemoteNick, const CString& sFileName, const CString& sModuleName = ""); - bool GetFile(const CString& sRemoteNick, const CString& sRemoteIP, unsigned short uRemotePort, const CString& sFileName, unsigned long uFileSize, const CString& sModuleName = ""); - bool ResumeFile(unsigned short uPort, unsigned long uFileSize); CString GetCurNick() const; bool Clone(const CUser& User, CString& sErrorRet, bool bCloneChans = true); void BounceAllClients();