]>
Commit | Line | Data |
---|---|---|
5f8fb56d AW |
1 | /* |
2 | * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd). | |
3 | * monitor.c - Code for server-side notify lists | |
4 | * | |
5 | * Copyright (C) 2005 Lee Hardy <lee -at- leeh.co.uk> | |
6 | * Copyright (C) 2005 ircd-ratbox development team | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are | |
10 | * met: | |
11 | * | |
12 | * 1.Redistributions of source code must retain the above copyright notice, | |
13 | * this list of conditions and the following disclaimer. | |
14 | * 2.Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in the | |
16 | * documentation and/or other materials provided with the distribution. | |
17 | * 3.The name of the author may not be used to endorse or promote products | |
18 | * derived from this software without specific prior written permission. | |
19 | * | |
20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
30 | * POSSIBILITY OF SUCH DAMAGE. | |
5f8fb56d AW |
31 | */ |
32 | #include "stdinc.h" | |
33 | #include "client.h" | |
34 | #include "monitor.h" | |
35 | #include "hash.h" | |
36 | #include "numeric.h" | |
37 | #include "send.h" | |
3de22662 | 38 | #include "irc_radixtree.h" |
5f8fb56d | 39 | |
3de22662 | 40 | static struct irc_radixtree *monitor_tree; |
5f8fb56d AW |
41 | |
42 | void | |
43 | init_monitor(void) | |
44 | { | |
3de22662 | 45 | monitor_tree = irc_radixtree_create("monitor lists", irc_radixtree_irccasecanon); |
5f8fb56d AW |
46 | } |
47 | ||
48 | struct monitor * | |
49 | find_monitor(const char *name, int add) | |
50 | { | |
51 | struct monitor *monptr; | |
5f8fb56d | 52 | |
3de22662 AC |
53 | monptr = irc_radixtree_retrieve(monitor_tree, name); |
54 | if (monptr != NULL) | |
55 | return monptr; | |
5f8fb56d AW |
56 | |
57 | if(add) | |
58 | { | |
3de22662 | 59 | monptr = rb_malloc(sizeof(*monptr)); |
5f8fb56d | 60 | rb_strlcpy(monptr->name, name, sizeof(monptr->name)); |
3de22662 | 61 | irc_radixtree_add(monitor_tree, monptr->name, monptr); |
5f8fb56d | 62 | |
5f8fb56d AW |
63 | return monptr; |
64 | } | |
65 | ||
66 | return NULL; | |
67 | } | |
68 | ||
69 | void | |
70 | free_monitor(struct monitor *monptr) | |
71 | { | |
72 | if (rb_dlink_list_length(&monptr->users) > 0) | |
73 | return; | |
74 | ||
3de22662 AC |
75 | irc_radixtree_delete(monitor_tree, monptr->name); |
76 | rb_free(monptr); | |
5f8fb56d AW |
77 | } |
78 | ||
79 | /* monitor_signon() | |
80 | * | |
81 | * inputs - client who has just connected | |
82 | * outputs - | |
83 | * side effects - notifies any clients monitoring this nickname that it has | |
84 | * connected to the network | |
85 | */ | |
86 | void | |
87 | monitor_signon(struct Client *client_p) | |
88 | { | |
89 | char buf[USERHOST_REPLYLEN]; | |
90 | struct monitor *monptr = find_monitor(client_p->name, 0); | |
91 | ||
92 | /* noones watching this nick */ | |
93 | if(monptr == NULL) | |
94 | return; | |
95 | ||
5203cba5 | 96 | snprintf(buf, sizeof(buf), "%s!%s@%s", client_p->name, client_p->username, client_p->host); |
5f8fb56d AW |
97 | |
98 | sendto_monitor(monptr, form_str(RPL_MONONLINE), me.name, "*", buf); | |
99 | } | |
100 | ||
101 | /* monitor_signoff() | |
102 | * | |
103 | * inputs - client who is exiting | |
104 | * outputs - | |
105 | * side effects - notifies any clients monitoring this nickname that it has | |
106 | * left the network | |
107 | */ | |
108 | void | |
109 | monitor_signoff(struct Client *client_p) | |
110 | { | |
111 | struct monitor *monptr = find_monitor(client_p->name, 0); | |
112 | ||
113 | /* noones watching this nick */ | |
114 | if(monptr == NULL) | |
115 | return; | |
116 | ||
117 | sendto_monitor(monptr, form_str(RPL_MONOFFLINE), me.name, "*", | |
118 | client_p->name); | |
119 | } | |
120 | ||
121 | void | |
122 | clear_monitor(struct Client *client_p) | |
123 | { | |
124 | struct monitor *monptr; | |
125 | rb_dlink_node *ptr, *next_ptr; | |
126 | ||
127 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->monitor_list.head) | |
128 | { | |
129 | monptr = ptr->data; | |
130 | ||
131 | rb_dlinkFindDestroy(client_p, &monptr->users); | |
132 | rb_free_rb_dlink_node(ptr); | |
133 | ||
7a40c9a5 | 134 | free_monitor(monptr); |
5f8fb56d AW |
135 | } |
136 | ||
137 | client_p->localClient->monitor_list.head = client_p->localClient->monitor_list.tail = NULL; | |
138 | client_p->localClient->monitor_list.length = 0; | |
139 | } |