ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_away.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (15 years ago) by michael
Content type: text/x-csrc
File size: 6963 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

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

Properties

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