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 * ---------------------------------------------------
25 static ConfigReader *helpop;
27 /*bool do_helpop(const char**, int, userrec*);
28 void sendtohelpop(userrec*, int, const char**);*/
30 /* $ModDesc: /helpop Command, Works like Unreal helpop */
32 /** Handles user mode +h
34 class Helpop : public ModeHandler
37 Helpop(InspIRCd* Instance) : ModeHandler(Instance, 'h', 0, 0, false, MODETYPE_USER, true) { }
39 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
43 if (!dest->IsModeSet('h'))
45 dest->SetMode('h',true);
46 return MODEACTION_ALLOW;
51 if (dest->IsModeSet('h'))
53 dest->SetMode('h',false);
54 return MODEACTION_ALLOW;
58 return MODEACTION_DENY;
64 class cmd_helpop : public command_t
67 cmd_helpop (InspIRCd* Instance) : command_t(Instance, "HELPOP", 0, 1)
69 this->source = "m_helpop.so";
70 syntax = "[?|!]<any-text>";
73 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
76 std::string output = " ";
83 do_helpop(NULL,pcnt,user);
87 if (*parameters[0] == '!')
89 // Force send to all +h users
90 sendtohelpop(user, pcnt, parameters);
92 else if (*parameters[0] == '?')
94 // Force to the helpop system with no forward if not found.
95 if (do_helpop(parameters, pcnt, user) == false)
97 // Not handled by the Database, Tell the user, and bail.
98 for (int i = 1; output != ""; i++)
100 snprintf(a,MAXBUF,"line%d",i);
101 output = helpop->ReadValue("helpop_nohelp", a, 0);
105 user->WriteServ("290 "+std::string(user->nick)+" :"+output);
112 // Check with the helpop database, if not found send to +h
113 if (do_helpop(parameters, pcnt, user) == false)
115 // Not handled by the Database, Tell the user, and forward.
116 for (int i = 1; output != ""; i++)
118 snprintf(a,MAXBUF,"line%d",i);
119 /* "nohelpo" for opers "nohelp" for users */
120 output = helpop->ReadValue("helpop_nohelpo", a, 0);
123 user->WriteServ("290 "+std::string(user->nick)+" :"+output);
127 sendtohelpop(user, pcnt, parameters);
135 bool do_helpop(const char** parameters, int pcnt, userrec *src)
138 std::string output = " "; // a fix bought to you by brain :p
144 strcpy(search,"helpop_start");
148 if (*parameters[0] == '?')
150 strlcpy(search, "helpop_", MAXBUF);
151 strlcat(search, parameters[0], MAXBUF);
154 for (char* n = search; *n; n++)
157 for (int i = 1; output != ""; i++)
159 snprintf(a,MAXBUF,"line%d",i);
160 output = helpop->ReadValue(search, a, 0);
163 src->WriteServ("290 "+std::string(src->nick)+" :"+output);
170 void sendtohelpop(userrec *src, int pcnt, const char **params)
172 const char* first = params[0];
178 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
179 for (int i = 1; i < pcnt; i++)
181 line = line + std::string(params[i]) + " ";
183 ServerInstance->WriteMode("oh",WM_AND,line.c_str());
187 /** Thrown by m_helpop
189 class HelpopException : public ModuleException
194 HelpopException(std::string message) : err(message) { }
195 ~HelpopException() throw() { };
196 virtual const char* GetReason() { return err.c_str(); }
199 class ModuleHelpop : public Module
203 cmd_helpop* mycommand;
207 ModuleHelpop(InspIRCd* Me)
211 ho = new Helpop(ServerInstance);
212 ServerInstance->AddMode(ho, 'h');
213 mycommand = new cmd_helpop(ServerInstance);
214 ServerInstance->AddCommand(mycommand);
217 virtual void ReadConfig()
219 helpop = new ConfigReader(ServerInstance);
220 if ((helpop->ReadValue("helpop_nohelp", "line1", 0) == "") ||
221 (helpop->ReadValue("helpop_nohelpo", "line1", 0) == "") ||
222 (helpop->ReadValue("helpop_start", "line1", 0) == ""))
224 HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
229 void Implements(char* List)
231 List[I_OnRehash] = List[I_OnWhois] = 1;
234 virtual void OnRehash(const std::string ¶meter)
241 virtual void OnWhois(userrec* src, userrec* dst)
243 if (dst->IsModeSet('h'))
245 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
249 virtual ~ModuleHelpop()
251 ServerInstance->Modes->DelMode(ho);
256 virtual Version GetVersion()
258 return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
262 class ModuleHelpopFactory : public ModuleFactory
265 ModuleHelpopFactory()
269 ~ModuleHelpopFactory()
273 virtual Module * CreateModule(InspIRCd* Me)
275 return new ModuleHelpop(Me);
280 extern "C" void * init_module( void )
282 return new ModuleHelpopFactory;