/* +------------------------------------+ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * * InspIRCd: (C) 2002-2007 InspIRCd Development Team * See: http://www.inspircd.org/wiki/index.php/Credits * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ #include "users.h" #include "channels.h" #include "modules.h" #include "inspircd.h" /* $ModDesc: /helpop Command, Works like Unreal helpop */ static std::map helpop_map; /** Handles user mode +h */ class Helpop : public ModeHandler { public: Helpop(InspIRCd* Instance) : ModeHandler(Instance, 'h', 0, 0, false, MODETYPE_USER, true) { } ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) { if (adding) { if (!dest->IsModeSet('h')) { dest->SetMode('h',true); return MODEACTION_ALLOW; } } else { if (dest->IsModeSet('h')) { dest->SetMode('h',false); return MODEACTION_ALLOW; } } return MODEACTION_DENY; } }; /** Handles /HELPOP */ class cmd_helpop : public command_t { public: cmd_helpop (InspIRCd* Instance) : command_t(Instance, "HELPOP", 0, 1) { this->source = "m_helpop.so"; syntax = ""; } CmdResult Handle (const char** parameters, int pcnt, userrec *user) { irc::string parameter = parameters[0]; user->WriteServ("NOTICE %s :*** HELPOP for %s", user->nick, parameters[0]); if (parameter == "index") { /* iterate over all helpop items */ for (std::map::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++) { user->WriteServ("NOTICE %s :HELPOP KEY: %s", user->nick, iter->first.c_str()); } } else { std::map::iterator iter = helpop_map.find(parameter); if (iter == helpop_map.end()) { iter = helpop_map.find("nohelp"); } std::string value = iter->second; irc::sepstream stream(value, '\n'); std::string token = "*"; while ((token = stream.GetToken()) != "") { user->WriteServ("NOTICE %s :%s", user->nick, token.c_str()); } } user->WriteServ("NOTICE %s :*** HELPOP End", user->nick); return CMD_SUCCESS; } }; /** Thrown by m_helpop */ class HelpopException : public ModuleException { private: std::string err; public: HelpopException(std::string message) : err(message) { } ~HelpopException() throw() { }; virtual const char* GetReason() { return err.c_str(); } }; class ModuleHelpop : public Module { private: std::string h_file; cmd_helpop* mycommand; Helpop* ho; public: ModuleHelpop(InspIRCd* Me) : Module::Module(Me) { ReadConfig(); ho = new Helpop(ServerInstance); ServerInstance->AddMode(ho, 'h'); mycommand = new cmd_helpop(ServerInstance); ServerInstance->AddCommand(mycommand); } virtual void ReadConfig() { ConfigReader *MyConf = new ConfigReader(ServerInstance); helpop_map.clear(); for (int i = 0; i < MyConf->Enumerate("helpop"); i++) { irc::string key = assign(MyConf->ReadValue("helpop", "key", i)); std::string value = MyConf->ReadValue("helpop", "value", i); if (key == "index") { HelpopException e("m_helpop: The key 'index' is reserved for internal purposes. Please remove it."); throw(e); } helpop_map[key] = value; } if (helpop_map.find("start") == helpop_map.end()) { // error! HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf."); throw(e); } else if (helpop_map.find("nohelp") == helpop_map.end()) { // error! HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf."); throw(e); } } void Implements(char* List) { List[I_OnRehash] = List[I_OnWhois] = 1; } virtual void OnRehash(const std::string ¶meter) { ReadConfig(); } virtual void OnWhois(userrec* src, userrec* dst) { if (dst->IsModeSet('h')) { ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help."); } } virtual ~ModuleHelpop() { ServerInstance->Modes->DelMode(ho); DELETE(ho); } virtual Version GetVersion() { return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION); } }; class ModuleHelpopFactory : public ModuleFactory { public: ModuleHelpopFactory() { } ~ModuleHelpopFactory() { } virtual Module * CreateModule(InspIRCd* Me) { return new ModuleHelpop(Me); } }; extern "C" void * init_module( void ) { return new ModuleHelpopFactory; }