ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_watch.c
Revision: 3368
Committed: Mon Apr 21 14:24:16 2014 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 7508 byte(s)
Log Message:
- Style corrections

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997 Jukka Santala (Donwulff)
5 * Copyright (c) 2000-2014 ircd-hybrid development team
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 */
22
23 /*! \file m_watch.c
24 * \brief Includes required functions for processing the WATCH command.
25 * \version $Id$
26 */
27
28 #include "stdinc.h"
29 #include "client.h"
30 #include "irc_string.h"
31 #include "ircd.h"
32 #include "numeric.h"
33 #include "conf.h"
34 #include "send.h"
35 #include "parse.h"
36 #include "modules.h"
37 #include "user.h"
38 #include "watch.h"
39
40
41 /*
42 * RPL_NOWON - Online at the moment (Succesfully added to WATCH-list)
43 * RPL_NOWOFF - Offline at the moment (Succesfully added to WATCH-list)
44 * RPL_WATCHOFF - Succesfully removed from WATCH-list.
45 * ERR_TOOMANYWATCH - Take a guess :> Too many WATCH entries.
46 */
47 static void
48 show_watch(struct Client *source_p, const char *name,
49 enum irc_numerics rpl1, enum irc_numerics rpl2)
50 {
51 const struct Client *target_p = NULL;
52
53 if ((target_p = find_person(source_p, name)))
54 sendto_one_numeric(source_p, &me, rpl1,
55 target_p->name, target_p->username,
56 target_p->host, target_p->tsinfo);
57 else
58 sendto_one_numeric(source_p, &me, rpl2, name, "*", "*", 0);
59 }
60
61 /*! \brief WATCH command handler
62 *
63 * \param source_p Pointer to allocated Client struct from which the message
64 * originally comes from. This can be a local or remote client.
65 * \param parc Integer holding the number of supplied arguments.
66 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
67 * pointers.
68 * \note Valid arguments for this command are:
69 * - parv[0] = command
70 * - parv[1] = watch options
71 */
72 static int
73 m_watch(struct Client *source_p, int parc, char *parv[])
74 {
75 dlink_node *ptr = NULL;
76 char *s = NULL;
77 char *p = NULL;
78 char *user;
79 char def[2] = "l";
80 unsigned int list_requested = 0;
81
82 /*
83 * Default to 'l' - list who's currently online
84 */
85 if (parc < 2)
86 parv[1] = def;
87
88 for (s = strtoken(&p, parv[1], ", "); s;
89 s = strtoken(&p, NULL, ", "))
90 {
91 if ((user = strchr(s, '!')))
92 *user++ = '\0'; /* Not used */
93
94 /*
95 * Prefix of "+", they want to add a name to their WATCH
96 * list.
97 */
98 if (*s == '+')
99 {
100 if (*(s + 1))
101 {
102 if (dlink_list_length(&source_p->localClient->watches) >=
103 ConfigFileEntry.max_watch)
104 {
105 sendto_one_numeric(source_p, &me, ERR_TOOMANYWATCH, s + 1, ConfigFileEntry.max_watch);
106 continue;
107 }
108
109 watch_add_to_hash_table(s + 1, source_p);
110 }
111
112 show_watch(source_p, s + 1, RPL_NOWON, RPL_NOWOFF);
113 continue;
114 }
115
116 /*
117 * Prefix of "-", coward wants to remove somebody from their
118 * WATCH list. So do it. :-)
119 */
120 if (*s == '-')
121 {
122 watch_del_from_hash_table(s + 1, source_p);
123 show_watch(source_p, s + 1, RPL_WATCHOFF, RPL_WATCHOFF);
124 continue;
125 }
126
127 /*
128 * Fancy "C" or "c", they want to nuke their WATCH list and start
129 * over, so be it.
130 */
131 if (*s == 'C' || *s == 'c')
132 {
133 watch_del_watch_list(source_p);
134 continue;
135 }
136
137 /*
138 * Now comes the fun stuff, "S" or "s" returns a status report of
139 * their WATCH list. I imagine this could be CPU intensive if
140 * it's done alot, perhaps an auto-lag on this?
141 */
142 if (*s == 'S' || *s == 's')
143 {
144 char buf[IRCD_BUFSIZE] = "";
145 const struct Watch *anptr = NULL;
146 unsigned int count = 0;
147
148 if (list_requested & 0x1)
149 continue;
150
151 list_requested |= 0x1;
152
153 /*
154 * Send a list of how many users they have on their WATCH list
155 * and how many WATCH lists they are on.
156 */
157 if ((anptr = watch_find_hash(source_p->name)))
158 count = dlink_list_length(&anptr->watched_by);
159
160 sendto_one_numeric(source_p, &me, RPL_WATCHSTAT,
161 dlink_list_length(&source_p->localClient->watches), count);
162
163 /*
164 * Send a list of everybody in their WATCH list. Be careful
165 * not to buffer overflow.
166 */
167 if ((ptr = source_p->localClient->watches.head) == NULL)
168 {
169 sendto_one_numeric(source_p, &me, RPL_ENDOFWATCHLIST, *s);
170 continue;
171 }
172
173 anptr = ptr->data;
174 strlcpy(buf, anptr->nick, sizeof(buf));
175
176 count = strlen(source_p->name) + strlen(me.name) + 10 +
177 strlen(buf);
178
179 while ((ptr = ptr->next))
180 {
181 anptr = ptr->data;
182
183 if (count + strlen(anptr->nick) + 1 > IRCD_BUFSIZE - 2)
184 {
185 sendto_one_numeric(source_p, &me, RPL_WATCHLIST, buf);
186 buf[0] = '\0';
187 count = strlen(source_p->name) + strlen(me.name) + 10;
188 }
189
190 strlcat(buf, " ", sizeof(buf));
191 strlcat(buf, anptr->nick, sizeof(buf));
192 count += (strlen(anptr->nick) + 1);
193 }
194
195 sendto_one_numeric(source_p, &me, RPL_WATCHLIST, buf);
196 sendto_one_numeric(source_p, &me, RPL_ENDOFWATCHLIST, *s);
197 continue;
198 }
199
200 /*
201 * Well that was fun, NOT. Now they want a list of everybody in
202 * their WATCH list AND if they are online or offline? Sheesh,
203 * greedy aren't we?
204 */
205 if (*s == 'L' || *s == 'l')
206 {
207 const struct Client *target_p = NULL;
208
209 if (list_requested & 0x2)
210 continue;
211
212 list_requested |= 0x2;
213
214 DLINK_FOREACH(ptr, source_p->localClient->watches.head)
215 {
216 const struct Watch *anptr = ptr->data;
217
218 if ((target_p = find_person(source_p, anptr->nick)))
219 sendto_one_numeric(source_p, &me, RPL_NOWON,
220 target_p->name, target_p->username,
221 target_p->host, target_p->tsinfo);
222
223 /*
224 * But actually, only show them offline if it's a capital
225 * 'L' (full list wanted).
226 */
227 else if (*s == 'L')
228 sendto_one_numeric(source_p, &me, RPL_NOWOFF, anptr->nick,
229 "*", "*", anptr->lasttime);
230 }
231
232 sendto_one_numeric(source_p, &me, RPL_ENDOFWATCHLIST, *s);
233 continue;
234 }
235
236 /* Hmm.. unknown prefix character.. Ignore it. :-) */
237 }
238
239 return 0;
240 }
241
242 static struct Message watch_msgtab =
243 {
244 "WATCH", 0, 0, 0, 1, MFLG_SLOW, 0,
245 { m_unregistered, m_watch, m_ignore, m_ignore, m_watch, m_ignore }
246 };
247
248 static void
249 module_init(void)
250 {
251 mod_add_cmd(&watch_msgtab);
252 add_isupport("WATCH", NULL, ConfigFileEntry.max_watch);
253 }
254
255 static void
256 module_exit(void)
257 {
258 mod_del_cmd(&watch_msgtab);
259 delete_isupport("WATCH");
260 }
261
262 struct module module_entry =
263 {
264 .node = { NULL, NULL, NULL },
265 .name = NULL,
266 .version = "$Revision$",
267 .handle = NULL,
268 .modinit = module_init,
269 .modexit = module_exit,
270 .flags = 0
271 };

Properties

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