X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_helpop.cpp;h=bae4e73aefd1085cf1bea1e66bd7821419949c91;hb=eb4229deed0281ae566ef7e55a144e5d3183a4b2;hp=f447a054e8fbfec2a2331a0978a00fda69cc7242;hpb=e909e1a3ca2995bab67d7a64d38ec937265c94fa;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp index f447a054e..bae4e73ae 100644 --- a/src/modules/m_helpop.cpp +++ b/src/modules/m_helpop.cpp @@ -1,6 +1,23 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * Inspire is copyright (C) 2002-2004 ChatSpike-Dev. + * E-mail: + * + * + * + * Written by Craig Edwards, Craig McLure, and others. + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + #include "users.h" #include "channels.h" #include "modules.h" +#include "helperfuncs.h" // Global Vars ConfigReader *helpop; @@ -16,9 +33,12 @@ void sendtohelpop(userrec*, int, char**); void handle_helpop(char **parameters, int pcnt, userrec *user) { char a[MAXBUF]; - std::string output; + std::string output = " "; - if (parameters[0] == "") { do_helpop(NULL,pcnt,user); } + if (pcnt < 1) { + do_helpop(NULL,pcnt,user); + return; + } if (parameters[0][0] == '!') { @@ -32,13 +52,11 @@ void handle_helpop(char **parameters, int pcnt, userrec *user) { snprintf(a,MAXBUF,"line%d",i); output = helpop->ReadValue("nohelp", std::string(a), 0); - // Send line to client.. - Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output); + if(output != "") { + Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output); + } } } - } else if (strchr(user->modes,'o')) { - // Its an oper whos not using ?, send to all +h - sendtohelpop(user, pcnt, parameters); } else { // Check with the helpop database, if not found send to +h if (do_helpop(parameters, pcnt, user) == false) { @@ -47,8 +65,9 @@ void handle_helpop(char **parameters, int pcnt, userrec *user) { snprintf(a,MAXBUF,"line%d",i); output = helpop->ReadValue("nohelpo", std::string(a), 0); - // Send line to client.. - Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output); + if (output != "") { + Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output); + } } // Forward. sendtohelpop(user, pcnt, parameters); @@ -59,31 +78,39 @@ void handle_helpop(char **parameters, int pcnt, userrec *user) bool do_helpop(char **parameters, int pcnt, userrec *src) { char *search; - std::string output; + std::string output = " "; // a fix bought to you by brain :p char a[MAXBUF]; - if (!parameters) { strcpy(search, "start"); } - else { search = parameters[0]; } + if (!parameters) { + search = "start"; + } + else { + search = parameters[0]; + } - if (search[0] == '?') { search++; } + if (search[0] == '?') { + search++; + } - // Make sure it exists. - if (helpop->ReadValue(std::string(search), "line1", 0) == "") - { - // Tell caller.. - return false; - } + // FIX by brain: make the string lowercase, ConfigReader is + // case sensitive + char lower[MAXBUF]; + strlcpy(lower,search,MAXBUF); + for (int t = 0; t < strlen(lower); t++) + lower[t] = tolower(lower[t]); - // Somethings there.. tell the person who wants to know :p + int nlines = 0; for (int i = 1; output != ""; i++) { snprintf(a,MAXBUF,"line%d",i); - output = helpop->ReadValue(std::string(search), std::string(a), 0); - // Send line to client.. - Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output); + output = helpop->ReadValue(lower, a, 0); + if (output != "") { + Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output); + nlines++; + } } - return true; + return (nlines>0); } @@ -115,42 +142,32 @@ class ModuleHelpop : public Module h_file = conf->ReadValue("helpop", "file", 0); if (h_file == "") { - printf("WE ARE AAAAALL GONNA DIEEEEEEEEEEEE!!"); - exit(0); + log(DEFAULT,"m_helpop: Helpop file not Specified."); + return; } helpop = new ConfigReader(h_file); - if (!helpop->Verify()) - { - printf("Thats it.. were all dead."); - exit(0); - } if ((helpop->ReadValue("nohelp", "line1", 0) == "") || (helpop->ReadValue("nohelpo", "line1", 0) == "") || (helpop->ReadValue("start", "line1", 0) == "")) { - printf("m_helpop: Important Shit Missing. Please check your file."); - exit(0); + log(DEFAULT,"m_helpop: Helpop file is missing important entries. Please check the example conf."); + return; } if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0)) { - Srv->Log(DEFAULT,"pr0n Found. Send it to Craig@chatspike.net for investigation."); - printf("Could not claim usermode +h for this module!"); - exit(0); + Srv->Log(DEFAULT,"Unable to claim the +h usermode."); + return; } - /*if (!*/Srv->AddCommand("HELPOP",handle_helpop,0,1);/*) - { - Srv->Log(DEFAULT,"Someone br0ked it.. not me"); - printf("B0RKED! JUMP SHIP.. AAAAAAAAAAAAAAAAAHHHHHH!"); - exit(0); - }*/ + // Loads of comments, untill supported properly. + Srv->AddCommand("HELPOP",handle_helpop,0,0,"m_helpop.so"); } - virtual bool OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) + virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { if ((modechar == 'h') && (type == MT_CLIENT)) { @@ -159,8 +176,9 @@ class ModuleHelpop : public Module return 0; } - virtual void OnWhois(userrec* src, userrec* dst) { - if (strchr(src->modes,'h')) + virtual void OnWhois(userrec* src, userrec* dst) + { + if (strchr(dst->modes,'h')) { Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help."); } @@ -183,7 +201,7 @@ class ModuleHelpop : public Module virtual Version GetVersion() { - return Version(0,0,0,1); + return Version(1,0,0,1,VF_STATIC|VF_VENDOR); } }; @@ -209,4 +227,3 @@ extern "C" void * init_module( void ) { return new ModuleHelpopFactory; } -