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 |
if (!IsFloodDone(source_p)) |
49 |
flood_endgrace(source_p); |
50 |
|
51 |
if (parc < 2 || EmptyString(parv[1])) |
52 |
{ |
53 |
/* Marking as not away */ |
54 |
if (source_p->away[0]) |
55 |
{ |
56 |
source_p->away[0] = '\0'; |
57 |
/* we now send this only if they were away before --is */ |
58 |
sendto_server(client_p, CAP_TS6, NOCAPS, |
59 |
":%s AWAY", ID(source_p)); |
60 |
sendto_server(client_p, NOCAPS, CAP_TS6, |
61 |
":%s AWAY", source_p->name); |
62 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
63 |
":%s!%s@%s AWAY", |
64 |
source_p->name, source_p->username, |
65 |
source_p->host); |
66 |
} |
67 |
|
68 |
sendto_one(source_p, form_str(RPL_UNAWAY), |
69 |
me.name, source_p->name); |
70 |
return; |
71 |
} |
72 |
|
73 |
if ((CurrentTime - source_p->localClient->last_away) < ConfigFileEntry.pace_wait) |
74 |
{ |
75 |
sendto_one(source_p, form_str(RPL_LOAD2HI), |
76 |
me.name, source_p->name); |
77 |
return; |
78 |
} |
79 |
|
80 |
source_p->localClient->last_away = CurrentTime; |
81 |
sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name); |
82 |
|
83 |
if (!strncmp(source_p->away, parv[1], sizeof(source_p->away) - 1)) |
84 |
return; |
85 |
|
86 |
strlcpy(source_p->away, parv[1], sizeof(source_p->away)); |
87 |
|
88 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
89 |
":%s!%s@%s AWAY :%s", |
90 |
source_p->name, source_p->username, |
91 |
source_p->host, source_p->away); |
92 |
sendto_server(client_p, CAP_TS6, NOCAPS, |
93 |
":%s AWAY :%s", ID(source_p), source_p->away); |
94 |
sendto_server(client_p, NOCAPS, CAP_TS6, |
95 |
":%s AWAY :%s", source_p->name, source_p->away); |
96 |
} |
97 |
|
98 |
static void |
99 |
ms_away(struct Client *client_p, struct Client *source_p, |
100 |
int parc, char *parv[]) |
101 |
{ |
102 |
if (!IsClient(source_p)) |
103 |
return; |
104 |
|
105 |
if (parc < 2 || EmptyString(parv[1])) |
106 |
{ |
107 |
/* Marking as not away */ |
108 |
if (source_p->away[0]) |
109 |
{ |
110 |
source_p->away[0] = '\0'; |
111 |
/* we now send this only if they were away before --is */ |
112 |
sendto_server(client_p, CAP_TS6, NOCAPS, |
113 |
":%s AWAY", ID(source_p)); |
114 |
sendto_server(client_p, NOCAPS, CAP_TS6, |
115 |
":%s AWAY", source_p->name); |
116 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
117 |
":%s!%s@%s AWAY", |
118 |
source_p->name, source_p->username, |
119 |
source_p->host); |
120 |
} |
121 |
|
122 |
return; |
123 |
} |
124 |
|
125 |
if (!strncmp(source_p->away, parv[1], sizeof(source_p->away) - 1)) |
126 |
return; |
127 |
|
128 |
strlcpy(source_p->away, parv[1], sizeof(source_p->away)); |
129 |
|
130 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
131 |
":%s!%s@%s AWAY :%s", |
132 |
source_p->name, source_p->username, |
133 |
source_p->host, source_p->away); |
134 |
sendto_server(client_p, CAP_TS6, NOCAPS, |
135 |
":%s AWAY :%s", ID(source_p), source_p->away); |
136 |
sendto_server(client_p, NOCAPS, CAP_TS6, |
137 |
":%s AWAY :%s", source_p->name, source_p->away); |
138 |
} |
139 |
|
140 |
static struct Message away_msgtab = { |
141 |
"AWAY", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
142 |
{ m_unregistered, m_away, ms_away, m_ignore, m_away, m_ignore } |
143 |
}; |
144 |
|
145 |
static void |
146 |
module_init(void) |
147 |
{ |
148 |
mod_add_cmd(&away_msgtab); |
149 |
add_isupport("AWAYLEN", NULL, AWAYLEN); |
150 |
} |
151 |
|
152 |
static void |
153 |
module_exit(void) |
154 |
{ |
155 |
mod_del_cmd(&away_msgtab); |
156 |
delete_isupport("AWAYLEN"); |
157 |
} |
158 |
|
159 |
struct module module_entry = { |
160 |
.node = { NULL, NULL, NULL }, |
161 |
.name = NULL, |
162 |
.version = "$Revision$", |
163 |
.handle = NULL, |
164 |
.modinit = module_init, |
165 |
.modexit = module_exit, |
166 |
.flags = 0 |
167 |
}; |