5 #include "../nick/nick.h"
15 hlc_profile
* hlc_add(const char *str
)
19 if (hlc_get(str
) != NULL
)
22 tmp
= (hlc_profile
*)malloc(sizeof(hlc_profile
));
23 tmp
->name
= getsstring(str
, strlen(str
));
24 tmp
->next
= hlc_profiles
;
29 hlc_profile
*hlc_del(hlc_profile
*hlc_prof
)
31 hchannel
*hchan
= hchannels
;
32 hlc_profile
**ptr
= &hlc_profiles
;
34 for (;hchan
;hchan
= hchan
->next
)
35 if (hchan
->lc_profile
== hlc_prof
)
36 hchan
->lc_profile
= NULL
;
38 for (;*ptr
;ptr
= &(*ptr
)->next
)
41 hlc_profile
*tmp
= (*ptr
)->next
;
42 freesstring ((*ptr
)->name
);
50 void hlc_del_all(void)
53 hlc_del(hlc_profiles
);
56 hlc_profile
*hlc_get(const char *str
)
58 hlc_profile
*hlc_prof
= hlc_profiles
;
59 for (;hlc_prof
;hlc_prof
= hlc_prof
->next
)
60 if (!ci_strcmp(hlc_prof
->name
->content
, str
))
65 const char *hlc_get_cname(hlc_component comp
)
70 return "Error, contact strutsi";
74 /* static functions, used internally */
76 static int hlc_violation_handle(hchannel
*hchan
, huser
* husr
, int violation
)
78 if (husr
->lc
[violation
] >= hchan
->lc_profile
->tolerance_remove
) /* get rid of the thing */
80 const char *banmask
= hban_ban_string(husr
->real_user
, HBAN_HOST
);
81 char reason_buffer
[128];
82 sprintf(reason_buffer
, "Excessive violations: %s", hlc_get_violation_name(violation
));
83 hban_add(banmask
, reason_buffer
, time(NULL
) + HLC_DEFAULT_BANTIME
, 0);
85 if (IsAccount(husr
->real_user
))
86 haccount_add(huser_get_auth(husr
), H_LAMER
);
90 if (husr
->lc
[violation
] >= hchan
->lc_profile
->tolerance_kick
) /* get rid of the thing */
92 helpmod_kick(hchan
, husr
, "Channel rule violation: %s", hlc_get_violation_name(violation
));
95 if (husr
->lc
[violation
] >= hchan
->lc_profile
->tolerance_warn
) /* get rid of the thing */
97 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
));
103 static int hlc_check_caps(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
110 if (strchr(line
, ' '))
111 firstword
= strchr(line
, ' ') - line
;
115 /* Handle the thing sent with /me */
116 if (!strncmp(line
, "\1ACTION", 6 + 1))
118 else if (firstword
&& firstword
< NICKLEN
+ 3)
120 char buffer
[NICKLEN
+ 3];
121 strncpy(buffer
, line
, firstword
);
122 buffer
[firstword
] = '\0';
123 if (buffer
[firstword
- 1] == ':')
124 buffer
[firstword
- 1] = '\0';
125 if (getnickbynick(buffer
))
129 for (i
= 0;line
[i
];i
++)
131 if (isalpha(line
[i
]))
133 if (isupper(line
[i
]))
140 if ((noncaps
+ caps
) < hlc_prof
->caps_min_count
)
143 if (((100 * caps
) / (caps
+ noncaps
)) >= hlc_prof
->caps_max_percentage
) /* violation */
145 return ++husr
->lc
[HLC_CAPS
];
151 static int hlc_check_repeat(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
153 if (!strncmp(husr
->last_line
, line
, strlen(husr
->last_line
)) && (strlen(husr
->last_line
) >= hlc_prof
->repeats_min_length
))
154 husr
->last_line_repeats
++;
155 else if (!strcmp(husr
->last_line
, line
))
156 husr
->last_line_repeats
++;
158 husr
->last_line_repeats
= 0;
160 strcpy(husr
->last_line
, line
);
162 if (husr
->last_line_repeats
>= hlc_prof
->repeats_max_count
&& strlen(line
) >= hlc_prof
->repeats_min_length
) /* violation */
163 return ++husr
->lc
[HLC_REPEAT
];
168 static int hlc_check_character_repeats(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
174 for (i
= 0;line
[i
];i
++)
178 if (repeats
>= hlc_prof
->character_repeat_max_count
&& isalnum(chr
)) /* violation */
179 return ++husr
->lc
[HLC_CHARACTER_REPEAT
];
180 else if (repeats
>= hlc_prof
->symbol_repeat_max_count
&& ispunct(chr
)) /* violation */
181 return ++husr
->lc
[HLC_CHARACTER_REPEAT
];
188 for (i
=0, repeats
= 0; line
[i
]; i
++)
190 if (ispunct(line
[i
]))
195 if (repeats
>= hlc_prof
->symbol_max_count
)
196 return ++husr
->lc
[HLC_CHARACTER_REPEAT
];
201 static int hlc_check_flood(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
203 if (husr
->flood_val
< time(NULL
))
204 husr
->flood_val
= time(NULL
);
208 if ((husr
->flood_val
- time(NULL
)) > (hlc_prof
->tolerance_flood
))
210 husr
->flood_val
= time(NULL
);
211 return ++husr
->lc
[HLC_FLOOD
];
217 static int hlc_check_spam(hlc_profile
*hlc_prof
, huser
*husr
, const char *line
)
219 if (husr
->spam_val
< (float)time(NULL
))
220 husr
->spam_val
= (float)time(NULL
);
222 husr
->spam_val
+= (hlc_prof
->constant_spam
* (double)strlen(line
));
224 if (((int)husr
->spam_val
- time(NULL
)) >= (hlc_prof
->tolerance_spam
))
226 husr
->spam_val
= time(NULL
);
227 return ++husr
->lc
[HLC_SPAM
];
232 /* checks a string for lameness, returns non-zero if lameness is present */
233 int hlc_check(hchannel
*hchan
, huser
* husr
, const char *line
)
235 if (hchan
== NULL
|| hchan
->lc_profile
== NULL
)
238 if (hlc_check_flood(hchan
->lc_profile
, husr
, line
))
239 if (hlc_violation_handle(hchan
, husr
, HLC_FLOOD
))
241 if (hlc_check_spam(hchan
->lc_profile
, husr
, line
))
242 if (hlc_violation_handle(hchan
, husr
, HLC_SPAM
))
244 if (hlc_check_caps(hchan
->lc_profile
, husr
, line
))
245 if (hlc_violation_handle(hchan
, husr
, HLC_CAPS
))
247 if (hlc_check_repeat(hchan
->lc_profile
, husr
, line
))
248 if (hlc_violation_handle(hchan
, husr
, HLC_REPEAT
))
250 if (hlc_check_character_repeats(hchan
->lc_profile
, husr
, line
))
251 if (hlc_violation_handle(hchan
, husr
, HLC_CHARACTER_REPEAT
))
257 const char *hlc_get_violation_name(hlc_violation violation
)
262 return "Excessive use of capital letters";
265 case HLC_CHARACTER_REPEAT
:
266 return "Improper use of language";
272 return "Error, please contact strutsi";