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

# User Rev Content
1 michael 876 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 michael 876 *
4 michael 2820 * Copyright (c) 1997 Jukka Santala (Donwulff)
5     * Copyright (c) 2000-2014 ircd-hybrid development team
6 michael 876 *
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 michael 2820 /*! \file m_watch.c
24     * \brief Includes required functions for processing the WATCH command.
25     * \version $Id$
26     */
27    
28 michael 876 #include "stdinc.h"
29     #include "client.h"
30     #include "irc_string.h"
31     #include "ircd.h"
32     #include "numeric.h"
33 michael 1309 #include "conf.h"
34 michael 876 #include "send.h"
35     #include "parse.h"
36     #include "modules.h"
37 michael 3347 #include "user.h"
38 michael 876 #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 michael 3156 show_watch(struct Client *source_p, const char *name,
49 michael 3109 enum irc_numerics rpl1, enum irc_numerics rpl2)
50 michael 876 {
51     const struct Client *target_p = NULL;
52    
53 michael 3156 if ((target_p = find_person(source_p, name)))
54     sendto_one_numeric(source_p, &me, rpl1,
55 michael 3109 target_p->name, target_p->username,
56     target_p->host, target_p->tsinfo);
57 michael 876 else
58 michael 3156 sendto_one_numeric(source_p, &me, rpl2, name, "*", "*", 0);
59 michael 876 }
60    
61 michael 3294 /*! \brief WATCH command handler
62 michael 876 *
63 michael 3294 * \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 michael 876 */
72 michael 2820 static int
73 michael 3156 m_watch(struct Client *source_p, int parc, char *parv[])
74 michael 876 {
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 michael 3368 if (*(s + 1))
101 michael 876 {
102     if (dlink_list_length(&source_p->localClient->watches) >=
103     ConfigFileEntry.max_watch)
104     {
105 michael 3109 sendto_one_numeric(source_p, &me, ERR_TOOMANYWATCH, s + 1, ConfigFileEntry.max_watch);
106 michael 876 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 michael 3294 * their WATCH list. I imagine this could be CPU intensive if
140 michael 876 * it's done alot, perhaps an auto-lag on this?
141     */
142     if (*s == 'S' || *s == 's')
143     {
144 michael 3213 char buf[IRCD_BUFSIZE] = "";
145 michael 876 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 michael 3109 sendto_one_numeric(source_p, &me, RPL_WATCHSTAT,
161 michael 876 dlink_list_length(&source_p->localClient->watches), count);
162    
163     /*
164 michael 3294 * Send a list of everybody in their WATCH list. Be careful
165 michael 876 * not to buffer overflow.
166     */
167     if ((ptr = source_p->localClient->watches.head) == NULL)
168     {
169 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFWATCHLIST, *s);
170 michael 876 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 michael 3109 sendto_one_numeric(source_p, &me, RPL_WATCHLIST, buf);
186 michael 876 buf[0] = '\0';
187     count = strlen(source_p->name) + strlen(me.name) + 10;
188     }
189    
190 michael 3213 strlcat(buf, " ", sizeof(buf));
191     strlcat(buf, anptr->nick, sizeof(buf));
192 michael 876 count += (strlen(anptr->nick) + 1);
193     }
194    
195 michael 3109 sendto_one_numeric(source_p, &me, RPL_WATCHLIST, buf);
196     sendto_one_numeric(source_p, &me, RPL_ENDOFWATCHLIST, *s);
197 michael 876 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 michael 3109 sendto_one_numeric(source_p, &me, RPL_NOWON,
220     target_p->name, target_p->username,
221     target_p->host, target_p->tsinfo);
222    
223 michael 876 /*
224     * But actually, only show them offline if it's a capital
225     * 'L' (full list wanted).
226     */
227     else if (*s == 'L')
228 michael 3109 sendto_one_numeric(source_p, &me, RPL_NOWOFF, anptr->nick,
229     "*", "*", anptr->lasttime);
230 michael 876 }
231    
232 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFWATCHLIST, *s);
233 michael 876 continue;
234     }
235    
236     /* Hmm.. unknown prefix character.. Ignore it. :-) */
237     }
238 michael 2820
239     return 0;
240 michael 876 }
241 michael 1230
242 michael 2820 static struct Message watch_msgtab =
243     {
244 michael 1230 "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 michael 2820 struct module module_entry =
263     {
264 michael 1230 .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