1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
16 /* $ModDesc: /helpop Command, Works like Unreal helpop */
17 static std::map<irc::string, std::string> helpop_map;
20 /** Handles user mode +h
22 class Helpop : public SimpleUserModeHandler
25 Helpop(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'h') { }
30 class CommandHelpop : public Command
33 CommandHelpop (InspIRCd* Instance) : Command(Instance, "HELPOP", 0, 0)
35 this->source = "m_helpop.so";
36 syntax = "<any-text>";
39 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
41 irc::string parameter("start");
42 if (parameters.size() > 0)
43 parameter = parameters[0].c_str();
45 if (parameter == "index")
47 /* iterate over all helpop items */
48 user->WriteServ("290 %s :HELPOP topic index", user->nick.c_str());
49 for (std::map<irc::string, std::string>::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
51 user->WriteServ("292 %s : %s", user->nick.c_str(), iter->first.c_str());
53 user->WriteServ("292 %s :*** End of HELPOP topic index", user->nick.c_str());
57 user->WriteServ("290 %s :*** HELPOP for %s", user->nick.c_str(), parameter.c_str());
58 user->WriteServ("292 %s : -", user->nick.c_str());
60 std::map<irc::string, std::string>::iterator iter = helpop_map.find(parameter);
62 if (iter == helpop_map.end())
64 iter = helpop_map.find("nohelp");
67 std::string value = iter->second;
68 irc::sepstream stream(value, '\n');
69 std::string token = "*";
71 while (stream.GetToken(token))
73 // Writing a blank line will not work with some clients
75 user->WriteServ("292 %s : ", user->nick.c_str());
77 user->WriteServ("292 %s :%s", user->nick.c_str(), token.c_str());
80 user->WriteServ("292 %s : -", user->nick.c_str());
81 user->WriteServ("292 %s :*** End of HELPOP", user->nick.c_str());
84 /* We dont want these going out over the network, return CMD_FAILURE
85 * to make sure the protocol module thinks theyre not worth sending.
91 class ModuleHelpop : public Module
95 CommandHelpop* mycommand;
99 ModuleHelpop(InspIRCd* Me)
103 ho = new Helpop(ServerInstance);
104 if (!ServerInstance->Modes->AddMode(ho))
105 throw ModuleException("Could not add new modes!");
106 mycommand = new CommandHelpop(ServerInstance);
107 ServerInstance->AddCommand(mycommand);
108 Implementation eventlist[] = { I_OnRehash, I_OnWhois };
109 ServerInstance->Modules->Attach(eventlist, this, 2);
112 virtual void ReadConfig()
114 ConfigReader MyConf(ServerInstance);
118 for (int i = 0; i < MyConf.Enumerate("helpop"); i++)
120 irc::string key = assign(MyConf.ReadValue("helpop", "key", i));
121 std::string value = MyConf.ReadValue("helpop", "value", i, true); /* Linefeeds allowed! */
125 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
128 helpop_map[key] = value;
131 if (helpop_map.find("start") == helpop_map.end())
134 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
136 else if (helpop_map.find("nohelp") == helpop_map.end())
139 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
145 virtual void OnRehash(User* user, const std::string ¶meter)
150 virtual void OnWhois(User* src, User* dst)
152 if (dst->IsModeSet('h'))
154 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
158 virtual ~ModuleHelpop()
160 ServerInstance->Modes->DelMode(ho);
164 virtual Version GetVersion()
166 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
170 MODULE_INIT(ModuleHelpop)