1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 * ---------------------------------------------------
20 static ConfigReader *helpop;
22 /*bool do_helpop(const char**, int, userrec*);
23 void sendtohelpop(userrec*, int, const char**);*/
25 /* $ModDesc: /helpop Command, Works like Unreal helpop */
27 /** Handles user mode +h
29 class Helpop : public ModeHandler
32 Helpop(InspIRCd* Instance) : ModeHandler(Instance, 'h', 0, 0, false, MODETYPE_USER, true) { }
34 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
38 if (!dest->IsModeSet('h'))
40 dest->SetMode('h',true);
41 return MODEACTION_ALLOW;
46 if (dest->IsModeSet('h'))
48 dest->SetMode('h',false);
49 return MODEACTION_ALLOW;
53 return MODEACTION_DENY;
59 class cmd_helpop : public command_t
62 cmd_helpop (InspIRCd* Instance) : command_t(Instance, "HELPOP", 0, 1)
64 this->source = "m_helpop.so";
65 syntax = "[?|!]<any-text>";
68 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
71 std::string output = " ";
78 do_helpop(NULL,pcnt,user);
82 if (*parameters[0] == '!')
84 // Force send to all +h users
85 sendtohelpop(user, pcnt, parameters);
87 else if (*parameters[0] == '?')
89 // Force to the helpop system with no forward if not found.
90 if (do_helpop(parameters, pcnt, user) == false)
92 // Not handled by the Database, Tell the user, and bail.
93 for (int i = 1; output != ""; i++)
95 snprintf(a,MAXBUF,"line%d",i);
96 output = helpop->ReadValue("helpop_nohelp", a, 0);
100 user->WriteServ("290 "+std::string(user->nick)+" :"+output);
107 // Check with the helpop database, if not found send to +h
108 if (do_helpop(parameters, pcnt, user) == false)
110 // Not handled by the Database, Tell the user, and forward.
111 for (int i = 1; output != ""; i++)
113 snprintf(a,MAXBUF,"line%d",i);
114 /* "nohelpo" for opers "nohelp" for users */
115 output = helpop->ReadValue("helpop_nohelpo", a, 0);
118 user->WriteServ("290 "+std::string(user->nick)+" :"+output);
122 sendtohelpop(user, pcnt, parameters);
130 bool do_helpop(const char** parameters, int pcnt, userrec *src)
133 std::string output = " "; // a fix bought to you by brain :p
139 strcpy(search,"helpop_start");
143 if (*parameters[0] == '?')
145 strlcpy(search, "helpop_", MAXBUF);
146 strlcat(search, parameters[0], MAXBUF);
149 for (char* n = search; *n; n++)
152 for (int i = 1; output != ""; i++)
154 snprintf(a,MAXBUF,"line%d",i);
155 output = helpop->ReadValue(search, a, 0);
158 src->WriteServ("290 "+std::string(src->nick)+" :"+output);
165 void sendtohelpop(userrec *src, int pcnt, const char **params)
167 const char* first = params[0];
173 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
174 for (int i = 1; i < pcnt; i++)
176 line = line + std::string(params[i]) + " ";
178 ServerInstance->WriteMode("oh",WM_AND,line.c_str());
182 /** Thrown by m_helpop
184 class HelpopException : public ModuleException
189 HelpopException(std::string message) : err(message) { }
190 ~HelpopException() throw() { };
191 virtual const char* GetReason() { return err.c_str(); }
194 class ModuleHelpop : public Module
198 cmd_helpop* mycommand;
202 ModuleHelpop(InspIRCd* Me)
206 ho = new Helpop(ServerInstance);
207 ServerInstance->AddMode(ho, 'h');
208 mycommand = new cmd_helpop(ServerInstance);
209 ServerInstance->AddCommand(mycommand);
212 virtual void ReadConfig()
214 helpop = new ConfigReader(ServerInstance);
215 if ((helpop->ReadValue("helpop_nohelp", "line1", 0) == "") ||
216 (helpop->ReadValue("helpop_nohelpo", "line1", 0) == "") ||
217 (helpop->ReadValue("helpop_start", "line1", 0) == ""))
219 HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
224 void Implements(char* List)
226 List[I_OnRehash] = List[I_OnWhois] = 1;
229 virtual void OnRehash(const std::string ¶meter)
236 virtual void OnWhois(userrec* src, userrec* dst)
238 if (dst->IsModeSet('h'))
240 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
244 virtual ~ModuleHelpop()
246 ServerInstance->Modes->DelMode(ho);
251 virtual Version GetVersion()
253 return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
257 class ModuleHelpopFactory : public ModuleFactory
260 ModuleHelpopFactory()
264 ~ModuleHelpopFactory()
268 virtual Module * CreateModule(InspIRCd* Me)
270 return new ModuleHelpop(Me);
275 extern "C" void * init_module( void )
277 return new ModuleHelpopFactory;