Created
May 4, 2011 16:47
-
-
Save kylef/955548 to your computer and use it in GitHub Desktop.
ZNC module to auth you with UserServ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2004-2011 See the AUTHORS file for details. | |
* | |
* This program is free software; you can redistribute it and/or modify it | |
* under the terms of the GNU General Public License version 2 as published | |
* by the Free Software Foundation. | |
*/ | |
#include "User.h" | |
class CUserServ : public CModule | |
{ | |
public: | |
MODCONSTRUCTOR(CUserServ) | |
{ | |
} | |
virtual ~CUserServ() | |
{ | |
} | |
virtual bool OnLoad(const CString& sArgs, CString& sMessage) | |
{ | |
if (sArgs.empty()) | |
m_sPass = GetNV("Password"); | |
else { | |
m_sPass = sArgs; | |
SetNV("Password", m_sPass); | |
SetArgs(""); | |
} | |
return true; | |
} | |
virtual void OnModCommand(const CString& sCommand) | |
{ | |
CString sCmdName = sCommand.Token(0).AsLower(); | |
if (sCmdName == "set") { | |
CString sPass = sCommand.Token(1, true); | |
m_sPass = sPass; | |
SetNV("Password", m_sPass); | |
PutModule("Password set"); | |
} else if (sCmdName == "clear") { | |
m_sPass = ""; | |
DelNV("Password"); | |
} else { | |
PutModule("Commands: set <password>, clear"); | |
} | |
} | |
void HandleMessage(CNick& Nick, const CString& sMessage) | |
{ | |
if (!m_sPass.empty() | |
&& Nick.GetNick().Equals("UserServ") | |
&& (sMessage.find("msg") != CString::npos | |
|| sMessage.find("authenticate") != CString::npos) | |
&& sMessage.AsUpper().find("IDENTIFY") != CString::npos | |
&& sMessage.find("help") == CString::npos) { | |
PutIRC("PRIVMSG UserServ :IDENTIFY " + m_sPass); | |
} | |
} | |
virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage) | |
{ | |
HandleMessage(Nick, sMessage); | |
return CONTINUE; | |
} | |
virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage) | |
{ | |
HandleMessage(Nick, sMessage); | |
return CONTINUE; | |
} | |
private: | |
CString m_sPass; | |
}; | |
MODULEDEFS(CUserServ, "Auths you with UserServ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment