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("nohelp", std::string(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("nohelpo", std::string(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,"start");
148 if (*parameters[0] == '?')
150 strlcpy(search,parameters[0],MAXBUF);
153 for (char* n = search; *n; n++)
156 for (int i = 1; output != ""; i++)
158 snprintf(a,MAXBUF,"line%d",i);
159 output = helpop->ReadValue(search, a, 0);
162 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());
186 /** Thrown by m_helpop
188 class HelpopException : public ModuleException
193 HelpopException(std::string message) : err(message) { }
194 virtual const char* GetReason() { return err.c_str(); }
197 class ModuleHelpop : public Module
202 cmd_helpop* mycommand;
206 ModuleHelpop(InspIRCd* Me)
210 ho = new Helpop(ServerInstance);
211 ServerInstance->AddMode(ho, 'h');
212 mycommand = new cmd_helpop(ServerInstance);
213 ServerInstance->AddCommand(mycommand);
216 virtual void ReadConfig()
218 conf = new ConfigReader(ServerInstance);
219 h_file = conf->ReadValue("helpop", "file", 0);
224 HelpopException e("Missing helpop file");
228 helpop = new ConfigReader(ServerInstance, h_file);
229 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
230 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
231 (helpop->ReadValue("start", "line1", 0) == ""))
233 HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
238 void Implements(char* List)
240 List[I_OnRehash] = List[I_OnWhois] = 1;
243 virtual void OnRehash(const std::string ¶meter)
252 virtual void OnWhois(userrec* src, userrec* dst)
254 if (dst->IsModeSet('h'))
256 src->WriteServ("310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
260 virtual ~ModuleHelpop()
262 ServerInstance->Modes->DelMode(ho);
268 virtual Version GetVersion()
270 return Version(1,0,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
274 class ModuleHelpopFactory : public ModuleFactory
277 ModuleHelpopFactory()
281 ~ModuleHelpopFactory()
285 virtual Module * CreateModule(InspIRCd* Me)
287 return new ModuleHelpop(Me);
292 extern "C" void * init_module( void )
294 return new ModuleHelpopFactory;