/[svn]/ircd-hybrid-8/modules/m_away.c
ViewVC logotype

Contents of /ircd-hybrid-8/modules/m_away.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1449 - (show annotations)
Tue Jun 26 18:17:03 2012 UTC (8 years ago) by michael
File MIME type: text/x-chdr
File size: 4634 byte(s)
- Merged m_away() and mo_away(). Also, /away is no longer time-limited.
- Same goes for /list

1 /*
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 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "client.h"
27 #include "irc_string.h"
28 #include "ircd.h"
29 #include "numeric.h"
30 #include "send.h"
31 #include "parse.h"
32 #include "modules.h"
33 #include "conf.h"
34 #include "s_serv.h"
35 #include "packet.h"
36 #include "s_user.h"
37
38
39 /*
40 * m_away
41 * parv[0] = sender prefix
42 * parv[1] = away message
43 */
44 static void
45 m_away(struct Client *client_p, struct Client *source_p,
46 int parc, char *parv[])
47 {
48 char *cur_away_msg = source_p->away;
49 char *new_away_msg = NULL;
50 size_t nbytes = 0;
51
52 if (!IsFloodDone(source_p))
53 flood_endgrace(source_p);
54
55 if (parc < 2 || EmptyString(parv[1]))
56 {
57 /* Marking as not away */
58 if (cur_away_msg)
59 {
60 /* we now send this only if they were away before --is */
61 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
62 ":%s AWAY", ID(source_p));
63 sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
64 ":%s AWAY", source_p->name);
65
66 MyFree(cur_away_msg);
67 source_p->away = NULL;
68 }
69
70 sendto_one(source_p, form_str(RPL_UNAWAY),
71 me.name, source_p->name);
72 return;
73 }
74
75 new_away_msg = parv[1];
76 nbytes = strlen(new_away_msg);
77
78 if (nbytes > (size_t)AWAYLEN) {
79 new_away_msg[AWAYLEN] = '\0';
80 nbytes = AWAYLEN;
81 }
82
83 /* we now send this only if they
84 * weren't away already --is */
85 if (!cur_away_msg)
86 {
87 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
88 ":%s AWAY :%s", ID(source_p), new_away_msg);
89 sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
90 ":%s AWAY :%s", source_p->name, new_away_msg);
91 }
92 else
93 MyFree(cur_away_msg);
94
95 cur_away_msg = MyMalloc(nbytes + 1);
96 strcpy(cur_away_msg, new_away_msg);
97 source_p->away = cur_away_msg;
98
99 sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name);
100 }
101
102 static void
103 ms_away(struct Client *client_p, struct Client *source_p,
104 int parc, char *parv[])
105 {
106 char *cur_away_msg = NULL;
107 char *new_away_msg = NULL;
108 size_t nbytes = 0;
109
110 if (!IsClient(source_p))
111 return;
112
113 cur_away_msg = source_p->away;
114
115 if (parc < 2 || EmptyString(parv[1]))
116 {
117 /* Marking as not away */
118 if (cur_away_msg)
119 {
120 /* we now send this only if they were away before --is */
121 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
122 ":%s AWAY", ID(source_p));
123 sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
124 ":%s AWAY", source_p->name);
125
126 MyFree(cur_away_msg);
127 source_p->away = NULL;
128 }
129
130 return;
131 }
132
133 new_away_msg = parv[1];
134
135 nbytes = strlen(new_away_msg);
136 if (nbytes > (size_t)AWAYLEN) {
137 new_away_msg[AWAYLEN] = '\0';
138 nbytes = AWAYLEN;
139 }
140
141 /* we now send this only if they
142 * weren't away already --is */
143 if (!cur_away_msg)
144 {
145 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
146 ":%s AWAY :%s", ID(source_p), new_away_msg);
147 sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
148 ":%s AWAY :%s", source_p->name, new_away_msg);
149 }
150 else
151 MyFree(cur_away_msg);
152
153 cur_away_msg = MyMalloc(nbytes + 1);
154 strcpy(cur_away_msg, new_away_msg);
155 source_p->away = cur_away_msg;
156 }
157
158 static struct Message away_msgtab = {
159 "AWAY", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
160 { m_unregistered, m_away, ms_away, m_ignore, m_away, m_ignore }
161 };
162
163 static void
164 module_init(void)
165 {
166 mod_add_cmd(&away_msgtab);
167 add_isupport("AWAYLEN", NULL, AWAYLEN);
168 }
169
170 static void
171 module_exit(void)
172 {
173 mod_del_cmd(&away_msgtab);
174 delete_isupport("AWAYLEN");
175 }
176
177 struct module module_entry = {
178 .node = { NULL, NULL, NULL },
179 .name = NULL,
180 .version = "$Revision$",
181 .handle = NULL,
182 .modinit = module_init,
183 .modexit = module_exit,
184 .flags = 0
185 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28