ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_away.c
Revision: 1156
Committed: Tue Aug 9 20:29:20 2011 UTC (14 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_away.c
File size: 6978 byte(s)
Log Message:
- create ircd-hybrid-8 "branch"

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "irc_string.h"
29     #include "ircd.h"
30     #include "numeric.h"
31     #include "send.h"
32     #include "msg.h"
33     #include "parse.h"
34     #include "modules.h"
35     #include "s_conf.h"
36     #include "s_serv.h"
37     #include "packet.h"
38     #include "s_user.h"
39    
40     static void m_away(struct Client *, struct Client *, int, char *[]);
41     static void mo_away(struct Client *, struct Client *, int, char *[]);
42     static void ms_away(struct Client *, struct Client *, int, char *[]);
43    
44     struct Message away_msgtab = {
45     "AWAY", 0, 0, 0, 0, MFLG_SLOW, 0,
46     {m_unregistered, m_away, ms_away, m_ignore, mo_away, m_ignore}
47     };
48    
49     void
50     _modinit(void)
51     {
52     mod_add_cmd(&away_msgtab);
53     add_isupport("AWAYLEN", NULL, AWAYLEN);
54     }
55    
56     void
57     _moddeinit(void)
58     {
59     mod_del_cmd(&away_msgtab);
60     delete_isupport("AWAYLEN");
61     }
62    
63 knight 31 const char *_version = "$Revision$";
64 adx 30
65     /***********************************************************************
66     * m_away() - Added 14 Dec 1988 by jto.
67     * Not currently really working, I don't like this
68     * call at all...
69     *
70     * ...trying to make it work. I don't like it either,
71     * but perhaps it's worth the load it causes to net.
72     * This requires flooding of the whole net like NICK,
73     * USER, MODE, etc messages... --msa
74     ***********************************************************************/
75    
76     /*
77     * m_away
78     * parv[0] = sender prefix
79     * parv[1] = away message
80     */
81     static void
82     m_away(struct Client *client_p, struct Client *source_p,
83     int parc, char *parv[])
84     {
85     char *cur_away_msg = source_p->away;
86     char *new_away_msg = NULL;
87     size_t nbytes = 0;
88    
89     if (!IsFloodDone(source_p))
90     flood_endgrace(source_p);
91    
92     if (parc < 2 || EmptyString(parv[1]))
93     {
94     /* Marking as not away */
95     if (cur_away_msg)
96     {
97     /* we now send this only if they were away before --is */
98 michael 885 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
99     ":%s AWAY", ID(source_p));
100     sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
101     ":%s AWAY", source_p->name);
102 adx 30
103     MyFree(cur_away_msg);
104     source_p->away = NULL;
105     }
106    
107     sendto_one(source_p, form_str(RPL_UNAWAY),
108     me.name, source_p->name);
109     return;
110     }
111    
112     /* Marking as away */
113     if ((CurrentTime - source_p->localClient->last_away) < ConfigFileEntry.pace_wait)
114     {
115     sendto_one(source_p, form_str(RPL_LOAD2HI),
116     me.name, source_p->name);
117     return;
118     }
119    
120     source_p->localClient->last_away = CurrentTime;
121     new_away_msg = parv[1];
122    
123     nbytes = strlen(new_away_msg);
124     if (nbytes > (size_t)AWAYLEN) {
125     new_away_msg[AWAYLEN] = '\0';
126     nbytes = AWAYLEN;
127     }
128    
129     /* we now send this only if they
130     * weren't away already --is */
131     if (!cur_away_msg)
132     {
133 michael 885 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
134     ":%s AWAY :%s", ID(source_p), new_away_msg);
135     sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
136     ":%s AWAY :%s", source_p->name, new_away_msg);
137 adx 30 }
138     else
139     MyFree(cur_away_msg);
140    
141     cur_away_msg = MyMalloc(nbytes + 1);
142     strcpy(cur_away_msg, new_away_msg);
143     source_p->away = cur_away_msg;
144    
145     sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name);
146     }
147    
148     static void
149     mo_away(struct Client *client_p, struct Client *source_p,
150     int parc, char *parv[])
151     {
152     char *cur_away_msg = source_p->away;
153     char *new_away_msg = NULL;
154     size_t nbytes = 0;
155    
156     if (!IsFloodDone(source_p))
157     flood_endgrace(source_p);
158    
159     if (parc < 2 || EmptyString(parv[1]))
160     {
161     /* Marking as not away */
162     if (cur_away_msg)
163     {
164     /* we now send this only if they were away before --is */
165 michael 885 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
166     ":%s AWAY", ID(source_p));
167     sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
168     ":%s AWAY", source_p->name);
169 adx 30
170     MyFree(cur_away_msg);
171     source_p->away = NULL;
172     }
173    
174     sendto_one(source_p, form_str(RPL_UNAWAY),
175     me.name, source_p->name);
176     return;
177     }
178    
179     new_away_msg = parv[1];
180    
181     nbytes = strlen(new_away_msg);
182     if (nbytes > (size_t)AWAYLEN) {
183     new_away_msg[AWAYLEN] = '\0';
184     nbytes = AWAYLEN;
185     }
186    
187     /* we now send this only if they
188     * weren't away already --is */
189     if (!cur_away_msg)
190     {
191 michael 885 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
192     ":%s AWAY :%s", ID(source_p), new_away_msg);
193     sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
194     ":%s AWAY :%s", source_p->name, new_away_msg);
195 adx 30 }
196     else
197     MyFree(cur_away_msg);
198    
199     cur_away_msg = MyMalloc(nbytes + 1);
200     strcpy(cur_away_msg, new_away_msg);
201     source_p->away = cur_away_msg;
202    
203     sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name);
204     }
205    
206     static void
207     ms_away(struct Client *client_p, struct Client *source_p,
208     int parc, char *parv[])
209     {
210     char *cur_away_msg = NULL;
211     char *new_away_msg = NULL;
212     size_t nbytes = 0;
213    
214     if (!IsClient(source_p))
215     return;
216    
217     cur_away_msg = source_p->away;
218    
219     if (parc < 2 || EmptyString(parv[1]))
220     {
221     /* Marking as not away */
222     if (cur_away_msg)
223     {
224     /* we now send this only if they were away before --is */
225 michael 885 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
226     ":%s AWAY", ID(source_p));
227     sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
228     ":%s AWAY", source_p->name);
229 adx 30
230     MyFree(cur_away_msg);
231     source_p->away = NULL;
232     }
233    
234     return;
235     }
236    
237     new_away_msg = parv[1];
238    
239     nbytes = strlen(new_away_msg);
240     if (nbytes > (size_t)AWAYLEN) {
241     new_away_msg[AWAYLEN] = '\0';
242     nbytes = AWAYLEN;
243     }
244    
245     /* we now send this only if they
246     * weren't away already --is */
247     if (!cur_away_msg)
248     {
249 michael 885 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
250     ":%s AWAY :%s", ID(source_p), new_away_msg);
251     sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
252     ":%s AWAY :%s", source_p->name, new_away_msg);
253 adx 30 }
254     else
255     MyFree(cur_away_msg);
256    
257     cur_away_msg = MyMalloc(nbytes + 1);
258     strcpy(cur_away_msg, new_away_msg);
259     source_p->away = cur_away_msg;
260     }

Properties

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