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