2 * IRC - Internet Relay Chat, ircd/destruct_event.c
3 * Copyright (C) 2002 Carlo Wood <carlo@alinoe.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 1, or (at your option)
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, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "channel.h" /* destruct_channel */
25 #include "ircd_alloc.h"
27 #include "ircd_events.h"
34 struct DestructEvent {
35 struct DestructEvent* next_event;
36 struct DestructEvent* prev_event;
38 struct Channel* chptr;
41 static struct DestructEvent* minute_list_top;
42 static struct DestructEvent* minute_list_bottom;
43 static struct DestructEvent* days_list_top;
44 static struct DestructEvent* days_list_bottom;
46 void schedule_destruct_event_1m(struct Channel* chptr)
48 struct DestructEvent* new_event;
50 /* Ignore request when we already have a destruct request */
51 if (chptr->destruct_event)
54 /* Create a new destruct event and add it at the top of the list. */
55 new_event = (struct DestructEvent*)MyMalloc(sizeof(struct DestructEvent));
56 new_event->expires = TStime() + 60; /* 1 minute from now */
57 new_event->next_event = NULL;
58 new_event->prev_event = minute_list_top;
59 new_event->chptr = chptr;
62 minute_list_top->next_event = new_event;
63 minute_list_top = new_event;
64 if (!minute_list_bottom)
65 minute_list_bottom = new_event;
67 chptr->destruct_event = new_event;
70 void schedule_destruct_event_48h(struct Channel* chptr)
72 struct DestructEvent* new_event;
74 /* Ignore request when we already have a destruct request */
75 if (chptr->destruct_event)
78 /* Create a new destruct event and add it at the top of the list. */
79 new_event = (struct DestructEvent*)MyMalloc(sizeof(struct DestructEvent));
80 new_event->expires = TStime() + 172800; /* 48 hours from now */
81 new_event->next_event = NULL;
82 new_event->prev_event = days_list_top;
83 new_event->chptr = chptr;
86 days_list_top->next_event = new_event;
87 days_list_top = new_event;
88 if (!days_list_bottom)
89 days_list_bottom = new_event;
91 chptr->destruct_event = new_event;
94 void remove_destruct_event(struct Channel* chptr)
96 struct DestructEvent* event = chptr->destruct_event;
98 assert(event != NULL);
101 if (event->prev_event)
102 event->prev_event->next_event = event->next_event;
103 if (event->next_event)
104 event->next_event->prev_event = event->prev_event;
106 /* correct top and bottom pointers */
107 if (days_list_top == event)
108 days_list_top = event->prev_event;
109 if (minute_list_top == event)
110 minute_list_top = event->prev_event;
111 if (days_list_bottom == event)
112 days_list_bottom = event->next_event;
113 if (minute_list_bottom == event)
114 minute_list_bottom = event->next_event;
119 chptr->destruct_event = NULL;
122 void exec_expired_destruct_events(struct Event* ev)
125 struct DestructEvent** list_bottom;
126 for(list_bottom = &minute_list_bottom; i < 2; ++i, list_bottom = &days_list_bottom)
128 while (*list_bottom && TStime() >= (*list_bottom)->expires)
130 struct Channel* chptr = (*list_bottom)->chptr;
131 /* Send DESTRUCT message */
132 sendcmdto_serv_butone(&me, CMD_DESTRUCT, 0, "%s %Tu", chptr->chname, chptr->creationtime);
133 remove_destruct_event(chptr);
134 destruct_channel(chptr);