| 1 |
adx |
30 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
8751 |
* Copyright (c) 1997-2019 ircd-hybrid development team |
| 5 |
adx |
30 |
* |
| 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 |
michael |
4564 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
adx |
30 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
michael |
2820 |
/*! \file m_topic.c |
| 23 |
|
|
* \brief Includes required functions for processing the TOPIC command. |
| 24 |
|
|
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
adx |
30 |
#include "stdinc.h" |
| 28 |
michael |
1011 |
#include "list.h" |
| 29 |
adx |
30 |
#include "channel.h" |
| 30 |
|
|
#include "channel_mode.h" |
| 31 |
|
|
#include "client.h" |
| 32 |
michael |
5537 |
#include "conf.h" |
| 33 |
adx |
30 |
#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 |
michael |
3332 |
/*! \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 |
michael |
7089 |
* - parv[2] = topic text, if setting topic (can be an empty string) |
| 54 |
adx |
30 |
*/ |
| 55 |
michael |
9078 |
static void |
| 56 |
michael |
3156 |
m_topic(struct Client *source_p, int parc, char *parv[]) |
| 57 |
adx |
30 |
{ |
| 58 |
michael |
9082 |
struct Channel *channel = NULL; |
| 59 |
adx |
30 |
|
| 60 |
michael |
885 |
if (EmptyString(parv[1])) |
| 61 |
adx |
30 |
{ |
| 62 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC"); |
| 63 |
michael |
9078 |
return; |
| 64 |
adx |
30 |
} |
| 65 |
|
|
|
| 66 |
michael |
9082 |
if ((channel = hash_find_channel(parv[1])) == NULL) |
| 67 |
adx |
30 |
{ |
| 68 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
| 69 |
michael |
9078 |
return; |
| 70 |
michael |
895 |
} |
| 71 |
|
|
|
| 72 |
|
|
/* setting topic */ |
| 73 |
|
|
if (parc > 2) |
| 74 |
|
|
{ |
| 75 |
michael |
9082 |
const struct ChannelMember *member = NULL; |
| 76 |
michael |
895 |
|
| 77 |
michael |
9082 |
if ((member = find_channel_link(source_p, channel)) == NULL) |
| 78 |
adx |
30 |
{ |
| 79 |
michael |
9082 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, channel->name); |
| 80 |
michael |
9078 |
return; |
| 81 |
adx |
30 |
} |
| 82 |
|
|
|
| 83 |
michael |
9082 |
if (!HasCMode(channel, MODE_TOPICLIMIT) || |
| 84 |
michael |
8043 |
has_member_flags(member, CHFL_CHANOP | CHFL_HALFOP)) |
| 85 |
adx |
30 |
{ |
| 86 |
michael |
6931 |
char topic_info[NICKLEN + USERLEN + HOSTLEN + 3]; /* +3 for !, @, \0 */ |
| 87 |
michael |
885 |
|
| 88 |
michael |
1203 |
snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name, |
| 89 |
|
|
source_p->username, source_p->host); |
| 90 |
michael |
9082 |
channel_set_topic(channel, parv[2], topic_info, event_base->time.sec_real, true); |
| 91 |
adx |
30 |
|
| 92 |
michael |
4963 |
sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s", |
| 93 |
michael |
9082 |
source_p->id, channel->name, |
| 94 |
|
|
channel->topic); |
| 95 |
|
|
sendto_channel_local(NULL, channel, 0, 0, 0, ":%s!%s@%s TOPIC %s :%s", |
| 96 |
michael |
895 |
source_p->name, |
| 97 |
|
|
source_p->username, |
| 98 |
|
|
source_p->host, |
| 99 |
michael |
9082 |
channel->name, channel->topic); |
| 100 |
adx |
30 |
} |
| 101 |
michael |
895 |
else |
| 102 |
michael |
9082 |
sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, channel->name); |
| 103 |
michael |
895 |
} |
| 104 |
|
|
else /* only asking for topic */ |
| 105 |
|
|
{ |
| 106 |
michael |
9082 |
if (!SecretChannel(channel) || IsMember(source_p, channel)) |
| 107 |
adx |
30 |
{ |
| 108 |
michael |
9082 |
if (channel->topic[0] == '\0') |
| 109 |
|
|
sendto_one_numeric(source_p, &me, RPL_NOTOPIC, channel->name); |
| 110 |
adx |
30 |
else |
| 111 |
|
|
{ |
| 112 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_TOPIC, |
| 113 |
michael |
9082 |
channel->name, channel->topic); |
| 114 |
|
|
sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, channel->name, |
| 115 |
|
|
channel->topic_info, |
| 116 |
|
|
channel->topic_time); |
| 117 |
adx |
30 |
} |
| 118 |
|
|
} |
| 119 |
|
|
else |
| 120 |
michael |
9082 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, channel->name); |
| 121 |
adx |
30 |
} |
| 122 |
|
|
} |
| 123 |
michael |
1230 |
|
| 124 |
michael |
3332 |
|
| 125 |
|
|
/*! \brief TOPIC command handler |
| 126 |
|
|
* |
| 127 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 128 |
|
|
* originally comes from. This can be a local or remote client. |
| 129 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 130 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 131 |
|
|
* pointers. |
| 132 |
|
|
* \note Valid arguments for this command are: |
| 133 |
|
|
* - parv[0] = command |
| 134 |
|
|
* - parv[1] = channel name |
| 135 |
michael |
7089 |
* - parv[2] = topic text (can be an empty string) |
| 136 |
michael |
3332 |
*/ |
| 137 |
michael |
9078 |
static void |
| 138 |
michael |
3156 |
ms_topic(struct Client *source_p, int parc, char *parv[]) |
| 139 |
michael |
1799 |
{ |
| 140 |
michael |
9082 |
struct Channel *channel = NULL; |
| 141 |
michael |
6931 |
char topic_info[NICKLEN + USERLEN + HOSTLEN + 3]; /* +3 for !, @, \0 */ |
| 142 |
michael |
1799 |
|
| 143 |
michael |
7087 |
if (parc < 3) |
| 144 |
michael |
1799 |
{ |
| 145 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC"); |
| 146 |
michael |
9078 |
return; |
| 147 |
michael |
1799 |
} |
| 148 |
|
|
|
| 149 |
michael |
9082 |
if ((channel = hash_find_channel(parv[1])) == NULL) |
| 150 |
michael |
1799 |
{ |
| 151 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
| 152 |
michael |
9078 |
return; |
| 153 |
michael |
1799 |
} |
| 154 |
|
|
|
| 155 |
michael |
8430 |
if (IsClient(source_p)) |
| 156 |
michael |
1799 |
snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name, |
| 157 |
|
|
source_p->username, source_p->host); |
| 158 |
michael |
8667 |
else if (IsHidden(source_p) || ConfigServerHide.hide_servers) |
| 159 |
|
|
strlcpy(topic_info, me.name, sizeof(topic_info)); |
| 160 |
michael |
8430 |
else |
| 161 |
|
|
strlcpy(topic_info, source_p->name, sizeof(topic_info)); |
| 162 |
|
|
|
| 163 |
michael |
9082 |
channel_set_topic(channel, parv[2], topic_info, event_base->time.sec_real, false); |
| 164 |
michael |
1799 |
|
| 165 |
michael |
4963 |
sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s", |
| 166 |
michael |
9082 |
source_p->id, channel->name, |
| 167 |
|
|
channel->topic); |
| 168 |
michael |
1799 |
|
| 169 |
michael |
8430 |
if (IsClient(source_p)) |
| 170 |
michael |
9082 |
sendto_channel_local(NULL, channel, 0, 0, 0, ":%s!%s@%s TOPIC %s :%s", |
| 171 |
michael |
1799 |
source_p->name, |
| 172 |
|
|
source_p->username, |
| 173 |
|
|
source_p->host, |
| 174 |
michael |
9082 |
channel->name, channel->topic); |
| 175 |
michael |
8430 |
else |
| 176 |
michael |
9082 |
sendto_channel_local(NULL, channel, 0, 0, 0, ":%s TOPIC %s :%s", |
| 177 |
michael |
8430 |
(IsHidden(source_p) || ConfigServerHide.hide_servers) ? me.name : source_p->name, |
| 178 |
michael |
9082 |
channel->name, channel->topic); |
| 179 |
michael |
1799 |
} |
| 180 |
|
|
|
| 181 |
michael |
2820 |
static struct Message topic_msgtab = |
| 182 |
|
|
{ |
| 183 |
michael |
5880 |
.cmd = "TOPIC", |
| 184 |
|
|
.args_min = 2, |
| 185 |
|
|
.args_max = MAXPARA, |
| 186 |
michael |
8714 |
.flags = MFLG_ENDGRACE, |
| 187 |
michael |
5880 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
| 188 |
|
|
.handlers[CLIENT_HANDLER] = m_topic, |
| 189 |
|
|
.handlers[SERVER_HANDLER] = ms_topic, |
| 190 |
|
|
.handlers[ENCAP_HANDLER] = m_ignore, |
| 191 |
|
|
.handlers[OPER_HANDLER] = m_topic |
| 192 |
michael |
1230 |
}; |
| 193 |
|
|
|
| 194 |
|
|
static void |
| 195 |
|
|
module_init(void) |
| 196 |
|
|
{ |
| 197 |
|
|
mod_add_cmd(&topic_msgtab); |
| 198 |
|
|
} |
| 199 |
|
|
|
| 200 |
|
|
static void |
| 201 |
|
|
module_exit(void) |
| 202 |
|
|
{ |
| 203 |
|
|
mod_del_cmd(&topic_msgtab); |
| 204 |
|
|
} |
| 205 |
|
|
|
| 206 |
michael |
2820 |
struct module module_entry = |
| 207 |
|
|
{ |
| 208 |
michael |
1230 |
.version = "$Revision$", |
| 209 |
|
|
.modinit = module_init, |
| 210 |
|
|
.modexit = module_exit, |
| 211 |
|
|
}; |