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 * ---------------------------------------------------
25 void handle_helpop(char**, int, userrec*);
26 bool do_helpop(char**, int, userrec*);
27 void sendtohelpop(userrec*, int, char**);
30 /* $ModDesc: /helpop Command, Works like Unreal helpop */
32 void handle_helpop(char **parameters, int pcnt, userrec *user)
35 std::string output = " ";
38 do_helpop(NULL,pcnt,user);
42 if (parameters[0][0] == '!')
44 // Force send to all +h users
45 sendtohelpop(user, pcnt, parameters);
46 } else if (parameters[0][0] == '?') {
47 // Force to the helpop system with no forward if not found.
48 if (do_helpop(parameters, pcnt, user) == false) {
49 // Not handled by the Database, Tell the user, and forward.
50 for (int i = 1; output != ""; i++)
52 snprintf(a,MAXBUF,"line%d",i);
53 output = helpop->ReadValue("nohelp", std::string(a), 0);
55 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
60 // Check with the helpop database, if not found send to +h
61 if (do_helpop(parameters, pcnt, user) == false) {
62 // Not handled by the Database, Tell the user, and forward.
63 for (int i = 1; output != ""; i++)
65 snprintf(a,MAXBUF,"line%d",i);
66 output = helpop->ReadValue("nohelpo", std::string(a), 0);
68 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
72 sendtohelpop(user, pcnt, parameters);
77 bool do_helpop(char **parameters, int pcnt, userrec *src)
80 std::string output = " "; // a fix bought to you by brain :p
87 search = parameters[0];
90 if (search[0] == '?') {
94 // FIX by brain: make the string lowercase, ConfigReader is
97 strlcpy(lower,search,MAXBUF);
98 for (int t = 0; t < strlen(lower); t++)
99 lower[t] = tolower(lower[t]);
103 for (int i = 1; output != ""; i++)
105 snprintf(a,MAXBUF,"line%d",i);
106 output = helpop->ReadValue(lower, a, 0);
108 Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
117 void sendtohelpop(userrec *src, int pcnt, char **params)
119 char* first = params[0];
120 if (first[0] == '!') { first++; }
121 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
122 for (int i = 1; i < pcnt; i++)
124 line = line + std::string(params[i]) + " ";
126 Srv->SendToModeMask("oh",WM_AND,line);
129 class ModuleHelpop : public Module
139 conf = new ConfigReader;
141 h_file = conf->ReadValue("helpop", "file", 0);
144 printf("m_helpop: Helpop file not Specified.");
148 helpop = new ConfigReader(h_file);
150 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
151 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
152 (helpop->ReadValue("start", "line1", 0) == ""))
154 printf("m_helpop: Helpop file is missing important entries. Please check the example conf.");
158 if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
160 Srv->Log(DEFAULT,"Unable to claim the +h usermode.");
161 printf("m_helpop: Unable to claim the +h usermode!");
165 // Loads of comments, untill supported properly.
166 Srv->AddCommand("HELPOP",handle_helpop,0,0,"m_helpop.so");
170 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
172 if ((modechar == 'h') && (type == MT_CLIENT))
179 virtual void OnWhois(userrec* src, userrec* dst)
181 if (strchr(dst->modes,'h'))
183 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
187 virtual void OnOper(userrec* user)
189 char* modes[2]; // only two parameters
190 modes[0] = user->nick; // first parameter is the nick
191 modes[1] = "+h"; // second parameter is the mode
192 Srv->SendMode(modes,2,user); // send these, forming the command "MODE <nick> +h"
195 virtual ~ModuleHelpop()
202 virtual Version GetVersion()
204 return Version(0,0,0,1);
208 class ModuleHelpopFactory : public ModuleFactory
211 ModuleHelpopFactory()
215 ~ModuleHelpopFactory()
219 virtual Module * CreateModule()
221 return new ModuleHelpop;
226 extern "C" void * init_module( void )
228 return new ModuleHelpopFactory;