13 hlc_profile
* hlc_add(const char *str
)
17 if (hlc_get(str
) != NULL
)
20 tmp
= (hlc_profile
*)malloc(sizeof(hlc_profile
));
21 tmp
->name
= getsstring(str
, strlen(str
));
22 tmp
->next
= hlc_profiles
;
27 hlc_profile
*hlc_del(hlc_profile
*hlc_prof
)
29 hchannel
*hchan
= hchannels
;
30 hlc_profile
**ptr
= &hlc_profiles
;
32 for (;hchan
;hchan
= hchan
->next
)
33 if (hchan
->lc_profile
== hlc_prof
)
34 hchan
->lc_profile
= NULL
;
36 for (;*ptr
;ptr
= &(*ptr
)->next
)
39 hlc_profile
*tmp
= (*ptr
)->next
;
40 freesstring ((*ptr
)->name
);
48 void hlc_del_all(void)
51 hlc_del(hlc_profiles
);
54 hlc_profile
*hlc_get(const char *str
)
56 hlc_profile
*hlc_prof
= hlc_profiles
;
57 for (;hlc_prof
;hlc_prof
= hlc_prof
->next
)
58 if (!ci_strcmp(hlc_prof
->name
->content
, str
))
63 const char *hlc_get_cname(hlc_component comp
)
68 return "Error, contact strutsi";
72 /* static functions, used internally */
74 static int hlc_violation_handle(hchannel
*hchan
, huser
* husr
, int violation
)
76 if (husr
->lc
[violation
] >= hchan
->lc_profile
->tolerance_remove
) /* get rid of the thing */
78 const char *banmask
= hban_ban_string(husr
->real_user
, HBAN_HOST
);
79 char reason_buffer
[128];
80 sprintf(reason_buffer
, "Excessive violations: %s", hlc_get_violation_name(violation
));
81 hban_add(banmask
, reason_buffer
, time(NULL
) + HLC_DEFAULT_BANTIME
, 0);
83 if (IsAccount(husr
->real_user
))
84 haccount_add(huser_get_auth(husr
), H_LAMER
);
88 if (husr
->lc
[violation
] >= hchan
->lc_profile
->tolerance_kick
) /* get rid of the thing */
90 helpmod_kick(hchan
, husr
, "Channel rule violation: %s", hlc_get_violation_name(violation
));
93 if (husr
->lc
[violation
] >= hchan
->lc_profile
->tolerance_warn
) /* get rid of the thing */
95 helpmod_reply(husr
, NULL
, "You are violating the channel rule of %s : %s. Continuous violation of this rule will result in you being removed from %s", hchannel_get_name(hchan
), hlc_get_violation_name(violation
), hchannel_get_name(hchan
));
101 static int hlc_check_caps(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
108 if (strchr(line
, ' '))
109 firstword
= strchr(line
, ' ') - line
;
113 /* Handle the thing sent with /me */
114 if (!strncmp(line
, "\1ACTION", 6 + 1))
116 else if (firstword
&& firstword
< NICKLEN
+ 3)
118 char buffer
[NICKLEN
+ 3];
119 strncpy(buffer
, line
, firstword
);
120 buffer
[firstword
] = '\0';
121 if (buffer
[firstword
- 1] == ':')
122 buffer
[firstword
- 1] = '\0';
123 if (getnickbynick(buffer
))
127 for (i
= 0;line
[i
];i
++)
129 if (isalpha(line
[i
]))
131 if (isupper(line
[i
]))
138 if ((noncaps
+ caps
) < hlc_prof
->caps_min_count
)
141 if (((100 * caps
) / (caps
+ noncaps
)) >= hlc_prof
->caps_max_percentage
) /* violation */
143 return ++husr
->lc
[HLC_CAPS
];
149 static int hlc_check_repeat(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
151 if (!strncmp(husr
->last_line
, line
, strlen(husr
->last_line
)) && (strlen(husr
->last_line
) >= hlc_prof
->repeats_min_length
))
152 husr
->last_line_repeats
++;
153 else if (!strcmp(husr
->last_line
, line
))
154 husr
->last_line_repeats
++;
156 husr
->last_line_repeats
= 0;
158 strcpy(husr
->last_line
, line
);
160 if (husr
->last_line_repeats
>= hlc_prof
->repeats_max_count
&& strlen(line
) >= hlc_prof
->repeats_min_length
) /* violation */
161 return ++husr
->lc
[HLC_REPEAT
];
166 static int hlc_check_character_repeats(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
172 for (i
= 0;line
[i
];i
++)
176 if (repeats
>= hlc_prof
->character_repeat_max_count
&& isalnum(chr
)) /* violation */
177 return ++husr
->lc
[HLC_CHARACTER_REPEAT
];
178 else if (repeats
>= hlc_prof
->symbol_repeat_max_count
&& ispunct(chr
)) /* violation */
179 return ++husr
->lc
[HLC_CHARACTER_REPEAT
];
186 for (i
=0, repeats
= 0; line
[i
]; i
++)
188 if (ispunct(line
[i
]))
193 if (repeats
>= hlc_prof
->symbol_max_count
)
194 return ++husr
->lc
[HLC_CHARACTER_REPEAT
];
199 static int hlc_check_flood(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
201 if (husr
->flood_val
< time(NULL
))
202 husr
->flood_val
= time(NULL
);
206 if ((husr
->flood_val
- time(NULL
)) > (hlc_prof
->tolerance_flood
))
208 husr
->flood_val
= time(NULL
);
209 return ++husr
->lc
[HLC_FLOOD
];
215 static int hlc_check_spam(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
217 if (husr
->spam_val
< (float)time(NULL
))
218 husr
->spam_val
= (float)time(NULL
);
220 husr
->spam_val
+= (hlc_prof
->constant_spam
* (double)strlen(line
));
222 if (((int)husr
->spam_val
- time(NULL
)) >= (hlc_prof
->tolerance_spam
))
224 husr
->spam_val
= time(NULL
);
225 return ++husr
->lc
[HLC_SPAM
];
230 /* checks a string for lameness, returns non-zero if lameness is present */
231 int hlc_check(hchannel
*hchan
, huser
* husr
, const char *line
)
233 if (hchan
== NULL
|| hchan
->lc_profile
== NULL
)
236 if (hlc_check_flood(hchan
->lc_profile
, husr
, line
))
237 if (hlc_violation_handle(hchan
, husr
, HLC_FLOOD
))
239 if (hlc_check_spam(hchan
->lc_profile
, husr
, line
))
240 if (hlc_violation_handle(hchan
, husr
, HLC_SPAM
))
242 if (hlc_check_caps(hchan
->lc_profile
, husr
, line
))
243 if (hlc_violation_handle(hchan
, husr
, HLC_CAPS
))
245 if (hlc_check_repeat(hchan
->lc_profile
, husr
, line
))
246 if (hlc_violation_handle(hchan
, husr
, HLC_REPEAT
))
248 if (hlc_check_character_repeats(hchan
->lc_profile
, husr
, line
))
249 if (hlc_violation_handle(hchan
, husr
, HLC_CHARACTER_REPEAT
))
255 const char *hlc_get_violation_name(hlc_violation violation
)
260 return "Excessive use of capital letters";
263 case HLC_CHARACTER_REPEAT
:
264 return "Improper use of language";
270 return "Error, please contact strutsi";