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