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(char**, int, userrec*);
29 void sendtohelpop(userrec*, int, 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 (char **parameters, int pcnt, userrec *user)
72 std::string output = " ";
79 do_helpop(NULL,pcnt,user);
83 if (parameters[0][0] == '!')
85 // Force send to all +h users
86 sendtohelpop(user, pcnt, parameters);
88 else if (parameters[0][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(char **parameters, int pcnt, userrec *src)
133 std::string output = " "; // a fix bought to you by brain :p
143 search = parameters[0];
146 if (search[0] == '?')
153 for (int i = 1; output != ""; i++)
155 snprintf(a,MAXBUF,"line%d",i);
156 output = helpop->ReadValue(search, a, 0);
159 Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
168 void sendtohelpop(userrec *src, int pcnt, char **params)
170 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 Srv->SendToModeMask("oh",WM_AND,line);
184 class HelpopException : public ModuleException
189 HelpopException(std::string message) : err(message) { }
190 virtual const char* GetReason() { return err.c_str(); }
193 class ModuleHelpop : public Module
198 cmd_helpop* mycommand;
202 ModuleHelpop(Server* Me)
209 Srv->AddMode(ho, 'h');
210 mycommand = new cmd_helpop();
211 Srv->AddCommand(mycommand);
214 virtual void ReadConfig()
216 conf = new ConfigReader;
217 h_file = conf->ReadValue("helpop", "file", 0);
222 HelpopException e("Missing helpop file");
226 helpop = new ConfigReader(h_file);
227 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
228 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
229 (helpop->ReadValue("start", "line1", 0) == ""))
231 HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
236 void Implements(char* List)
238 List[I_OnRehash] = List[I_OnWhois] = 1;
241 virtual void OnRehash(const std::string ¶meter)
250 virtual void OnWhois(userrec* src, userrec* dst)
252 if (dst->IsModeSet('h'))
254 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
258 virtual ~ModuleHelpop()
265 virtual Version GetVersion()
267 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
271 class ModuleHelpopFactory : public ModuleFactory
274 ModuleHelpopFactory()
278 ~ModuleHelpopFactory()
282 virtual Module * CreateModule(Server* Me)
284 return new ModuleHelpop(Me);
289 extern "C" void * init_module( void )
291 return new ModuleHelpopFactory;