1 /* spamserv.c - anti spam service
2 * Copyright 2004 feigling
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. Important limitations are
8 * listed in the COPYING file that accompanies this software.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, email evilnet-devel@lists.sourceforge.net.
31 #define SPAMSERV_CONF_NAME "services/spamserv"
33 #define KEY_EXCEPTIONS "exceptions"
34 #define KEY_BADWORDS "badwords"
35 #define KEY_FLAGS "flags"
36 #define KEY_INFO "info"
37 #define KEY_EXPIRY "expiry"
39 #define KEY_DEBUG_CHANNEL "debug_channel"
40 #define KEY_GLOBAL_EXCEPTIONS "global_exceptions"
41 #define KEY_GLOBAL_BADWORDS "global_badwords"
42 #define KEY_NETWORK_RULES "network_rules"
43 #define KEY_TRIGGER "trigger"
44 #define KEY_SHORT_BAN_DURATION "short_ban_duration"
45 #define KEY_LONG_BAN_DURATION "long_ban_duration"
46 #define KEY_GLINE_DURATION "gline_duration"
47 #define KEY_EXCEPTION_MAX "exception_max"
48 #define KEY_EXCEPTION_MIN_LEN "exception_min_len"
49 #define KEY_EXCEPTION_MAX_LEN "exception_max_len"
50 #define KEY_BADWORD_MAX "badword_max"
51 #define KEY_BADWORD_MIN_LEN "badword_min_len"
52 #define KEY_BADWORD_MAX_LEN "badword_max_len"
53 #define KEY_ADV_CHAN_MUST_EXIST "adv_chan_must_exist"
54 #define KEY_STRIP_MIRC_CODES "strip_mirc_codes"
55 #define KEY_ALLOW_MOVE_MERGE "allow_move_merge"
57 #define SPAMSERV_FUNC(NAME) MODCMD_FUNC(NAME)
58 #define SPAMSERV_SYNTAX() svccmd_send_help(user, spamserv, cmd)
59 #define SPAMSERV_MIN_PARMS(N) do { \
62 ss_reply(MSG_MISSING_PARAMS, argv[0]); \
64 return 0; } } while(0)
66 struct userNode
*spamserv
;
67 static struct module *spamserv_module
;
68 static struct service
*spamserv_service
;
69 static struct log_type
*SS_LOG
;
70 static unsigned long crc_table
[256];
72 dict_t registered_channels_dict
;
73 dict_t connected_users_dict
;
74 dict_t killed_users_dict
;
76 #define spamserv_notice(target, format...) send_message(target , spamserv , ## format)
77 #define spamserv_debug(format...) do { if(spamserv_conf.debug_channel) send_channel_notice(spamserv_conf.debug_channel , spamserv , ## format); } while(0)
78 #define ss_reply(format...) send_message(user , spamserv , ## format)
80 #define SET_SUBCMDS_SIZE 13
82 const char *set_subcommands
[SET_SUBCMDS_SIZE
] = {"SPAMLIMIT", "BADREACTION", "ADVREACTION", "WARNREACTION", "ADVSCAN", "SPAMSCAN", "BADWORDSCAN", "CHANFLOODSCAN", "JOINFLOODSCAN", "SCANCHANOPS", "SCANHALFOPS", "SCANVOICED"};
84 extern struct string_list
*autojoin_channels
;
85 static void spamserv_clear_spamNodes(struct chanNode
*channel
);
86 static void spamserv_punish(struct chanNode
*channel
, struct userNode
*user
, time_t expires
, char *reason
, int ban
);
87 static unsigned long crc32(const char *text
);
89 #define BINARY_OPTION(arguments...) return binary_option(arguments, user, channel, argc, argv);
90 #define MULTIPLE_OPTION(arguments...) return multiple_option(arguments, values, ArrayLength(values), user, channel, argc, argv);
92 static const struct message_entry msgtab
[] = {
93 { "SSMSG_CHANNEL_OPTIONS", "Channel Options:" },
94 { "SSMSG_STRING_VALUE", "$b%s$b%s" },
95 { "SSMSG_NUMERIC_VALUE", "$b%s$b%d - %s" },
96 { "SSMSG_INVALID_NUM_SET", "$b'%d'$b is an invalid %s setting." },
97 { "SSMSG_INVALID_OPTION", "$b%s$b is not a valid %s option." },
98 { "SSMSG_INVALID_BINARY", "$b%s$b is an invalid binary value." },
100 { "SSMSG_NOT_REGISTERED", "$b%s$b has not been registered with $b$X$b." },
101 { "SSMSG_NOT_REGISTERED_CS", "$b%s$b has not been registered with $b$C$b." },
102 { "SSMSG_ALREADY_REGISTERED", "$b%s$b is already registered." },
103 { "SSMSG_DEBUG_CHAN", "You may not register the debug channel." },
104 { "SSMSG_SUSPENDED_CS", "$b$C$b access to $b%s$b has been temporarily suspended, thus you can't %s it." },
105 { "SSMSG_SUSPENDED", "$b$X$b access to $b%s$b has been temporarily suspended." },
106 { "SSMSG_NO_REGISTER", "Due to an error it was not possible to register $b%s$b." },
107 { "SSMSG_REG_SUCCESS", "Channel $b%s$b registered." },
108 { "SSMSG_UNREG_SUCCESS", "$b%s$b has been unregistered." },
109 { "SSMSG_NO_ACCESS", "You lack sufficient access to use this command." },
110 { "SSMSG_MUST_BE_OPER", "You must be an irc operator to set this option." },
111 { "SSMSG_CONFIRM_UNREG", "To confirm this unregistration, you must append 'CONFIRM' to the end of your command. For example, 'unregister CONFIRM'." },
113 { "SSMSG_NO_EXCEPTIONS", "No words found in the exception list." },
114 { "SSMSG_NO_SUCH_EXCEPTION", "Word $b%s$b not found in the exception list." },
115 { "SSMSG_EXCEPTION_LIST", "The following words are in the exception list:" },
116 { "SSMSG_EXCEPTION_ADDED", "Word $b%s$b added to the exception list." },
117 { "SSMSG_EXCEPTION_DELETED", "Word $b%s$b deleted from the exception list." },
118 { "SSMSG_EXCEPTION_IN_LIST", "The word $b%s$b is already in the exception list." },
119 { "SSMSG_EXCEPTION_MAX", "The exception list has reached the maximum exceptions (max %lu). Delete a word to add another one." },
120 { "SSMSG_EXCEPTION_TOO_SHORT", "The word must be at least %lu characters long." },
121 { "SSMSG_EXCEPTION_TOO_LONG", "The word may not be longer than %lu characters." },
123 { "SSMSG_NO_BADWORDS", "No words found in the badword list." },
124 { "SSMSG_NO_SUCH_BADWORD", "Word $b%s$b not found in the badword list." },
125 { "SSMSG_BADWORD_LIST", "The following words are in the badword list:" },
126 { "SSMSG_BADWORD_ADDED", "Word $b%s$b added to the badword list." },
127 { "SSMSG_BADWORD_DELETED", "Word $b%s$b deleted from the badword list." },
128 { "SSMSG_BADWORD_IN_LIST", "The word $b%s$b is already in the badword list." },
129 { "SSMSG_BADWORD_MAX", "The badword list has reached the maximum badwords (max %lu). Delete a word to add another one." },
130 { "SSMSG_BADWORD_TOO_SHORT", "The word must be at least %lu characters long." },
131 { "SSMSG_BADWORD_TOO_LONG", "The word may not be longer than %lu characters." },
133 { "SSMSG_STATUS", "$bStatus:$b" },
134 { "SSMSG_STATUS_USERS", "Total Users Online: %u" },
135 { "SSMSG_STATUS_CHANNELS", "Registered Channels: %u" },
136 { "SSMSG_STATUS_MEMORY", "$bMemory Information:$b" },
137 { "SSMSG_STATUS_CHANNEL_LIST", "$bRegistered Channels:$b" },
138 { "SSMSG_STATUS_NO_CHANNEL", "No channels registered." },
140 { "SSMSG_WARNING_T", "%s is against the network rules" },
141 { "SSMSG_WARNING_2_T", "You are violating the network rules" },
142 { "SSMSG_WARNING_RULES_T", "%s is against the network rules. Read the network rules at %s" },
143 { "SSMSG_WARNING_RULES_2_T", "You are violating the network rules. Read the network rules at %s" },
148 #define SSMSG_DEBUG_KICK "Kicked user $b%s$b from $b%s$b, reason: %s"
149 #define SSMSG_DEBUG_BAN "Banned user $b%s$b from $b%s$b, reason: %s"
150 #define SSMSG_DEBUG_KILL "Killed user $b%s$b, last violation in $b%s$b"
151 #define SSMSG_DEBUG_GLINE "Glined user $b%s$b, host $b%s$b, last violation in $b%s$b"
152 #define SSMSG_DEBUG_RECONNECT "Killed user $b%s$b reconnected to the network"
154 #define SSMSG_SPAM "Spamming"
155 #define SSMSG_FLOOD "Flooding the channel/network"
156 #define SSMSG_ADV "Advertising"
157 #define SSMSG_BAD "Badwords"
158 #define SSMSG_JOINFLOOD "Join flooding the channel"
160 #define SSMSG_WARNING "%s is against the network rules"
161 #define SSMSG_WARNING_2 "You are violating the network rules"
162 #define SSMSG_WARNING_RULES "%s is against the network rules. Read the network rules at %s"
163 #define SSMSG_WARNING_RULES_2 "You are violating the network rules. Read the network rules at %s"
166 #define SSMSG_WARNING "SSMSG_WARNING_T"
167 #define SSMSG_WARNING_2 "SSMSG_WARNING_2_T"
168 #define SSMSG_WARNING_RULES "SSMSG_WARNING_RULES_T"
169 #define SSMSG_WARNING_RULES_2 "SSMSG_WARNING_RULES_2_T"
174 struct chanNode
*debug_channel
;
175 struct string_list
*global_exceptions
;
176 struct string_list
*global_badwords
;
177 const char *network_rules
;
178 unsigned char trigger
;
179 unsigned long short_ban_duration
;
180 unsigned long long_ban_duration
;
181 unsigned long gline_duration
;
182 unsigned long exception_max
;
183 unsigned long exception_min_len
;
184 unsigned long exception_max_len
;
185 unsigned long badword_max
;
186 unsigned long badword_min_len
;
187 unsigned long badword_max_len
;
188 unsigned int adv_chan_must_exist
: 1;
189 unsigned int strip_mirc_codes
: 1;
190 unsigned int allow_move_merge
: 1;
193 /***********************************************/
195 /***********************************************/
198 get_chanInfo(const char *channelname
)
200 return dict_find(registered_channels_dict
, channelname
, 0);
204 spamserv_join_channel(struct chanNode
*channel
)
206 struct mod_chanmode change
;
207 mod_chanmode_init(&change
);
209 change
.args
[0].mode
= MODE_CHANOP
;
210 change
.args
[0].u
.member
= AddChannelUser(spamserv
, channel
);
211 mod_chanmode_announce(spamserv
, channel
, &change
);
215 spamserv_part_channel(struct chanNode
*channel
, char *reason
)
217 /* we only have to clear the spamNodes because every other node expires on it's own */
218 spamserv_clear_spamNodes(channel
);
219 DelChannelUser(spamserv
, channel
, reason
, 0);
222 static struct chanInfo
*
223 spamserv_register_channel(struct chanNode
*channel
, struct string_list
*exceptions
, struct string_list
*badwords
, unsigned int flags
, char *info
)
225 struct chanInfo
*cInfo
= malloc(sizeof(struct chanInfo
));
229 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for cInfo; channel: %s", channel
->name
);
233 cInfo
->channel
= channel
;
234 cInfo
->exceptions
= exceptions
? string_list_copy(exceptions
) : alloc_string_list(1);
235 cInfo
->badwords
= badwords
? string_list_copy(badwords
) : alloc_string_list(1);
236 cInfo
->flags
= flags
;
237 safestrncpy(cInfo
->info
, info
, sizeof(cInfo
->info
));
238 cInfo
->suspend_expiry
= 0;
239 dict_insert(registered_channels_dict
, cInfo
->channel
->name
, cInfo
);
245 spamserv_unregister_channel(struct chanInfo
*cInfo
)
250 dict_remove(registered_channels_dict
, cInfo
->channel
->name
);
251 free_string_list(cInfo
->exceptions
);
252 free_string_list(cInfo
->badwords
);
257 spamserv_cs_suspend(struct chanNode
*channel
, time_t expiry
, int suspend
, char *reason
)
259 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
265 cInfo
->flags
|= CHAN_SUSPENDED
;
266 cInfo
->suspend_expiry
= expiry
;
267 spamserv_part_channel(channel
, reason
);
271 if(CHECK_SUSPENDED(cInfo
))
273 cInfo
->flags
&= ~CHAN_SUSPENDED
;
274 cInfo
->suspend_expiry
= 0;
281 spamserv_cs_move_merge(struct userNode
*user
, struct chanNode
*channel
, struct chanNode
*target
, int move
)
283 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
289 if(!spamserv_conf
.allow_move_merge
|| get_chanInfo(target
->name
))
292 snprintf(reason
, sizeof(reason
), "unregistered due to a channel move to %s", target
->name
);
294 snprintf(reason
, sizeof(reason
), "unregistered due to a channel merge into %s", target
->name
);
296 spamserv_cs_unregister(user
, channel
, manually
, reason
);
300 cInfo
->channel
= target
;
302 dict_remove(registered_channels_dict
, channel
->name
);
303 dict_insert(registered_channels_dict
, target
->name
, cInfo
);
307 snprintf(reason
, sizeof(reason
), "Channel moved to %s by %s.", target
->name
, user
->handle_info
->handle
);
311 spamserv_join_channel(target
);
312 snprintf(reason
, sizeof(reason
), "%s merged into %s by %s.", channel
->name
, target
->name
, user
->handle_info
->handle
);
315 if(!CHECK_SUSPENDED(cInfo
))
316 spamserv_part_channel(channel
, reason
);
319 snprintf(reason
, sizeof(reason
), "$X (channel %s) moved to %s by %s.", channel
->name
, target
->name
, user
->handle_info
->handle
);
321 snprintf(reason
, sizeof(reason
), "$X (channel %s) merged into %s by %s.", channel
->name
, target
->name
, user
->handle_info
->handle
);
323 global_message(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, reason
);
331 spamserv_cs_unregister(struct userNode
*user
, struct chanNode
*channel
, enum cs_unreg type
, char *reason
)
333 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
337 char global
[MAXLEN
], partmsg
[MAXLEN
];
342 snprintf(global
, sizeof(global
), "$X (channel %s) %s by %s.", channel
->name
, reason
, user
->handle_info
->handle
);
343 snprintf(partmsg
, sizeof(partmsg
), "%s %s by %s.", channel
->name
, reason
, user
->handle_info
->handle
);
346 snprintf(global
, sizeof(global
), "$X (channel %s) registration expired.", channel
->name
);
347 snprintf(partmsg
, sizeof(partmsg
), "%s registration expired.", channel
->name
);
350 snprintf(global
, sizeof(global
), "$X (channel %s) lost all users.", channel
->name
);
351 snprintf(partmsg
, sizeof(partmsg
), "%s lost all users.", channel
->name
);
355 if(!CHECK_SUSPENDED(cInfo
))
356 spamserv_part_channel(channel
, partmsg
);
358 spamserv_unregister_channel(cInfo
);
359 global_message(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, global
);
363 /***********************************************/
365 /***********************************************/
367 static struct userInfo
*
368 get_userInfo(const char *nickname
)
370 return dict_find(connected_users_dict
, nickname
, 0);
374 spamserv_create_spamNode(struct chanNode
*channel
, struct userInfo
*uInfo
, char *text
)
376 struct spamNode
*sNode
= malloc(sizeof(struct spamNode
));
380 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for sNode; channel: %s; user: %s", channel
->name
, uInfo
->user
->nick
);
384 sNode
->channel
= channel
;
385 sNode
->crc32
= crc32(text
);
391 struct spamNode
*temp
= uInfo
->spam
;
407 spamserv_delete_spamNode(struct userInfo
*uInfo
, struct spamNode
*sNode
)
412 if(sNode
== uInfo
->spam
)
413 uInfo
->spam
= sNode
->next
;
416 sNode
->next
->prev
= sNode
->prev
;
418 sNode
->prev
->next
= sNode
->next
;
424 spamserv_clear_spamNodes(struct chanNode
*channel
)
426 struct userInfo
*uInfo
;
427 struct spamNode
*sNode
;
430 for(i
= 0; i
< channel
->members
.used
; i
++)
432 if((uInfo
= get_userInfo(channel
->members
.list
[i
]->user
->nick
)))
434 if((sNode
= uInfo
->spam
))
436 for(; sNode
; sNode
= sNode
->next
)
437 if(sNode
->channel
== channel
)
441 spamserv_delete_spamNode(uInfo
, sNode
);
448 spamserv_create_floodNode(struct chanNode
*channel
, struct userNode
*user
, struct floodNode
**uI_fNode
)
450 struct floodNode
*fNode
= malloc(sizeof(struct floodNode
));
454 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for fNode; channel: %s; user: %s", channel
->name
, user
->nick
);
458 fNode
->channel
= channel
;
466 struct floodNode
*temp
= *uI_fNode
;
482 spamserv_delete_floodNode(struct floodNode
**uI_fNode
, struct floodNode
*fNode
)
487 if(fNode
== *uI_fNode
)
488 *uI_fNode
= fNode
->next
;
491 fNode
->next
->prev
= fNode
->prev
;
493 fNode
->prev
->next
= fNode
->next
;
499 spamserv_create_user(struct userNode
*user
)
501 struct userInfo
*uInfo
= malloc(sizeof(struct userInfo
));
502 struct killNode
*kNode
= dict_find(killed_users_dict
, irc_ntoa(&user
->ip
), 0);
506 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for uInfo; nick: %s", user
->nick
);
511 spamserv_debug(SSMSG_DEBUG_RECONNECT
, user
->nick
);
516 uInfo
->joinflood
= NULL
;
517 uInfo
->flags
= kNode
? USER_KILLED
: 0;
518 uInfo
->warnlevel
= kNode
? kNode
->warnlevel
: 0;
522 dict_insert(connected_users_dict
, user
->nick
, uInfo
);
526 dict_remove(killed_users_dict
, irc_ntoa(&user
->ip
));
532 spamserv_delete_user(struct userInfo
*uInfo
)
539 spamserv_delete_spamNode(uInfo
, uInfo
->spam
);
543 spamserv_delete_floodNode(&uInfo
->flood
, uInfo
->flood
);
546 while(uInfo
->joinflood
)
547 spamserv_delete_floodNode(&uInfo
->joinflood
, uInfo
->joinflood
);
549 dict_remove(connected_users_dict
, uInfo
->user
->nick
);
554 spamserv_new_user_func(struct userNode
*user
)
557 spamserv_create_user(user
);
563 spamserv_del_user_func(struct userNode
*user
, struct userNode
*killer
, UNUSED_ARG(const char *why
))
565 struct userInfo
*uInfo
= get_userInfo(user
->nick
);
566 struct killNode
*kNode
;
568 if(killer
== spamserv
)
570 kNode
= malloc(sizeof(struct killNode
));
574 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for killNode - nickname %s", user
->nick
);
575 spamserv_delete_user(uInfo
);
579 if(uInfo
->warnlevel
> KILL_WARNLEVEL
)
580 kNode
->warnlevel
= uInfo
->warnlevel
- KILL_WARNLEVEL
;
582 kNode
->warnlevel
= 0;
586 dict_insert(killed_users_dict
, irc_ntoa(&user
->ip
), kNode
);
589 spamserv_delete_user(uInfo
);
593 spamserv_nick_change_func(struct userNode
*user
, const char *old_nick
)
595 struct userInfo
*uInfo
= get_userInfo(old_nick
);
597 dict_remove(connected_users_dict
, old_nick
);
598 dict_insert(connected_users_dict
, user
->nick
, uInfo
);
602 spamserv_user_join(struct modeNode
*mNode
)
604 struct chanNode
*channel
= mNode
->channel
;
605 struct userNode
*user
= mNode
->user
;
606 struct chanInfo
*cInfo
;
607 struct userInfo
*uInfo
;
608 struct floodNode
*jfNode
;
610 if(user
->uplink
->burst
|| !(cInfo
= get_chanInfo(channel
->name
)) || !CHECK_JOINFLOOD(cInfo
) || !(uInfo
= get_userInfo(user
->nick
)))
613 if(!(jfNode
= uInfo
->joinflood
))
615 spamserv_create_floodNode(channel
, user
, &uInfo
->joinflood
);
619 for(; jfNode
; jfNode
= jfNode
->next
)
620 if(jfNode
->channel
== channel
)
625 spamserv_create_floodNode(channel
, user
, &uInfo
->joinflood
);
632 if(jfNode
->count
> JOINFLOOD_MAX
)
636 spamserv_delete_floodNode(&uInfo
->joinflood
, jfNode
);
637 snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_JOINFLOOD
, spamserv_conf
.network_rules
);
638 spamserv_punish(channel
, user
, JOINFLOOD_B_DURATION
, reason
, 1);
647 spamserv_user_part(struct modeNode
*mn
, UNUSED_ARG(const char *reason
))
649 struct userNode
*user
= mn
->user
;
650 struct chanNode
*channel
= mn
->channel
;
651 struct userInfo
*uInfo
;
652 struct spamNode
*sNode
;
653 struct floodNode
*fNode
;
655 if(user
->dead
|| !get_chanInfo(channel
->name
) || !(uInfo
= get_userInfo(user
->nick
)))
658 if((sNode
= uInfo
->spam
))
660 for(; sNode
; sNode
= sNode
->next
)
661 if(sNode
->channel
== channel
)
665 spamserv_delete_spamNode(uInfo
, sNode
);
668 if((fNode
= uInfo
->flood
))
670 for(; fNode
; fNode
= fNode
->next
)
671 if(fNode
->channel
== channel
)
675 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
679 /***********************************************/
681 /***********************************************/
689 for(i
= 0; i
< 256; i
++)
693 for(j
= 8; j
> 0; j
--)
697 crc
= (crc
>> 1) ^ 0xEDB88320L
;
710 crc32(const char *text
)
712 register unsigned long crc
= 0xFFFFFFFF;
713 unsigned int c
, i
= 0;
715 while((c
= (unsigned int)text
[i
++]) != 0)
716 crc
= ((crc
>> 8) & 0x00FFFFFF) ^ crc_table
[(crc
^c
) & 0xFF];
718 return (crc
^0xFFFFFFFF);
722 timeq_flood(UNUSED_ARG(void *data
))
725 struct userInfo
*uInfo
;
726 struct floodNode
*fNode
;
728 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
730 uInfo
= iter_data(it
);
732 if(!(fNode
= uInfo
->flood
))
735 for(; fNode
; fNode
= fNode
->next
)
737 if(now
- fNode
->time
> FLOOD_EXPIRE
)
739 if(!(--fNode
->count
))
740 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
745 timeq_add(now
+ FLOOD_TIMEQ_FREQ
, timeq_flood
, NULL
);
749 timeq_joinflood(UNUSED_ARG(void *data
))
752 struct userInfo
*uInfo
;
753 struct floodNode
*fNode
;
755 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
757 uInfo
= iter_data(it
);
759 if(!(fNode
= uInfo
->joinflood
))
762 for(; fNode
; fNode
= fNode
->next
)
764 if(now
- fNode
->time
> JOINFLOOD_EXPIRE
)
766 if(!(--fNode
->count
))
767 spamserv_delete_floodNode(&uInfo
->joinflood
, fNode
);
772 timeq_add(now
+ JOINFLOOD_TIMEQ_FREQ
, timeq_joinflood
, NULL
);
776 timeq_bad(UNUSED_ARG(void *data
))
779 struct userInfo
*uInfo
;
781 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
783 uInfo
= iter_data(it
);
785 if(uInfo
->lastbad
&& uInfo
->lastbad
- now
> BAD_EXPIRE
)
788 uInfo
->flags
&= ~USER_BAD_WARNED
;
792 timeq_add(now
+ BAD_TIMEQ_FREQ
, timeq_bad
, NULL
);
796 timeq_adv(UNUSED_ARG(void *data
))
799 struct userInfo
*uInfo
;
801 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
803 uInfo
= iter_data(it
);
805 if(uInfo
->lastadv
&& uInfo
->lastadv
- now
> ADV_EXPIRE
)
808 uInfo
->flags
&= ~USER_ADV_WARNED
;
812 timeq_add(now
+ ADV_TIMEQ_FREQ
, timeq_adv
, NULL
);
816 timeq_warnlevel(UNUSED_ARG(void *data
))
819 struct userInfo
*uInfo
;
821 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
823 uInfo
= iter_data(it
);
825 if(uInfo
->warnlevel
> 0)
829 timeq_add(now
+ WARNLEVEL_TIMEQ_FREQ
, timeq_warnlevel
, NULL
);
833 timeq_kill(UNUSED_ARG(void *data
))
836 struct killNode
*kNode
;
838 for(it
= dict_first(killed_users_dict
); it
; it
= iter_next(it
))
840 kNode
= iter_data(it
);
842 if(kNode
->time
- now
> KILL_EXPIRE
)
846 timeq_add(now
+ KILL_TIMEQ_FREQ
, timeq_kill
, NULL
);
850 binary_option(char *name
, unsigned long mask
, struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[])
852 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
857 if(enabled_string(argv
[1]))
859 cInfo
->flags
|= mask
;
862 else if(disabled_string(argv
[1]))
864 cInfo
->flags
&= ~mask
;
869 spamserv_notice(user
, "SSMSG_INVALID_BINARY", argv
[1]);
875 value
= (cInfo
->flags
& mask
) ? 1 : 0;
878 spamserv_notice(user
, "SSMSG_STRING_VALUE", name
, value
? "Enabled." : "Disabled.");
890 multiple_option(char *name
, char *description
, enum channelinfo info
, struct valueData
*values
, int count
, struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[])
892 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
897 index
= atoi(argv
[1]);
899 if(index
< 0 || index
>= count
)
901 spamserv_notice(user
, "SSMSG_INVALID_NUM_SET", index
, description
);
903 for(index
= 0; index
< count
; index
++)
904 spamserv_notice(user
, "SSMSG_NUMERIC_VALUE", name
, index
, values
[index
].description
);
909 if(values
[index
].oper_only
&& !IsOper(user
))
911 spamserv_notice(user
, "SSMSG_MUST_BE_OPER");
915 cInfo
->info
[info
] = values
[index
].value
;
919 for(index
= 0; index
< count
&& cInfo
->info
[info
] != values
[index
].value
; index
++);
922 spamserv_notice(user
, "SSMSG_NUMERIC_VALUE", name
, index
, values
[index
].description
);
927 show_exceptions(struct userNode
*user
, struct chanInfo
*cInfo
)
929 struct helpfile_table table
;
932 if(!cInfo
->exceptions
->used
)
934 spamserv_notice(user
, "SSMSG_NO_EXCEPTIONS");
938 spamserv_notice(user
, "SSMSG_EXCEPTION_LIST");
942 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
943 table
.contents
= alloca(cInfo
->exceptions
->used
* sizeof(*table
.contents
));
945 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
947 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
948 table
.contents
[table
.length
][0] = cInfo
->exceptions
->list
[i
];
952 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
958 show_badwords(struct userNode
*user
, struct chanInfo
*cInfo
)
960 struct helpfile_table table
;
963 if(!cInfo
->badwords
->used
)
965 spamserv_notice(user
, "SSMSG_NO_BADWORDS");
969 spamserv_notice(user
, "SSMSG_BADWORD_LIST");
973 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
974 table
.contents
= alloca(cInfo
->badwords
->used
* sizeof(*table
.contents
));
976 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
978 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
979 table
.contents
[table
.length
][0] = cInfo
->badwords
->list
[i
];
983 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
989 show_memory_usage(struct userNode
*user
)
992 struct helpfile_table table
;
993 struct chanInfo
*cInfo
;
994 struct userInfo
*uInfo
;
995 struct spamNode
*sNode
;
996 struct floodNode
*fNode
;
997 double channel_size
= 0, user_size
, size
;
998 unsigned int spamcount
= 0, floodcount
= 0, i
, j
;
1001 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
1003 cInfo
= iter_data(it
);
1005 if(!cInfo
->exceptions
->used
)
1008 if(!cInfo
->badwords
->used
)
1011 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1012 channel_size
+= strlen(cInfo
->exceptions
->list
[i
]) * sizeof(char);
1014 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1015 channel_size
+= strlen(cInfo
->badwords
->list
[i
]) * sizeof(char);
1018 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
1020 uInfo
= iter_data(it
);
1022 for(sNode
= uInfo
->spam
; sNode
; sNode
= sNode
->next
, spamcount
++);
1023 for(fNode
= uInfo
->flood
; fNode
; fNode
= fNode
->next
, floodcount
++);
1024 for(fNode
= uInfo
->joinflood
; fNode
; fNode
= fNode
->next
, floodcount
++);
1027 channel_size
+= dict_size(registered_channels_dict
) * sizeof(struct chanInfo
);
1029 user_size
= dict_size(connected_users_dict
) * sizeof(struct userInfo
) +
1030 dict_size(killed_users_dict
) * sizeof(struct killNode
) +
1031 spamcount
* sizeof(struct spamNode
) +
1032 floodcount
* sizeof(struct floodNode
);
1034 size
= channel_size
+ user_size
;
1036 ss_reply("SSMSG_STATUS_MEMORY");
1040 table
.flags
= TABLE_NO_FREE
| TABLE_NO_HEADERS
| TABLE_PAD_LEFT
;
1041 table
.contents
= calloc(table
.length
, sizeof(char**));
1044 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
1045 snprintf(buffer
, sizeof(buffer
), "Channel Memory Usage:");
1046 table
.contents
[0][0] = strdup(buffer
);
1047 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", channel_size
);
1048 table
.contents
[0][1] = strdup(buffer
);
1049 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", channel_size
/ 1024);
1050 table
.contents
[0][2] = strdup(buffer
);
1051 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", channel_size
/ 1024 / 1024);
1052 table
.contents
[0][3] = strdup(buffer
);
1055 table
.contents
[1] = calloc(table
.width
, sizeof(char*));
1056 snprintf(buffer
, sizeof(buffer
), "User Memory Usage :");
1057 table
.contents
[1][0] = strdup(buffer
);
1058 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", user_size
);
1059 table
.contents
[1][1] = strdup(buffer
);
1060 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", user_size
/ 1024);
1061 table
.contents
[1][2] = strdup(buffer
);
1062 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", user_size
/ 1024 / 1024);
1063 table
.contents
[1][3] = strdup(buffer
);
1065 // total memory usage
1066 table
.contents
[2] = calloc(table
.width
, sizeof(char*));
1067 snprintf(buffer
, sizeof(buffer
), "Total Memory Usage :");
1068 table
.contents
[2][0] = strdup(buffer
);
1069 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", size
);
1070 table
.contents
[2][1] = strdup(buffer
);
1071 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", size
/ 1024);
1072 table
.contents
[2][2] = strdup(buffer
);
1073 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", size
/ 1024 / 1024);
1074 table
.contents
[2][3] = strdup(buffer
);
1076 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1078 for(i
= 0; i
< table
.length
; i
++)
1080 for(j
= 0; j
< table
.width
; j
++)
1081 free((char*)table
.contents
[i
][j
]);
1083 free(table
.contents
[i
]);
1086 free(table
.contents
);
1090 show_registered_channels(struct userNode
*user
)
1092 struct helpfile_table table
;
1095 spamserv_notice(user
, "SSMSG_STATUS_CHANNEL_LIST");
1097 if(!dict_size(registered_channels_dict
))
1099 spamserv_notice(user
, "SSMSG_STATUS_NO_CHANNEL");
1105 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1106 table
.contents
= alloca(dict_size(registered_channels_dict
) * sizeof(*table
.contents
));
1108 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
1110 struct chanInfo
*cInfo
= iter_data(it
);
1112 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1113 table
.contents
[table
.length
][0] = cInfo
->channel
->name
;
1117 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1120 /***********************************************/
1122 /***********************************************/
1125 SPAMSERV_FUNC(cmd_register
)
1127 struct chanInfo
*cInfo
;
1128 char reason
[MAXLEN
];
1130 if(!channel
|| !channel
->channel_info
)
1132 ss_reply("SSMSG_NOT_REGISTERED_CS", channel
->name
);
1136 if(get_chanInfo(channel
->name
))
1138 ss_reply("SSMSG_ALREADY_REGISTERED", channel
->name
);
1142 if(IsSuspended(channel
->channel_info
))
1144 ss_reply("SSMSG_SUSPENDED_CS", channel
->name
, "register");
1148 if(channel
== spamserv_conf
.debug_channel
)
1150 ss_reply("SSMSG_DEBUG_CHAN");
1154 if(!(cInfo
= spamserv_register_channel(channel
, spamserv_conf
.global_exceptions
, spamserv_conf
.global_badwords
, CHAN_FLAGS_DEFAULT
, CHAN_INFO_DEFAULT
)))
1156 ss_reply("SSMSG_NO_REGISTER", channel
->name
);
1160 spamserv_join_channel(cInfo
->channel
);
1162 snprintf(reason
, sizeof(reason
), "%s (channel %s) registered by %s.", spamserv
->nick
, channel
->name
, user
->handle_info
->handle
);
1163 global_message(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, reason
);
1164 ss_reply("SSMSG_REG_SUCCESS", channel
->name
);
1170 SPAMSERV_FUNC(cmd_unregister
)
1172 struct chanInfo
*cInfo
;
1173 struct chanData
*cData
;
1174 struct userData
*uData
;
1175 char reason
[MAXLEN
];
1177 if(!channel
|| !(cData
= channel
->channel_info
) || !(cInfo
= get_chanInfo(channel
->name
)))
1179 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1183 if(!(uData
= GetChannelUser(cData
, user
->handle_info
)) || (uData
->access
< UL_OWNER
))
1185 ss_reply("SSMSG_NO_ACCESS");
1189 if(!IsHelping(user
))
1191 if(IsSuspended(cData
))
1193 ss_reply("SSMSG_SUSPENDED_CS", channel
->name
, "unregister");
1197 if(argc
< 2 || strcasecmp(argv
[1], "CONFIRM"))
1199 ss_reply("SSMSG_CONFIRM_UNREG");
1204 if(!CHECK_SUSPENDED(cInfo
))
1206 snprintf(reason
, sizeof(reason
), "%s unregistered by %s.", spamserv
->nick
, user
->handle_info
->handle
);
1207 spamserv_part_channel(channel
, reason
);
1210 spamserv_unregister_channel(cInfo
);
1212 snprintf(reason
, sizeof(reason
), "%s (channel %s) unregistered by %s.", spamserv
->nick
, channel
->name
, user
->handle_info
->handle
);
1213 global_message(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, reason
);
1214 ss_reply("SSMSG_UNREG_SUCCESS", channel
->name
);
1220 SPAMSERV_FUNC(cmd_status
)
1222 ss_reply("SSMSG_STATUS");
1223 ss_reply("SSMSG_STATUS_USERS", dict_size(connected_users_dict
));
1224 ss_reply("SSMSG_STATUS_CHANNELS", dict_size(registered_channels_dict
));
1226 if(IsOper(user
) && argc
> 1)
1228 if(!irccasecmp(argv
[1], "memory"))
1229 show_memory_usage(user
);
1230 else if(!irccasecmp(argv
[1], "channels"))
1231 show_registered_channels(user
);
1238 SPAMSERV_FUNC(cmd_addexception
)
1240 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1241 struct userData
*uData
;
1244 if(!cInfo
|| !channel
->channel_info
)
1246 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1250 if(CHECK_SUSPENDED(cInfo
))
1252 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1256 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1258 ss_reply("SSMSG_NO_ACCESS");
1263 return show_exceptions(user
, cInfo
);
1265 if(cInfo
->exceptions
->used
== spamserv_conf
.exception_max
&& !IsOper(user
))
1267 ss_reply("SSMSG_EXCEPTION_MAX", spamserv_conf
.exception_max
);
1271 if(strlen(argv
[1]) < spamserv_conf
.exception_min_len
)
1273 ss_reply("SSMSG_EXCEPTION_TOO_SHORT", spamserv_conf
.exception_min_len
);
1276 else if(strlen(argv
[1]) > spamserv_conf
.exception_max_len
)
1278 ss_reply("SSMSG_EXCEPTION_TOO_LONG", spamserv_conf
.exception_max_len
);
1282 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1284 if(!irccasecmp(argv
[1], cInfo
->exceptions
->list
[i
]))
1286 ss_reply("SSMSG_EXCEPTION_IN_LIST", argv
[1]);
1291 string_list_append(cInfo
->exceptions
, strdup(argv
[1]));
1292 ss_reply("SSMSG_EXCEPTION_ADDED", argv
[1]);
1298 SPAMSERV_FUNC(cmd_delexception
)
1300 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1301 struct userData
*uData
;
1305 if(!cInfo
|| !channel
->channel_info
)
1307 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1311 if(CHECK_SUSPENDED(cInfo
))
1313 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1317 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1319 ss_reply("SSMSG_NO_ACCESS");
1324 return show_exceptions(user
, cInfo
);
1326 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1328 if(!irccasecmp(argv
[1], cInfo
->exceptions
->list
[i
]))
1337 ss_reply("SSMSG_NO_SUCH_EXCEPTION", argv
[1]);
1341 string_list_delete(cInfo
->exceptions
, i
);
1342 ss_reply("SSMSG_EXCEPTION_DELETED", argv
[1]);
1348 SPAMSERV_FUNC(cmd_addbadword
)
1350 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1351 struct userData
*uData
;
1354 if(!cInfo
|| !channel
->channel_info
)
1356 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1360 if(CHECK_SUSPENDED(cInfo
))
1362 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1366 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1368 ss_reply("SSMSG_NO_ACCESS");
1373 return show_badwords(user
, cInfo
);
1375 if(cInfo
->badwords
->used
== spamserv_conf
.badword_max
&& !IsOper(user
))
1377 ss_reply("SSMSG_BADWORD_MAX", spamserv_conf
.badword_max
);
1381 if(strlen(argv
[1]) < spamserv_conf
.badword_min_len
)
1383 ss_reply("SSMSG_BADWORD_TOO_SHORT", spamserv_conf
.badword_min_len
);
1386 else if(strlen(argv
[1]) > spamserv_conf
.badword_max_len
)
1388 ss_reply("SSMSG_BADWORD_TOO_LONG", spamserv_conf
.badword_max_len
);
1392 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1394 if(!irccasecmp(argv
[1], cInfo
->badwords
->list
[i
]))
1396 ss_reply("SSMSG_BADWORD_IN_LIST", argv
[1]);
1401 string_list_append(cInfo
->badwords
, strdup(argv
[1]));
1402 ss_reply("SSMSG_BADWORD_ADDED", argv
[1]);
1408 SPAMSERV_FUNC(cmd_delbadword
)
1410 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1411 struct userData
*uData
;
1415 if(!cInfo
|| !channel
->channel_info
)
1417 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1421 if(CHECK_SUSPENDED(cInfo
))
1423 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1427 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1429 ss_reply("SSMSG_NO_ACCESS");
1434 return show_badwords(user
, cInfo
);
1436 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1438 if(!irccasecmp(argv
[1], cInfo
->badwords
->list
[i
]))
1447 ss_reply("SSMSG_NO_SUCH_BADWORD", argv
[1]);
1451 string_list_delete(cInfo
->badwords
, i
);
1452 ss_reply("SSMSG_BADWORD_DELETED", argv
[1]);
1458 SPAMSERV_FUNC(cmd_set
)
1460 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1461 struct userData
*uData
;
1462 struct svccmd
*subcmd
;
1463 char cmd_name
[MAXLEN
];
1468 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1472 if(CHECK_SUSPENDED(cInfo
))
1474 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1478 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1480 ss_reply("SSMSG_NO_ACCESS");
1486 ss_reply("SSMSG_CHANNEL_OPTIONS");
1488 for(i
= 0; i
< SET_SUBCMDS_SIZE
; i
++)
1490 sprintf(cmd_name
, "%s %s", cmd
->name
, set_subcommands
[i
]);
1492 if((subcmd
= dict_find(cmd
->parent
->commands
, cmd_name
, NULL
)))
1493 subcmd
->command
->func(user
, channel
, 1, argv
+ 1, subcmd
);
1499 sprintf(cmd_name
, "%s %s", cmd
->name
, argv
[1]);
1500 subcmd
= dict_find(cmd
->parent
->commands
, cmd_name
, NULL
);
1504 reply("SSMSG_INVALID_OPTION", argv
[1], argv
[0]);
1508 return subcmd
->command
->func(user
, channel
, argc
- 1, argv
+ 1, subcmd
);
1512 SPAMSERV_FUNC(opt_spamlimit
)
1514 struct valueData values
[] =
1516 {"Users may send the same message $b2$b times.", 'a', 0},
1517 {"Users may send the same message $b3$b times.", 'b', 0},
1518 {"Users may send the same message $b4$b times.", 'c', 0},
1519 {"Users may send the same message $b5$b times.", 'd', 0},
1520 {"Users may send the same message $b6$b times.", 'e', 0}
1523 MULTIPLE_OPTION("SpamLimit ", "SpamLimit", ci_SpamLimit
);
1527 SPAMSERV_FUNC(opt_advreaction
)
1529 struct valueData values
[] =
1531 {"Kick on disallowed advertising.", 'k', 0},
1532 {"Kickban on disallowed advertising.", 'b', 0},
1533 {"Short timed ban on disallowed advertising.", 's', 0},
1534 {"Long timed ban on disallowed advertising.", 'l', 0},
1535 {"Kill on disallowed advertising.", 'd', 1}
1538 MULTIPLE_OPTION("AdvReaction ", "AdvReaction", ci_AdvReaction
);
1542 SPAMSERV_FUNC(opt_warnreaction
)
1544 struct valueData values
[] =
1546 {"Kick after warning.", 'k', 0},
1547 {"Kickban after warning.", 'b', 0},
1548 {"Short timed ban after warning.", 's', 0},
1549 {"Long timed ban after warning.", 'l', 0},
1550 {"Kill after warning.", 'd', 1}
1553 MULTIPLE_OPTION("WarnReaction ", "WarnReaction", ci_WarnReaction
);
1557 SPAMSERV_FUNC(opt_badreaction
)
1559 struct valueData values
[] =
1561 {"Kick on disallowed badwords.", 'k', 0},
1562 {"Kickban on disallowed badwords.", 'b', 0},
1563 {"Short timed ban on disallowed badwords.", 's', 0},
1564 {"Long timed ban on disallowed badwords.", 'l', 0},
1565 {"Kill on disallowed badwords.", 'd', 1}
1568 MULTIPLE_OPTION("BadReaction ", "BadReaction", ci_BadReaction
);
1572 SPAMSERV_FUNC(opt_advscan
)
1574 BINARY_OPTION("AdvScan ", CHAN_ADV_SCAN
);
1578 SPAMSERV_FUNC(opt_spamscan
)
1580 BINARY_OPTION("SpamScan ", CHAN_SPAMSCAN
);
1584 SPAMSERV_FUNC(opt_badwordscan
)
1586 BINARY_OPTION("BadWordScan ", CHAN_BADWORDSCAN
);
1590 SPAMSERV_FUNC(opt_chanfloodscan
)
1592 BINARY_OPTION("ChanFloodScan ", CHAN_CHANFLOODSCAN
);
1596 SPAMSERV_FUNC(opt_joinflood
)
1598 BINARY_OPTION("JoinFloodScan ", CHAN_JOINFLOOD
);
1602 SPAMSERV_FUNC(opt_scanops
)
1604 BINARY_OPTION("ScanChanOps ", CHAN_SCAN_CHANOPS
);
1608 SPAMSERV_FUNC(opt_scanhalfops
)
1610 BINARY_OPTION("ScanHalfOps ", CHAN_SCAN_HALFOPS
);
1614 SPAMSERV_FUNC(opt_scanvoiced
)
1616 BINARY_OPTION("ScanVoiced ", CHAN_SCAN_VOICED
);
1620 to_lower(char *message
)
1622 unsigned int i
, diff
= 'a' - 'A';
1624 for(i
= 0; i
< strlen(message
); i
++)
1626 if((message
[i
] >= 'A') && (message
[i
] <= 'Z'))
1627 message
[i
] = message
[i
] + diff
;
1632 strip_mirc_codes(char *text
)
1634 // taken from xchat and modified
1635 int nc
= 0, i
= 0, col
= 0, len
= strlen(text
);
1636 static char new_str
[MAXLEN
];
1640 if((col
&& isdigit(*text
) && nc
< 2) ||
1641 (col
&& *text
== ',' && isdigit(*(text
+ 1)) && nc
< 3))
1680 is_in_exception_list(struct chanInfo
*cInfo
, char *message
)
1684 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1685 if(strstr(message
, cInfo
->exceptions
->list
[i
]))
1692 is_in_badword_list(struct chanInfo
*cInfo
, char *message
)
1696 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1697 if(strstr(message
, cInfo
->badwords
->list
[i
]))
1704 check_badwords(struct chanInfo
*cInfo
, char *message
)
1706 if(spamserv_conf
.strip_mirc_codes
)
1707 message
= strip_mirc_codes(message
);
1709 /* This needs improving */
1710 if(is_in_exception_list(cInfo
, message
))
1713 if(is_in_badword_list(cInfo
, message
))
1720 check_advertising(struct chanInfo
*cInfo
, char *message
)
1724 if(spamserv_conf
.strip_mirc_codes
)
1725 message
= strip_mirc_codes(message
);
1727 if(is_in_exception_list(cInfo
, message
))
1730 while(message
[i
] != 0)
1732 if(message
[i
] == '#')
1734 char channelname
[CHANNELLEN
];
1737 if(!spamserv_conf
.adv_chan_must_exist
)
1740 /* only return 1, if the channel does exist */
1742 while((message
[i
] != 0) && (message
[i
] != ' '))
1744 channelname
[j
] = message
[i
];
1749 channelname
[j
] = '\0';
1751 if(GetChannel(channelname
))
1754 else if((message
[i
] == 'w') && (message
[i
+1] == 'w') && (message
[i
+2] == 'w') && (message
[i
+3] == '.'))
1756 else if((message
[i
] == 'h') && (message
[i
+1] == 't') && (message
[i
+2] == 't') && (message
[i
+3] == 'p') && (message
[i
+4] == ':'))
1758 else if((message
[i
] == 'f') && (message
[i
+1] == 't') && (message
[i
+2] == 'p') && ((message
[i
+3] == '.') || (message
[i
+3] == ':')))
1768 spamserv_punish(struct chanNode
*channel
, struct userNode
*user
, time_t expires
, char *reason
, int ban
)
1772 struct mod_chanmode change
;
1773 char *hostmask
= generate_hostmask(user
, GENMASK_STRICT_HOST
| GENMASK_ANY_IDENT
);
1775 sanitize_ircmask(hostmask
);
1778 add_channel_ban(channel
->channel_info
, hostmask
, spamserv
->nick
, now
, now
, now
+ expires
, reason
);
1780 mod_chanmode_init(&change
);
1782 change
.args
[0].mode
= MODE_BAN
;
1783 change
.args
[0].u
.hostmask
= hostmask
;
1784 mod_chanmode_announce(spamserv
, channel
, &change
);
1788 spamserv_debug(SSMSG_DEBUG_BAN
, user
->nick
, channel
->name
, reason
);
1791 spamserv_debug(SSMSG_DEBUG_KICK
, user
->nick
, channel
->name
, reason
);
1793 KickChannelUser(user
, channel
, spamserv
, reason
);
1797 spamserv_channel_message(struct chanNode
*channel
, struct userNode
*user
, char *text
)
1799 struct chanInfo
*cInfo
;
1800 struct userInfo
*uInfo
;
1801 struct spamNode
*sNode
;
1802 struct floodNode
*fNode
;
1803 unsigned int violation
= 0;
1804 char reason
[MAXLEN
];
1806 /* make sure: spamserv is not disabled; x3 is running; spamserv is in the chan; chan is regged, user does exist */
1807 if(!spamserv
|| quit_services
|| !GetUserMode(channel
, spamserv
) || !(cInfo
= get_chanInfo(channel
->name
)) || !(uInfo
= get_userInfo(user
->nick
)))
1810 if(!CHECK_CHANOPS(cInfo
))
1812 struct modeNode
*mn
= GetUserMode(channel
, user
);
1813 if(mn
->modes
& MODE_CHANOP
)
1817 if(!CHECK_HALFOPS(cInfo
))
1819 struct modeNode
*mn
= GetUserMode(channel
, user
);
1820 if(mn
->modes
& MODE_HALFOP
)
1824 if(!CHECK_VOICED(cInfo
))
1826 struct modeNode
*mn
= GetUserMode(channel
, user
);
1827 if((mn
->modes
& MODE_VOICE
) && !(mn
->modes
& MODE_CHANOP
) && !(mn
->modes
& MODE_HALFOP
))
1833 if(CHECK_SPAM(cInfo
))
1835 if(!(sNode
= uInfo
->spam
))
1837 spamserv_create_spamNode(channel
, uInfo
, text
);
1841 for(; sNode
; sNode
= sNode
->next
)
1842 if(sNode
->channel
== channel
)
1847 spamserv_create_spamNode(channel
, uInfo
, text
);
1851 unsigned long crc
= crc32(text
);
1853 if(crc
== sNode
->crc32
)
1855 unsigned int spamlimit
= 2;
1858 switch(cInfo
->info
[ci_SpamLimit
])
1860 case 'a': spamlimit
= 2; break;
1861 case 'b': spamlimit
= 3; break;
1862 case 'c': spamlimit
= 4; break;
1863 case 'd': spamlimit
= 5; break;
1864 case 'e': spamlimit
= 6; break;
1867 if(sNode
->count
== spamlimit
)
1869 uInfo
->warnlevel
+= SPAM_WARNLEVEL
;
1871 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
1872 if (spamserv_conf
.network_rules
)
1873 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_SPAM
, spamserv_conf
.network_rules
);
1875 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_SPAM
, spamserv_conf
.network_rules
);
1878 else if(sNode
->count
> spamlimit
)
1880 switch(cInfo
->info
[ci_WarnReaction
])
1882 case 'k': uInfo
->flags
|= USER_KICK
; break;
1883 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
1884 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
1885 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
1886 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
1889 spamserv_delete_spamNode(uInfo
, sNode
);
1890 uInfo
->warnlevel
+= SPAM_WARNLEVEL
;
1903 if(CHECK_FLOOD(cInfo
))
1905 if(!(fNode
= uInfo
->flood
))
1907 spamserv_create_floodNode(channel
, user
, &uInfo
->flood
);
1911 for(; fNode
; fNode
= fNode
->next
)
1912 if(fNode
->channel
== channel
)
1917 spamserv_create_floodNode(channel
, user
, &uInfo
->flood
);
1921 if(((now
- fNode
->time
) < FLOOD_EXPIRE
))
1925 if(fNode
->count
== FLOOD_MAX_LINES
- 1)
1927 uInfo
->warnlevel
+= FLOOD_WARNLEVEL
;
1929 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
1930 if (spamserv_conf
.network_rules
)
1931 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_FLOOD
, spamserv_conf
.network_rules
);
1933 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_FLOOD
, spamserv_conf
.network_rules
);
1936 else if(fNode
->count
> FLOOD_MAX_LINES
)
1938 switch(cInfo
->info
[ci_WarnReaction
])
1940 case 'k': uInfo
->flags
|= USER_KICK
; break;
1941 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
1942 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
1943 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
1944 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
1947 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
1948 uInfo
->warnlevel
+= FLOOD_WARNLEVEL
;
1958 if(CHECK_BADWORDSCAN(cInfo
) && check_badwords(cInfo
, text
))
1960 if(CHECK_BAD_WARNED(uInfo
))
1962 switch(cInfo
->info
[ci_BadReaction
])
1964 case 'k': uInfo
->flags
|= USER_KICK
; break;
1965 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
1966 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
1967 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
1968 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
1971 uInfo
->warnlevel
+= BAD_WARNLEVEL
;
1976 uInfo
->flags
|= USER_BAD_WARNED
;
1977 uInfo
->lastbad
= now
;
1978 uInfo
->warnlevel
+= BAD_WARNLEVEL
;
1980 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
1981 if (spamserv_conf
.network_rules
)
1982 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_BAD
, spamserv_conf
.network_rules
);
1984 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_BAD
, spamserv_conf
.network_rules
);
1989 if(CHECK_ADV(cInfo
) && check_advertising(cInfo
, text
))
1991 if(CHECK_ADV_WARNED(uInfo
))
1993 switch(cInfo
->info
[ci_AdvReaction
])
1995 case 'k': uInfo
->flags
|= USER_KICK
; break;
1996 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
1997 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
1998 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
1999 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2002 uInfo
->warnlevel
+= ADV_WARNLEVEL
;
2007 uInfo
->flags
|= USER_ADV_WARNED
;
2008 uInfo
->lastadv
= now
;
2009 uInfo
->warnlevel
+= ADV_WARNLEVEL
;
2011 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2012 if (spamserv_conf
.network_rules
)
2013 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_ADV
, spamserv_conf
.network_rules
);
2015 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_ADV
, spamserv_conf
.network_rules
);
2020 if(!CHECK_WARNED(uInfo
) && !CHECK_KILL(uInfo
) && !CHECK_GLINE(uInfo
) && uInfo
->warnlevel
== MAX_WARNLEVEL
)
2022 uInfo
->flags
|= USER_WARNED
;
2023 if (spamserv_conf
.network_rules
)
2024 snprintf(reason
, sizeof(reason
), SSMSG_WARNING_RULES_2
, spamserv_conf
.network_rules
);
2026 snprintf(reason
, sizeof(reason
), SSMSG_WARNING_2
);
2027 irc_notice(spamserv
, user
->numeric
, reason
);
2028 irc_privmsg(spamserv
, user
->numeric
, reason
);
2030 else if(uInfo
->warnlevel
> MAX_WARNLEVEL
)
2032 if(CHECK_KILLED(uInfo
))
2033 uInfo
->flags
|= USER_GLINE
;
2035 uInfo
->flags
|= USER_KILL
;
2046 case 1: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_SPAM
, spamserv_conf
.network_rules
); break;
2047 case 2: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_FLOOD
, spamserv_conf
.network_rules
); break;
2048 case 3: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_ADV
, spamserv_conf
.network_rules
); break;
2049 case 4: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_BAD
, spamserv_conf
.network_rules
); break;
2050 default: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES_2
: SSMSG_WARNING_2
, spamserv_conf
.network_rules
); break;
2053 if(CHECK_GLINE(uInfo
))
2055 int size
= strlen(user
->hostname
) + 3;
2056 char *mask
= alloca(size
);
2057 snprintf(mask
, size
, "*@%s", user
->hostname
);
2058 gline_add(spamserv
->nick
, mask
, spamserv_conf
.gline_duration
, reason
, now
, 1, 0);
2059 spamserv_debug(SSMSG_DEBUG_GLINE
, user
->nick
, user
->hostname
, channel
->name
);
2061 else if(CHECK_KILL(uInfo
))
2063 DelUser(user
, spamserv
, 1, reason
);
2064 spamserv_debug(SSMSG_DEBUG_KILL
, user
->nick
, channel
->name
);
2066 else if(CHECK_LONG_TBAN(uInfo
))
2068 spamserv_punish(channel
, user
, spamserv_conf
.long_ban_duration
, reason
, 1);
2070 else if(CHECK_SHORT_TBAN(uInfo
))
2072 spamserv_punish(channel
, user
, spamserv_conf
.short_ban_duration
, reason
, 1);
2074 else if(CHECK_KICKBAN(uInfo
))
2076 spamserv_punish(channel
, user
, 0, reason
, 1);
2078 else if(CHECK_KICK(uInfo
))
2080 spamserv_punish(channel
, user
, 0, reason
, 0);
2085 spamserv_saxdb_read(struct dict
*database
)
2088 struct record_data
*hir
;
2089 struct chanNode
*channel
;
2090 struct chanInfo
*cInfo
;
2091 struct string_list
*strlist
, *strlist2
;
2096 for(it
= dict_first(database
); it
; it
= iter_next(it
))
2098 hir
= iter_data(it
);
2100 if(hir
->type
!= RECDB_OBJECT
)
2102 log_module(SS_LOG
, LOG_WARNING
, "Unexpected rectype %d for %s.", hir
->type
, iter_key(it
));
2106 channel
= GetChannel(iter_key(it
));
2108 strlist
= database_get_data(hir
->d
.object
, KEY_EXCEPTIONS
, RECDB_STRING_LIST
);
2109 strlist2
= database_get_data(hir
->d
.object
, KEY_BADWORDS
, RECDB_STRING_LIST
);
2111 str
= database_get_data(hir
->d
.object
, KEY_FLAGS
, RECDB_QSTRING
);
2112 flags
= str
? atoi(str
) : 0;
2114 info
= database_get_data(hir
->d
.object
, KEY_INFO
, RECDB_QSTRING
);
2116 str
= database_get_data(hir
->d
.object
, KEY_EXPIRY
, RECDB_QSTRING
);
2117 expiry
= str
? strtoul(str
, NULL
, 0) : 0;
2121 if((cInfo
= spamserv_register_channel(channel
, strlist
, strlist2
, flags
, info
)))
2123 /* if the channel is suspended and expiry = 0 it means: channel will
2124 never expire ! it does NOT mean, the channel is not suspended */
2125 if(CHECK_SUSPENDED(cInfo
) && expiry
&& (expiry
< now
))
2127 cInfo
->flags
&= ~CHAN_SUSPENDED
;
2128 spamserv_join_channel(cInfo
->channel
);
2130 else if(!CHECK_SUSPENDED(cInfo
))
2131 spamserv_join_channel(cInfo
->channel
);
2133 cInfo
->suspend_expiry
= expiry
;
2137 log_module(SS_LOG
, LOG_ERROR
, "Couldn't register channel %s. Channel or info invalid.", iter_key(it
));
2144 spamserv_saxdb_write(struct saxdb_context
*ctx
)
2148 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
2150 struct chanInfo
*cInfo
= iter_data(it
);
2152 saxdb_start_record(ctx
, cInfo
->channel
->name
, 1);
2154 if(cInfo
->exceptions
->used
)
2155 saxdb_write_string_list(ctx
, KEY_EXCEPTIONS
, cInfo
->exceptions
);
2157 if(cInfo
->badwords
->used
)
2158 saxdb_write_string_list(ctx
, KEY_BADWORDS
, cInfo
->badwords
);
2161 saxdb_write_int(ctx
, KEY_FLAGS
, cInfo
->flags
);
2163 saxdb_write_string(ctx
, KEY_INFO
, cInfo
->info
);
2165 if(cInfo
->suspend_expiry
)
2166 saxdb_write_int(ctx
, KEY_EXPIRY
, cInfo
->suspend_expiry
);
2168 saxdb_end_record(ctx
);
2174 spamserv_conf_read(void)
2179 if(!(conf_node
= conf_get_data(SPAMSERV_CONF_NAME
, RECDB_OBJECT
)))
2181 log_module(SS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", SPAMSERV_CONF_NAME
);
2185 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
2189 spamserv_conf
.debug_channel
= AddChannel(str
, now
, "+tinms", NULL
, NULL
);
2191 if(spamserv_conf
.debug_channel
)
2192 spamserv_join_channel(spamserv_conf
.debug_channel
);
2196 spamserv_conf
.debug_channel
= NULL
;
2199 spamserv_conf
.global_exceptions
= database_get_data(conf_node
, KEY_GLOBAL_EXCEPTIONS
, RECDB_STRING_LIST
);
2201 spamserv_conf
.global_badwords
= database_get_data(conf_node
, KEY_GLOBAL_BADWORDS
, RECDB_STRING_LIST
);
2203 str
= database_get_data(conf_node
, KEY_NETWORK_RULES
, RECDB_QSTRING
);
2204 spamserv_conf
.network_rules
= str
? str
: NULL
;
2206 str
= database_get_data(conf_node
, KEY_TRIGGER
, RECDB_QSTRING
);
2207 spamserv_conf
.trigger
= str
? str
[0] : 0;
2209 str
= database_get_data(conf_node
, KEY_SHORT_BAN_DURATION
, RECDB_QSTRING
);
2210 spamserv_conf
.short_ban_duration
= str
? ParseInterval(str
) : ParseInterval("15m");
2212 str
= database_get_data(conf_node
, KEY_LONG_BAN_DURATION
, RECDB_QSTRING
);
2213 spamserv_conf
.long_ban_duration
= str
? ParseInterval(str
) : ParseInterval("1h");
2215 str
= database_get_data(conf_node
, KEY_GLINE_DURATION
, RECDB_QSTRING
);
2216 spamserv_conf
.gline_duration
= str
? ParseInterval(str
) : ParseInterval("1h");
2218 str
= database_get_data(conf_node
, KEY_EXCEPTION_MAX
, RECDB_QSTRING
);
2219 spamserv_conf
.exception_max
= str
? strtoul(str
, NULL
, 0) : 10;
2221 str
= database_get_data(conf_node
, KEY_EXCEPTION_MIN_LEN
, RECDB_QSTRING
);
2222 spamserv_conf
.exception_min_len
= str
? strtoul(str
, NULL
, 0) : 4;
2224 str
= database_get_data(conf_node
, KEY_EXCEPTION_MAX_LEN
, RECDB_QSTRING
);
2225 spamserv_conf
.exception_max_len
= str
? strtoul(str
, NULL
, 0) : 15;
2227 str
= database_get_data(conf_node
, KEY_BADWORD_MAX
, RECDB_QSTRING
);
2228 spamserv_conf
.badword_max
= str
? strtoul(str
, NULL
, 0) : 10;
2230 str
= database_get_data(conf_node
, KEY_BADWORD_MIN_LEN
, RECDB_QSTRING
);
2231 spamserv_conf
.badword_min_len
= str
? strtoul(str
, NULL
, 0) : 4;
2233 str
= database_get_data(conf_node
, KEY_BADWORD_MAX_LEN
, RECDB_QSTRING
);
2234 spamserv_conf
.badword_max_len
= str
? strtoul(str
, NULL
, 0) : 15;
2236 str
= database_get_data(conf_node
, KEY_ADV_CHAN_MUST_EXIST
, RECDB_QSTRING
);
2237 spamserv_conf
.adv_chan_must_exist
= str
? enabled_string(str
) : 1;
2239 str
= database_get_data(conf_node
, KEY_STRIP_MIRC_CODES
, RECDB_QSTRING
);
2240 spamserv_conf
.strip_mirc_codes
= str
? enabled_string(str
) : 0;
2242 str
= database_get_data(conf_node
, KEY_ALLOW_MOVE_MERGE
, RECDB_QSTRING
);
2243 spamserv_conf
.allow_move_merge
= str
? enabled_string(str
) : 0;
2247 spamserv_db_cleanup(void)
2251 while((it
= dict_first(registered_channels_dict
)))
2253 spamserv_unregister_channel(iter_data(it
));
2256 while((it
= dict_first(killed_users_dict
)))
2258 free(iter_data(it
));
2261 dict_delete(registered_channels_dict
);
2262 dict_delete(connected_users_dict
);
2263 dict_delete(killed_users_dict
);
2267 init_spamserv(const char *nick
)
2269 struct chanNode
*chan
;
2275 const char *modes
= conf_get_data("services/spamserv/modes", RECDB_QSTRING
);
2276 spamserv
= AddService(nick
, modes
? modes
: NULL
, "Anti Spam Services", NULL
);
2277 spamserv_service
= service_register(spamserv
);
2279 conf_register_reload(spamserv_conf_read
);
2281 SS_LOG
= log_register_type("SpamServ", "file:spamserv.log");
2283 registered_channels_dict
= dict_new();
2284 connected_users_dict
= dict_new();
2285 killed_users_dict
= dict_new();
2287 saxdb_register("SpamServ", spamserv_saxdb_read
, spamserv_saxdb_write
);
2289 reg_new_user_func(spamserv_new_user_func
);
2290 reg_del_user_func(spamserv_del_user_func
);
2291 reg_nick_change_func(spamserv_nick_change_func
);
2292 reg_join_func(spamserv_user_join
);
2293 reg_part_func(spamserv_user_part
);
2295 timeq_add(now
+ FLOOD_TIMEQ_FREQ
, timeq_flood
, NULL
);
2296 timeq_add(now
+ JOINFLOOD_TIMEQ_FREQ
, timeq_joinflood
, NULL
);
2297 timeq_add(now
+ ADV_TIMEQ_FREQ
, timeq_adv
, NULL
);
2298 timeq_add(now
+ BAD_TIMEQ_FREQ
, timeq_bad
, NULL
);
2299 timeq_add(now
+ WARNLEVEL_TIMEQ_FREQ
, timeq_warnlevel
, NULL
);
2300 timeq_add(now
+ KILL_TIMEQ_FREQ
, timeq_kill
, NULL
);
2302 spamserv_module
= module_register("SpamServ", SS_LOG
, "spamserv.help", NULL
);
2303 modcmd_register(spamserv_module
, "REGISTER", cmd_register
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, "flags", "+acceptchan,+helping", NULL
);
2304 modcmd_register(spamserv_module
, "UNREGISTER", cmd_unregister
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, "flags", "+loghostmask", NULL
);
2305 modcmd_register(spamserv_module
, "ADDEXCEPTION", cmd_addexception
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2306 modcmd_register(spamserv_module
, "DELEXCEPTION", cmd_delexception
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2307 modcmd_register(spamserv_module
, "ADDBADWORD", cmd_addbadword
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2308 modcmd_register(spamserv_module
, "DELBADWORD", cmd_delbadword
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2309 modcmd_register(spamserv_module
, "STATUS", cmd_status
, 1, 0, NULL
);
2310 modcmd_register(spamserv_module
, "SET", cmd_set
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2311 modcmd_register(spamserv_module
, "SET SPAMLIMIT", opt_spamlimit
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2312 modcmd_register(spamserv_module
, "SET BADREACTION", opt_badreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2313 modcmd_register(spamserv_module
, "SET ADVREACTION", opt_advreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2314 modcmd_register(spamserv_module
, "SET WARNREACTION", opt_warnreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2315 modcmd_register(spamserv_module
, "SET ADVSCAN", opt_advscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2316 modcmd_register(spamserv_module
, "SET BADWORDSCAN", opt_badwordscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2317 modcmd_register(spamserv_module
, "SET SPAMSCAN", opt_spamscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2318 modcmd_register(spamserv_module
, "SET CHANFLOODSCAN", opt_chanfloodscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2319 modcmd_register(spamserv_module
, "SET JOINFLOODSCAN", opt_joinflood
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2320 modcmd_register(spamserv_module
, "SET SCANCHANOPS", opt_scanops
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2321 modcmd_register(spamserv_module
, "SET SCANHALFOPS", opt_scanhalfops
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2322 modcmd_register(spamserv_module
, "SET SCANVOICED", opt_scanvoiced
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
2324 spamserv_service
->trigger
= spamserv_conf
.trigger
;
2327 if (autojoin_channels
&& spamserv
) {
2328 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
2329 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
2330 AddChannelUser(spamserv
, chan
)->modes
|= MODE_CHANOP
;
2334 reg_exit_func(spamserv_db_cleanup
);
2335 message_register_table(msgtab
);