diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/.make | 3 | ||||
-rw-r--r-- | src/modules/m_cloaking.cpp | 73 | ||||
-rw-r--r-- | src/modules/m_foobar.cpp | 113 | ||||
-rw-r--r-- | src/modules/m_randquote.cpp | 89 |
4 files changed, 278 insertions, 0 deletions
diff --git a/src/modules/.make b/src/modules/.make new file mode 100644 index 000000000..0f68a9fad --- /dev/null +++ b/src/modules/.make @@ -0,0 +1,3 @@ +g++ -I../../include -fPIC -frtti -O3 -shared -o m_cloaking.so m_cloaking.cpp +g++ -I../../include -fPIC -frtti -O3 -shared -o m_foobar.so m_foobar.cpp +g++ -I../../include -fPIC -frtti -O3 -shared -o m_randquote.so m_randquote.cpp diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp new file mode 100644 index 000000000..91ab49054 --- /dev/null +++ b/src/modules/m_cloaking.cpp @@ -0,0 +1,73 @@ +#include <stdio.h> + +#include "users.h" +#include "channels.h" +#include "modules.h" + +/* $ModDesc: Provides masking of user hostnames */ + +class ModuleCloaking : public Module +{ + private: + + Server *Srv; + + public: + ModuleCloaking() + { + Srv = new Server; + } + + virtual ~ModuleCloaking() + { + delete Srv; + } + + virtual Version GetVersion() + { + return Version(1,0,0,0); + } + + virtual void OnUserConnect(userrec* user) + { + if (strstr(user->dhost,".")) + { + string a = strstr(user->dhost,"."); + char ra[64]; + long seed,s2; + memcpy(&seed,user->dhost,sizeof(long)); + memcpy(&s2,a.c_str(),sizeof(long)); + sprintf(ra,"%.8X",seed*s2*strlen(user->host)); + string b = Srv->GetNetworkName() + "-" + ra + a; + Srv->Debug("cloak: allocated "+b); + strcpy(user->dhost,b.c_str()); + } + } + +}; + + +class ModuleCloakingFactory : public ModuleFactory +{ + public: + ModuleCloakingFactory() + { + } + + ~ModuleCloakingFactory() + { + } + + virtual Module * CreateModule() + { + return new ModuleCloaking; + } + +}; + + +extern "C" void * init_module( void ) +{ + return new ModuleCloakingFactory; +} + diff --git a/src/modules/m_foobar.cpp b/src/modules/m_foobar.cpp new file mode 100644 index 000000000..9aed188d8 --- /dev/null +++ b/src/modules/m_foobar.cpp @@ -0,0 +1,113 @@ +#include "users.h" +#include "channels.h" +#include "modules.h" + +/* $ModDesc: A dummy module for testing */ + +// Class ModuleFoobar inherits from Module +// It just outputs simple debug strings to show its methods are working. + +class ModuleFoobar : public Module +{ + private: + + // It is recommended that your class makes use of one or more Server + // objects. A server object is a class which contains methods which + // encapsulate the exports from the core of the ircd. + // such methods include Debug, SendChannel, etc. + + Server *Srv; + public: + ModuleFoobar() + { + // The constructor just creates an instance of the server class + + Srv = new Server; + } + + virtual ~ModuleFoobar() + { + // destructor deletes the instance of the server class + + delete Srv; + } + + virtual Version GetVersion() + { + // this method instantiates a class of type Version, and returns + // the modules version information using it. + + return Version(1,0,0,0); + } + + virtual void OnUserConnect(userrec* user) + { + // method called when a user connects + + string b = user->nick; + Srv->Debug("Foobar: User connecting: " + b); + } + + virtual void OnUserQuit(userrec* user) + { + // method called when a user disconnects + + string b = user->nick; + Srv->Debug("Foobar: User quitting: " + b); + } + + virtual void OnUserJoin(userrec* user, chanrec* channel) + { + // method called when a user joins a channel + + string c = channel->name; + string b = user->nick; + Srv->Debug("Foobar: User " + b + " joined " + c); + } + + virtual void OnUserPart(userrec* user, chanrec* channel) + { + // method called when a user parts a channel + + string c = channel->name; + string b = user->nick; + Srv->Debug("Foobar: User " + b + " parted " + c); + } + +}; + + +// +// The ModuleFoobarFactory class inherits from ModuleFactory +// and creates a ModuleFoobar object when requested. +// + +class ModuleFoobarFactory : public ModuleFactory +{ + public: + ModuleFoobarFactory() + { + } + + ~ModuleFoobarFactory() + { + } + + virtual Module * CreateModule() + { + return new ModuleFoobar; + } + +}; + + +// +// The "C" linkage factory0() function creates the ModuleFoobarFactory +// class for this library +// + +extern "C" void * init_module( void ) +{ + return new ModuleFoobarFactory; +} + diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp new file mode 100644 index 000000000..aebf7c0ad --- /dev/null +++ b/src/modules/m_randquote.cpp @@ -0,0 +1,89 @@ +#include <stdio.h> +#include <stdlib.h> +#include <fstream> + +#include "users.h" +#include "channels.h" +#include "modules.h" + + +/* $ModDesc: Provides random Quotes on Connect. */ + +class ModuleRandQuote : public Module +{ + private: + + Server *Srv; + ConfigReader *conf; + FileReader *quotes; + + string q_file; + string prefix; + string suffix; + + public: + ModuleRandQuote() + { + Srv = new Server; + conf = new ConfigReader; + + q_file = conf->ReadValue("randquote","file",0); + prefix = conf->ReadValue("randquote","prefix",0); + suffix = conf->ReadValue("randquote","suffix",0); + + quotes = new FileReader(q_file); + } + + virtual ~ModuleRandQuote() + { + delete Srv; + delete conf; + delete quotes; + } + + virtual Version GetVersion() + { + return Version(1,0,0,0); + } + + virtual void OnUserConnect(userrec* user) + { + string str; + int fsize; + char buf[MAXBUF]; + + fsize = quotes->FileSize(); + srand(time(NULL)); + str = quotes->GetLine(rand() % fsize); + + sprintf(buf,"NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str()); + Srv->SendServ(user->fd, buf); + return; + } +}; + + +class ModuleRandQuoteFactory : public ModuleFactory +{ + public: + ModuleRandQuoteFactory() + { + } + + ~ModuleRandQuoteFactory() + { + } + + virtual Module * CreateModule() + { + return new ModuleRandQuote; + } + +}; + + +extern "C" void * init_module( void ) +{ + return new ModuleRandQuoteFactory; +} + |