1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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 ModeHandler
25 Helpop(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'h', 0, 0, false, MODETYPE_USER, true) { }
27 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
31 if (!dest->IsModeSet('h'))
33 dest->SetMode('h',true);
34 return MODEACTION_ALLOW;
39 if (dest->IsModeSet('h'))
41 dest->SetMode('h',false);
42 return MODEACTION_ALLOW;
46 return MODEACTION_DENY;
52 class CommandHelpop : public Command
55 CommandHelpop (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator, "HELPOP", 0, 0)
57 syntax = "<any-text>";
60 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
62 irc::string parameter("start");
63 if (parameters.size() > 0)
64 parameter = parameters[0].c_str();
66 if (parameter == "index")
68 /* iterate over all helpop items */
69 user->WriteServ("290 %s :HELPOP topic index", user->nick.c_str());
70 for (std::map<irc::string, std::string>::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
72 user->WriteServ("292 %s : %s", user->nick.c_str(), iter->first.c_str());
74 user->WriteServ("292 %s :*** End of HELPOP topic index", user->nick.c_str());
78 user->WriteServ("290 %s :*** HELPOP for %s", user->nick.c_str(), parameter.c_str());
79 user->WriteServ("292 %s : -", user->nick.c_str());
81 std::map<irc::string, std::string>::iterator iter = helpop_map.find(parameter);
83 if (iter == helpop_map.end())
85 iter = helpop_map.find("nohelp");
88 std::string value = iter->second;
89 irc::sepstream stream(value, '\n');
90 std::string token = "*";
92 while (stream.GetToken(token))
94 // Writing a blank line will not work with some clients
96 user->WriteServ("292 %s : ", user->nick.c_str());
98 user->WriteServ("292 %s :%s", user->nick.c_str(), token.c_str());
101 user->WriteServ("292 %s : -", user->nick.c_str());
102 user->WriteServ("292 %s :*** End of HELPOP", user->nick.c_str());
105 /* We dont want these going out over the network, return CMD_FAILURE
106 * to make sure the protocol module thinks theyre not worth sending.
112 class ModuleHelpop : public Module
120 ModuleHelpop(InspIRCd* Me)
121 : Module(Me), cmd(Me, this), ho(Me, this)
124 if (!ServerInstance->Modes->AddMode(&ho))
125 throw ModuleException("Could not add new modes!");
126 ServerInstance->AddCommand(&cmd);
127 Implementation eventlist[] = { I_OnRehash, I_OnWhois };
128 ServerInstance->Modules->Attach(eventlist, this, 2);
131 virtual void ReadConfig()
133 ConfigReader MyConf(ServerInstance);
137 for (int i = 0; i < MyConf.Enumerate("helpop"); i++)
139 irc::string key = assign(MyConf.ReadValue("helpop", "key", i));
140 std::string value = MyConf.ReadValue("helpop", "value", i, true); /* Linefeeds allowed! */
144 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
147 helpop_map[key] = value;
150 if (helpop_map.find("start") == helpop_map.end())
153 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
155 else if (helpop_map.find("nohelp") == helpop_map.end())
158 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
164 virtual void OnRehash(User* user)
169 virtual void OnWhois(User* src, User* dst)
171 if (dst->IsModeSet('h'))
173 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
177 virtual ~ModuleHelpop()
179 ServerInstance->Modes->DelMode(&ho);
182 virtual Version GetVersion()
184 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
188 MODULE_INIT(ModuleHelpop)