diff --git a/Buffer.cpp b/Buffer.cpp index bb59c0f5..95c24757 100644 --- a/Buffer.cpp +++ b/Buffer.cpp @@ -2,15 +2,19 @@ #include "Buffer.h" -CBufLine::CBufLine(const CString& sPre, const CString& sPost) { +CBufLine::CBufLine(const CString& sPre, const CString& sPost, bool bIncNick=true) { m_sPre = sPre; m_sPost = sPost; + m_bIncNick = bIncNick; } CBufLine::~CBufLine() {} void CBufLine::GetLine(const CString& sTarget, CString& sRet) { - sRet = m_sPre + sTarget + m_sPost; + if(m_bIncNick) + sRet = m_sPre + sTarget + m_sPost; + else + sRet = m_sPre + m_sPost; } CBuffer::CBuffer(unsigned int uLineCount) { @@ -19,7 +23,7 @@ CBuffer::CBuffer(unsigned int uLineCount) { CBuffer::~CBuffer() {} -int CBuffer::AddLine(const CString& sPre, const CString& sPost) { +int CBuffer::AddLine(const CString& sPre, const CString& sPost, bool bIncNick) { if (!m_uLineCount) { return 0; } @@ -28,7 +32,7 @@ int CBuffer::AddLine(const CString& sPre, const CString& sPost) { erase(begin()); } - push_back(CBufLine(sPre, sPost)); + push_back(CBufLine(sPre, sPost, bIncNick)); return size(); } diff --git a/Buffer.h b/Buffer.h index d05144fa..5fd31566 100644 --- a/Buffer.h +++ b/Buffer.h @@ -9,7 +9,7 @@ using std::vector; class CBufLine { public: - CBufLine(const CString& sPre, const CString& sPost); + CBufLine(const CString& sPre, const CString& sPost, bool bIncNick); virtual ~CBufLine(); void GetLine(const CString& sTarget, CString& sRet); @@ -17,6 +17,7 @@ private: protected: CString m_sPre; CString m_sPost; + bool m_bIncNick; }; class CBuffer : private vector { @@ -24,7 +25,7 @@ public: CBuffer(unsigned int uLineCount = 100); virtual ~CBuffer(); - int AddLine(const CString& sPre, const CString& sPost); + int AddLine(const CString& sPre, const CString& sPost, bool bIncNick = true); bool GetNextLine(const CString& sTarget, CString& sRet); bool GetLine(const CString& sTarget, CString& sRet, unsigned int uIdx); bool IsEmpty() { return empty(); } diff --git a/IRCSock.cpp b/IRCSock.cpp index 3b64f77a..7018e02f 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -634,6 +634,10 @@ void CIRCSock::ReadLine(const CString& sData) { m_pUser->PutUser(":" + Nick.GetNickMask() + " PRIVMSG " + sTarget + " :" + sMsg); return; } + } else if (sCmd.CaseCmp("WALLOPS") == 0) { + // :blub!dummy@rox-8DBEFE92 WALLOPS :this is a test + CString sMsg = sRest.Token(0, true); + m_pUser->AddQueryBuffer(":" + Nick.GetNickMask() + " WALLOPS ", sMsg, false); } } } diff --git a/User.h b/User.h index 5bbb4bfd..a18d5f57 100644 --- a/User.h +++ b/User.h @@ -66,9 +66,9 @@ public: #endif // Buffers - void AddRawBuffer(const CString& sPre, const CString& sPost) { m_RawBuffer.AddLine(sPre, sPost); } - void AddMotdBuffer(const CString& sPre, const CString& sPost) { m_MotdBuffer.AddLine(sPre, sPost); } - void AddQueryBuffer(const CString& sPre, const CString& sPost) { m_QueryBuffer.AddLine(sPre, sPost); } + void AddRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.AddLine(sPre, sPost, bIncNick); } + void AddMotdBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_MotdBuffer.AddLine(sPre, sPost, bIncNick); } + void AddQueryBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_QueryBuffer.AddLine(sPre, sPost, bIncNick); } void ClearRawBuffer() { m_RawBuffer.Clear(); } void ClearMotdBuffer() { m_MotdBuffer.Clear(); } void ClearQueryBuffer() { m_QueryBuffer.Clear(); } diff --git a/modules/antiidle.cpp b/modules/antiidle.cpp new file mode 100644 index 00000000..385a3d63 --- /dev/null +++ b/modules/antiidle.cpp @@ -0,0 +1,96 @@ +#include "main.h" +#include "User.h" +#include "Nick.h" +#include "Modules.h" + +class CAntiIdle; + +class CAntiIdleJob : public CTimer +{ +public: + CAntiIdleJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription) + : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {} + + virtual ~CAntiIdleJob() {} + +protected: + virtual void RunJob(); +}; + +class CAntiIdle : public CModule +{ +public: + MODCONSTRUCTOR(CAntiIdle) { + SetInterval(30); + } + + virtual ~CAntiIdle() { } + + virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) + { + if(!sArgs.Trim_n().empty()) + SetInterval(sArgs.ToInt()); + + return true; + } + + virtual void OnModCommand( const CString& sCommand ) + { + CString sCmdName = sCommand.Token(0).AsLower(); + if(sCmdName == "set") + { + CString sInterval = sCommand.Token(1, true); + SetInterval(sInterval.ToInt()); + + if(m_uiInterval == 0) + PutModule("AntiIdle is now turned off."); + else + PutModule("AntiIdle is now set to " + CString(m_uiInterval) + " seconds."); + } else if(sCmdName == "off") { + SetInterval(0); + PutModule("AntiIdle is now turned off"); + } else if(sCmdName == "show") { + if(m_uiInterval == 0) + PutModule("AntiIdle is turned off."); + else + PutModule("AntiIdle is set to " + CString(m_uiInterval) + " seconds."); + } else + { + PutModule("Commands: set, off, show"); + } + } + + virtual EModRet OnPrivMsg(CNick &Nick, CString &sMessage) { + if(Nick.GetNick() == GetUser()->GetIRCNick().GetNick() + && sMessage == "\xAE") + return HALTCORE; + + return CONTINUE; + } + +private: + void SetInterval(uint i) { + if(i < 0) + return; + + m_uiInterval = i; + + RemTimer("AntiIdle"); + + if(m_uiInterval == 0) { + return; + } + + AddTimer(new CAntiIdleJob(this, m_uiInterval, 0, "AntiIdle", "Periodically sends a msg to the user")); + } + + unsigned int m_uiInterval; +}; + +//! This function sends a query with (r) back to the user +void CAntiIdleJob::RunJob() { + CString sNick = GetModule()->GetUser()->GetIRCNick().GetNick(); + GetModule()->PutIRC("PRIVMSG " + sNick + " :\xAE"); +} + +MODULEDEFS(CAntiIdle, "Hides your real idle time")