ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_invite.c
Revision: 9271
Committed: Wed Feb 12 16:58:58 2020 UTC (5 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 3354 byte(s)
Log Message:
- propset

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2020 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file channel_invite.c
23 * \brief Channel invitation related functions
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "memory.h"
29 #include "list.h"
30 #include "event.h"
31 #include "channel.h"
32 #include "channel_invite.h"
33 #include "conf.h"
34
35
36 struct Invite *
37 invite_find(struct Channel *channel, struct Client *client)
38 {
39 dlink_node *node, *node_next;
40 dlink_list *list;
41
42 /* Take the shortest of the two lists */
43 if (dlink_list_length(&client->connection->invited) < dlink_list_length(&channel->invites))
44 list = &client->connection->invited;
45 else
46 list = &channel->invites;
47
48 DLINK_FOREACH_SAFE(node, node_next, list->head)
49 {
50 struct Invite *invite = node->data;
51
52 if (ConfigChannel.invite_expire_time &&
53 ConfigChannel.invite_expire_time + invite->when < event_base->time.sec_monotonic)
54 invite_del(invite);
55 else if (invite->channel == channel && invite->client == client)
56 return invite;
57 }
58
59 return NULL;
60 }
61
62 /*! \brief Adds client to invite list
63 * \param channel Pointer to channel block
64 * \param client Pointer to client to add invite to
65 */
66 void
67 invite_add(struct Channel *channel, struct Client *client)
68 {
69 struct Invite *invite = invite_find(channel, client);
70 if (invite)
71 invite_del(invite);
72
73 invite = xcalloc(sizeof(*invite));
74 invite->client = client;
75 invite->channel = channel;
76 invite->when = event_base->time.sec_monotonic;
77
78 /* Delete last link in chain if the list is max length */
79 while (dlink_list_length(&client->connection->invited) &&
80 dlink_list_length(&client->connection->invited) >= ConfigChannel.max_invites)
81 invite_del(client->connection->invited.tail->data);
82
83 /* Add client to channel invite list */
84 dlinkAdd(invite, &invite->chan_node, &channel->invites);
85
86 /* Add channel to the end of the client invite list */
87 dlinkAdd(invite, &invite->user_node, &client->connection->invited);
88 }
89
90 /*! \brief Delete Invite block from channel invite list
91 * and client invite list
92 * \param invite Pointer to Invite struct
93 */
94 void
95 invite_del(struct Invite *invite)
96 {
97 dlinkDelete(&invite->user_node, &invite->client->connection->invited);
98 dlinkDelete(&invite->chan_node, &invite->channel->invites);
99
100 /* Release memory pointed to by 'invite' */
101 xfree(invite);
102 }
103
104 /*! \brief Removes and frees all Invite blocks from a list
105 * \param list Pointer to a dlink_list
106 */
107 void
108 invite_clear_list(dlink_list *list)
109 {
110 while (list->head)
111 invite_del(list->head->data);
112 }

Properties

Name Value
svn:eol-style native
svn:keywords Id