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"
25 static ConfigReader *helpop;
28 bool do_helpop(const char**, int, userrec*);
29 void sendtohelpop(userrec*, int, const char**);
31 /* $ModDesc: /helpop Command, Works like Unreal helpop */
33 class Helpop : public ModeHandler
36 Helpop() : ModeHandler('h', 0, 0, false, MODETYPE_USER, true) { }
38 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
42 if (!dest->IsModeSet('h'))
44 dest->SetMode('h',true);
45 return MODEACTION_ALLOW;
50 if (dest->IsModeSet('h'))
52 dest->SetMode('h',false);
53 return MODEACTION_ALLOW;
57 return MODEACTION_DENY;
61 class cmd_helpop : public command_t
64 cmd_helpop () : command_t("HELPOP",0,1)
66 this->source = "m_helpop.so";
69 void Handle (const char** parameters, int pcnt, userrec *user)
72 std::string output = " ";
79 do_helpop(NULL,pcnt,user);
83 if (*parameters[0] == '!')
85 // Force send to all +h users
86 sendtohelpop(user, pcnt, parameters);
88 else if (*parameters[0] == '?')
90 // Force to the helpop system with no forward if not found.
91 if (do_helpop(parameters, pcnt, user) == false)
93 // Not handled by the Database, Tell the user, and bail.
94 for (int i = 1; output != ""; i++)
96 snprintf(a,MAXBUF,"line%d",i);
97 output = helpop->ReadValue("nohelp", std::string(a), 0);
101 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
108 // Check with the helpop database, if not found send to +h
109 if (do_helpop(parameters, pcnt, user) == false)
111 // Not handled by the Database, Tell the user, and forward.
112 for (int i = 1; output != ""; i++)
114 snprintf(a,MAXBUF,"line%d",i);
115 /* "nohelpo" for opers "nohelp" for users */
116 output = helpop->ReadValue("nohelpo", std::string(a), 0);
119 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
123 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,"start");
143 if (*parameters[0] == '?')
145 strlcpy(search,parameters[0],MAXBUF);
150 for (int i = 1; output != ""; i++)
152 snprintf(a,MAXBUF,"line%d",i);
153 output = helpop->ReadValue(search, a, 0);
156 Srv->SendTo(NULL,src,"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 Srv->SendToModeMask("oh",WM_AND,line);
181 class HelpopException : public ModuleException
186 HelpopException(std::string message) : err(message) { }
187 virtual const char* GetReason() { return err.c_str(); }
190 class ModuleHelpop : public Module
195 cmd_helpop* mycommand;
199 ModuleHelpop(Server* Me)
206 Srv->AddMode(ho, 'h');
207 mycommand = new cmd_helpop();
208 Srv->AddCommand(mycommand);
211 virtual void ReadConfig()
213 conf = new ConfigReader;
214 h_file = conf->ReadValue("helpop", "file", 0);
219 HelpopException e("Missing helpop file");
223 helpop = new ConfigReader(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 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
255 virtual ~ModuleHelpop()
262 virtual Version GetVersion()
264 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
268 class ModuleHelpopFactory : public ModuleFactory
271 ModuleHelpopFactory()
275 ~ModuleHelpopFactory()
279 virtual Module * CreateModule(Server* Me)
281 return new ModuleHelpop(Me);
286 extern "C" void * init_module( void )
288 return new ModuleHelpopFactory;