summaryrefslogtreecommitdiff
path: root/src/modules/m_randquote.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2003-01-23 19:45:57 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2003-01-23 19:45:57 +0000
commit73b9d0c5cb02f0ea8350de28bc3687e0af70ea0f (patch)
treea5845579b1363762650f0e45c62a13890e1efa43 /src/modules/m_randquote.cpp
Initial revision
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@132 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_randquote.cpp')
-rw-r--r--src/modules/m_randquote.cpp89
1 files changed, 89 insertions, 0 deletions
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;
+}
+