2 * ircd-ratbox: A slightly useful ircd.
3 * m_topic.c: Sets a channel topic.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
34 #include "s_newconf.h"
43 static int m_topic(struct Client
*, struct Client
*, int, const char **);
44 static int ms_topic(struct Client
*, struct Client
*, int, const char **);
46 struct Message topic_msgtab
= {
47 "TOPIC", 0, 0, 0, MFLG_SLOW
,
48 {mg_unreg
, {m_topic
, 2}, {m_topic
, 2}, {ms_topic
, 5}, mg_ignore
, {m_topic
, 2}}
51 mapi_clist_av1 topic_clist
[] = { &topic_msgtab
, NULL
};
52 DECLARE_MODULE_AV1(topic
, NULL
, NULL
, topic_clist
, NULL
, NULL
, "$Revision: 254 $");
56 * parv[1] = channel name
57 * parv[2] = new topic, if setting topic
60 m_topic(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
62 struct Channel
*chptr
= NULL
;
63 struct membership
*msptr
;
68 if((p
= strchr(parv
[1], ',')))
73 if(IsOperSpy(source_p
) && parv
[1][0] == '!')
80 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
81 me
.name
, source_p
->name
, "TOPIC");
86 if(MyClient(source_p
) && !IsFloodDone(source_p
))
87 flood_endgrace(source_p
);
89 if(!IsChannelName(name
))
91 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
92 form_str(ERR_NOSUCHCHANNEL
), name
);
96 chptr
= find_channel(name
);
100 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
101 form_str(ERR_NOSUCHCHANNEL
), name
);
108 char topic_info
[USERHOST_REPLYLEN
];
110 msptr
= find_channel_membership(chptr
, source_p
);
114 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
,
115 form_str(ERR_NOTONCHANNEL
), name
);
119 if(MyClient(source_p
) && !is_chanop_voiced(msptr
) &&
121 !add_channel_target(source_p
, chptr
))
123 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
124 me
.name
, source_p
->name
, chptr
->chname
);
128 if(MyClient(source_p
) && (chptr
->mode
.mode
& MODE_TOPICLIMIT
) && !is_any_op(msptr
))
130 if(IsOverride(source_p
))
132 sendto_wallops_flags(UMODE_WALLOP
, &me
,
133 "%s is overriding TOPIC on [%s]",
134 get_oper_name(source_p
), chptr
->chname
);
135 sendto_server(NULL
, chptr
, NOCAPS
, NOCAPS
,
136 ":%s WALLOPS :%s is overriding TOPIC on [%s]",
137 me
.name
, get_oper_name(source_p
), chptr
->chname
);
141 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
142 me
.name
, source_p
->name
, parv
[1]);
148 if(ConfigChannel
.host_in_topic
)
149 rb_sprintf(topic_info
, "%s!%s@%s",
150 source_p
->name
, source_p
->username
, source_p
->host
);
152 rb_strlcpy(topic_info
, source_p
->name
, sizeof(topic_info
));
154 set_channel_topic(chptr
, parv
[2], topic_info
, rb_current_time());
156 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
158 use_id(source_p
), chptr
->chname
,
159 chptr
->topic
== NULL
? "" : chptr
->topic
);
160 sendto_channel_local(ALL_MEMBERS
,
161 chptr
, ":%s!%s@%s TOPIC %s :%s",
162 source_p
->name
, source_p
->username
,
163 source_p
->host
, chptr
->chname
,
164 chptr
->topic
== NULL
? "" : chptr
->topic
);
167 else if(MyClient(source_p
))
170 report_operspy(source_p
, "TOPIC", chptr
->chname
);
171 if(!IsMember(source_p
, chptr
) && SecretChannel(chptr
) &&
174 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
,
175 form_str(ERR_NOTONCHANNEL
), name
);
178 if(chptr
->topic
== NULL
)
179 sendto_one(source_p
, form_str(RPL_NOTOPIC
),
180 me
.name
, source_p
->name
, name
);
183 sendto_one(source_p
, form_str(RPL_TOPIC
),
184 me
.name
, source_p
->name
, chptr
->chname
, chptr
->topic
);
186 sendto_one(source_p
, form_str(RPL_TOPICWHOTIME
),
187 me
.name
, source_p
->name
, chptr
->chname
,
188 chptr
->topic_info
, chptr
->topic_time
);
197 * parv[1] = channel name
198 * parv[2] = topic_info
199 * parv[3] = topic_info time
200 * parv[4] = new channel topic
202 * Let servers always set a topic
205 ms_topic(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
207 struct Channel
*chptr
= NULL
;
209 if(IsChannelName(parv
[1]))
211 if((chptr
= find_channel(parv
[1])) == NULL
)
214 set_channel_topic(chptr
, parv
[4], parv
[2], atoi(parv
[3]));
216 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s TOPIC %s :%s",
217 source_p
->name
, parv
[1],
218 chptr
->topic
== NULL
? "" : chptr
->topic
);