]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_ison.c: Provides a single line answer of whether a user is online. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
26 | #include "client.h" | |
4562c604 | 27 | #include "match.h" |
212380e3 AC |
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 | #include "hash.h" | |
37 | ||
38 | #include <string.h> | |
39 | ||
428ca87b | 40 | static int m_ison(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
212380e3 AC |
41 | |
42 | struct Message ison_msgtab = { | |
7baa37a9 | 43 | "ISON", 0, 0, 0, 0, |
212380e3 AC |
44 | {mg_unreg, {m_ison, 2}, mg_ignore, mg_ignore, mg_ignore, {m_ison, 2}} |
45 | }; | |
46 | ||
47 | mapi_clist_av1 ison_clist[] = { &ison_msgtab, NULL }; | |
f1156bf0 EM |
48 | |
49 | static const char ison_desc[] = "Provides the ISON command to check if a set of users is online"; | |
50 | ||
51 | DECLARE_MODULE_AV2(ison, NULL, NULL, ison_clist, NULL, NULL, NULL, NULL, ison_desc); | |
212380e3 AC |
52 | |
53 | static char buf[BUFSIZE]; | |
54 | static char buf2[BUFSIZE]; | |
55 | ||
56 | ||
57 | /* | |
58 | * m_ison added by Darren Reed 13/8/91 to act as an efficent user indicator | |
59 | * with respect to cpu/bandwidth used. Implemented for NOTIFY feature in | |
60 | * clients. Designed to reduce number of whois requests. Can process | |
61 | * nicknames in batches as long as the maximum buffer length. | |
62 | * | |
63 | * format: | |
64 | * ISON :nicklist | |
65 | */ | |
66 | static int | |
428ca87b | 67 | m_ison(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
68 | { |
69 | struct Client *target_p; | |
70 | char *nick; | |
71 | char *p; | |
72 | char *current_insert_point, *current_insert_point2; | |
73 | int len; | |
74 | int i; | |
75 | int done = 0; | |
76 | ||
77 | current_insert_point2 = buf2; | |
78 | *buf2 = '\0'; | |
79 | ||
5203cba5 | 80 | sprintf(buf, form_str(RPL_ISON), me.name, source_p->name); |
212380e3 AC |
81 | len = strlen(buf); |
82 | current_insert_point = buf + len; | |
83 | ||
84 | /* rfc1489 is ambigious about how to handle ISON | |
85 | * this should handle both interpretations. | |
86 | */ | |
87 | for (i = 1; i < parc; i++) | |
88 | { | |
89 | char *cs = LOCAL_COPY(parv[i]); | |
4a2651e5 | 90 | for (nick = rb_strtok_r(cs, " ", &p); nick; nick = rb_strtok_r(NULL, " ", &p)) |
212380e3 AC |
91 | { |
92 | target_p = find_named_client(nick); | |
93 | ||
94 | if(target_p != NULL) | |
95 | { | |
96 | len = strlen(target_p->name); | |
97 | if((current_insert_point + (len + 5)) < (buf + sizeof(buf))) | |
98 | { | |
99 | memcpy((void *) current_insert_point, | |
100 | (void *) target_p->name, len); | |
101 | current_insert_point += len; | |
102 | *current_insert_point++ = ' '; | |
103 | } | |
104 | else | |
105 | { | |
106 | done = 1; | |
107 | break; | |
108 | } | |
109 | } | |
110 | } | |
111 | if(done) | |
112 | break; | |
113 | } | |
114 | ||
115 | /* current_insert_point--; | |
116 | * Do NOT take out the trailing space, it breaks ircII | |
117 | * --Rodder */ | |
118 | ||
119 | *current_insert_point = '\0'; | |
120 | *current_insert_point2 = '\0'; | |
121 | ||
122 | sendto_one(source_p, "%s", buf); | |
123 | ||
124 | return 0; | |
125 | } |