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 = " ";
43 do_helpop(NULL,pcnt,user);
47 if (parameters[0][0] == '!')
49 // Force send to all +h users
50 sendtohelpop(user, pcnt, parameters);
52 else if (parameters[0][0] == '?')
54 // Force to the helpop system with no forward if not found.
55 if (do_helpop(parameters, pcnt, user) == false)
57 // Not handled by the Database, Tell the user, and bail.
58 for (int i = 1; output != ""; i++)
60 snprintf(a,MAXBUF,"line%d",i);
61 output = helpop->ReadValue("nohelp", std::string(a), 0);
65 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
72 // Check with the helpop database, if not found send to +h
73 if (do_helpop(parameters, pcnt, user) == false)
75 // Not handled by the Database, Tell the user, and forward.
76 for (int i = 1; output != ""; i++)
78 snprintf(a,MAXBUF,"line%d",i);
79 /* "nohelpo" for opers "nohelp" for users */
80 output = helpop->ReadValue("nohelpo", std::string(a), 0);
83 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
87 sendtohelpop(user, pcnt, parameters);
92 bool do_helpop(char **parameters, int pcnt, userrec *src)
95 std::string output = " "; // a fix bought to you by brain :p
106 search = parameters[0];
109 if (search[0] == '?')
114 /* XXX - don't we have an strtolower()? if not, might pay to add one.. that works on char *, preferably.. */
115 strlcpy(lower, search, MAXBUF);
116 for (unsigned int t = 0; t < strlen(lower); t++)
117 lower[t] = tolower(lower[t]);
120 for (int i = 1; output != ""; i++)
122 snprintf(a,MAXBUF,"line%d",i);
123 output = helpop->ReadValue(lower, a, 0);
126 Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
135 void sendtohelpop(userrec *src, int pcnt, char **params)
137 char* first = params[0];
143 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
144 for (int i = 1; i < pcnt; i++)
146 line = line + std::string(params[i]) + " ";
148 Srv->SendToModeMask("oh",WM_AND,line);
151 class ModuleHelpop : public Module
163 if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
165 Srv->Log(DEFAULT,"Unable to claim the +h usermode.");
169 Srv->AddCommand("HELPOP",handle_helpop,0,0,"m_helpop.so");
172 virtual void ReadConfig()
174 conf = new ConfigReader;
175 h_file = conf->ReadValue("helpop", "file", 0);
179 log(DEFAULT,"m_helpop: Helpop file not Specified.");
183 helpop = new ConfigReader(h_file);
184 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
185 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
186 (helpop->ReadValue("start", "line1", 0) == ""))
188 log(DEFAULT,"m_helpop: Helpop file is missing important entries. Please check the example conf.");
194 virtual void OnRehash()
202 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
204 if ((modechar == 'h') && (type == MT_CLIENT))
211 virtual void OnWhois(userrec* src, userrec* dst)
213 if (strchr(dst->modes,'h'))
215 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
219 virtual ~ModuleHelpop()
226 virtual Version GetVersion()
228 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
232 class ModuleHelpopFactory : public ModuleFactory
235 ModuleHelpopFactory()
239 ~ModuleHelpopFactory()
243 virtual Module * CreateModule()
245 return new ModuleHelpop;
250 extern "C" void * init_module( void )
252 return new ModuleHelpopFactory;