]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cban.cpp
66abbfc228dc92f1b1d0cbe0fa7e02b4edacf807
[user/henk/code/inspircd.git] / src / modules / m_cban.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2005 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 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "helperfuncs.h"
24
25 /* $ModDesc: Gives /cban, aka C:lines. Think Q:lines, for channels. */
26
27 extern time_t TIME;
28 Server *Srv;
29
30 class CBan
31 {
32  private:
33         unsigned long expiry;
34         std::string chname;
35         std::string reason;
36
37  public:
38         CBan(std::string chname, std::string reason, unsigned long expiry)
39         {
40
41         }
42
43         std::string GetName()
44         {
45                 return chname;
46         }
47
48         std::string GetReason()
49         {
50                 return reason;
51         }
52
53         unsigned long GetExpiry()
54         {
55                 return expiry;
56         }
57 };
58
59 vector<CBan> cbans;
60 /* don't ask why this is here. */
61
62 class cmd_cban : public command_t
63 {
64  private:
65         Server *Srv;
66
67  public:
68         cmd_cban () : command_t("CBAN", 'o', 1)
69         {
70                 this->source = "m_cban.so";
71         }
72
73         void Handle(char **parameters, int pcnt, userrec *user)
74         {
75                 /* syntax: CBAN #channel time :reason goes here */
76                 /* 'time' is a human-readable timestring, like 2d3h2s. */
77
78                 std::string chname;
79                 std::string reason;
80                 unsigned long expiry;
81
82                 if (pcnt == 1)
83                 {
84                         /* form: CBAN #channel removes a CBAN */
85                 }
86                 else if (pcnt >= 2)
87                 {
88                         /* full form to add a CBAN */
89                         /* XXX - checking on chnames */
90                         chname = parameters[0];
91                         expiry = TIME + Srv->CalcDuration(parameters[1]);
92                         reason = parameters[2];
93
94                         CBan meow(chname, reason, expiry);
95                         cbans.push_back(meow);
96                 }
97         }
98 };
99
100 class ModuleCBan : public Module
101 {
102         cmd_cban* mycommand;
103
104  public:
105         ModuleCBan(Server* Me) : Module::Module(Me)
106         {
107                 Srv = Me;
108                 mycommand = new cmd_cban();
109                 Srv->AddCommand(mycommand);
110         }
111
112         virtual int OnUserPreJoin (userrec *user, chanrec *chan, const char *cname)
113         {
114                 /* check cbans in here, and apply as necessary. */
115
116                 std::string chname = cname;
117
118                 for (unsigned int a = 0; a < cbans.size(); a++)
119                 {
120                         if (chname == cbans[a].GetName())
121                         {
122                                 /* matches CBAN */
123                                 return 1;
124                         }
125                 }
126
127                 /* Allow the change. */
128                 return 0;
129         }
130
131         virtual ~ModuleCBan()
132         {
133         }
134         
135         virtual Version GetVersion()
136         {
137                 return Version(1,0,0,0,VF_VENDOR);
138         }
139 };
140
141
142 class ModuleCBanFactory : public ModuleFactory
143 {
144  public:
145         ModuleCBanFactory()
146         {
147         }
148         
149         ~ModuleCBanFactory()
150         {
151         }
152         
153         virtual Module * CreateModule(Server* Me)
154         {
155                 return new ModuleCBan(Me);
156         }
157         
158 };
159
160
161 extern "C" void * init_module( void )
162 {
163         return new ModuleCBanFactory;
164 }
165