From e909e1a3ca2995bab67d7a64d38ec937265c94fa Mon Sep 17 00:00:00 2001 From: frostycoolslug Date: Thu, 8 Apr 2004 01:21:46 +0000 Subject: /helpop command Module. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@444 e03df62e-2008-0410-955e-edbf42e46eb7 --- configure | 41 ++++++++- src/modules/m_helpop.cpp | 212 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+), 3 deletions(-) create mode 100644 src/modules/m_helpop.cpp diff --git a/configure b/configure index eccddf5fd..f4d71549b 100755 --- a/configure +++ b/configure @@ -14,8 +14,6 @@ # ######################################## -# echo -e "\033[1;37mtest\033[0;37m" - echo "Configuring default values..." ME=`pwd` @@ -28,6 +26,7 @@ NICK_LENGT=32 CHAN_LENGT=64 MAX_CHANNE=20 MAXI_MODES=20 +OSNAME=`(uname -s) 2>/dev/null` || OSNAME="unknown" if [ -z $MAX_CLIENT_T ] ; then MAX_CLIENT_T=1024 @@ -43,7 +42,43 @@ if [ -e ".config.cache" -a -z "$CLEAN" ] ; then . .config.cache fi -OSNAME=`(uname -s) 2>/dev/null` || OSNAME="unknown" +if [ "$1" = "-update" -o "$2" = "-update" ] ; then + # They wanna update their Makefile.. good for 'em + # Make sure .config.cache exists + if [ ! -e ".config.cache" ] ; then + echo "You have not run ./configure before. Please do this before trying to run the update script." + exit 0 + fi + # Right, load the cache values + . .config.cache + # Check for modules + + case "$OSNAME" in + (FreeBSD) + LDLIBS="-Ldl" + FLAGS="-fPIC -frtti -O3" + MAKEPROG="gmake" + ;; + (*) + LDLIBS="-ldl" + FLAGS="-fPIC -frtti -O3" + MAKEPROG="make" + ;; + esac + + MODULES="" + for module in src/modules/*.cpp ; do + mod=`echo $module | sed 's/.cpp/.so/' | sed 's/src\/modules\///'` + MODULES="$MODULES $mod" + done + + # Write the new makefile. + . .Makefile.inc + echo "Complete." + exit 1; +fi + + if [ -z $MAX_CLIENT ] ; then MAX_CLIENT=$MAX_CLIENT_T fi diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp new file mode 100644 index 000000000..f447a054e --- /dev/null +++ b/src/modules/m_helpop.cpp @@ -0,0 +1,212 @@ +#include "users.h" +#include "channels.h" +#include "modules.h" + +// Global Vars +ConfigReader *helpop; +Server *Srv; + +void handle_helpop(char**, int, userrec*); +bool do_helpop(char**, int, userrec*); +void sendtohelpop(userrec*, int, char**); + + +/* $ModDesc: /helpop Command, Works like Unreal helpop */ + +void handle_helpop(char **parameters, int pcnt, userrec *user) +{ + char a[MAXBUF]; + std::string output; + + if (parameters[0] == "") { do_helpop(NULL,pcnt,user); } + + if (parameters[0][0] == '!') + { + // Force send to all +h users + sendtohelpop(user, pcnt, parameters); + } else if (parameters[0][0] == '?') { + // Force to the helpop system with no forward if not found. + if (do_helpop(parameters, pcnt, user) == false) { + // Not handled by the Database, Tell the user, and forward. + for (int i = 1; output != ""; i++) + { + 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); + } + } + } 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) { + // Not handled by the Database, Tell the user, and forward. + for (int i = 1; output != ""; i++) + { + 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); + } + // Forward. + sendtohelpop(user, pcnt, parameters); + } + } +} + +bool do_helpop(char **parameters, int pcnt, userrec *src) +{ + char *search; + std::string output; + char a[MAXBUF]; + + if (!parameters) { strcpy(search, "start"); } + else { search = parameters[0]; } + + if (search[0] == '?') { search++; } + + // Make sure it exists. + if (helpop->ReadValue(std::string(search), "line1", 0) == "") + { + // Tell caller.. + return false; + } + + // Somethings there.. tell the person who wants to know :p + + 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); + } + return true; +} + + + +void sendtohelpop(userrec *src, int pcnt, char **params) +{ + char* first = params[0]; + if (first[0] == '!') { first++; } + std::string line = "*** HELPOPS - From "+std::string(src->nick)+": "+std::string(first)+" "; + for (int i = 1; i < pcnt; i++) + { + line = line + std::string(params[i]) + " "; + } + Srv->SendToModeMask("oh",WM_AND,line); +} + +class ModuleHelpop : public Module +{ + private: + ConfigReader *conf; + std::string h_file; + + public: + ModuleHelpop() + { + Srv = new Server; + conf = new ConfigReader; + + h_file = conf->ReadValue("helpop", "file", 0); + + if (h_file == "") { + printf("WE ARE AAAAALL GONNA DIEEEEEEEEEEEE!!"); + exit(0); + } + + 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); + } + + 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); + } + + /*if (!*/Srv->AddCommand("HELPOP",handle_helpop,0,1);/*) + { + Srv->Log(DEFAULT,"Someone br0ked it.. not me"); + printf("B0RKED! JUMP SHIP.. AAAAAAAAAAAAAAAAAHHHHHH!"); + exit(0); + }*/ + + } + + virtual bool OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) + { + if ((modechar == 'h') && (type == MT_CLIENT)) + { + return 1; + } + return 0; + } + + virtual void OnWhois(userrec* src, userrec* dst) { + if (strchr(src->modes,'h')) + { + Srv->SendTo(NULL,src,"310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help."); + } + } + + virtual void OnOper(userrec* user) + { + char* modes[2]; // only two parameters + modes[0] = user->nick; // first parameter is the nick + modes[1] = "+h"; // second parameter is the mode + Srv->SendMode(modes,2,user); // send these, forming the command "MODE +h" + } + + virtual ~ModuleHelpop() + { + delete Srv; + delete conf; + delete helpop; + } + + virtual Version GetVersion() + { + return Version(0,0,0,1); + } +}; + +class ModuleHelpopFactory : public ModuleFactory +{ + public: + ModuleHelpopFactory() + { + } + + ~ModuleHelpopFactory() + { + } + + virtual Module * CreateModule() + { + return new ModuleHelpop; + } + +}; + +extern "C" void * init_module( void ) +{ + return new ModuleHelpopFactory; +} + -- cgit v1.2.3