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";
67 syntax = "[?|!]<any-text>";
70 void Handle (const char** parameters, int pcnt, userrec *user)
73 std::string output = " ";
80 do_helpop(NULL,pcnt,user);
84 if (*parameters[0] == '!')
86 // Force send to all +h users
87 sendtohelpop(user, pcnt, parameters);
89 else if (*parameters[0] == '?')
91 // Force to the helpop system with no forward if not found.
92 if (do_helpop(parameters, pcnt, user) == false)
94 // Not handled by the Database, Tell the user, and bail.
95 for (int i = 1; output != ""; i++)
97 snprintf(a,MAXBUF,"line%d",i);
98 output = helpop->ReadValue("nohelp", std::string(a), 0);
102 user->WriteServ("290 "+std::string(user->nick)+" :"+output);
109 // Check with the helpop database, if not found send to +h
110 if (do_helpop(parameters, pcnt, user) == false)
112 // Not handled by the Database, Tell the user, and forward.
113 for (int i = 1; output != ""; i++)
115 snprintf(a,MAXBUF,"line%d",i);
116 /* "nohelpo" for opers "nohelp" for users */
117 output = helpop->ReadValue("nohelpo", std::string(a), 0);
120 user->WriteServ("290 "+std::string(user->nick)+" :"+output);
124 sendtohelpop(user, pcnt, parameters);
131 bool do_helpop(const char** parameters, int pcnt, userrec *src)
134 std::string output = " "; // a fix bought to you by brain :p
140 strcpy(search,"start");
144 if (*parameters[0] == '?')
146 strlcpy(search,parameters[0],MAXBUF);
151 for (int i = 1; output != ""; i++)
153 snprintf(a,MAXBUF,"line%d",i);
154 output = helpop->ReadValue(search, a, 0);
157 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 Srv->SendToModeMask("oh",WM_AND,line);
182 class HelpopException : public ModuleException
187 HelpopException(std::string message) : err(message) { }
188 virtual const char* GetReason() { return err.c_str(); }
191 class ModuleHelpop : public Module
196 cmd_helpop* mycommand;
200 ModuleHelpop(Server* Me)
207 Srv->AddMode(ho, 'h');
208 mycommand = new cmd_helpop();
209 Srv->AddCommand(mycommand);
212 virtual void ReadConfig()
214 conf = new ConfigReader;
215 h_file = conf->ReadValue("helpop", "file", 0);
220 HelpopException e("Missing helpop file");
224 helpop = new ConfigReader(h_file);
225 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
226 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
227 (helpop->ReadValue("start", "line1", 0) == ""))
229 HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
234 void Implements(char* List)
236 List[I_OnRehash] = List[I_OnWhois] = 1;
239 virtual void OnRehash(const std::string ¶meter)
248 virtual void OnWhois(userrec* src, userrec* dst)
250 if (dst->IsModeSet('h'))
252 src->WriteServ("310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
256 virtual ~ModuleHelpop()
263 virtual Version GetVersion()
265 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
269 class ModuleHelpopFactory : public ModuleFactory
272 ModuleHelpopFactory()
276 ~ModuleHelpopFactory()
280 virtual Module * CreateModule(Server* Me)
282 return new ModuleHelpop(Me);
287 extern "C" void * init_module( void )
289 return new ModuleHelpopFactory;