1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_topic.c: Sets a channel topic. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "handlers.h" |
27 |
#include "channel.h" |
28 |
#include "channel_mode.h" |
29 |
#include "client.h" |
30 |
#include "hash.h" |
31 |
#include "ircd.h" |
32 |
#include "numeric.h" |
33 |
#include "send.h" |
34 |
#include "server.h" |
35 |
#include "msg.h" |
36 |
#include "parse.h" |
37 |
#include "conf/modules.h" |
38 |
#include "packet.h" |
39 |
#include "common.h" |
40 |
|
41 |
static void m_topic(struct Client *, struct Client *, int, char *[]); |
42 |
|
43 |
struct Message topic_msgtab = { |
44 |
"TOPIC", 0, 0, 2, 0, MFLG_SLOW, 0, |
45 |
{ m_unregistered, m_topic, m_topic, m_ignore, m_topic, m_ignore } |
46 |
}; |
47 |
|
48 |
INIT_MODULE(m_topic, "$Revision$") |
49 |
{ |
50 |
mod_add_cmd(&topic_msgtab); |
51 |
} |
52 |
|
53 |
CLEANUP_MODULE |
54 |
{ |
55 |
mod_del_cmd(&topic_msgtab); |
56 |
} |
57 |
|
58 |
/* m_topic() |
59 |
* parv[0] = sender prefix |
60 |
* parv[1] = channel name |
61 |
* parv[2] = new topic, if setting topic |
62 |
*/ |
63 |
static void |
64 |
m_topic(struct Client *client_p, struct Client *source_p, |
65 |
int parc, char *parv[]) |
66 |
{ |
67 |
struct Channel *chptr = NULL; |
68 |
char *p = NULL; |
69 |
struct Membership *ms = NULL; |
70 |
const char *from = NULL, *to = NULL; |
71 |
|
72 |
/* Servers do not use TOPIC, they communicate via TBURST/TB instead */ |
73 |
if (!IsClient(source_p)) |
74 |
return; |
75 |
|
76 |
if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p)) |
77 |
{ |
78 |
from = me.id; |
79 |
to = source_p->id; |
80 |
} |
81 |
else |
82 |
{ |
83 |
from = me.name; |
84 |
to = source_p->name; |
85 |
} |
86 |
|
87 |
if ((p = strchr(parv[1], ',')) != NULL) |
88 |
*p = '\0'; |
89 |
|
90 |
if (*parv[1] == '\0') |
91 |
{ |
92 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
93 |
from, to, "TOPIC"); |
94 |
return; |
95 |
} |
96 |
|
97 |
if (MyClient(source_p) && !IsFloodDone(source_p)) |
98 |
flood_endgrace(source_p); |
99 |
|
100 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
101 |
{ |
102 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
103 |
from, to, parv[1]); |
104 |
return; |
105 |
} |
106 |
|
107 |
/* setting topic */ |
108 |
if (parc > 2) |
109 |
{ |
110 |
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
111 |
{ |
112 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
113 |
from, to, parv[1]); |
114 |
return; |
115 |
} |
116 |
|
117 |
if (!(chptr->mode.mode & MODE_TOPICLIMIT) || |
118 |
has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP)) |
119 |
{ |
120 |
char topic_info[USERHOST_REPLYLEN]; |
121 |
|
122 |
ircsprintf(topic_info, "%s!%s@%s", |
123 |
source_p->name, source_p->username, source_p->host); |
124 |
set_channel_topic(chptr, parv[2], topic_info, CurrentTime); |
125 |
|
126 |
sendto_server(client_p, NULL, chptr, CAP_TS6, NOCAPS, |
127 |
":%s TOPIC %s :%s", |
128 |
ID(source_p), chptr->chname, |
129 |
chptr->topic == NULL ? "" : chptr->topic); |
130 |
sendto_server(client_p, NULL, chptr, NOCAPS, CAP_TS6, |
131 |
":%s TOPIC %s :%s", |
132 |
source_p->name, chptr->chname, |
133 |
chptr->topic == NULL ? "" : chptr->topic); |
134 |
sendto_channel_local(ALL_MEMBERS, NO, |
135 |
chptr, ":%s!%s@%s TOPIC %s :%s", |
136 |
source_p->name, |
137 |
source_p->username, |
138 |
source_p->host, |
139 |
chptr->chname, chptr->topic == NULL ? |
140 |
"" : chptr->topic); |
141 |
} |
142 |
else |
143 |
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), |
144 |
from, to, chptr->chname); |
145 |
} |
146 |
else /* only asking for topic */ |
147 |
{ |
148 |
if (!SecretChannel(chptr) || IsMember(source_p, chptr)) |
149 |
{ |
150 |
if (chptr->topic == NULL) |
151 |
sendto_one(source_p, form_str(RPL_NOTOPIC), |
152 |
from, to, chptr->chname); |
153 |
else |
154 |
{ |
155 |
sendto_one(source_p, form_str(RPL_TOPIC), |
156 |
from, to, |
157 |
chptr->chname, chptr->topic); |
158 |
sendto_one(source_p, form_str(RPL_TOPICWHOTIME), |
159 |
from, to, chptr->chname, |
160 |
chptr->topic_info, |
161 |
chptr->topic_time); |
162 |
} |
163 |
} |
164 |
else |
165 |
{ |
166 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
167 |
from, to, chptr->chname); |
168 |
} |
169 |
} |
170 |
} |