ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_away.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 7212 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


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 "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"
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     #ifndef STATIC_MODULES
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 #endif
65    
66     /***********************************************************************
67     * m_away() - Added 14 Dec 1988 by jto.
68     * Not currently really working, I don't like this
69     * call at all...
70     *
71     * ...trying to make it work. I don't like it either,
72     * but perhaps it's worth the load it causes to net.
73     * This requires flooding of the whole net like NICK,
74     * USER, MODE, etc messages... --msa
75     ***********************************************************************/
76    
77     /*
78     * m_away
79     * parv[0] = sender prefix
80     * parv[1] = away message
81     */
82     static void
83     m_away(struct Client *client_p, struct Client *source_p,
84     int parc, char *parv[])
85     {
86     char *cur_away_msg = source_p->away;
87     char *new_away_msg = NULL;
88     size_t nbytes = 0;
89    
90     if (!IsFloodDone(source_p))
91     flood_endgrace(source_p);
92    
93     if (parc < 2 || EmptyString(parv[1]))
94     {
95     /* Marking as not away */
96     if (cur_away_msg)
97     {
98     /* we now send this only if they were away before --is */
99     sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
100     NOFLAGS, ":%s AWAY", ID(source_p));
101     sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
102     NOFLAGS, ":%s AWAY", source_p->name);
103    
104     MyFree(cur_away_msg);
105     source_p->away = NULL;
106     }
107    
108     sendto_one(source_p, form_str(RPL_UNAWAY),
109     me.name, source_p->name);
110     return;
111     }
112    
113     /* Marking as away */
114     if ((CurrentTime - source_p->localClient->last_away) < ConfigFileEntry.pace_wait)
115     {
116     sendto_one(source_p, form_str(RPL_LOAD2HI),
117     me.name, source_p->name);
118     return;
119     }
120    
121     source_p->localClient->last_away = CurrentTime;
122     new_away_msg = parv[1];
123    
124     nbytes = strlen(new_away_msg);
125     if (nbytes > (size_t)AWAYLEN) {
126     new_away_msg[AWAYLEN] = '\0';
127     nbytes = AWAYLEN;
128     }
129    
130     /* we now send this only if they
131     * weren't away already --is */
132     if (!cur_away_msg)
133     {
134     sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
135     NOFLAGS, ":%s AWAY :%s", ID(source_p), new_away_msg);
136     sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
137     NOFLAGS, ":%s AWAY :%s", source_p->name, new_away_msg);
138     }
139     else
140     MyFree(cur_away_msg);
141    
142     cur_away_msg = MyMalloc(nbytes + 1);
143     strcpy(cur_away_msg, new_away_msg);
144     source_p->away = cur_away_msg;
145    
146     sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name);
147     }
148    
149     static void
150     mo_away(struct Client *client_p, struct Client *source_p,
151     int parc, char *parv[])
152     {
153     char *cur_away_msg = source_p->away;
154     char *new_away_msg = NULL;
155     size_t nbytes = 0;
156    
157     if (!IsFloodDone(source_p))
158     flood_endgrace(source_p);
159    
160     if (parc < 2 || EmptyString(parv[1]))
161     {
162     /* Marking as not away */
163     if (cur_away_msg)
164     {
165     /* we now send this only if they were away before --is */
166     sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
167     NOFLAGS, ":%s AWAY", ID(source_p));
168     sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
169     NOFLAGS, ":%s AWAY", source_p->name);
170    
171     MyFree(cur_away_msg);
172     source_p->away = NULL;
173     }
174    
175     sendto_one(source_p, form_str(RPL_UNAWAY),
176     me.name, source_p->name);
177     return;
178     }
179    
180     new_away_msg = parv[1];
181    
182     nbytes = strlen(new_away_msg);
183     if (nbytes > (size_t)AWAYLEN) {
184     new_away_msg[AWAYLEN] = '\0';
185     nbytes = AWAYLEN;
186     }
187    
188     /* we now send this only if they
189     * weren't away already --is */
190     if (!cur_away_msg)
191     {
192     sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
193     NOFLAGS, ":%s AWAY :%s", ID(source_p), new_away_msg);
194     sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
195     NOFLAGS, ":%s AWAY :%s", source_p->name, new_away_msg);
196     }
197     else
198     MyFree(cur_away_msg);
199    
200     cur_away_msg = MyMalloc(nbytes + 1);
201     strcpy(cur_away_msg, new_away_msg);
202     source_p->away = cur_away_msg;
203    
204     sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name);
205     }
206    
207     static void
208     ms_away(struct Client *client_p, struct Client *source_p,
209     int parc, char *parv[])
210     {
211     char *cur_away_msg = NULL;
212     char *new_away_msg = NULL;
213     size_t nbytes = 0;
214    
215     if (!IsClient(source_p))
216     return;
217    
218     cur_away_msg = source_p->away;
219    
220     if (parc < 2 || EmptyString(parv[1]))
221     {
222     /* Marking as not away */
223     if (cur_away_msg)
224     {
225     /* we now send this only if they were away before --is */
226     sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
227     NOFLAGS, ":%s AWAY", ID(source_p));
228     sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
229     NOFLAGS, ":%s AWAY", source_p->name);
230    
231     MyFree(cur_away_msg);
232     source_p->away = NULL;
233     }
234    
235     return;
236     }
237    
238     new_away_msg = parv[1];
239    
240     nbytes = strlen(new_away_msg);
241     if (nbytes > (size_t)AWAYLEN) {
242     new_away_msg[AWAYLEN] = '\0';
243     nbytes = AWAYLEN;
244     }
245    
246     /* we now send this only if they
247     * weren't away already --is */
248     if (!cur_away_msg)
249     {
250     sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS,
251     NOFLAGS, ":%s AWAY :%s", ID(source_p), new_away_msg);
252     sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6,
253     NOFLAGS, ":%s AWAY :%s", source_p->name, new_away_msg);
254     }
255     else
256     MyFree(cur_away_msg);
257    
258     cur_away_msg = MyMalloc(nbytes + 1);
259     strcpy(cur_away_msg, new_away_msg);
260     source_p->away = cur_away_msg;
261     }

Properties

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