1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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**);
34 /* $ModDesc: /helpop Command, Works like Unreal helpop */
36 void handle_helpop(char **parameters, int pcnt, userrec *user)
39 std::string output = " ";
46 do_helpop(NULL,pcnt,user);
50 if (parameters[0][0] == '!')
52 // Force send to all +h users
53 sendtohelpop(user, pcnt, parameters);
55 else if (parameters[0][0] == '?')
57 // Force to the helpop system with no forward if not found.
58 if (do_helpop(parameters, pcnt, user) == false)
60 // Not handled by the Database, Tell the user, and bail.
61 for (int i = 1; output != ""; i++)
63 snprintf(a,MAXBUF,"line%d",i);
64 output = helpop->ReadValue("nohelp", std::string(a), 0);
68 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
75 // Check with the helpop database, if not found send to +h
76 if (do_helpop(parameters, pcnt, user) == false)
78 // Not handled by the Database, Tell the user, and forward.
79 for (int i = 1; output != ""; i++)
81 snprintf(a,MAXBUF,"line%d",i);
82 /* "nohelpo" for opers "nohelp" for users */
83 output = helpop->ReadValue("nohelpo", std::string(a), 0);
86 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
90 sendtohelpop(user, pcnt, parameters);
95 bool do_helpop(char **parameters, int pcnt, userrec *src)
98 std::string output = " "; // a fix bought to you by brain :p
109 search = parameters[0];
112 if (search[0] == '?')
117 /* XXX - don't we have an strtolower()? if not, might pay to add one.. that works on char *, preferably.. */
118 strlcpy(lower, search, MAXBUF);
119 for (unsigned int t = 0; t < strlen(lower); t++)
120 lower[t] = tolower(lower[t]);
123 for (int i = 1; output != ""; i++)
125 snprintf(a,MAXBUF,"line%d",i);
126 output = helpop->ReadValue(lower, a, 0);
129 Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
138 void sendtohelpop(userrec *src, int pcnt, char **params)
140 char* first = params[0];
146 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
147 for (int i = 1; i < pcnt; i++)
149 line = line + std::string(params[i]) + " ";
151 Srv->SendToModeMask("oh",WM_AND,line);
154 class ModuleHelpop : public Module
161 ModuleHelpop(Server* Me)
167 if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
169 Srv->Log(DEFAULT,"Unable to claim the +h usermode.");
173 Srv->AddCommand("HELPOP",handle_helpop,0,0,"m_helpop.so");
176 virtual void ReadConfig()
178 conf = new ConfigReader;
179 h_file = conf->ReadValue("helpop", "file", 0);
184 log(DEFAULT,"m_helpop: Helpop file not Specified.");
188 helpop = new ConfigReader(h_file);
189 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
190 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
191 (helpop->ReadValue("start", "line1", 0) == ""))
193 log(DEFAULT,"m_helpop: Helpop file is missing important entries. Please check the example conf.");
199 virtual void OnRehash(std::string parameter)
208 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
210 if ((modechar == 'h') && (type == MT_CLIENT))
217 virtual void OnWhois(userrec* src, userrec* dst)
219 if (strchr(dst->modes,'h'))
221 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
225 virtual ~ModuleHelpop()
231 virtual Version GetVersion()
233 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
237 class ModuleHelpopFactory : public ModuleFactory
240 ModuleHelpopFactory()
244 ~ModuleHelpopFactory()
248 virtual Module * CreateModule(Server* Me)
250 return new ModuleHelpop(Me);
255 extern "C" void * init_module( void )
257 return new ModuleHelpopFactory;