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) : ModeHandler(Instance, 'h', 0, 0, false, MODETYPE_USER, true) { }
27 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
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) : Command(Instance, "HELPOP", 0, 0)
57 this->source = "m_helpop.so";
58 syntax = "<any-text>";
61 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
63 irc::string parameter("start");
64 if (parameters.size() > 0)
65 parameter = parameters[0].c_str();
67 if (parameter == "index")
69 /* iterate over all helpop items */
70 user->WriteServ("290 %s :HELPOP topic index", user->nick.c_str());
71 for (std::map<irc::string, std::string>::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
73 user->WriteServ("292 %s : %s", user->nick.c_str(), iter->first.c_str());
75 user->WriteServ("292 %s :*** End of HELPOP topic index", user->nick.c_str());
79 user->WriteServ("290 %s :*** HELPOP for %s", user->nick.c_str(), parameter.c_str());
80 user->WriteServ("292 %s : -", user->nick.c_str());
82 std::map<irc::string, std::string>::iterator iter = helpop_map.find(parameter);
84 if (iter == helpop_map.end())
86 iter = helpop_map.find("nohelp");
89 std::string value = iter->second;
90 irc::sepstream stream(value, '\n');
91 std::string token = "*";
93 while (stream.GetToken(token))
95 // Writing a blank line will not work with some clients
97 user->WriteServ("292 %s : ", user->nick.c_str());
99 user->WriteServ("292 %s :%s", user->nick.c_str(), token.c_str());
102 user->WriteServ("292 %s : -", user->nick.c_str());
103 user->WriteServ("292 %s :*** End of HELPOP", user->nick.c_str());
106 /* We dont want these going out over the network, return CMD_FAILURE
107 * to make sure the protocol module thinks theyre not worth sending.
113 class ModuleHelpop : public Module
117 CommandHelpop* mycommand;
121 ModuleHelpop(InspIRCd* Me)
125 ho = new Helpop(ServerInstance);
126 if (!ServerInstance->Modes->AddMode(ho))
127 throw ModuleException("Could not add new modes!");
128 mycommand = new CommandHelpop(ServerInstance);
129 ServerInstance->AddCommand(mycommand);
130 Implementation eventlist[] = { I_OnRehash, I_OnWhois };
131 ServerInstance->Modules->Attach(eventlist, this, 2);
134 virtual void ReadConfig()
136 ConfigReader MyConf(ServerInstance);
140 for (int i = 0; i < MyConf.Enumerate("helpop"); i++)
142 irc::string key = assign(MyConf.ReadValue("helpop", "key", i));
143 std::string value = MyConf.ReadValue("helpop", "value", i, true); /* Linefeeds allowed! */
147 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
150 helpop_map[key] = value;
153 if (helpop_map.find("start") == helpop_map.end())
156 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
158 else if (helpop_map.find("nohelp") == helpop_map.end())
161 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
167 virtual void OnRehash(User* user, const std::string ¶meter)
172 virtual void OnWhois(User* src, User* dst)
174 if (dst->IsModeSet('h'))
176 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
180 virtual ~ModuleHelpop()
182 ServerInstance->Modes->DelMode(ho);
186 virtual Version GetVersion()
188 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
192 MODULE_INIT(ModuleHelpop)