9 void handle_helpop(char**, int, userrec*);
10 bool do_helpop(char**, int, userrec*);
11 void sendtohelpop(userrec*, int, char**);
14 /* $ModDesc: /helpop Command, Works like Unreal helpop */
16 void handle_helpop(char **parameters, int pcnt, userrec *user)
19 std::string output = " ";
22 do_helpop(NULL,pcnt,user);
26 // FIX by brain: make the string lowercase, ConfigReader is
28 char* lower = parameters[0];
29 for (int t = 0; t < strlen(lower); t++)
30 lower[t] = tolower(lower[t]);
32 if (parameters[0][0] == '!')
34 // Force send to all +h users
35 sendtohelpop(user, pcnt, parameters);
36 } else if (parameters[0][0] == '?') {
37 // Force to the helpop system with no forward if not found.
38 if (do_helpop(parameters, pcnt, user) == false) {
39 // Not handled by the Database, Tell the user, and forward.
40 for (int i = 1; output != ""; i++)
42 snprintf(a,MAXBUF,"line%d",i);
43 output = helpop->ReadValue("nohelp", std::string(a), 0);
45 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
49 } else if (strchr(user->modes,'o')) {
50 // Its an oper whos not using ?, send to all +h
51 sendtohelpop(user, pcnt, parameters);
53 // Check with the helpop database, if not found send to +h
54 if (do_helpop(parameters, pcnt, user) == false) {
55 // Not handled by the Database, Tell the user, and forward.
56 for (int i = 1; output != ""; i++)
58 snprintf(a,MAXBUF,"line%d",i);
59 output = helpop->ReadValue("nohelpo", std::string(a), 0);
61 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
65 sendtohelpop(user, pcnt, parameters);
70 bool do_helpop(char **parameters, int pcnt, userrec *src)
73 std::string output = " "; // a fix bought to you by brain :p
80 search = parameters[0];
83 if (search[0] == '?') {
88 for (int i = 1; output != ""; i++)
90 snprintf(a,MAXBUF,"line%d",i);
91 output = helpop->ReadValue(search, a, 0);
93 Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
102 void sendtohelpop(userrec *src, int pcnt, char **params)
104 char* first = params[0];
105 if (first[0] == '!') { first++; }
106 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
107 for (int i = 1; i < pcnt; i++)
109 line = line + std::string(params[i]) + " ";
111 Srv->SendToModeMask("oh",WM_AND,line);
114 class ModuleHelpop : public Module
124 conf = new ConfigReader;
126 h_file = conf->ReadValue("helpop", "file", 0);
129 printf("m_helpop: Helpop file not Specified.");
133 helpop = new ConfigReader(h_file);
134 if (!helpop->Verify())
136 printf("m_helpop: Invalid Helpop File. Please Ensure it exists and is error free.");
140 /*if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
141 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
142 (helpop->ReadValue("start", "line1", 0) == ""))
144 printf("m_helpop: Helpop file is missing important entries. Please check the example conf.");
148 if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
150 Srv->Log(DEFAULT,"Unable to claim the +h usermode.");
151 printf("m_helpop: Unable to claim the +h usermode!");
155 // Loads of comments, untill supported properly.
156 Srv->AddCommand("HELPOP",handle_helpop,0,0);
160 virtual bool OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
162 if ((modechar == 'h') && (type == MT_CLIENT))
169 virtual void OnWhois(userrec* src, userrec* dst)
171 if (strchr(src->modes,'h'))
173 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
177 virtual void OnOper(userrec* user)
179 char* modes[2]; // only two parameters
180 modes[0] = user->nick; // first parameter is the nick
181 modes[1] = "+h"; // second parameter is the mode
182 Srv->SendMode(modes,2,user); // send these, forming the command "MODE <nick> +h"
185 virtual ~ModuleHelpop()
192 virtual Version GetVersion()
194 return Version(0,0,0,1);
198 class ModuleHelpopFactory : public ModuleFactory
201 ModuleHelpopFactory()
205 ~ModuleHelpopFactory()
209 virtual Module * CreateModule()
211 return new ModuleHelpop;
216 extern "C" void * init_module( void )
218 return new ModuleHelpopFactory;