Anope IRC Services  Version 1.8
cs_tban.c
Go to the documentation of this file.
1 /* cs_tban.c - Bans the user for a given length of time
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Based on the original module by Rob <rob@anope.org>
7  * Included in the Anope module pack since Anope 1.7.8
8  * Anope Coder: Rob <rob@anope.org>
9  *
10  * Please read COPYING and README for further details.
11  *
12  * Send bug reports to the Anope Coder instead of the module
13  * author, because any changes since the inclusion into anope
14  * are not supported by the original author.
15  *
16  */
17 /*************************************************************************/
18 
19 #include "module.h"
20 
21 #define AUTHOR "Rob"
22 #define VERSION VERSION_STRING
23 
24 static void myHelp(User * u);
25 static void myFullHelpSyntax(User * u);
26 static int myFullHelp(User * u);
27 static void mySendResponse(User * u, char *channel, char *mask, char *time);
28 
29 static int do_tban(User * u);
30 static void addBan(Channel * c, time_t timeout, char *banmask);
31 static int delBan(int argc, char **argv);
32 static int canBanUser(Channel * c, User * u, User * u2);
33 
34 static void mAddLanguages(void);
35 
36 #define LANG_NUM_STRINGS 4
37 #define TBAN_HELP 0
38 #define TBAN_SYNTAX 1
39 #define TBAN_HELP_DETAIL 2
40 #define TBAN_RESPONSE 3
41 
42 int AnopeInit(int argc, char **argv)
43 {
44  Command *c;
45  int status = 0;
46 
48  c = createCommand("TBAN", do_tban, NULL, -1, -1, -1, -1, -1);
50  status = moduleAddCommand(CHANSERV, c, MOD_HEAD);
51 
52  mAddLanguages();
53 
57 
58  if (status != MOD_ERR_OK) {
59  return MOD_STOP;
60  }
61  return MOD_CONT;
62 }
63 
64 void AnopeFini(void)
65 {
66  /* module is unloading */
67 }
68 
69 static void myHelp(User * u)
70 {
72 }
73 
74 static void myFullHelpSyntax(User * u)
75 {
77 }
78 
79 static int myFullHelp(User * u)
80 {
82  notice(s_ChanServ, u->nick, "");
84  return MOD_CONT;
85 }
86 
87 static void mySendResponse(User * u, char *channel, char *mask, char *time)
88 {
89  moduleNoticeLang(s_ChanServ, u, TBAN_RESPONSE, mask, channel, time);
90 }
91 
92 static int do_tban(User * u)
93 {
94  char mask[BUFSIZE];
95  Channel *c;
96  User *u2 = NULL;
97 
98  char *buffer = moduleGetLastBuffer();
99  char *chan;
100  char *nick;
101  char *time;
102 
103  chan = myStrGetToken(buffer, ' ', 0);
104  nick = myStrGetToken(buffer, ' ', 1);
105  time = myStrGetToken(buffer, ' ', 2);
106 
107  if (time && chan && nick) {
108 
109  if (!(c = findchan(chan))) {
110  notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
111  } else if (!(u2 = finduser(nick))) {
112  notice_lang(s_ChanServ, u, NICK_X_NOT_IN_USE, nick);
113  } else {
114  if (canBanUser(c, u, u2)) {
115  get_idealban(c->ci, u2, mask, sizeof(mask));
116  addBan(c, dotime(time), mask);
117  mySendResponse(u, chan, mask, time);
118  }
119  }
120  } else {
121  myFullHelpSyntax(u);
122  }
123  if (time)
124  free(time);
125  if (nick)
126  free(nick);
127  if (chan)
128  free(chan);
129 
130  return MOD_CONT;
131 }
132 
133 static void addBan(Channel * c, time_t timeout, char *banmask)
134 {
135  char *av[3];
136  char *cb[2];
137 
138  cb[0] = c->name;
139  cb[1] = banmask;
140 
141  av[0] = sstrdup("+b");
142  av[1] = banmask;
143 
144  anope_cmd_mode(whosends(c->ci), c->name, "+b %s", av[1]);
145  chan_set_modes(s_ChanServ, c, 2, av, 1);
146 
147  free(av[0]);
148  moduleAddCallback("tban", time(NULL) + timeout, delBan, 2, cb);
149 }
150 
151 static int delBan(int argc, char **argv)
152 {
153  char *av[3];
154  Channel *c;
155 
156  av[0] = sstrdup("-b");
157  av[1] = argv[1];
158 
159  if ((c = findchan(argv[0])) && c->ci) {
160  anope_cmd_mode(whosends(c->ci), c->name, "-b %s", av[1]);
161  chan_set_modes(s_ChanServ, c, 2, av, 1);
162  }
163 
164  free(av[0]);
165 
166  return MOD_CONT;
167 }
168 
169 static int canBanUser(Channel * c, User * u, User * u2)
170 {
171  ChannelInfo *ci;
172  int ok = 0;
173  if (!(ci = c->ci)) {
174  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
175  } else if (ci->flags & CI_VERBOTEN) {
176  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, c->name);
177  } else if (!check_access(u, ci, CA_BAN)) {
178  notice_lang(s_ChanServ, u, ACCESS_DENIED);
179  } else if (ircd->except && is_excepted(ci, u2)) {
180  notice_lang(s_ChanServ, u, CHAN_EXCEPTED, u2->nick, ci->name);
181  } else if (ircd->protectedumode && is_protected(u2)) {
182  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
183  } else {
184  ok = 1;
185  }
186 
187  return ok;
188 }
189 
190 
191 static void mAddLanguages(void)
192 {
193  char *langtable_en_us[] = {
194  " TBAN Bans the user for a given length of time",
195  "Syntax: TBAN channel nick time",
196  "Bans the given user from a channel for a specified length of\n"
197  "time. If the ban is removed before by hand, it will NOT be replaced.",
198  "%s banned from %s, will auto-expire in %s"
199  };
200 
201  char *langtable_nl[] = {
202  " TBAN Verban een gebruiker voor een bepaalde tijd",
203  "Syntax: TBAN kanaal nick tijd",
204  "Verbant de gegeven gebruiken van het gegeven kanaal voor de\n"
205  "gegeven tijdsduur. Als de verbanning eerder wordt verwijderd,\n"
206  "zal deze NIET worden vervangen.",
207  "%s verbannen van %s, zal verlopen in %s"
208  };
209 
210  char *langtable_de[] = {
211  " TBAN Bant ein User fr eine bestimmte Zeit aus ein Channel",
212  "Syntax: TBAN Channel Nickname Zeit",
213  "Bant ein User fr eine bestimmte Zeit aus ein Channel\n"
214  "Wenn der Ban manuell entfernt wird, wird es NICHT ersetzt.",
215  "%s gebannt von %s, wird auto-auslaufen in %s"
216  };
217 
218  char *langtable_pt[] = {
219  " TBAN Bane o usurio por um determinado perodo de tempo",
220  "Sintaxe: TBAN canal nick tempo",
221  "Bane de um canal o usurio especificado por um determinado perodo de\n"
222  "tempo. Se o ban for removido manualmente antes do tempo, ele no ser recolocado.",
223  "%s foi banido do %s, ir auto-expirar em %s"
224  };
225 
226  char *langtable_ru[] = {
227  " TBAN , ": TBAN # ", " \n" ": ( ) \n" " !", " %s %s %s " }; char *langtable_it[] = { " TBAN Banna l'utente per un periodo di tempo specificato", "Sintassi: TBAN canale nick tempo", "Banna l'utente specificato da un canale per un periodo di tempo\n" "specificato. Se il ban viene rimosso a mano prima della scadenza, NON verr rimpiazzato.", "%s bannato da %s, scadr automaticamente tra %s" }; char *langtable_fr[] = { " TBAN Bannit l'utilisateur pour une priode dfinie", "Syntaxe: \002TBAN \037canal\037 \037pseudo\037 \037dure\037\002", "Bannit un utilisateur d'un canal pour une dure spcifie.\n" "Si le ban est retir manuellement avant la fin du dlai, il ne sera PAS remis.", "%s banni de %s, avec expiration dans %s" }; moduleInsertLanguage(LANG_EN_US, LANG_NUM_STRINGS, langtable_en_us); moduleInsertLanguage(LANG_NL, LANG_NUM_STRINGS, langtable_nl); moduleInsertLanguage(LANG_DE, LANG_NUM_STRINGS, langtable_de); moduleInsertLanguage(LANG_PT, LANG_NUM_STRINGS, langtable_pt); moduleInsertLanguage(LANG_RU, LANG_NUM_STRINGS, langtable_ru); moduleInsertLanguage(LANG_IT, LANG_NUM_STRINGS, langtable_it); moduleInsertLanguage(LANG_FR, LANG_NUM_STRINGS, langtable_fr); } /* EOF */ ",
228  ": TBAN # ",
229  " \n"
230  ": ( ) n" " !", " %s %s %s " }; char *langtable_it[] = { " TBAN Banna l'utente per un periodo di tempo specificato", "Sintassi: TBAN canale nick tempo", "Banna l'utente specificato da un canale per un periodo di tempo\n" "specificato. Se il ban viene rimosso a mano prima della scadenza, NON verr rimpiazzato.", "%s bannato da %s, scadr automaticamente tra %s" }; char *langtable_fr[] = { " TBAN Bannit l'utilisateur pour une priode dfinie", "Syntaxe: \002TBAN \037canal\037 \037pseudo\037 \037dure\037\002", "Bannit un utilisateur d'un canal pour une dure spcifie.\n" "Si le ban est retir manuellement avant la fin du dlai, il ne sera PAS remis.", "%s banni de %s, avec expiration dans %s" }; moduleInsertLanguage(LANG_EN_US, LANG_NUM_STRINGS, langtable_en_us); moduleInsertLanguage(LANG_NL, LANG_NUM_STRINGS, langtable_nl); moduleInsertLanguage(LANG_DE, LANG_NUM_STRINGS, langtable_de); moduleInsertLanguage(LANG_PT, LANG_NUM_STRINGS, langtable_pt); moduleInsertLanguage(LANG_RU, LANG_NUM_STRINGS, langtable_ru); moduleInsertLanguage(LANG_IT, LANG_NUM_STRINGS, langtable_it); moduleInsertLanguage(LANG_FR, LANG_NUM_STRINGS, langtable_fr); } /* EOF */ \n"
231  " !",
232  " %s %s %s "
233  };
234 
235  char *langtable_it[] = {
236  " TBAN Banna l'utente per un periodo di tempo specificato",
237  "Sintassi: TBAN canale nick tempo",
238  "Banna l'utente specificato da un canale per un periodo di tempo\n"
239  "specificato. Se il ban viene rimosso a mano prima della scadenza, NON verr rimpiazzato.",
240  "%s bannato da %s, scadr automaticamente tra %s"
241  };
242 
243  char *langtable_fr[] = {
244  " TBAN Bannit l'utilisateur pour une priode dfinie",
245  "Syntaxe: \002TBAN \037canal\037 \037pseudo\037 \037dure\037\002",
246  "Bannit un utilisateur d'un canal pour une dure spcifie.\n"
247  "Si le ban est retir manuellement avant la fin du dlai, il ne sera PAS remis.",
248  "%s banni de %s, avec expiration dans %s"
249  };
250 
258 }
259 
260 
261 /* EOF */
#define LANG_DE
Definition: services.h:1324
char nick[NICKMAX]
Definition: services.h:875
MDE void moduleNoticeLang(char *source, User *u, int number,...)
Definition: modules.c:2680
E IRCDVar * ircd
Definition: extern.h:39
#define LANG_RU
Definition: services.h:1328
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
E int dotime(const char *s)
Definition: misc.c:364
static void addBan(Channel *c, time_t timeout, char *banmask)
Definition: cs_tban.c:133
int AnopeInit(int argc, char **argv)
Definition: cs_tban.c:42
#define CA_BAN
Definition: services.h:786
#define TBAN_RESPONSE
Definition: cs_tban.c:40
#define LANG_NL
Definition: services.h:1327
E void notice(char *source, char *dest, const char *fmt,...)
Definition: send.c:274
#define CI_VERBOTEN
Definition: services.h:725
E void chan_set_modes(const char *source, Channel *chan, int ac, char **av, int check)
Definition: channels.c:161
static void mySendResponse(User *u, char *channel, char *mask, char *time)
Definition: cs_tban.c:87
E int is_protected(User *user)
Definition: users.c:924
#define TBAN_HELP
Definition: cs_tban.c:37
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
ChannelInfo * ci
Definition: services.h:1001
static int myFullHelp(User *u)
Definition: cs_tban.c:79
char name[CHANMAX]
Definition: services.h:654
int except
Definition: services.h:320
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
MDE char * moduleGetLastBuffer(void)
Definition: modules.c:1988
E int is_excepted(ChannelInfo *ci, User *user)
Definition: users.c:950
static void mAddLanguages(void)
Definition: cs_tban.c:191
E Channel * findchan(const char *chan)
Definition: channels.c:394
E char * sstrdup(const char *s)
Definition: memory.c:105
E int get_idealban(ChannelInfo *ci, User *u, char *ret, int retlen)
Definition: chanserv.c:2380
#define MOD_STOP
Definition: modules.h:53
#define LANG_FR
Definition: services.h:1321
uint32 flags
Definition: services.h:669
static void myHelp(User *u)
Definition: cs_tban.c:69
#define AUTHOR
Definition: cs_tban.c:21
E User * finduser(const char *nick)
Definition: users.c:323
static int canBanUser(Channel *c, User *u, User *u2)
Definition: cs_tban.c:169
uint32 protectedumode
Definition: services.h:323
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
#define TBAN_HELP_DETAIL
Definition: cs_tban.c:39
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
static int delBan(int argc, char **argv)
Definition: cs_tban.c:151
#define MOD_ERR_OK
Definition: modules.h:71
#define MOD_CONT
Definition: modules.h:54
#define LANG_NUM_STRINGS
Definition: cs_tban.c:36
#define LANG_IT
Definition: services.h:1323
MDE void moduleInsertLanguage(int langNumber, int ac, char **av)
Definition: modules.c:2650
#define whosends(ci)
Definition: extern.h:163
static void myFullHelpSyntax(User *u)
Definition: cs_tban.c:74
E void anope_cmd_mode(char *source, char *dest, const char *fmt,...)
Definition: ircd.c:211
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
E char * myStrGetToken(const char *str, const char dilim, int token_number)
Definition: misc.c:654
static int do_tban(User *u)
Definition: cs_tban.c:92
#define LANG_EN_US
Definition: services.h:1315
MDE int moduleAddHelp(Command *c, int(*func)(User *u))
Definition: modules.c:2064
char name[CHANMAX]
Definition: services.h:1000
MDE int moduleAddCallback(char *name, time_t when, int(*func)(int argc, char *argv[]), int argc, char **argv)
Definition: modules.c:1794
void AnopeFini(void)
Definition: cs_tban.c:64
E char * s_ChanServ
Definition: extern.h:285
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define TBAN_SYNTAX
Definition: cs_tban.c:38
#define MOD_HEAD
Definition: module.h:12
#define LANG_PT
Definition: services.h:1320
#define BUFSIZE
Definition: config.h:47
#define VERSION
Definition: cs_tban.c:22