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 |
|
38 |
static void do_ison(struct Client *, struct Client *, int, char *[]); |
39 |
static void m_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, m_ignore, 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 |
const char *_version = "$Revision$"; |
59 |
#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 |
do_ison(client_p, source_p, parc, parv); |
77 |
} |
78 |
|
79 |
static void |
80 |
do_ison(struct Client *client_p, struct Client *source_p, |
81 |
int parc, char *parv[]) |
82 |
{ |
83 |
struct Client *target_p = NULL; |
84 |
char *nick; |
85 |
char *p = NULL; |
86 |
char *current_insert_point = NULL; |
87 |
char buf[IRCD_BUFSIZE]; |
88 |
int len; |
89 |
int i; |
90 |
int done = 0; |
91 |
|
92 |
len = ircsprintf(buf, form_str(RPL_ISON), me.name, parv[0]); |
93 |
current_insert_point = buf + len; |
94 |
|
95 |
/* |
96 |
* rfc1459 is ambigious about how to handle ISON |
97 |
* this should handle both interpretations. |
98 |
*/ |
99 |
for (i = 1; i < parc; i++) |
100 |
{ |
101 |
for (nick = strtoken(&p, parv[i], " "); nick; |
102 |
nick = strtoken(&p, NULL, " ")) |
103 |
{ |
104 |
if ((target_p = find_person(client_p, nick))) |
105 |
{ |
106 |
len = strlen(target_p->name); |
107 |
|
108 |
if ((current_insert_point + (len + 5)) < (buf + sizeof(buf))) |
109 |
{ |
110 |
memcpy(current_insert_point, target_p->name, len); |
111 |
current_insert_point += len; |
112 |
*current_insert_point++ = ' '; |
113 |
} |
114 |
else |
115 |
{ |
116 |
done = 1; |
117 |
break; |
118 |
} |
119 |
} |
120 |
} |
121 |
|
122 |
if (done) |
123 |
break; |
124 |
} |
125 |
|
126 |
/* |
127 |
* current_insert_point--; |
128 |
* Do NOT take out the trailing space, it breaks ircII |
129 |
* --Rodder |
130 |
*/ |
131 |
*current_insert_point = '\0'; |
132 |
|
133 |
sendto_one(source_p, "%s", buf); |
134 |
} |