ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/modules/m_ison.c
Revision: 34
Committed: Sun Oct 2 21:05:51 2005 UTC (18 years, 5 months ago) by lusky
Content type: text/x-csrc
File size: 5167 byte(s)
Log Message:
create 7.2 branch, we can move/rename it as needed.


File Contents

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

Properties

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