From fdb16bb170bc8a89a54f0ef61c88c88efc7cfed0 Mon Sep 17 00:00:00 2001 From: cflakes Date: Sat, 9 Jan 2010 23:27:34 +0000 Subject: [PATCH] Overhaul for the send_raw module in extra. Mostly done by zynox, big thanks for that. Changes in detail: - send_raw is now a user module. It can only be loaded by admin users. - by prepending "in" or "out" to the /msg *send_raw command, e.g. /msg *send_raw testuser in :znc!znc@znc PRIVMSG #chan :Hello dude, only you can see this (znc user=testuser!) you can now also send raw IRC lines to the connected clients instead of just to the IRC server. - Fixed a spelling mistake. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1697 726aef4b-f618-498e-8847-2d620e286838 --- AUTHORS | 1 + modules/extra/send_raw.cpp | 40 +++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/AUTHORS b/AUTHORS index 960566f9..86fc36b3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -23,3 +23,4 @@ cnu - master of destruction (security issues) Ingmar "KiNgMaR" Runge Michael "Svedrin" Ziegler Robert Lacroix (http://www.robertlacroix.com) +zynox diff --git a/modules/extra/send_raw.cpp b/modules/extra/send_raw.cpp index c5deaac6..e1cdc799 100644 --- a/modules/extra/send_raw.cpp +++ b/modules/extra/send_raw.cpp @@ -9,34 +9,48 @@ #include "User.h" #include "znc.h" -class CSendRaw_Mod: public CGlobalModule { +class CSendRaw_Mod: public CModule { public: - GLOBALMODCONSTRUCTOR(CSendRaw_Mod) {} + MODCONSTRUCTOR(CSendRaw_Mod) {} virtual ~CSendRaw_Mod() { } - virtual void OnModCommand(const CString& sLine) { - CString sUser = sLine.Token(0); - CString sSend = sLine.Token(1, true); - CUser *pUser; - + virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) { if (!m_pUser->IsAdmin()) { - PutModule("You must have admin privileges to use this"); - return; + sErrorMsg = "You must have admin privileges to load this module"; + return false; } - pUser = CZNC::Get().FindUser(sUser); + return true; + } + + virtual void OnModCommand(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("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"); return; } - pUser->PutIRC(sSend); + if (!sDirection.CaseCmp("in")) { + pUser->PutUser(sLine.Token(2, true)); + } else if (!sDirection.CaseCmp("out")) { + pUser->PutIRC(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)); + } + PutModule("done"); } }; -GLOBALMODULEDEFS(CSendRaw_Mod, "Let's you send some raw IRC lines as someone else"); +MODULEDEFS(CSendRaw_Mod, "Lets you send some raw IRC lines as/to someone else"); +