| 1 |
adx |
30 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
7924 |
* Copyright (c) 1997-2017 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 |
4565 |
* 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 |
5538 |
#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 |
7090 |
* - parv[2] = topic text, if setting topic (can be an empty string) |
| 54 |
adx |
30 |
*/ |
| 55 |
michael |
2820 |
static int |
| 56 |
michael |
3156 |
m_topic(struct Client *source_p, int parc, char *parv[]) |
| 57 |
adx |
30 |
{ |
| 58 |
|
|
struct Channel *chptr = NULL; |
| 59 |
|
|
|
| 60 |
michael |
885 |
if (EmptyString(parv[1])) |
| 61 |
adx |
30 |
{ |
| 62 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC"); |
| 63 |
michael |
2820 |
return 0; |
| 64 |
adx |
30 |
} |
| 65 |
|
|
|
| 66 |
michael |
1799 |
if (!IsFloodDone(source_p)) |
| 67 |
adx |
30 |
flood_endgrace(source_p); |
| 68 |
|
|
|
| 69 |
michael |
895 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
| 70 |
adx |
30 |
{ |
| 71 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
| 72 |
michael |
2820 |
return 0; |
| 73 |
michael |
895 |
} |
| 74 |
|
|
|
| 75 |
|
|
/* setting topic */ |
| 76 |
|
|
if (parc > 2) |
| 77 |
|
|
{ |
| 78 |
michael |
4815 |
const struct Membership *member = NULL; |
| 79 |
michael |
895 |
|
| 80 |
michael |
4815 |
if ((member = find_channel_link(source_p, chptr)) == NULL) |
| 81 |
adx |
30 |
{ |
| 82 |
michael |
4618 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name); |
| 83 |
michael |
2820 |
return 0; |
| 84 |
adx |
30 |
} |
| 85 |
|
|
|
| 86 |
michael |
8044 |
if (!HasCMode(chptr, MODE_TOPICLIMIT) || |
| 87 |
|
|
has_member_flags(member, CHFL_CHANOP | CHFL_HALFOP)) |
| 88 |
adx |
30 |
{ |
| 89 |
michael |
6932 |
char topic_info[NICKLEN + USERLEN + HOSTLEN + 3]; /* +3 for !, @, \0 */ |
| 90 |
michael |
885 |
|
| 91 |
michael |
1203 |
snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name, |
| 92 |
|
|
source_p->username, source_p->host); |
| 93 |
michael |
3941 |
channel_set_topic(chptr, parv[2], topic_info, CurrentTime, 1); |
| 94 |
adx |
30 |
|
| 95 |
michael |
4962 |
sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s", |
| 96 |
michael |
4618 |
source_p->id, chptr->name, |
| 97 |
michael |
1203 |
chptr->topic); |
| 98 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s TOPIC %s :%s", |
| 99 |
michael |
895 |
source_p->name, |
| 100 |
|
|
source_p->username, |
| 101 |
|
|
source_p->host, |
| 102 |
michael |
4618 |
chptr->name, chptr->topic); |
| 103 |
adx |
30 |
} |
| 104 |
michael |
895 |
else |
| 105 |
michael |
4618 |
sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->name); |
| 106 |
michael |
895 |
} |
| 107 |
|
|
else /* only asking for topic */ |
| 108 |
|
|
{ |
| 109 |
|
|
if (!SecretChannel(chptr) || IsMember(source_p, chptr)) |
| 110 |
adx |
30 |
{ |
| 111 |
michael |
1203 |
if (chptr->topic[0] == '\0') |
| 112 |
michael |
4618 |
sendto_one_numeric(source_p, &me, RPL_NOTOPIC, chptr->name); |
| 113 |
adx |
30 |
else |
| 114 |
|
|
{ |
| 115 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_TOPIC, |
| 116 |
michael |
4618 |
chptr->name, chptr->topic); |
| 117 |
|
|
sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->name, |
| 118 |
michael |
3109 |
chptr->topic_info, |
| 119 |
|
|
chptr->topic_time); |
| 120 |
adx |
30 |
} |
| 121 |
|
|
} |
| 122 |
|
|
else |
| 123 |
michael |
4618 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name); |
| 124 |
adx |
30 |
} |
| 125 |
michael |
2820 |
|
| 126 |
|
|
return 0; |
| 127 |
adx |
30 |
} |
| 128 |
michael |
1230 |
|
| 129 |
michael |
3332 |
|
| 130 |
|
|
/*! \brief TOPIC command handler |
| 131 |
|
|
* |
| 132 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 133 |
|
|
* originally comes from. This can be a local or remote client. |
| 134 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 135 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 136 |
|
|
* pointers. |
| 137 |
|
|
* \note Valid arguments for this command are: |
| 138 |
|
|
* - parv[0] = command |
| 139 |
|
|
* - parv[1] = channel name |
| 140 |
michael |
7090 |
* - parv[2] = topic text (can be an empty string) |
| 141 |
michael |
3332 |
*/ |
| 142 |
michael |
2820 |
static int |
| 143 |
michael |
3156 |
ms_topic(struct Client *source_p, int parc, char *parv[]) |
| 144 |
michael |
1799 |
{ |
| 145 |
|
|
struct Channel *chptr = NULL; |
| 146 |
michael |
6932 |
char topic_info[NICKLEN + USERLEN + HOSTLEN + 3]; /* +3 for !, @, \0 */ |
| 147 |
michael |
1799 |
|
| 148 |
michael |
7088 |
if (parc < 3) |
| 149 |
michael |
1799 |
{ |
| 150 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "TOPIC"); |
| 151 |
michael |
2820 |
return 0; |
| 152 |
michael |
1799 |
} |
| 153 |
|
|
|
| 154 |
|
|
if ((chptr = hash_find_channel(parv[1])) == NULL) |
| 155 |
|
|
{ |
| 156 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
| 157 |
michael |
2820 |
return 0; |
| 158 |
michael |
1799 |
} |
| 159 |
|
|
|
| 160 |
|
|
if (!IsClient(source_p)) |
| 161 |
|
|
strlcpy(topic_info, source_p->name, sizeof(topic_info)); |
| 162 |
|
|
else |
| 163 |
|
|
snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name, |
| 164 |
|
|
source_p->username, source_p->host); |
| 165 |
michael |
3941 |
channel_set_topic(chptr, parv[2], topic_info, CurrentTime, 0); |
| 166 |
michael |
1799 |
|
| 167 |
michael |
4962 |
sendto_server(source_p, 0, 0, ":%s TOPIC %s :%s", |
| 168 |
michael |
4618 |
source_p->id, chptr->name, |
| 169 |
michael |
1799 |
chptr->topic); |
| 170 |
|
|
|
| 171 |
|
|
if (!IsClient(source_p)) |
| 172 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s TOPIC %s :%s", |
| 173 |
michael |
5752 |
(IsHidden(source_p) || ConfigServerHide.hide_servers) ? me.name : source_p->name, |
| 174 |
michael |
4618 |
chptr->name, chptr->topic); |
| 175 |
michael |
1799 |
|
| 176 |
|
|
else |
| 177 |
michael |
6759 |
sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s TOPIC %s :%s", |
| 178 |
michael |
1799 |
source_p->name, |
| 179 |
|
|
source_p->username, |
| 180 |
|
|
source_p->host, |
| 181 |
michael |
4618 |
chptr->name, chptr->topic); |
| 182 |
michael |
2820 |
return 0; |
| 183 |
michael |
1799 |
} |
| 184 |
|
|
|
| 185 |
|
|
|
| 186 |
michael |
2820 |
static struct Message topic_msgtab = |
| 187 |
|
|
{ |
| 188 |
michael |
5881 |
.cmd = "TOPIC", |
| 189 |
|
|
.args_min = 2, |
| 190 |
|
|
.args_max = MAXPARA, |
| 191 |
|
|
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
| 192 |
|
|
.handlers[CLIENT_HANDLER] = m_topic, |
| 193 |
|
|
.handlers[SERVER_HANDLER] = ms_topic, |
| 194 |
|
|
.handlers[ENCAP_HANDLER] = m_ignore, |
| 195 |
|
|
.handlers[OPER_HANDLER] = m_topic |
| 196 |
michael |
1230 |
}; |
| 197 |
|
|
|
| 198 |
|
|
static void |
| 199 |
|
|
module_init(void) |
| 200 |
|
|
{ |
| 201 |
|
|
mod_add_cmd(&topic_msgtab); |
| 202 |
|
|
} |
| 203 |
|
|
|
| 204 |
|
|
static void |
| 205 |
|
|
module_exit(void) |
| 206 |
|
|
{ |
| 207 |
|
|
mod_del_cmd(&topic_msgtab); |
| 208 |
|
|
} |
| 209 |
|
|
|
| 210 |
michael |
2820 |
struct module module_entry = |
| 211 |
|
|
{ |
| 212 |
michael |
1230 |
.version = "$Revision$", |
| 213 |
|
|
.modinit = module_init, |
| 214 |
|
|
.modexit = module_exit, |
| 215 |
|
|
}; |