1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2019 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_away.c |
23 |
* \brief Includes required functions for processing the AWAY command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "client.h" |
29 |
#include "irc_string.h" |
30 |
#include "ircd.h" |
31 |
#include "numeric.h" |
32 |
#include "send.h" |
33 |
#include "parse.h" |
34 |
#include "modules.h" |
35 |
#include "conf.h" |
36 |
#include "server.h" |
37 |
#include "user.h" |
38 |
#include "isupport.h" |
39 |
|
40 |
|
41 |
/*! |
42 |
* |
43 |
* \param source_p Pointer to client to set (un)away |
44 |
* \param message Away message; can be NULL |
45 |
*/ |
46 |
static void |
47 |
do_away(struct Client *source_p, const char *message) |
48 |
{ |
49 |
assert(IsClient(source_p)); |
50 |
|
51 |
if (EmptyString(message)) |
52 |
{ |
53 |
/* Marking as not away */ |
54 |
if (source_p->away[0]) |
55 |
{ |
56 |
source_p->away[0] = '\0'; |
57 |
|
58 |
/* We now send this only if they were away before --is */ |
59 |
sendto_server(source_p, 0, 0, ":%s AWAY", source_p->id); |
60 |
sendto_common_channels_local(source_p, true, CAP_AWAY_NOTIFY, 0, ":%s!%s@%s AWAY", |
61 |
source_p->name, source_p->username, source_p->host); |
62 |
} |
63 |
|
64 |
if (MyConnect(source_p)) |
65 |
sendto_one_numeric(source_p, &me, RPL_UNAWAY); |
66 |
return; |
67 |
} |
68 |
|
69 |
if (MyConnect(source_p)) |
70 |
{ |
71 |
if ((source_p->connection->away.last_attempt + ConfigGeneral.away_time) < CurrentTime) |
72 |
source_p->connection->away.count = 0; |
73 |
|
74 |
if (source_p->connection->away.count > ConfigGeneral.away_count) |
75 |
{ |
76 |
sendto_one_numeric(source_p, &me, ERR_TOOMANYAWAY); |
77 |
return; |
78 |
} |
79 |
|
80 |
source_p->connection->away.last_attempt = CurrentTime; |
81 |
source_p->connection->away.count++; |
82 |
sendto_one_numeric(source_p, &me, RPL_NOWAWAY); |
83 |
|
84 |
if (strncmp(source_p->away, message, sizeof(source_p->away) - 1) == 0) |
85 |
return; |
86 |
} |
87 |
|
88 |
strlcpy(source_p->away, message, sizeof(source_p->away)); |
89 |
sendto_common_channels_local(source_p, true, CAP_AWAY_NOTIFY, 0, ":%s!%s@%s AWAY :%s", |
90 |
source_p->name, source_p->username, |
91 |
source_p->host, source_p->away); |
92 |
sendto_server(source_p, 0, 0, ":%s AWAY :%s", |
93 |
source_p->id, source_p->away); |
94 |
} |
95 |
|
96 |
/*! \brief AWAY command handler |
97 |
* |
98 |
* \param source_p Pointer to allocated Client struct from which the message |
99 |
* originally comes from. This can be a local or remote client. |
100 |
* \param parc Integer holding the number of supplied arguments. |
101 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
102 |
* pointers. |
103 |
* \note Valid arguments for this command are: |
104 |
* - parv[0] = command |
105 |
* - parv[1] = away message |
106 |
*/ |
107 |
static int |
108 |
m_away(struct Client *source_p, int parc, char *parv[]) |
109 |
{ |
110 |
const char *const message = parv[1]; |
111 |
|
112 |
do_away(source_p, message); |
113 |
return 0; |
114 |
} |
115 |
|
116 |
/*! \brief AWAY command handler |
117 |
* |
118 |
* \param source_p Pointer to allocated Client struct from which the message |
119 |
* originally comes from. This can be a local or remote client. |
120 |
* \param parc Integer holding the number of supplied arguments. |
121 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
122 |
* pointers. |
123 |
* \note Valid arguments for this command are: |
124 |
* - parv[0] = command |
125 |
* - parv[1] = away message |
126 |
*/ |
127 |
static int |
128 |
ms_away(struct Client *source_p, int parc, char *parv[]) |
129 |
{ |
130 |
const char *const message = parv[1]; |
131 |
|
132 |
do_away(source_p, message); |
133 |
return 0; |
134 |
} |
135 |
|
136 |
static struct Message away_msgtab = |
137 |
{ |
138 |
.cmd = "AWAY", |
139 |
.args_max = MAXPARA, |
140 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
141 |
.handlers[CLIENT_HANDLER] = m_away, |
142 |
.handlers[SERVER_HANDLER] = ms_away, |
143 |
.handlers[ENCAP_HANDLER] = m_ignore, |
144 |
.handlers[OPER_HANDLER] = m_away |
145 |
}; |
146 |
|
147 |
static void |
148 |
module_init(void) |
149 |
{ |
150 |
mod_add_cmd(&away_msgtab); |
151 |
isupport_add("AWAYLEN", NULL, AWAYLEN); |
152 |
} |
153 |
|
154 |
static void |
155 |
module_exit(void) |
156 |
{ |
157 |
mod_del_cmd(&away_msgtab); |
158 |
isupport_delete("AWAYLEN"); |
159 |
} |
160 |
|
161 |
struct module module_entry = |
162 |
{ |
163 |
.version = "$Revision$", |
164 |
.modinit = module_init, |
165 |
.modexit = module_exit, |
166 |
}; |