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 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 char* const* parameters, int pcnt, User *user)
63 irc::string parameter("start");
65 parameter = parameters[0];
67 if (parameter == "index")
69 /* iterate over all helpop items */
70 user->WriteServ("NOTICE %s :HELPOP topic index", user->nick);
71 for (std::map<irc::string, std::string>::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
73 user->WriteServ("NOTICE %s : %s", user->nick, iter->first.c_str());
75 user->WriteServ("NOTICE %s :*** End of HELPOP topic index", user->nick);
79 user->WriteServ("NOTICE %s :*** HELPOP for %s", user->nick, parameter.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))
93 user->WriteServ("NOTICE %s :%s", user->nick, token.c_str());
95 user->WriteServ("NOTICE %s :*** End of HELPOP", user->nick);
98 /* We dont want these going out over the network, return CMD_FAILURE
99 * to make sure the protocol module thinks theyre not worth sending.
105 class ModuleHelpop : public Module
109 CommandHelpop* mycommand;
113 ModuleHelpop(InspIRCd* Me)
117 ho = new Helpop(ServerInstance);
118 if (!ServerInstance->Modes->AddMode(ho))
119 throw ModuleException("Could not add new modes!");
120 mycommand = new CommandHelpop(ServerInstance);
121 ServerInstance->AddCommand(mycommand);
122 Implementation eventlist[] = { I_OnRehash, I_OnWhois };
123 ServerInstance->Modules->Attach(eventlist, this, 2);
126 virtual void ReadConfig()
128 ConfigReader *MyConf = new ConfigReader(ServerInstance);
132 for (int i = 0; i < MyConf->Enumerate("helpop"); i++)
134 irc::string key = assign(MyConf->ReadValue("helpop", "key", i));
135 std::string value = MyConf->ReadValue("helpop", "value", i, true); /* Linefeeds allowed! */
139 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
142 helpop_map[key] = value;
145 if (helpop_map.find("start") == helpop_map.end())
148 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
150 else if (helpop_map.find("nohelp") == helpop_map.end())
153 throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
159 virtual void OnRehash(User* user, const std::string ¶meter)
164 virtual void OnWhois(User* src, User* dst)
166 if (dst->IsModeSet('h'))
168 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
172 virtual ~ModuleHelpop()
174 ServerInstance->Modes->DelMode(ho);
178 virtual Version GetVersion()
180 return Version(1,2,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
184 MODULE_INIT(ModuleHelpop)