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 void 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);
132 bool do_helpop(const char** parameters, int pcnt, userrec *src)
135 std::string output = " "; // a fix bought to you by brain :p
141 strcpy(search,"start");
145 if (*parameters[0] == '?')
147 strlcpy(search,parameters[0],MAXBUF);
150 for (char* n = search; *n; n++)
153 for (int i = 1; output != ""; i++)
155 snprintf(a,MAXBUF,"line%d",i);
156 output = helpop->ReadValue(search, a, 0);
159 src->WriteServ("290 "+std::string(src->nick)+" :"+output);
166 void sendtohelpop(userrec *src, int pcnt, const char **params)
168 const char* first = params[0];
174 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
175 for (int i = 1; i < pcnt; i++)
177 line = line + std::string(params[i]) + " ";
179 ServerInstance->WriteMode("oh",WM_AND,line.c_str());
183 class HelpopException : public ModuleException
188 HelpopException(std::string message) : err(message) { }
189 virtual const char* GetReason() { return err.c_str(); }
192 class ModuleHelpop : public Module
197 cmd_helpop* mycommand;
201 ModuleHelpop(InspIRCd* Me)
205 ho = new Helpop(ServerInstance);
206 ServerInstance->AddMode(ho, 'h');
207 mycommand = new cmd_helpop(ServerInstance);
208 ServerInstance->AddCommand(mycommand);
211 virtual void ReadConfig()
213 conf = new ConfigReader(ServerInstance);
214 h_file = conf->ReadValue("helpop", "file", 0);
219 HelpopException e("Missing helpop file");
223 helpop = new ConfigReader(ServerInstance, h_file);
224 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
225 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
226 (helpop->ReadValue("start", "line1", 0) == ""))
228 HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
233 void Implements(char* List)
235 List[I_OnRehash] = List[I_OnWhois] = 1;
238 virtual void OnRehash(const std::string ¶meter)
247 virtual void OnWhois(userrec* src, userrec* dst)
249 if (dst->IsModeSet('h'))
251 src->WriteServ("310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
255 virtual ~ModuleHelpop()
257 ServerInstance->Modes->DelMode(ho);
263 virtual Version GetVersion()
265 return Version(1,0,0,1,VF_COMMON|VF_VENDOR);
269 class ModuleHelpopFactory : public ModuleFactory
272 ModuleHelpopFactory()
276 ~ModuleHelpopFactory()
280 virtual Module * CreateModule(InspIRCd* Me)
282 return new ModuleHelpop(Me);
287 extern "C" void * init_module( void )
289 return new ModuleHelpopFactory;