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 void handle_helpop(char**, int, userrec*);
29 bool do_helpop(char**, int, userrec*);
30 void sendtohelpop(userrec*, int, char**);
32 /* $ModDesc: /helpop Command, Works like Unreal helpop */
34 class cmd_helpop : public command_t
37 cmd_helpop () : command_t("HELPOP",0,0)
39 this->source = "m_helpop.so";
42 void Handle (char **parameters, int pcnt, userrec *user)
45 std::string output = " ";
52 do_helpop(NULL,pcnt,user);
56 if (parameters[0][0] == '!')
58 // Force send to all +h users
59 sendtohelpop(user, pcnt, parameters);
61 else if (parameters[0][0] == '?')
63 // Force to the helpop system with no forward if not found.
64 if (do_helpop(parameters, pcnt, user) == false)
66 // Not handled by the Database, Tell the user, and bail.
67 for (int i = 1; output != ""; i++)
69 snprintf(a,MAXBUF,"line%d",i);
70 output = helpop->ReadValue("nohelp", std::string(a), 0);
74 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
81 // Check with the helpop database, if not found send to +h
82 if (do_helpop(parameters, pcnt, user) == false)
84 // Not handled by the Database, Tell the user, and forward.
85 for (int i = 1; output != ""; i++)
87 snprintf(a,MAXBUF,"line%d",i);
88 /* "nohelpo" for opers "nohelp" for users */
89 output = helpop->ReadValue("nohelpo", std::string(a), 0);
92 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
96 sendtohelpop(user, pcnt, parameters);
103 bool do_helpop(char **parameters, int pcnt, userrec *src)
106 std::string output = " "; // a fix bought to you by brain :p
117 search = parameters[0];
120 if (search[0] == '?')
125 /* XXX - don't we have an strtolower()? if not, might pay to add one.. that works on char *, preferably.. */
126 strlcpy(lower, search, MAXBUF);
127 for (unsigned int t = 0; t < strlen(lower); t++)
128 lower[t] = tolower(lower[t]);
131 for (int i = 1; output != ""; i++)
133 snprintf(a,MAXBUF,"line%d",i);
134 output = helpop->ReadValue(lower, a, 0);
137 Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
146 void sendtohelpop(userrec *src, int pcnt, char **params)
148 char* first = params[0];
154 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
155 for (int i = 1; i < pcnt; i++)
157 line = line + std::string(params[i]) + " ";
159 Srv->SendToModeMask("oh",WM_AND,line);
162 class HelpopException : public ModuleException
167 HelpopException(std::string message) : err(message) { }
168 virtual char* GetReason() { return (char*)err.c_str(); }
171 class ModuleHelpop : public Module
176 cmd_helpop* mycommand;
179 ModuleHelpop(Server* Me)
185 if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
187 Srv->Log(DEFAULT,"Unable to claim the +h usermode.");
191 mycommand = new cmd_helpop();
192 Srv->AddCommand(mycommand);
195 virtual void ReadConfig()
197 conf = new ConfigReader;
198 h_file = conf->ReadValue("helpop", "file", 0);
203 HelpopException e("Missing helpop file");
207 helpop = new ConfigReader(h_file);
208 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
209 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
210 (helpop->ReadValue("start", "line1", 0) == ""))
212 HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
217 void Implements(char* List)
219 List[I_OnRehash] = List[I_OnExtendedMode] = List[I_OnWhois] = 1;
222 virtual void OnRehash(std::string parameter)
231 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
233 if ((modechar == 'h') && (type == MT_CLIENT))
240 virtual void OnWhois(userrec* src, userrec* dst)
242 if (strchr(dst->modes,'h'))
244 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
248 virtual ~ModuleHelpop()
254 virtual Version GetVersion()
256 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
260 class ModuleHelpopFactory : public ModuleFactory
263 ModuleHelpopFactory()
267 ~ModuleHelpopFactory()
271 virtual Module * CreateModule(Server* Me)
273 return new ModuleHelpop(Me);
278 extern "C" void * init_module( void )
280 return new ModuleHelpopFactory;