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(Creator, 'h', PARAM_NONE, MODETYPE_USER)
30 ModeAction OnModeChange(User* source, User* dest, Channel* 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 CommandHelpop : public Command
58 CommandHelpop (InspIRCd* Instance, Module* Creator) : Command(Instance, Creator, "HELPOP", 0, 0)
60 syntax = "<any-text>";
63 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
65 irc::string parameter("start");
66 if (parameters.size() > 0)
67 parameter = parameters[0].c_str();
69 if (parameter == "index")
71 /* iterate over all helpop items */
72 user->WriteServ("290 %s :HELPOP topic index", user->nick.c_str());
73 for (std::map<irc::string, std::string>::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
75 user->WriteServ("292 %s : %s", user->nick.c_str(), iter->first.c_str());
77 user->WriteServ("292 %s :*** End of HELPOP topic index", user->nick.c_str());
81 user->WriteServ("290 %s :*** HELPOP for %s", user->nick.c_str(), parameter.c_str());
82 user->WriteServ("292 %s : -", user->nick.c_str());
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 (stream.GetToken(token))
97 // Writing a blank line will not work with some clients
99 user->WriteServ("292 %s : ", user->nick.c_str());
101 user->WriteServ("292 %s :%s", user->nick.c_str(), token.c_str());
104 user->WriteServ("292 %s : -", user->nick.c_str());
105 user->WriteServ("292 %s :*** End of HELPOP", user->nick.c_str());
108 /* We dont want these going out over the network, return CMD_FAILURE
109 * to make sure the protocol module thinks theyre not worth sending.
115 class ModuleHelpop : public Module
123 ModuleHelpop(InspIRCd* Me)
124 : Module(Me), cmd(Me, this), ho(Me, this)
127 if (!ServerInstance->Modes->AddMode(&ho))
128 throw ModuleException("Could not add new modes!");
129 ServerInstance->AddCommand(&cmd);
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)
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);
185 virtual Version GetVersion()
187 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
191 MODULE_INIT(ModuleHelpop)