]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_randquote.cpp
Updated header comments
[user/henk/code/inspircd.git] / src / modules / m_randquote.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <fstream>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23
24
25 /* $ModDesc: Provides random Quotes on Connect. */
26
27 class ModuleRandQuote : public Module
28 {
29  private:
30
31          Server *Srv;
32          ConfigReader *conf;
33          FileReader *quotes;
34
35          std::string q_file;
36          std::string prefix;
37          std::string suffix;
38          
39  public:
40         ModuleRandQuote()
41         {
42                 Srv = new Server;
43                 conf = new ConfigReader;
44
45
46                 q_file = conf->ReadValue("randquote","file",0);
47                 prefix = conf->ReadValue("randquote","prefix",0);
48                 suffix = conf->ReadValue("randquote","suffix",0);
49
50                 if (q_file == "") {
51                         printf("m_randquote: Quotefile not specified.. Please check your config.\n\n");
52                         exit(0);
53                 }
54
55
56                 quotes = new FileReader(q_file);
57                 if(!quotes->Exists())
58                 {
59                         printf("m_randquote: QuoteFile not Found!! Please check your config.\n\n");
60                         exit(0);
61                 }
62         }
63         
64         virtual ~ModuleRandQuote()
65         {
66                 delete Srv;
67                 delete conf;
68                 delete quotes;
69         }
70         
71         virtual Version GetVersion()
72         {
73                 return Version(1,0,0,0);
74         }
75         
76         virtual void OnUserConnect(userrec* user)
77         {
78                 std::string str;
79                 int fsize;
80                 char buf[MAXBUF];
81
82                 fsize = quotes->FileSize();
83                 srand(time(NULL));
84                 str = quotes->GetLine(rand() % fsize);
85                         
86                 sprintf(buf,"NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str());
87                 Srv->SendServ(user->fd, buf);
88                 return;
89         }
90 };
91
92
93 class ModuleRandQuoteFactory : public ModuleFactory
94 {
95  public:
96         ModuleRandQuoteFactory()
97         {
98         }
99         
100         ~ModuleRandQuoteFactory()
101         {
102         }
103         
104         virtual Module * CreateModule()
105         {
106                 return new ModuleRandQuote;
107         }
108         
109 };
110
111
112 extern "C" void * init_module( void )
113 {
114         return new ModuleRandQuoteFactory;
115 }
116