1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
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 "s_serv.h" |
37 |
#include "packet.h" |
38 |
#include "s_user.h" |
39 |
|
40 |
|
41 |
/* |
42 |
* m_away |
43 |
* parv[0] = command |
44 |
* parv[1] = away message |
45 |
*/ |
46 |
static int |
47 |
m_away(struct Client *source_p, int parc, char *parv[]) |
48 |
{ |
49 |
if (!IsFloodDone(source_p)) |
50 |
flood_endgrace(source_p); |
51 |
|
52 |
if (parc < 2 || EmptyString(parv[1])) |
53 |
{ |
54 |
/* Marking as not away */ |
55 |
if (source_p->away[0]) |
56 |
{ |
57 |
source_p->away[0] = '\0'; |
58 |
/* we now send this only if they were away before --is */ |
59 |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s AWAY", source_p->id); |
60 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
61 |
":%s!%s@%s AWAY", |
62 |
source_p->name, source_p->username, |
63 |
source_p->host); |
64 |
} |
65 |
|
66 |
sendto_one_numeric(source_p, &me, RPL_UNAWAY); |
67 |
return 0; |
68 |
} |
69 |
|
70 |
if ((CurrentTime - source_p->localClient->last_away) < ConfigFileEntry.pace_wait) |
71 |
{ |
72 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI); |
73 |
return 0; |
74 |
} |
75 |
|
76 |
source_p->localClient->last_away = CurrentTime; |
77 |
sendto_one_numeric(source_p, &me, RPL_NOWAWAY); |
78 |
|
79 |
if (!strncmp(source_p->away, parv[1], sizeof(source_p->away) - 1)) |
80 |
return 0; |
81 |
|
82 |
strlcpy(source_p->away, parv[1], sizeof(source_p->away)); |
83 |
|
84 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
85 |
":%s!%s@%s AWAY :%s", |
86 |
source_p->name, source_p->username, |
87 |
source_p->host, source_p->away); |
88 |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s AWAY :%s", |
89 |
source_p->id, source_p->away); |
90 |
return 0; |
91 |
} |
92 |
|
93 |
static int |
94 |
ms_away(struct Client *source_p, int parc, char *parv[]) |
95 |
{ |
96 |
if (parc < 2 || EmptyString(parv[1])) |
97 |
{ |
98 |
/* Marking as not away */ |
99 |
if (source_p->away[0]) |
100 |
{ |
101 |
source_p->away[0] = '\0'; |
102 |
/* we now send this only if they were away before --is */ |
103 |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s AWAY", source_p->id); |
104 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
105 |
":%s!%s@%s AWAY", |
106 |
source_p->name, source_p->username, |
107 |
source_p->host); |
108 |
} |
109 |
|
110 |
return 0; |
111 |
} |
112 |
|
113 |
if (!strncmp(source_p->away, parv[1], sizeof(source_p->away) - 1)) |
114 |
return 0; |
115 |
|
116 |
strlcpy(source_p->away, parv[1], sizeof(source_p->away)); |
117 |
|
118 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
119 |
":%s!%s@%s AWAY :%s", |
120 |
source_p->name, source_p->username, |
121 |
source_p->host, source_p->away); |
122 |
sendto_server(source_p, NOCAPS, NOCAPS, ":%s AWAY :%s", |
123 |
source_p->id, source_p->away); |
124 |
return 0; |
125 |
} |
126 |
|
127 |
static struct Message away_msgtab = |
128 |
{ |
129 |
"AWAY", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
130 |
{ m_unregistered, m_away, ms_away, m_ignore, m_away, m_ignore } |
131 |
}; |
132 |
|
133 |
static void |
134 |
module_init(void) |
135 |
{ |
136 |
mod_add_cmd(&away_msgtab); |
137 |
add_isupport("AWAYLEN", NULL, AWAYLEN); |
138 |
} |
139 |
|
140 |
static void |
141 |
module_exit(void) |
142 |
{ |
143 |
mod_del_cmd(&away_msgtab); |
144 |
delete_isupport("AWAYLEN"); |
145 |
} |
146 |
|
147 |
struct module module_entry = |
148 |
{ |
149 |
.node = { NULL, NULL, NULL }, |
150 |
.name = NULL, |
151 |
.version = "$Revision$", |
152 |
.handle = NULL, |
153 |
.modinit = module_init, |
154 |
.modexit = module_exit, |
155 |
.flags = 0 |
156 |
}; |