ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_away.c
Revision: 5881
Committed: Sun May 3 16:04:15 2015 UTC (10 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 5207 byte(s)
Log Message:
- Use C99-style initializers in all struct Message items
- Removed MFLG_SLOW
- Removed DUMMY_HANDLER

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 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
39
40 /*! \brief AWAY command handler
41 *
42 * \param source_p Pointer to allocated Client struct from which the message
43 * originally comes from. This can be a local or remote client.
44 * \param parc Integer holding the number of supplied arguments.
45 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
46 * pointers.
47 * \note Valid arguments for this command are:
48 * - parv[0] = command
49 * - parv[1] = away message
50 */
51 static int
52 m_away(struct Client *source_p, int parc, char *parv[])
53 {
54 const char *const message = parv[1];
55
56 if (EmptyString(message))
57 {
58 /* Marking as not away */
59 if (source_p->away[0])
60 {
61 source_p->away[0] = '\0';
62
63 /* We now send this only if they were away before --is */
64 sendto_server(source_p, 0, 0, ":%s AWAY", source_p->id);
65 sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, ":%s!%s@%s AWAY",
66 source_p->name, source_p->username,
67 source_p->host);
68 }
69
70 sendto_one_numeric(source_p, &me, RPL_UNAWAY);
71 return 0;
72 }
73
74 if ((source_p->connection->away.last_attempt + ConfigGeneral.away_time) < CurrentTime)
75 source_p->connection->away.count = 0;
76
77 if (source_p->connection->away.count > ConfigGeneral.away_count)
78 {
79 sendto_one_numeric(source_p, &me, ERR_TOOMANYAWAY);
80 return 0;
81 }
82
83 source_p->connection->away.last_attempt = CurrentTime;
84 source_p->connection->away.count++;
85
86 strlcpy(source_p->away, message, sizeof(source_p->away));
87
88 sendto_one_numeric(source_p, &me, RPL_NOWAWAY);
89 sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, ":%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 return 0;
95 }
96
97 /*! \brief AWAY command handler
98 *
99 * \param source_p Pointer to allocated Client struct from which the message
100 * originally comes from. This can be a local or remote client.
101 * \param parc Integer holding the number of supplied arguments.
102 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
103 * pointers.
104 * \note Valid arguments for this command are:
105 * - parv[0] = command
106 * - parv[1] = away message
107 */
108 static int
109 ms_away(struct Client *source_p, int parc, char *parv[])
110 {
111 const char *const message = parv[1];
112
113 if (EmptyString(message))
114 {
115 /* Marking as not away */
116 if (source_p->away[0])
117 {
118 source_p->away[0] = '\0';
119
120 /* We now send this only if they were away before --is */
121 sendto_server(source_p, 0, 0, ":%s AWAY", source_p->id);
122 sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, ":%s!%s@%s AWAY",
123 source_p->name, source_p->username,
124 source_p->host);
125 }
126
127 return 0;
128 }
129
130 strlcpy(source_p->away, message, sizeof(source_p->away));
131
132 sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, ":%s!%s@%s AWAY :%s",
133 source_p->name, source_p->username,
134 source_p->host, source_p->away);
135 sendto_server(source_p, 0, 0, ":%s AWAY :%s",
136 source_p->id, source_p->away);
137 return 0;
138 }
139
140 static struct Message away_msgtab =
141 {
142 .cmd = "AWAY",
143 .args_max = MAXPARA,
144 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
145 .handlers[CLIENT_HANDLER] = m_away,
146 .handlers[SERVER_HANDLER] = ms_away,
147 .handlers[ENCAP_HANDLER] = m_ignore,
148 .handlers[OPER_HANDLER] = m_away
149 };
150
151 static void
152 module_init(void)
153 {
154 mod_add_cmd(&away_msgtab);
155 add_isupport("AWAYLEN", NULL, AWAYLEN);
156 }
157
158 static void
159 module_exit(void)
160 {
161 mod_del_cmd(&away_msgtab);
162 delete_isupport("AWAYLEN");
163 }
164
165 struct module module_entry =
166 {
167 .version = "$Revision$",
168 .modinit = module_init,
169 .modexit = module_exit,
170 };

Properties

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