1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 *the file COPYING for details.
14 * ---------------------------------------------------
26 static ConfigReader *helpop;
30 bool do_helpop(const char**, int, userrec*);
31 void sendtohelpop(userrec*, int, const char**);
33 /* $ModDesc: /helpop Command, Works like Unreal helpop */
35 class Helpop : public ModeHandler
38 Helpop(InspIRCd* Instance) : ModeHandler(Instance, 'h', 0, 0, false, MODETYPE_USER, true) { }
40 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
44 if (!dest->IsModeSet('h'))
46 dest->SetMode('h',true);
47 return MODEACTION_ALLOW;
52 if (dest->IsModeSet('h'))
54 dest->SetMode('h',false);
55 return MODEACTION_ALLOW;
59 return MODEACTION_DENY;
63 class cmd_helpop : public command_t
66 cmd_helpop (InspIRCd* Instance) : command_t(Instance, "HELPOP", 0, 1)
68 this->source = "m_helpop.so";
69 syntax = "[?|!]<any-text>";
72 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
75 std::string output = " ";
82 do_helpop(NULL,pcnt,user);
86 if (*parameters[0] == '!')
88 // Force send to all +h users
89 sendtohelpop(user, pcnt, parameters);
91 else if (*parameters[0] == '?')
93 // Force to the helpop system with no forward if not found.
94 if (do_helpop(parameters, pcnt, user) == false)
96 // Not handled by the Database, Tell the user, and bail.
97 for (int i = 1; output != ""; i++)
99 snprintf(a,MAXBUF,"line%d",i);
100 output = helpop->ReadValue("nohelp", std::string(a), 0);
104 user->WriteServ("290 "+std::string(user->nick)+" :"+output);
111 // Check with the helpop database, if not found send to +h
112 if (do_helpop(parameters, pcnt, user) == false)
114 // Not handled by the Database, Tell the user, and forward.
115 for (int i = 1; output != ""; i++)
117 snprintf(a,MAXBUF,"line%d",i);
118 /* "nohelpo" for opers "nohelp" for users */
119 output = helpop->ReadValue("nohelpo", std::string(a), 0);
122 user->WriteServ("290 "+std::string(user->nick)+" :"+output);
126 sendtohelpop(user, pcnt, parameters);
134 bool do_helpop(const char** parameters, int pcnt, userrec *src)
137 std::string output = " "; // a fix bought to you by brain :p
143 strcpy(search,"start");
147 if (*parameters[0] == '?')
149 strlcpy(search,parameters[0],MAXBUF);
152 for (char* n = search; *n; n++)
155 for (int i = 1; output != ""; i++)
157 snprintf(a,MAXBUF,"line%d",i);
158 output = helpop->ReadValue(search, a, 0);
161 src->WriteServ("290 "+std::string(src->nick)+" :"+output);
168 void sendtohelpop(userrec *src, int pcnt, const char **params)
170 const char* first = params[0];
176 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
177 for (int i = 1; i < pcnt; i++)
179 line = line + std::string(params[i]) + " ";
181 ServerInstance->WriteMode("oh",WM_AND,line.c_str());
185 class HelpopException : public ModuleException
190 HelpopException(std::string message) : err(message) { }
191 virtual const char* GetReason() { return err.c_str(); }
194 class ModuleHelpop : public Module
199 cmd_helpop* mycommand;
203 ModuleHelpop(InspIRCd* Me)
207 ho = new Helpop(ServerInstance);
208 ServerInstance->AddMode(ho, 'h');
209 mycommand = new cmd_helpop(ServerInstance);
210 ServerInstance->AddCommand(mycommand);
213 virtual void ReadConfig()
215 conf = new ConfigReader(ServerInstance);
216 h_file = conf->ReadValue("helpop", "file", 0);
221 HelpopException e("Missing helpop file");
225 helpop = new ConfigReader(ServerInstance, h_file);
226 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
227 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
228 (helpop->ReadValue("start", "line1", 0) == ""))
230 HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
235 void Implements(char* List)
237 List[I_OnRehash] = List[I_OnWhois] = 1;
240 virtual void OnRehash(const std::string ¶meter)
249 virtual void OnWhois(userrec* src, userrec* dst)
251 if (dst->IsModeSet('h'))
253 src->WriteServ("310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
257 virtual ~ModuleHelpop()
259 ServerInstance->Modes->DelMode(ho);
265 virtual Version GetVersion()
267 return Version(1,0,0,1,VF_COMMON|VF_VENDOR);
271 class ModuleHelpopFactory : public ModuleFactory
274 ModuleHelpopFactory()
278 ~ModuleHelpopFactory()
282 virtual Module * CreateModule(InspIRCd* Me)
284 return new ModuleHelpop(Me);
289 extern "C" void * init_module( void )
291 return new ModuleHelpopFactory;