]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cban.cpp
Added debugging. Let's fix this sucker >:/
[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 = 0;
92 //TIME + Srv->CalcDuration(parameters[1]);
93                         reason = parameters[2];
94
95                         CBan meow(chname, reason, expiry);
96                         cbans.push_back(meow);
97                 }
98         }
99 };
100
101 class ModuleCBan : public Module
102 {
103         cmd_cban* mycommand;
104
105  public:
106         ModuleCBan(Server* Me) : Module::Module(Me)
107         {
108                 Srv = Me;
109                 mycommand = new cmd_cban();
110                 Srv->AddCommand(mycommand);
111         }
112
113         virtual int OnUserPreJoin(userrec *user, chanrec *chan, const char *cname)
114         {
115                 /* check cbans in here, and apply as necessary. */
116
117                 std::string chname = cname;
118
119                 for (unsigned int a = 0; a < cbans.size(); a++)
120                 {
121                         WriteOpers("m_cban: DEBUG: checking %s against %s in OnPreUserJoin()", chname, cbans[a].GetName());
122                         if (chname == cbans[a].GetName())
123                         {
124                                 /* matches CBAN */
125                                 WriteOpers("DENY join");
126                                 return 1;
127                         }
128                 }
129
130                 WriteOpers("DONE checking, allowed");
131
132                 /* Allow the change. */
133                 return 0;
134         }
135
136         virtual ~ModuleCBan()
137         {
138         }
139         
140         virtual Version GetVersion()
141         {
142                 return Version(1,0,0,0,VF_VENDOR);
143         }
144 };
145
146
147 class ModuleCBanFactory : public ModuleFactory
148 {
149  public:
150         ModuleCBanFactory()
151         {
152         }
153         
154         ~ModuleCBanFactory()
155         {
156         }
157         
158         virtual Module * CreateModule(Server* Me)
159         {
160                 return new ModuleCBan(Me);
161         }
162         
163 };
164
165
166 extern "C" void * init_module( void )
167 {
168         return new ModuleCBanFactory;
169 }
170