]> jfr.im git - irc/rqf/shadowircd.git/blob - src/monitor.c
Removal of ancient SVN ID's part one
[irc/rqf/shadowircd.git] / src / monitor.c
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.
31 *
32 */
33 #include "stdinc.h"
34 #include "client.h"
35 #include "monitor.h"
36 #include "hash.h"
37 #include "numeric.h"
38
39 struct monitor *monitorTable[MONITOR_HASH_SIZE];
40 static rb_bh *monitor_heap;
41
42 void
43 init_monitor(void)
44 {
45 monitor_heap = rb_bh_create(sizeof(struct monitor), MONITOR_HEAP_SIZE, "monitor_heap");
46 }
47
48 static inline unsigned int
49 hash_monitor_nick(const char *name)
50 {
51 return fnv_hash_upper((const unsigned char *)name, MONITOR_HASH_BITS);
52 }
53
54 struct monitor *
55 find_monitor(const char *name, int add)
56 {
57 struct monitor *monptr;
58
59 unsigned int hashv = hash_monitor_nick(name);
60
61 for(monptr = monitorTable[hashv]; monptr; monptr = monptr->hnext)
62 {
63 if(!irccmp(monptr->name, name))
64 return monptr;
65 }
66
67 if(add)
68 {
69 monptr = rb_bh_alloc(monitor_heap);
70 rb_strlcpy(monptr->name, name, sizeof(monptr->name));
71
72 monptr->hnext = monitorTable[hashv];
73 monitorTable[hashv] = monptr;
74
75 return monptr;
76 }
77
78 return NULL;
79 }
80
81 void
82 free_monitor(struct monitor *monptr)
83 {
84 rb_bh_free(monitor_heap, monptr);
85 }
86
87 /* monitor_signon()
88 *
89 * inputs - client who has just connected
90 * outputs -
91 * side effects - notifies any clients monitoring this nickname that it has
92 * connected to the network
93 */
94 void
95 monitor_signon(struct Client *client_p)
96 {
97 char buf[USERHOST_REPLYLEN];
98 struct monitor *monptr = find_monitor(client_p->name, 0);
99
100 /* noones watching this nick */
101 if(monptr == NULL)
102 return;
103
104 rb_snprintf(buf, sizeof(buf), "%s!%s@%s", client_p->name, client_p->username, client_p->host);
105
106 sendto_monitor(monptr, form_str(RPL_MONONLINE), me.name, "*", buf);
107 }
108
109 /* monitor_signoff()
110 *
111 * inputs - client who is exiting
112 * outputs -
113 * side effects - notifies any clients monitoring this nickname that it has
114 * left the network
115 */
116 void
117 monitor_signoff(struct Client *client_p)
118 {
119 struct monitor *monptr = find_monitor(client_p->name, 0);
120
121 /* noones watching this nick */
122 if(monptr == NULL)
123 return;
124
125 sendto_monitor(monptr, form_str(RPL_MONOFFLINE), me.name, "*",
126 client_p->name);
127 }
128
129 void
130 clear_monitor(struct Client *client_p)
131 {
132 struct monitor *monptr;
133 rb_dlink_node *ptr, *next_ptr;
134
135 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->monitor_list.head)
136 {
137 monptr = ptr->data;
138
139 rb_dlinkFindDestroy(client_p, &monptr->users);
140 rb_free_rb_dlink_node(ptr);
141 }
142
143 client_p->localClient->monitor_list.head = client_p->localClient->monitor_list.tail = NULL;
144 client_p->localClient->monitor_list.length = 0;
145 }