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 |
/* Marking as away */ |
76 |
if ((CurrentTime - source_p->localClient->last_away) < ConfigFileEntry.pace_wait) |
77 |
{ |
78 |
sendto_one(source_p, form_str(RPL_LOAD2HI), |
79 |
me.name, source_p->name); |
80 |
return; |
81 |
} |
82 |
|
83 |
source_p->localClient->last_away = CurrentTime; |
84 |
new_away_msg = parv[1]; |
85 |
|
86 |
nbytes = strlen(new_away_msg); |
87 |
if (nbytes > (size_t)AWAYLEN) { |
88 |
new_away_msg[AWAYLEN] = '\0'; |
89 |
nbytes = AWAYLEN; |
90 |
} |
91 |
|
92 |
/* we now send this only if they |
93 |
* weren't away already --is */ |
94 |
if (!cur_away_msg) |
95 |
{ |
96 |
sendto_server(client_p, NULL, CAP_TS6, NOCAPS, |
97 |
":%s AWAY :%s", ID(source_p), new_away_msg); |
98 |
sendto_server(client_p, NULL, NOCAPS, CAP_TS6, |
99 |
":%s AWAY :%s", source_p->name, new_away_msg); |
100 |
} |
101 |
else |
102 |
MyFree(cur_away_msg); |
103 |
|
104 |
cur_away_msg = MyMalloc(nbytes + 1); |
105 |
strcpy(cur_away_msg, new_away_msg); |
106 |
source_p->away = cur_away_msg; |
107 |
|
108 |
sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name); |
109 |
} |
110 |
|
111 |
static void |
112 |
mo_away(struct Client *client_p, struct Client *source_p, |
113 |
int parc, char *parv[]) |
114 |
{ |
115 |
char *cur_away_msg = source_p->away; |
116 |
char *new_away_msg = NULL; |
117 |
size_t nbytes = 0; |
118 |
|
119 |
if (!IsFloodDone(source_p)) |
120 |
flood_endgrace(source_p); |
121 |
|
122 |
if (parc < 2 || EmptyString(parv[1])) |
123 |
{ |
124 |
/* Marking as not away */ |
125 |
if (cur_away_msg) |
126 |
{ |
127 |
/* we now send this only if they were away before --is */ |
128 |
sendto_server(client_p, NULL, CAP_TS6, NOCAPS, |
129 |
":%s AWAY", ID(source_p)); |
130 |
sendto_server(client_p, NULL, NOCAPS, CAP_TS6, |
131 |
":%s AWAY", source_p->name); |
132 |
|
133 |
MyFree(cur_away_msg); |
134 |
source_p->away = NULL; |
135 |
} |
136 |
|
137 |
sendto_one(source_p, form_str(RPL_UNAWAY), |
138 |
me.name, source_p->name); |
139 |
return; |
140 |
} |
141 |
|
142 |
new_away_msg = parv[1]; |
143 |
|
144 |
nbytes = strlen(new_away_msg); |
145 |
if (nbytes > (size_t)AWAYLEN) { |
146 |
new_away_msg[AWAYLEN] = '\0'; |
147 |
nbytes = AWAYLEN; |
148 |
} |
149 |
|
150 |
/* we now send this only if they |
151 |
* weren't away already --is */ |
152 |
if (!cur_away_msg) |
153 |
{ |
154 |
sendto_server(client_p, NULL, CAP_TS6, NOCAPS, |
155 |
":%s AWAY :%s", ID(source_p), new_away_msg); |
156 |
sendto_server(client_p, NULL, NOCAPS, CAP_TS6, |
157 |
":%s AWAY :%s", source_p->name, new_away_msg); |
158 |
} |
159 |
else |
160 |
MyFree(cur_away_msg); |
161 |
|
162 |
cur_away_msg = MyMalloc(nbytes + 1); |
163 |
strcpy(cur_away_msg, new_away_msg); |
164 |
source_p->away = cur_away_msg; |
165 |
|
166 |
sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name); |
167 |
} |
168 |
|
169 |
static void |
170 |
ms_away(struct Client *client_p, struct Client *source_p, |
171 |
int parc, char *parv[]) |
172 |
{ |
173 |
char *cur_away_msg = NULL; |
174 |
char *new_away_msg = NULL; |
175 |
size_t nbytes = 0; |
176 |
|
177 |
if (!IsClient(source_p)) |
178 |
return; |
179 |
|
180 |
cur_away_msg = source_p->away; |
181 |
|
182 |
if (parc < 2 || EmptyString(parv[1])) |
183 |
{ |
184 |
/* Marking as not away */ |
185 |
if (cur_away_msg) |
186 |
{ |
187 |
/* we now send this only if they were away before --is */ |
188 |
sendto_server(client_p, NULL, CAP_TS6, NOCAPS, |
189 |
":%s AWAY", ID(source_p)); |
190 |
sendto_server(client_p, NULL, NOCAPS, CAP_TS6, |
191 |
":%s AWAY", source_p->name); |
192 |
|
193 |
MyFree(cur_away_msg); |
194 |
source_p->away = NULL; |
195 |
} |
196 |
|
197 |
return; |
198 |
} |
199 |
|
200 |
new_away_msg = parv[1]; |
201 |
|
202 |
nbytes = strlen(new_away_msg); |
203 |
if (nbytes > (size_t)AWAYLEN) { |
204 |
new_away_msg[AWAYLEN] = '\0'; |
205 |
nbytes = AWAYLEN; |
206 |
} |
207 |
|
208 |
/* we now send this only if they |
209 |
* weren't away already --is */ |
210 |
if (!cur_away_msg) |
211 |
{ |
212 |
sendto_server(client_p, NULL, CAP_TS6, NOCAPS, |
213 |
":%s AWAY :%s", ID(source_p), new_away_msg); |
214 |
sendto_server(client_p, NULL, NOCAPS, CAP_TS6, |
215 |
":%s AWAY :%s", source_p->name, new_away_msg); |
216 |
} |
217 |
else |
218 |
MyFree(cur_away_msg); |
219 |
|
220 |
cur_away_msg = MyMalloc(nbytes + 1); |
221 |
strcpy(cur_away_msg, new_away_msg); |
222 |
source_p->away = cur_away_msg; |
223 |
} |
224 |
|
225 |
static struct Message away_msgtab = { |
226 |
"AWAY", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
227 |
{m_unregistered, m_away, ms_away, m_ignore, mo_away, m_ignore} |
228 |
}; |
229 |
|
230 |
static void |
231 |
module_init(void) |
232 |
{ |
233 |
mod_add_cmd(&away_msgtab); |
234 |
add_isupport("AWAYLEN", NULL, AWAYLEN); |
235 |
} |
236 |
|
237 |
static void |
238 |
module_exit(void) |
239 |
{ |
240 |
mod_del_cmd(&away_msgtab); |
241 |
delete_isupport("AWAYLEN"); |
242 |
} |
243 |
|
244 |
struct module module_entry = { |
245 |
.node = { NULL, NULL, NULL }, |
246 |
.name = NULL, |
247 |
.version = "$Revision$", |
248 |
.handle = NULL, |
249 |
.modinit = module_init, |
250 |
.modexit = module_exit, |
251 |
.flags = 0 |
252 |
}; |