2 * Copyright (C) 1998 Peter Zelezny.
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.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23 #include <sys/types.h>
36 int ignored_ctcp
= 0; /* keep a count of all we ignore */
41 static int ignored_total
= 0;
44 * returns: struct ig, if this mask is in the ignore list already
48 ignore_exists (char *mask
)
50 struct ignore
*ig
= 0;
56 ig
= (struct ignore
*) list
->data
;
57 if (!rfc_casecmp (ig
->mask
, mask
))
70 * 2 success (old ignore has been changed)
74 ignore_add (char *mask
, int type
)
76 struct ignore
*ig
= 0;
77 int change_only
= FALSE
;
79 /* first check if it's already ignored */
80 ig
= ignore_exists (mask
);
85 ig
= malloc (sizeof (struct ignore
));
90 ig
->mask
= strdup (mask
);
94 ignore_list
= g_slist_prepend (ignore_list
, ig
);
104 ignore_showlist (session
*sess
)
107 GSList
*list
= ignore_list
;
111 EMIT_SIGNAL (XP_TE_IGNOREHEADER
, sess
, 0, 0, 0, 0, 0);
118 snprintf (tbuf
, sizeof (tbuf
), " %-25s ", ig
->mask
);
119 if (ig
->type
& IG_PRIV
)
120 strcat (tbuf
, _("YES "));
122 strcat (tbuf
, _("NO "));
123 if (ig
->type
& IG_NOTI
)
124 strcat (tbuf
, _("YES "));
126 strcat (tbuf
, _("NO "));
127 if (ig
->type
& IG_CHAN
)
128 strcat (tbuf
, _("YES "));
130 strcat (tbuf
, _("NO "));
131 if (ig
->type
& IG_CTCP
)
132 strcat (tbuf
, _("YES "));
134 strcat (tbuf
, _("NO "));
135 if (ig
->type
& IG_DCC
)
136 strcat (tbuf
, _("YES "));
138 strcat (tbuf
, _("NO "));
139 if (ig
->type
& IG_INVI
)
140 strcat (tbuf
, _("YES "));
142 strcat (tbuf
, _("NO "));
143 if (ig
->type
& IG_UNIG
)
144 strcat (tbuf
, _("YES "));
146 strcat (tbuf
, _("NO "));
148 PrintText (sess
, tbuf
);
149 /*EMIT_SIGNAL (XP_TE_IGNORELIST, sess, ig->mask, 0, 0, 0, 0); */
150 /* use this later, when TE's support 7 args */
155 EMIT_SIGNAL (XP_TE_IGNOREEMPTY
, sess
, 0, 0, 0, 0, 0);
157 EMIT_SIGNAL (XP_TE_IGNOREFOOTER
, sess
, 0, 0, 0, 0, 0);
162 * one of the args must be NULL, use mask OR *ig, not both
167 ignore_del (char *mask
, struct ignore
*ig
)
171 GSList
*list
= ignore_list
;
175 ig
= (struct ignore
*) list
->data
;
176 if (!rfc_casecmp (ig
->mask
, mask
))
184 ignore_list
= g_slist_remove (ignore_list
, ig
);
187 fe_ignore_update (1);
193 /* check if a msg should be ignored by browsing our ignore list */
196 ignore_check (char *host
, int type
)
199 GSList
*list
= ignore_list
;
201 /* check if there's an UNIGNORE first, they take precendance. */
204 ig
= (struct ignore
*) list
->data
;
205 if (ig
->type
& IG_UNIG
)
209 if (match (ig
->mask
, host
))
219 ig
= (struct ignore
*) list
->data
;
223 if (match (ig
->mask
, host
))
236 fe_ignore_update (2);
247 ignore_read_next_entry (char *my_cfg
, struct ignore
*ignore
)
251 /* Casting to char * done below just to satisfy compiler */
255 my_cfg
= cfg_get_str (my_cfg
, "mask", tbuf
, sizeof (tbuf
));
258 ignore
->mask
= strdup (tbuf
);
262 my_cfg
= cfg_get_str (my_cfg
, "type", tbuf
, sizeof (tbuf
));
263 ignore
->type
= atoi (tbuf
);
271 struct ignore
*ignore
;
276 fh
= xchat_open_file ("ignore.conf", O_RDONLY
, 0, 0);
282 cfg
= malloc (st
.st_size
+ 1);
284 i
= read (fh
, cfg
, st
.st_size
);
290 ignore
= malloc (sizeof (struct ignore
));
291 memset (ignore
, 0, sizeof (struct ignore
));
292 if ((my_cfg
= ignore_read_next_entry (my_cfg
, ignore
)))
293 ignore_list
= g_slist_prepend (ignore_list
, ignore
);
308 GSList
*temp
= ignore_list
;
311 fh
= xchat_open_file ("ignore.conf", O_TRUNC
| O_WRONLY
| O_CREAT
, 0600, XOF_DOMODE
);
316 ig
= (struct ignore
*) temp
->data
;
317 if (!(ig
->type
& IG_NOSAVE
))
319 snprintf (buf
, sizeof (buf
), "mask = %s\ntype = %d\n\n",
321 write (fh
, buf
, strlen (buf
));
331 flood_autodialog_timeout (gpointer data
)
333 prefs
.autodialog
= 1;
338 flood_check (char *nick
, char *ip
, server
*serv
, session
*sess
, int what
) /*0=ctcp 1=priv */
343 time_t ctcp_last_time;
345 unsigned int ctcp_number_limit;
346 unsigned int ctcp_time_limit;
352 current_time
= time (NULL
);
356 if (serv
->ctcp_last_time
== 0) /*first ctcp in this server */
358 serv
->ctcp_last_time
= time (NULL
);
359 serv
->ctcp_counter
++;
362 if (difftime (current_time
, serv
->ctcp_last_time
) < prefs
.ctcp_time_limit
) /*if we got the ctcp in the seconds limit */
364 serv
->ctcp_counter
++;
365 if (serv
->ctcp_counter
== prefs
.ctcp_number_limit
) /*if we reached the maximun numbers of ctcp in the seconds limits */
367 serv
->ctcp_last_time
= current_time
; /*we got the flood, restore all the vars for next one */
368 serv
->ctcp_counter
= 0;
369 for (i
= 0; i
< 128; i
++)
372 snprintf (real_ip
, sizeof (real_ip
), "*!*%s", &ip
[i
]);
373 /*ignore_add (char *mask, int priv, int noti, int chan,
374 int ctcp, int invi, int unignore, int no_save) */
376 snprintf (buf
, sizeof (buf
),
377 _("You are being CTCP flooded from %s, ignoring %s\n"),
379 PrintText (sess
, buf
);
381 /*FIXME: only ignore ctcp or all?, its ignoring ctcps for now */
382 ignore_add (real_ip
, IG_CTCP
);
389 if (serv
->msg_last_time
== 0)
391 serv
->msg_last_time
= time (NULL
);
392 serv
->ctcp_counter
++;
395 if (difftime (current_time
, serv
->msg_last_time
) <
396 prefs
.msg_time_limit
)
399 if (serv
->msg_counter
== prefs
.msg_number_limit
) /*if we reached the maximun numbers of ctcp in the seconds limits */
401 snprintf (buf
, sizeof (buf
),
402 _("You are being MSG flooded from %s, setting gui_auto_open_dialog OFF.\n"),
404 PrintText (sess
, buf
);
405 serv
->msg_last_time
= current_time
; /*we got the flood, restore all the vars for next one */
406 serv
->msg_counter
= 0;
407 /*ignore_add (char *mask, int priv, int noti, int chan,
408 int ctcp, int invi, int unignore, int no_save) */
410 if (prefs
.autodialog
)
412 /*FIXME: only ignore ctcp or all?, its ignoring ctcps for now */
413 prefs
.autodialog
= 0;
414 /* turn it back on in 30 secs */
415 fe_timeout_add (30000, flood_autodialog_timeout
, NULL
);