]>
jfr.im git - irc/quakenet/newserv.git/blob - invalidbans/invalidbans.c
2 #include "../core/schedule.h"
3 #include "../control/control.h"
4 #include "../lib/irc_string.h"
5 #include "../localuser/localuserchannel.h"
6 #include "../lib/version.h"
10 static int ib_nickext
;
12 typedef struct ibnick
{
17 static void ib_clear_ext(void *arg
) {
20 if (!np
->exts
[ib_nickext
])
23 free(np
->exts
[ib_nickext
]);
24 np
->exts
[ib_nickext
] = NULL
;
27 static void ib_hook_newnick(int hooknum
, void *arg
) {
29 np
->exts
[ib_nickext
] = NULL
;
32 static void ib_hook_lostnick(int hooknum
, void *arg
) {
34 ibnick
*inp
= np
->exts
[ib_nickext
];
39 deleteschedule(inp
->sched
, ib_clear_ext
, np
);
40 free(np
->exts
[ib_nickext
]);
43 static void ib_hook_modechange(int hooknum
, void *arg
) {
44 void **arglist
=(void **)arg
;
45 channel
*cp
=(channel
*)arglist
[0];
46 nick
*np
=(nick
*)arglist
[1];
47 long changeflags
=(long)arglist
[2];
50 int colons
, colonsnext
;
57 if (!(changeflags
& MODECHANGE_BANS
))
60 inp
= np
->exts
[ib_nickext
];
62 /* Ignore the mode change if the same user has recently
63 * set/unset a channel ban. */
64 if (inp
&& inp
->timeout
> time(NULL
))
68 deleteschedule(inp
->sched
, ib_clear_ext
, np
);
70 np
->exts
[ib_nickext
] = NULL
;
73 array_init(&bans
, 512);
75 for (cbp
= cp
->bans
; cbp
; cbp
= cbp
->next
) {
82 for (p
= cbp
->host
->content
; *p
; p
++) {
91 if (colons
- colonsnext
>= 8) {
92 slot
= array_getfreeslot(&bans
);
93 mask
= ((char *)bans
.content
) + slot
* 512;
94 strncpy(mask
, bantostring(cbp
), 512);
99 localsetmodeinit(&changes
, cp
, NULL
);
101 for (i
= 0; i
< bans
.cursi
; i
++) {
102 mask
= ((char *)bans
.content
) + i
* 512;
104 pos
= strchr(mask
, '@');
107 continue; /* This should never happen. */
109 pos
++; /* Skip over the @ sign. */
111 for (; *pos
; pos
++) {
118 localdosetmode_ban(&changes
, mask
, MCB_ADD
);
121 localsetmodeflush(&changes
, 1);
123 /* Ignore the user for a short amount of time. If it's a bot
124 * it'll probably try re-setting the ban immediately. */
125 inp
= malloc(sizeof(ibnick
));
126 inp
->timeout
= time(NULL
) + 15;
127 inp
->sched
= scheduleoneshot(inp
->timeout
+ 1, ib_clear_ext
, np
);
128 np
->exts
[ib_nickext
] = inp
;
135 registerhook(HOOK_NICK_NEWNICK
, &ib_hook_newnick
);
136 registerhook(HOOK_NICK_LOSTNICK
, &ib_hook_lostnick
);
137 registerhook(HOOK_CHANNEL_MODECHANGE
, &ib_hook_modechange
);
139 ib_nickext
= registernickext("invalidbans");
143 deregisterhook(HOOK_NICK_NEWNICK
, &ib_hook_newnick
);
144 deregisterhook(HOOK_NICK_LOSTNICK
, &ib_hook_lostnick
);
145 deregisterhook(HOOK_CHANNEL_MODECHANGE
, &ib_hook_modechange
);
147 releasenickext(ib_nickext
);