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 /* XXX - should all this be marked static? clear the global namespace, etc. */
29 void handle_helpop(char**, int, userrec*);
30 bool do_helpop(char**, int, userrec*);
31 void sendtohelpop(userrec*, int, char**);
33 /* $ModDesc: /helpop Command, Works like Unreal helpop */
35 class cmd_helpop : public command_t
38 cmd_helpop () : command_t("HELPOP",0,0)
40 this->source = "m_helpop.so";
43 void Handle (char **parameters, int pcnt, userrec *user)
46 std::string output = " ";
53 do_helpop(NULL,pcnt,user);
57 if (parameters[0][0] == '!')
59 // Force send to all +h users
60 sendtohelpop(user, pcnt, parameters);
62 else if (parameters[0][0] == '?')
64 // Force to the helpop system with no forward if not found.
65 if (do_helpop(parameters, pcnt, user) == false)
67 // Not handled by the Database, Tell the user, and bail.
68 for (int i = 1; output != ""; i++)
70 snprintf(a,MAXBUF,"line%d",i);
71 output = helpop->ReadValue("nohelp", std::string(a), 0);
75 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
82 // Check with the helpop database, if not found send to +h
83 if (do_helpop(parameters, pcnt, user) == false)
85 // Not handled by the Database, Tell the user, and forward.
86 for (int i = 1; output != ""; i++)
88 snprintf(a,MAXBUF,"line%d",i);
89 /* "nohelpo" for opers "nohelp" for users */
90 output = helpop->ReadValue("nohelpo", std::string(a), 0);
93 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
97 sendtohelpop(user, pcnt, parameters);
104 bool do_helpop(char **parameters, int pcnt, userrec *src)
107 std::string output = " "; // a fix bought to you by brain :p
118 search = parameters[0];
121 if (search[0] == '?')
126 /* XXX - don't we have an strtolower()? if not, might pay to add one.. that works on char *, preferably.. */
127 strlcpy(lower, search, MAXBUF);
128 for (unsigned int t = 0; t < strlen(lower); t++)
129 lower[t] = tolower(lower[t]);
132 for (int i = 1; output != ""; i++)
134 snprintf(a,MAXBUF,"line%d",i);
135 output = helpop->ReadValue(lower, a, 0);
138 Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
147 void sendtohelpop(userrec *src, int pcnt, char **params)
149 char* first = params[0];
155 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
156 for (int i = 1; i < pcnt; i++)
158 line = line + std::string(params[i]) + " ";
160 Srv->SendToModeMask("oh",WM_AND,line);
163 class ModuleHelpop : public Module
168 cmd_helpop* mycommand;
171 ModuleHelpop(Server* Me)
177 if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
179 Srv->Log(DEFAULT,"Unable to claim the +h usermode.");
183 mycommand = new cmd_helpop();
184 Srv->AddCommand(mycommand);
187 virtual void ReadConfig()
189 conf = new ConfigReader;
190 h_file = conf->ReadValue("helpop", "file", 0);
195 log(DEFAULT,"m_helpop: Helpop file not Specified.");
199 helpop = new ConfigReader(h_file);
200 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
201 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
202 (helpop->ReadValue("start", "line1", 0) == ""))
204 log(DEFAULT,"m_helpop: Helpop file is missing important entries. Please check the example conf.");
209 void Implements(char* List)
211 List[I_OnRehash] = List[I_OnExtendedMode] = List[I_OnWhois] = 1;
214 virtual void OnRehash(std::string parameter)
223 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
225 if ((modechar == 'h') && (type == MT_CLIENT))
232 virtual void OnWhois(userrec* src, userrec* dst)
234 if (strchr(dst->modes,'h'))
236 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
240 virtual ~ModuleHelpop()
246 virtual Version GetVersion()
248 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
252 class ModuleHelpopFactory : public ModuleFactory
255 ModuleHelpopFactory()
259 ~ModuleHelpopFactory()
263 virtual Module * CreateModule(Server* Me)
265 return new ModuleHelpop(Me);
270 extern "C" void * init_module( void )
272 return new ModuleHelpopFactory;