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 "ircd.h" |
29 |
#include "numeric.h" |
30 |
#include "send.h" |
31 |
#include "msg.h" |
32 |
#include "parse.h" |
33 |
#include "conf/modules.h" |
34 |
|
35 |
static void do_ison(struct Client *, struct Client *, int, char *[]); |
36 |
static void m_ison(struct Client *, struct Client *, int, char *[]); |
37 |
|
38 |
struct Message ison_msgtab = { |
39 |
"ISON", 0, 0, 1, 1, MFLG_SLOW, 0, |
40 |
{ m_unregistered, m_ison, m_ignore, m_ignore, m_ison, m_ignore } |
41 |
}; |
42 |
|
43 |
INIT_MODULE(m_ison, "$Revision$") |
44 |
{ |
45 |
mod_add_cmd(&ison_msgtab); |
46 |
} |
47 |
|
48 |
CLEANUP_MODULE |
49 |
{ |
50 |
mod_del_cmd(&ison_msgtab); |
51 |
} |
52 |
|
53 |
/* |
54 |
* m_ison added by Darren Reed 13/8/91 to act as an efficent user indicator |
55 |
* with respect to cpu/bandwidth used. Implemented for NOTIFY feature in |
56 |
* clients. Designed to reduce number of whois requests. Can process |
57 |
* nicknames in batches as long as the maximum buffer length. |
58 |
* |
59 |
* format: |
60 |
* ISON :nicklist |
61 |
*/ |
62 |
static void |
63 |
m_ison(struct Client *client_p, struct Client *source_p, |
64 |
int parc, char *parv[]) |
65 |
{ |
66 |
do_ison(client_p, source_p, parc, parv); |
67 |
} |
68 |
|
69 |
static void |
70 |
do_ison(struct Client *client_p, struct Client *source_p, |
71 |
int parc, char *parv[]) |
72 |
{ |
73 |
struct Client *target_p = NULL; |
74 |
char *nick; |
75 |
char *p; |
76 |
char *current_insert_point = NULL; |
77 |
char buf[IRCD_BUFSIZE]; |
78 |
int len; |
79 |
int i; |
80 |
int done = 0; |
81 |
|
82 |
len = ircsprintf(buf, form_str(RPL_ISON), me.name, parv[0]); |
83 |
current_insert_point = buf + len; |
84 |
|
85 |
/* rfc1459 is ambigious about how to handle ISON |
86 |
* this should handle both interpretations. |
87 |
*/ |
88 |
for (i = 1; i < parc; i++) |
89 |
{ |
90 |
for (nick = strtoken(&p, parv[i], " "); nick; |
91 |
nick = strtoken(&p, NULL, " ")) |
92 |
{ |
93 |
if ((target_p = find_person(client_p, nick))) |
94 |
{ |
95 |
len = strlen(target_p->name); |
96 |
|
97 |
if ((current_insert_point + (len + 5)) < (buf + sizeof(buf))) |
98 |
{ |
99 |
memcpy(current_insert_point, target_p->name, len); |
100 |
current_insert_point += len; |
101 |
*current_insert_point++ = ' '; |
102 |
} |
103 |
else |
104 |
{ |
105 |
done = 1; |
106 |
break; |
107 |
} |
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 |
|
120 |
*current_insert_point = '\0'; |
121 |
|
122 |
sendto_one(source_p, "%s", buf); |
123 |
} |