]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cban.cpp
b8b3e6ee17a03f05024b4efbcea7f63c444b1e12
[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 Server *Srv;
28 vector<CBan> cbans;
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 class cmd_cban : public command_t
60 {
61  private:
62         Server *Srv;
63
64  public:
65         cmd_cban () : command_t("CBAN", 'o', 1)
66         {
67                 this->source = "m_cban.so";
68         }
69
70         void Handle(char **parameters, int pcnt, userrec *user)
71         {
72                 /* syntax: CBAN #channel time :reason goes here */
73                 /* 'time' is a human-readable timestring, like 2d3h2s. */
74
75                 std::string chname;
76                 std::string reason;
77                 unsigned long expiry;
78
79                 if (pcnt == 1)
80                 {
81                         /* form: CBAN #channel removes a CBAN */
82                 }
83                 else if (pcnt >= 2)
84                 {
85                         /* full form to add a CBAN */
86                         /* XXX - checking on chnames */
87                         chname = parameters[0];
88                         expiry = TIME + Srv->Duration(parameters[1]);
89                         reason = parameters[2];
90
91                         CBan meow(chname, reason, expiry);
92                         cbans.push_back(meow)
93                 }
94         }
95 };
96
97 class ModuleCBan : public Module
98 {
99         cmd_cban* mycommand;
100
101  public:
102         ModuleCBan(Server* Me) : Module::Module(Me)
103         {
104                 Srv = Me;
105                 mycommand = new cmd_cban();
106                 Srv->AddCommand(mycommand);
107         }
108
109         virtual int OnUserPreJoin (userrec *user, chanrec *chan, const char *cname)
110         {
111                 /* check cbans in here, and apply as necessary. */
112
113                 std::string chname = cname;
114
115                 for (unsigned int a = 0; a < cbans.size(); a++)
116                 {
117                         if (chname == cbans[a].GetName())
118                         {
119                                 /* matches CBAN */
120                                 return 1;
121                         }
122                 }
123
124                 /* Allow the change. */
125                 return 0;
126         }
127
128         virtual ~ModuleCBan()
129         {
130         }
131         
132         virtual Version GetVersion()
133         {
134                 return Version(1,0,0,0,VF_VENDOR);
135         }
136 };
137
138
139 class ModuleCBanFactory : public ModuleFactory
140 {
141  public:
142         ModuleCBanFactory()
143         {
144         }
145         
146         ~ModuleCBanFactory()
147         {
148         }
149         
150         virtual Module * CreateModule(Server* Me)
151         {
152                 return new ModuleCBan(Me);
153         }
154         
155 };
156
157
158 extern "C" void * init_module( void )
159 {
160         return new ModuleCBanFactory;
161 }
162