ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_away.c
Revision: 470
Committed: Fri Feb 17 05:07:43 2006 UTC (18 years, 2 months ago) by db
Content type: text/x-csrc
File size: 8475 byte(s)
Log Message:
- fix compile errors with moved modules.h
- fix a few missing includes, msg.h and parse.h


File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_away.c: Sets/removes away status on a user.
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 #include "s_conf.h"
35 #include "s_serv.h"
36 #include "packet.h"
37 #include "s_user.h"
38
39 static void m_away(struct Client *, struct Client *, int, char *[]);
40 static void mo_away(struct Client *, struct Client *, int, char *[]);
41 static void ms_away(struct Client *, struct Client *, int, char *[]);
42
43 struct Message away_msgtab = {
44 "AWAY", 0, 0, 0, 0, MFLG_SLOW, 0,
45 { m_unregistered, m_away, ms_away, m_ignore, mo_away, m_ignore }
46 };
47
48 INIT_MODULE(m_away, "$Revision$")
49 {
50 mod_add_cmd(&away_msgtab);
51 add_isupport("AWAYLEN", NULL, AWAYLEN);
52 }
53
54 CLEANUP_MODULE
55 {
56 delete_isupport("AWAYLEN");
57 mod_del_cmd(&away_msgtab);
58 }
59
60 /*! \brief AWAY command handler (called for local clients only)
61 *
62 * \param client_p Pointer to allocated Client struct with physical connection
63 * to this server, i.e. with an open socket connected.
64 * \param source_p Pointer to allocated Client struct from which the message
65 * originally comes from. This can be a local or remote client.
66 * \param parc Integer holding the number of supplied arguments.
67 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
68 * pointers.
69 * \note Valid arguments for this command are:
70 * - parv[0] = sender prefix
71 * - parv[1] = away text (optional)
72 */
73 static void
74 m_away(struct Client *client_p, struct Client *source_p,
75 int parc, char *parv[])
76 {
77 char *cur_away_msg = source_p->away;
78 char *new_away_msg = NULL;
79 size_t nbytes = 0;
80
81 if (!IsFloodDone(source_p))
82 flood_endgrace(source_p);
83
84 if (parc < 2 || EmptyString(parv[1]))
85 {
86 /* Marking as not away */
87 if (cur_away_msg)
88 {
89 /* we now send this only if they were away before --is */
90 sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
91 ":%s AWAY", ID(source_p));
92 sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
93 ":%s AWAY", source_p->name);
94
95 MyFree(cur_away_msg);
96 source_p->away = NULL;
97 }
98
99 sendto_one(source_p, form_str(RPL_UNAWAY),
100 me.name, source_p->name);
101 return;
102 }
103
104 /* Marking as away */
105 if ((CurrentTime - source_p->localClient->last_away) < ConfigFileEntry.pace_wait)
106 {
107 sendto_one(source_p, form_str(RPL_LOAD2HI),
108 me.name, source_p->name);
109 return;
110 }
111
112 source_p->localClient->last_away = CurrentTime;
113 new_away_msg = parv[1];
114
115 nbytes = strlen(new_away_msg);
116 if (nbytes > (size_t)AWAYLEN) {
117 new_away_msg[AWAYLEN] = '\0';
118 nbytes = AWAYLEN;
119 }
120
121 /* we now send this only if they
122 * weren't away already --is */
123 if (!cur_away_msg)
124 {
125 sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
126 ":%s AWAY :%s", ID(source_p), new_away_msg);
127 sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
128 ":%s AWAY :%s", source_p->name, new_away_msg);
129 }
130 else
131 MyFree(cur_away_msg);
132
133 cur_away_msg = MyMalloc(nbytes + 1);
134 strcpy(cur_away_msg, new_away_msg);
135 source_p->away = cur_away_msg;
136
137 sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name);
138 }
139
140 /*! \brief AWAY command handler (called for operators only)
141 *
142 * \param client_p Pointer to allocated Client struct with physical connection
143 * to this server, i.e. with an open socket connected.
144 * \param source_p Pointer to allocated Client struct from which the message
145 * originally comes from. This can be a local or remote client.
146 * \param parc Integer holding the number of supplied arguments.
147 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
148 * pointers.
149 * \note Valid arguments for this command are:
150 * - parv[0] = sender prefix
151 * - parv[1] = away text (optional)
152 */
153 static void
154 mo_away(struct Client *client_p, struct Client *source_p,
155 int parc, char *parv[])
156 {
157 char *cur_away_msg = source_p->away;
158 char *new_away_msg = NULL;
159 size_t nbytes = 0;
160
161 if (!IsFloodDone(source_p))
162 flood_endgrace(source_p);
163
164 if (parc < 2 || EmptyString(parv[1]))
165 {
166 /* Marking as not away */
167 if (cur_away_msg)
168 {
169 /* we now send this only if they were away before --is */
170 sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
171 ":%s AWAY", ID(source_p));
172 sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
173 ":%s AWAY", source_p->name);
174
175 MyFree(cur_away_msg);
176 source_p->away = NULL;
177 }
178
179 sendto_one(source_p, form_str(RPL_UNAWAY),
180 me.name, source_p->name);
181 return;
182 }
183
184 new_away_msg = parv[1];
185
186 nbytes = strlen(new_away_msg);
187 if (nbytes > (size_t)AWAYLEN) {
188 new_away_msg[AWAYLEN] = '\0';
189 nbytes = AWAYLEN;
190 }
191
192 /* we now send this only if they
193 * weren't away already --is */
194 if (!cur_away_msg)
195 {
196 sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
197 ":%s AWAY :%s", ID(source_p), new_away_msg);
198 sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
199 ":%s AWAY :%s", source_p->name, new_away_msg);
200 }
201 else
202 MyFree(cur_away_msg);
203
204 cur_away_msg = MyMalloc(nbytes + 1);
205 strcpy(cur_away_msg, new_away_msg);
206 source_p->away = cur_away_msg;
207
208 sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name);
209 }
210
211 /*! \brief AWAY command handler (called for remote clients)
212 *
213 * \param client_p Pointer to allocated Client struct with physical connection
214 * to this server, i.e. with an open socket connected.
215 * \param source_p Pointer to allocated Client struct from which the message
216 * originally comes from. This can be a local or remote client.
217 * \param parc Integer holding the number of supplied arguments.
218 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
219 * pointers.
220 * \note Valid arguments for this command are:
221 * - parv[0] = sender prefix
222 * - parv[1] = away text (optional)
223 */
224 static void
225 ms_away(struct Client *client_p, struct Client *source_p,
226 int parc, char *parv[])
227 {
228 char *cur_away_msg = NULL;
229 char *new_away_msg = NULL;
230 size_t nbytes = 0;
231
232 if (!IsClient(source_p))
233 return;
234
235 cur_away_msg = source_p->away;
236
237 if (parc < 2 || EmptyString(parv[1]))
238 {
239 /* Marking as not away */
240 if (cur_away_msg)
241 {
242 /* we now send this only if they were away before --is */
243 sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
244 ":%s AWAY", ID(source_p));
245 sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
246 ":%s AWAY", source_p->name);
247
248 MyFree(cur_away_msg);
249 source_p->away = NULL;
250 }
251
252 return;
253 }
254
255 new_away_msg = parv[1];
256
257 nbytes = strlen(new_away_msg);
258 if (nbytes > (size_t)AWAYLEN) {
259 new_away_msg[AWAYLEN] = '\0';
260 nbytes = AWAYLEN;
261 }
262
263 /* we now send this only if they
264 * weren't away already --is */
265 if (!cur_away_msg)
266 {
267 sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
268 ":%s AWAY :%s", ID(source_p), new_away_msg);
269 sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
270 ":%s AWAY :%s", source_p->name, new_away_msg);
271 }
272 else
273 MyFree(cur_away_msg);
274
275 cur_away_msg = MyMalloc(nbytes + 1);
276 strcpy(cur_away_msg, new_away_msg);
277 source_p->away = cur_away_msg;
278 }

Properties

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