]> jfr.im git - solanum.git/blob - modules/m_away.c
m_message: global snote when massnotice is used
[solanum.git] / modules / m_away.c
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_away.c: Sets/removes away status on a user.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */
24
25 #include "stdinc.h"
26 #include "client.h"
27 #include "match.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_newconf.h"
38
39 static const char away_desc[] = "Provides the AWAY command to set yourself away";
40
41 static void m_away(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
42
43 struct Message away_msgtab = {
44 "AWAY", 0, 0, 0, 0,
45 {mg_unreg, {m_away, 0}, {m_away, 0}, mg_ignore, mg_ignore, {m_away, 0}}
46 };
47
48 mapi_clist_av1 away_clist[] = { &away_msgtab, NULL };
49
50 DECLARE_MODULE_AV2(away, NULL, NULL, away_clist, NULL, NULL, NULL, NULL, away_desc);
51
52 /***********************************************************************
53 * m_away() - Added 14 Dec 1988 by jto.
54 * Not currently really working, I don't like this
55 * call at all...
56 *
57 * ...trying to make it work. I don't like it either,
58 * but perhaps it's worth the load it causes to net.
59 * This requires flooding of the whole net like NICK,
60 * USER, MODE, etc messages... --msa
61 *
62 * The above comments have long since irrelvant, but
63 * are kept for historical purposes now ;)
64 ***********************************************************************/
65
66 /*
67 ** m_away
68 ** parv[1] = away message
69 */
70 static void
71 m_away(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
72 {
73 if(MyClient(source_p) && source_p->localClient->next_away &&
74 !IsFloodDone(source_p))
75 flood_endgrace(source_p);
76
77 if(!IsClient(source_p))
78 return;
79
80 if(parc < 2 || EmptyString(parv[1]))
81 {
82 /* Marking as not away */
83 if(source_p->user->away != NULL)
84 {
85 /* we now send this only if they were away before --is */
86 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
87 ":%s AWAY", use_id(source_p));
88 free_away(source_p);
89
90 sendto_common_channels_local_butone(source_p, CLICAP_AWAY_NOTIFY, NOCAPS, ":%s!%s@%s AWAY",
91 source_p->name, source_p->username, source_p->host);
92 }
93 if(MyConnect(source_p))
94 sendto_one_numeric(source_p, RPL_UNAWAY, form_str(RPL_UNAWAY));
95 return;
96 }
97
98 /* Rate limit this because it is sent to common channels. */
99 if (MyClient(source_p))
100 {
101 if(!IsOperGeneral(source_p) &&
102 source_p->localClient->next_away > rb_current_time())
103 {
104 sendto_one(source_p, form_str(RPL_LOAD2HI),
105 me.name, source_p->name, "AWAY");
106 return;
107 }
108 if(source_p->localClient->next_away < rb_current_time() -
109 ConfigFileEntry.away_interval)
110 source_p->localClient->next_away = rb_current_time();
111 else
112 source_p->localClient->next_away = rb_current_time() +
113 ConfigFileEntry.away_interval;
114 }
115
116 if(source_p->user->away == NULL)
117 allocate_away(source_p);
118 if(strncmp(source_p->user->away, parv[1], AWAYLEN - 1))
119 {
120 rb_strlcpy(source_p->user->away, parv[1], AWAYLEN);
121 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
122 ":%s AWAY :%s", use_id(source_p), source_p->user->away);
123 sendto_common_channels_local_butone(source_p,
124 CLICAP_AWAY_NOTIFY, NOCAPS,
125 ":%s!%s@%s AWAY :%s",
126 source_p->name,
127 source_p->username,
128 source_p->host,
129 source_p->user->away);
130 }
131
132 if(MyConnect(source_p))
133 sendto_one_numeric(source_p, RPL_NOWAWAY, form_str(RPL_NOWAWAY));
134 }