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 = " ";
21 if (parameters[0] == "") { do_helpop(NULL,pcnt,user); }
23 if (parameters[0][0] == '!')
25 // Force send to all +h users
26 sendtohelpop(user, pcnt, parameters);
27 } else if (parameters[0][0] == '?') {
28 // Force to the helpop system with no forward if not found.
29 if (do_helpop(parameters, pcnt, user) == false) {
30 // Not handled by the Database, Tell the user, and forward.
31 for (int i = 1; output != ""; i++)
33 snprintf(a,MAXBUF,"line%d",i);
34 output = helpop->ReadValue("nohelp", std::string(a), 0);
36 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
40 } else if (strchr(user->modes,'o')) {
41 // Its an oper whos not using ?, send to all +h
42 sendtohelpop(user, pcnt, parameters);
44 // Check with the helpop database, if not found send to +h
45 if (do_helpop(parameters, pcnt, user) == false) {
46 // Not handled by the Database, Tell the user, and forward.
47 for (int i = 1; output != ""; i++)
49 snprintf(a,MAXBUF,"line%d",i);
50 output = helpop->ReadValue("nohelpo", std::string(a), 0);
52 Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
56 sendtohelpop(user, pcnt, parameters);
61 bool do_helpop(char **parameters, int pcnt, userrec *src)
64 std::string output = " "; // a fix bought to you by brain :p
67 if (!parameters) { strcpy(search, "start"); }
68 else { search = parameters[0]; }
70 if (search[0] == '?') { search++; }
72 // Make sure it exists.
73 if (helpop->ReadValue(std::string(search), "line1", 0) == "")
79 // Somethings there.. tell the person who wants to know :p
81 for (int i = 1; output != ""; i++)
83 snprintf(a,MAXBUF,"line%d",i);
84 output = helpop->ReadValue(std::string(search), std::string(a), 0);
86 Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
94 void sendtohelpop(userrec *src, int pcnt, char **params)
96 char* first = params[0];
97 if (first[0] == '!') { first++; }
98 std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" ";
99 for (int i = 1; i < pcnt; i++)
101 line = line + std::string(params[i]) + " ";
103 Srv->SendToModeMask("oh",WM_AND,line);
106 class ModuleHelpop : public Module
116 conf = new ConfigReader;
118 h_file = conf->ReadValue("helpop", "file", 0);
121 printf("m_helpop: Helpop file not Specified.");
125 helpop = new ConfigReader(h_file);
126 if (!helpop->Verify())
128 printf("m_helpop: Invalid Helpop File. Please Ensure it exists and is error free.");
132 if ((helpop->ReadValue("nohelp", "line1", 0) == "") ||
133 (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
134 (helpop->ReadValue("start", "line1", 0) == ""))
136 printf("m_helpop: Helpop file is missing important entries. Please check the example conf.");
140 if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
142 Srv->Log(DEFAULT,"Unable to clame the +h usermode.");
143 printf("m_helpop: Unable to claim the +h usermode!");
147 // Loads of comments, untill supported properly.
148 /*if (!*/Srv->AddCommand("HELPOP",handle_helpop,0,0);/*)
150 Srv->Log(DEFAULT,"Unable to claim the HELPOP command.");
151 printf("m_helpop: Unable to claim the HELPOP command.");
157 virtual bool OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
159 if ((modechar == 'h') && (type == MT_CLIENT))
166 virtual void OnWhois(userrec* src, userrec* dst) {
167 if (strchr(src->modes,'h'))
169 Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
173 virtual void OnOper(userrec* user)
175 char* modes[2]; // only two parameters
176 modes[0] = user->nick; // first parameter is the nick
177 modes[1] = "+h"; // second parameter is the mode
178 Srv->SendMode(modes,2,user); // send these, forming the command "MODE <nick> +h"
181 virtual ~ModuleHelpop()
188 virtual Version GetVersion()
190 return Version(0,0,0,1);
194 class ModuleHelpopFactory : public ModuleFactory
197 ModuleHelpopFactory()
201 ~ModuleHelpopFactory()
205 virtual Module * CreateModule()
207 return new ModuleHelpop;
212 extern "C" void * init_module( void )
214 return new ModuleHelpopFactory;