ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_ison.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (19 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 5118 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_ison.c: Provides a single line answer of whether a user is online.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "ircd.h"
29     #include "numeric.h"
30     #include "send.h"
31     #include "msg.h"
32     #include "parse.h"
33     #include "modules.h"
34     #include "s_conf.h" /* ConfigFileEntry */
35     #include "s_serv.h" /* uplink/IsCapable */
36    
37     static void do_ison(struct Client *, struct Client *, struct Client *, int, char *[]);
38     static void m_ison(struct Client *, struct Client *, int, char *[]);
39     static void ms_ison(struct Client *, struct Client *, int, char *[]);
40    
41     struct Message ison_msgtab = {
42     "ISON", 0, 0, 1, 1, MFLG_SLOW, 0,
43     {m_unregistered, m_ison, ms_ison, m_ignore, m_ison, m_ignore}
44     };
45    
46     #ifndef STATIC_MODULES
47     void
48     _modinit(void)
49     {
50     mod_add_cmd(&ison_msgtab);
51     }
52    
53     void
54     _moddeinit(void)
55     {
56     mod_del_cmd(&ison_msgtab);
57     }
58 knight 31 const char *_version = "$Revision$";
59 adx 30 #endif
60    
61    
62    
63     /*
64     * m_ison added by Darren Reed 13/8/91 to act as an efficent user indicator
65     * with respect to cpu/bandwidth used. Implemented for NOTIFY feature in
66     * clients. Designed to reduce number of whois requests. Can process
67     * nicknames in batches as long as the maximum buffer length.
68     *
69     * format:
70     * ISON :nicklist
71     */
72     static void
73     m_ison(struct Client *client_p, struct Client *source_p,
74     int parc, char *parv[])
75     {
76     struct Client *up = NULL;
77    
78     if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL))
79     up = uplink;
80    
81     do_ison(client_p, up, source_p, parc, parv);
82     }
83    
84     /*
85     * ms_ison added by David Taylor 04/01/2000 to handle relayed ISON requests.
86     * It's slightly less bandwidth efficient than a normal ISON, but it's
87     * only ever going to get relayed over one link...
88     * Plus, we'll only ever relay each nick once in it's lifetime, if it
89     * exists...
90     * ISON :nicklist
91     */
92     static void
93     ms_ison(struct Client *client_p, struct Client *source_p,
94     int parc, char *parv[])
95     {
96     if (ServerInfo.hub && IsCapable(client_p, CAP_LL))
97     do_ison(client_p, NULL, source_p, parc, parv);
98     }
99    
100     static void
101     do_ison(struct Client *client_p, struct Client *up, struct Client *source_p,
102     int parc, char *parv[])
103     {
104     struct Client *target_p = NULL;
105     char *nick;
106     char *p;
107     char *current_insert_point, *current_insert_point2;
108     char buf[IRCD_BUFSIZE];
109     char buf2[IRCD_BUFSIZE];
110     int len;
111     int i;
112     int done = 0;
113     int relay_to_hub = 0;
114    
115     current_insert_point2 = buf2;
116     *buf2 = '\0';
117    
118     len = ircsprintf(buf, form_str(RPL_ISON), me.name, parv[0]);
119     current_insert_point = buf + len;
120    
121     /* rfc1459 is ambigious about how to handle ISON
122     * this should handle both interpretations.
123     */
124     for (i = 1; i < parc; i++)
125     {
126     for (nick = strtoken(&p, parv[i], " "); nick;
127     nick = strtoken(&p, NULL, " "))
128     {
129     if ((target_p = find_person(client_p, nick)))
130     {
131     len = strlen(target_p->name);
132    
133     if ((current_insert_point + (len + 5)) < (buf + sizeof(buf)))
134     {
135     memcpy(current_insert_point, target_p->name, len);
136     current_insert_point += len;
137     *current_insert_point++ = ' ';
138     }
139     else
140     {
141     done = 1;
142     break;
143     }
144     }
145    
146     if (up)
147     {
148     /* Build up a single list, for use if we relay.. */
149     len = strlen(nick);
150    
151     if ((current_insert_point2 + len + 5) < (buf2 + sizeof(buf2)))
152     {
153     memcpy(current_insert_point2, nick, len);
154     current_insert_point2 += len;
155     *current_insert_point2++ = ' ';
156     }
157    
158     if (target_p == NULL)
159     {
160     /*
161     * XXX Ick. we need to ask our hub if nick is online.
162     * it's probably safest to relay the whole command,
163     * unless we can answer it fully ourselves.
164     * -davidt
165     */
166     relay_to_hub = 1;
167    
168     /* Also cache info about nick */
169     sendto_one(up, ":%s NBURST %s", ID_or_name(&me, up), nick);
170     }
171     }
172     }
173    
174     if (done)
175     break;
176     }
177    
178     /* current_insert_point--;
179     * Do NOT take out the trailing space, it breaks ircII
180     * --Rodder */
181    
182     *current_insert_point = '\0';
183     *current_insert_point2 = '\0';
184    
185     if (relay_to_hub)
186     sendto_one(up, ":%s ISON :%s", ID_or_name(source_p, up), buf2);
187     else
188     sendto_one(source_p, "%s", buf);
189     }

Properties

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