1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2022 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_topic.c |
23 |
* \brief Includes required functions for processing the TOPIC command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "channel.h" |
30 |
#include "channel_mode.h" |
31 |
#include "client.h" |
32 |
#include "conf.h" |
33 |
#include "hash.h" |
34 |
#include "irc_string.h" |
35 |
#include "ircd.h" |
36 |
#include "numeric.h" |
37 |
#include "send.h" |
38 |
#include "parse.h" |
39 |
#include "modules.h" |
40 |
#include "packet.h" |
41 |
|
42 |
|
43 |
/*! \brief TOPIC command handler |
44 |
* |
45 |
* \param source_p Pointer to allocated Client struct from which the message |
46 |
* originally comes from. This can be a local or remote client. |
47 |
* \param parc Integer holding the number of supplied arguments. |
48 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
49 |
* pointers. |
50 |
* \note Valid arguments for this command are: |
51 |
* - parv[0] = command |
52 |
* - parv[1] = channel name |
53 |
* - parv[2] = topic text, if setting topic (can be an empty string) |
54 |
*/ |
55 |
static void |
56 |
m_topic(struct Client *source_p, int parc, char *parv[]) |
57 |
{ |
58 |
struct Channel *channel = hash_find_channel(parv[1]); |
59 |
if (channel == NULL) |
60 |
{ |
61 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
62 |
return; |
63 |
} |
64 |
|
65 |
/* Setting topic */ |
66 |
if (parc > 2) |
67 |
{ |
68 |
const struct ChannelMember *member = member_find_link(source_p, channel); |
69 |
if (member == NULL) |
70 |
{ |
71 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, channel->name); |
72 |
return; |
73 |
} |
74 |
|
75 |
if (HasCMode(channel, MODE_TOPICLIMIT) && member_highest_rank(member) < CHACCESS_HALFOP) |
76 |
sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, channel->name); |
77 |
else |
78 |
{ |
79 |
char topic_info[NICKLEN + USERLEN + HOSTLEN + 3]; /* +3 for !, @, \0 */ |
80 |
|
81 |
snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name, |
82 |
source_p->username, source_p->host); |
83 |
channel_set_topic(channel, parv[2], topic_info, event_base->time.sec_real, true); |
84 |
|
85 |
sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s", |
86 |
source_p->id, channel->name, |
87 |
channel->topic); |
88 |
sendto_channel_local(NULL, channel, 0, 0, 0, ":%s!%s@%s TOPIC %s :%s", |
89 |
source_p->name, |
90 |
source_p->username, |
91 |
source_p->host, |
92 |
channel->name, channel->topic); |
93 |
} |
94 |
} |
95 |
else /* Only asking for topic */ |
96 |
{ |
97 |
if (!SecretChannel(channel) || member_find_link(source_p, channel)) |
98 |
{ |
99 |
if (channel->topic[0] == '\0') |
100 |
sendto_one_numeric(source_p, &me, RPL_NOTOPIC, channel->name); |
101 |
else |
102 |
{ |
103 |
sendto_one_numeric(source_p, &me, RPL_TOPIC, |
104 |
channel->name, channel->topic); |
105 |
sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, channel->name, |
106 |
channel->topic_info, |
107 |
channel->topic_time); |
108 |
} |
109 |
} |
110 |
else |
111 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, channel->name); |
112 |
} |
113 |
} |
114 |
|
115 |
|
116 |
/*! \brief TOPIC command handler |
117 |
* |
118 |
* \param source_p Pointer to allocated Client struct from which the message |
119 |
* originally comes from. This can be a local or remote client. |
120 |
* \param parc Integer holding the number of supplied arguments. |
121 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
122 |
* pointers. |
123 |
* \note Valid arguments for this command are: |
124 |
* - parv[0] = command |
125 |
* - parv[1] = channel name |
126 |
* - parv[2] = topic text (can be an empty string) |
127 |
*/ |
128 |
static void |
129 |
ms_topic(struct Client *source_p, int parc, char *parv[]) |
130 |
{ |
131 |
struct Channel *channel = hash_find_channel(parv[1]); |
132 |
if (channel == NULL) |
133 |
{ |
134 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
135 |
return; |
136 |
} |
137 |
|
138 |
char topic_info[NICKLEN + USERLEN + HOSTLEN + 3]; /* +3 for !, @, \0 */ |
139 |
if (IsClient(source_p)) |
140 |
snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name, |
141 |
source_p->username, source_p->host); |
142 |
else if (IsHidden(source_p) || ConfigServerHide.hide_servers) |
143 |
strlcpy(topic_info, me.name, sizeof(topic_info)); |
144 |
else |
145 |
strlcpy(topic_info, source_p->name, sizeof(topic_info)); |
146 |
|
147 |
channel_set_topic(channel, parv[2], topic_info, event_base->time.sec_real, false); |
148 |
|
149 |
sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s", |
150 |
source_p->id, channel->name, |
151 |
channel->topic); |
152 |
|
153 |
if (IsClient(source_p)) |
154 |
sendto_channel_local(NULL, channel, 0, 0, 0, ":%s!%s@%s TOPIC %s :%s", |
155 |
source_p->name, |
156 |
source_p->username, |
157 |
source_p->host, |
158 |
channel->name, channel->topic); |
159 |
else |
160 |
sendto_channel_local(NULL, channel, 0, 0, 0, ":%s TOPIC %s :%s", |
161 |
(IsHidden(source_p) || ConfigServerHide.hide_servers) ? me.name : source_p->name, |
162 |
channel->name, channel->topic); |
163 |
} |
164 |
|
165 |
static struct Message topic_msgtab = |
166 |
{ |
167 |
.cmd = "TOPIC", |
168 |
.handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered }, |
169 |
.handlers[CLIENT_HANDLER] = { .handler = m_topic, .args_min = 2, .end_grace_period = true }, |
170 |
.handlers[SERVER_HANDLER] = { .handler = ms_topic, .args_min = 3, .empty_last_arg = true }, |
171 |
.handlers[ENCAP_HANDLER] = { .handler = m_ignore }, |
172 |
.handlers[OPER_HANDLER] = { .handler = m_topic, .args_min = 2, .end_grace_period = true } |
173 |
}; |
174 |
|
175 |
static void |
176 |
module_init(void) |
177 |
{ |
178 |
mod_add_cmd(&topic_msgtab); |
179 |
} |
180 |
|
181 |
static void |
182 |
module_exit(void) |
183 |
{ |
184 |
mod_del_cmd(&topic_msgtab); |
185 |
} |
186 |
|
187 |
struct module module_entry = |
188 |
{ |
189 |
.version = "$Revision$", |
190 |
.modinit = module_init, |
191 |
.modexit = module_exit, |
192 |
}; |