1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 /* $ModDesc: /helpop Command, Works like Unreal helpop */
20 static std::map<irc::string, std::string> helpop_map;
23 /** Handles user mode +h
25 class Helpop : public ModeHandler
28 Helpop(InspIRCd* Instance) : ModeHandler(Instance, 'h', 0, 0, false, MODETYPE_USER, true) { }
30 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
34 if (!dest->IsModeSet('h'))
36 dest->SetMode('h',true);
37 return MODEACTION_ALLOW;
42 if (dest->IsModeSet('h'))
44 dest->SetMode('h',false);
45 return MODEACTION_ALLOW;
49 return MODEACTION_DENY;
55 class cmd_helpop : public command_t
58 cmd_helpop (InspIRCd* Instance) : command_t(Instance, "HELPOP", 0, 0)
60 this->source = "m_helpop.so";
61 syntax = "<any-text>";
64 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
66 irc::string parameter;
68 parameter = parameters[0];
70 if (pcnt == 0 || parameter == "index")
72 /* iterate over all helpop items */
73 user->WriteServ("NOTICE %s :HELPOP topic index", user->nick);
74 for (std::map<irc::string, std::string>::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
76 user->WriteServ("NOTICE %s : %s", user->nick, iter->first.c_str());
78 user->WriteServ("NOTICE %s :*** End of HELPOP topic index", user->nick);
82 user->WriteServ("NOTICE %s :*** HELPOP for %s", user->nick, parameters[0]);
84 std::map<irc::string, std::string>::iterator iter = helpop_map.find(parameter);
86 if (iter == helpop_map.end())
88 iter = helpop_map.find("nohelp");
91 std::string value = iter->second;
92 irc::sepstream stream(value, '\n');
93 std::string token = "*";
95 while ((token = stream.GetToken()) != "")
97 user->WriteServ("NOTICE %s :%s", user->nick, token.c_str());
100 user->WriteServ("NOTICE %s :*** End of HELPOP", user->nick);
103 /* We dont want these going out over the network, return CMD_FAILURE
104 * to make sure the protocol module thinks theyre not worth sending.
110 class ModuleHelpop : public Module
114 cmd_helpop* mycommand;
118 ModuleHelpop(InspIRCd* Me)
122 ho = new Helpop(ServerInstance);
123 if (!ServerInstance->AddMode(ho, 'h'))
124 throw ModuleException("Could not add new modes!");
125 mycommand = new cmd_helpop(ServerInstance);
126 ServerInstance->AddCommand(mycommand);
129 virtual void ReadConfig()
131 ConfigReader *MyConf = new ConfigReader(ServerInstance);
135 for (int i = 0; i < MyConf->Enumerate("helpop"); i++)
137 irc::string key = assign(MyConf->ReadValue("helpop", "key", i));
138 std::string value = MyConf->ReadValue("helpop", "value", i, true); /* Linefeeds allowed! */
142 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
145 helpop_map[key] = value;
148 if (helpop_map.find("start") == helpop_map.end())
151 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
153 else if (helpop_map.find("nohelp") == helpop_map.end())
156 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
161 void Implements(char* List)
163 List[I_OnRehash] = List[I_OnWhois] = 1;
166 virtual void OnRehash(userrec* user, const std::string ¶meter)
171 virtual void OnWhois(userrec* src, userrec* dst)
173 if (dst->IsModeSet('h'))
175 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
179 virtual ~ModuleHelpop()
181 ServerInstance->Modes->DelMode(ho);
185 virtual Version GetVersion()
187 return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
191 class ModuleHelpopFactory : public ModuleFactory
194 ModuleHelpopFactory()
198 ~ModuleHelpopFactory()
202 virtual Module * CreateModule(InspIRCd* Me)
204 return new ModuleHelpop(Me);
209 extern "C" DllExport void * init_module( void )
211 return new ModuleHelpopFactory;