1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
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"
28 void handle_helpop(char**, int, userrec*);
29 bool do_helpop(char**, int, userrec*);
30 void sendtohelpop(userrec*, int, char**);
33 /* $ModDesc: /helpop Command, Works like Unreal helpop */
35 void handle_helpop(char **parameters, int pcnt, userrec *user)
38 std::string output = " ";
41 do_helpop(NULL,pcnt,user);
45 if (parameters[0][0] == '!')
47 // Force send to all +h users
48 sendtohelpop(user, pcnt, parameters);
49 } else if (parameters[0][0] == '?') {
50 // Force to the helpop system with no forward if not found.
51 if (do_helpop(parameters, pcnt, user) == false) {
52 // Not handled by the Database, Tell the user, and forward.
53 for (int i = 1; output != ""; i++)
55 snprintf(a,MAXBUF,"line%d",i);
56 output = helpop->ReadValue("nohelp", std::string(a), 0);
58 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
63 // Check with the helpop database, if not found send to +h
64 if (do_helpop(parameters, pcnt, user) == false) {
65 // Not handled by the Database, Tell the user, and forward.
66 for (int i = 1; output != ""; i++)
68 snprintf(a,MAXBUF,"line%d",i);
69 output = helpop->ReadValue("nohelpo", std::string(a), 0);
71 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
75 sendtohelpop(user, pcnt, parameters);
80 bool do_helpop(char **parameters, int pcnt, userrec *src)
83 std::string output = " "; // a fix bought to you by brain :p
90 search = parameters[0];
93 if (search[0] == '?') {
97 // FIX by brain: make the string lowercase, ConfigReader is
100 strlcpy(lower,search,MAXBUF);
101 for (int t = 0; t < strlen(lower); t++)
102 lower[t] = tolower(lower[t]);
106 for (int i = 1; output != ""; i++)
108 snprintf(a,MAXBUF,"line%d",i);
109 output = helpop->ReadValue(lower, a, 0);
111 Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
120 void sendtohelpop(userrec *src, int pcnt, char **params)
122 char* first = params[0];
123 if (first[0] == '!') { first++; }
124 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
125 for (int i = 1; i < pcnt; i++)
127 line = line + std::string(params[i]) + " ";
129 Srv->SendToModeMask("oh",WM_AND,line);
132 class ModuleHelpop : public Module
142 conf = new ConfigReader;
144 h_file = conf->ReadValue("helpop", "file", 0);
147 log(DEFAULT,"m_helpop: Helpop file not Specified.");
151 helpop = new ConfigReader(h_file);
153 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
154 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
155 (helpop->ReadValue("start", "line1", 0) == ""))
157 log(DEFAULT,"m_helpop: Helpop file is missing important entries. Please check the example conf.");
161 if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
163 Srv->Log(DEFAULT,"Unable to claim the +h usermode.");
167 // Loads of comments, untill supported properly.
168 Srv->AddCommand("HELPOP",handle_helpop,0,0,"m_helpop.so");
172 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
174 if ((modechar == 'h') && (type == MT_CLIENT))
181 virtual void OnWhois(userrec* src, userrec* dst)
183 if (strchr(dst->modes,'h'))
185 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
189 virtual void OnOper(userrec* user)
191 char* modes[2]; // only two parameters
192 modes[0] = user->nick; // first parameter is the nick
193 modes[1] = "+h"; // second parameter is the mode
194 Srv->SendMode(modes,2,user); // send these, forming the command "MODE <nick> +h"
197 virtual ~ModuleHelpop()
204 virtual Version GetVersion()
206 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
210 class ModuleHelpopFactory : public ModuleFactory
213 ModuleHelpopFactory()
217 ~ModuleHelpopFactory()
221 virtual Module * CreateModule()
223 return new ModuleHelpop;
228 extern "C" void * init_module( void )
230 return new ModuleHelpopFactory;