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 HelpopException : public ModuleException
168 HelpopException(std::string message) : err(message) { }
169 virtual char* GetReason() { return (char*)err.c_str(); }
172 class ModuleHelpop : public Module
177 cmd_helpop* mycommand;
180 ModuleHelpop(Server* Me)
186 if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
188 Srv->Log(DEFAULT,"Unable to claim the +h usermode.");
192 mycommand = new cmd_helpop();
193 Srv->AddCommand(mycommand);
196 virtual void ReadConfig()
198 conf = new ConfigReader;
199 h_file = conf->ReadValue("helpop", "file", 0);
204 HelpopException e("Missing helpop file");
208 helpop = new ConfigReader(h_file);
209 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
210 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
211 (helpop->ReadValue("start", "line1", 0) == ""))
213 HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
218 void Implements(char* List)
220 List[I_OnRehash] = List[I_OnExtendedMode] = List[I_OnWhois] = 1;
223 virtual void OnRehash(std::string parameter)
232 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
234 if ((modechar == 'h') && (type == MT_CLIENT))
241 virtual void OnWhois(userrec* src, userrec* dst)
243 if (strchr(dst->modes,'h'))
245 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
249 virtual ~ModuleHelpop()
255 virtual Version GetVersion()
257 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
261 class ModuleHelpopFactory : public ModuleFactory
264 ModuleHelpopFactory()
268 ~ModuleHelpopFactory()
272 virtual Module * CreateModule(Server* Me)
274 return new ModuleHelpop(Me);
279 extern "C" void * init_module( void )
281 return new ModuleHelpopFactory;