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 * ---------------------------------------------------
22 #include "helperfuncs.h"
26 static ConfigReader *helpop;
28 extern InspIRCd* ServerInstance;
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 () : command_t("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);
133 bool do_helpop(const char** parameters, int pcnt, userrec *src)
136 std::string output = " "; // a fix bought to you by brain :p
142 strcpy(search,"start");
146 if (*parameters[0] == '?')
148 strlcpy(search,parameters[0],MAXBUF);
151 for (char* n = search; *n; n++)
154 for (int i = 1; output != ""; i++)
156 snprintf(a,MAXBUF,"line%d",i);
157 output = helpop->ReadValue(search, a, 0);
160 src->WriteServ("290 "+std::string(src->nick)+" :"+output);
169 void sendtohelpop(userrec *src, int pcnt, const char **params)
171 const char* first = params[0];
177 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
178 for (int i = 1; i < pcnt; i++)
180 line = line + std::string(params[i]) + " ";
182 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();
210 ServerInstance->AddCommand(mycommand);
213 virtual void ReadConfig()
215 conf = new ConfigReader;
216 h_file = conf->ReadValue("helpop", "file", 0);
221 HelpopException e("Missing helpop file");
225 helpop = new ConfigReader(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()
264 virtual Version GetVersion()
266 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
270 class ModuleHelpopFactory : public ModuleFactory
273 ModuleHelpopFactory()
277 ~ModuleHelpopFactory()
281 virtual Module * CreateModule(InspIRCd* Me)
283 return new ModuleHelpop(Me);
288 extern "C" void * init_module( void )
290 return new ModuleHelpopFactory;