| 23 |
|
*/ |
| 24 |
|
|
| 25 |
|
#include "stdinc.h" |
| 26 |
< |
#include "tools.h" |
| 26 |
> |
#include "list.h" |
| 27 |
|
#include "handlers.h" |
| 28 |
|
#include "channel.h" |
| 29 |
|
#include "channel_mode.h" |
| 40 |
|
#include "parse.h" |
| 41 |
|
#include "modules.h" |
| 42 |
|
#include "packet.h" |
| 43 |
– |
#include "common.h" |
| 43 |
|
|
| 44 |
< |
static void m_topic(struct Client *, struct Client *, int, char **); |
| 46 |
< |
static void ms_topic(struct Client *, struct Client *, int, char **); |
| 44 |
> |
static void m_topic(struct Client *, struct Client *, int, char *[]); |
| 45 |
|
|
| 46 |
|
struct Message topic_msgtab = { |
| 47 |
< |
"TOPIC", 0, 0, 2, 0, MFLG_SLOW, 0, |
| 48 |
< |
{m_unregistered, m_topic, ms_topic, m_ignore, m_topic, m_ignore} |
| 47 |
> |
"TOPIC", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
| 48 |
> |
{m_unregistered, m_topic, m_topic, m_ignore, m_topic, m_ignore} |
| 49 |
|
}; |
| 50 |
|
|
| 53 |
– |
#ifndef STATIC_MODULES |
| 51 |
|
void |
| 52 |
|
_modinit(void) |
| 53 |
|
{ |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
const char *_version = "$Revision$"; |
| 67 |
– |
#endif |
| 64 |
|
|
| 65 |
|
/* m_topic() |
| 66 |
|
* parv[0] = sender prefix |
| 72 |
|
int parc, char *parv[]) |
| 73 |
|
{ |
| 74 |
|
struct Channel *chptr = NULL; |
| 79 |
– |
char *p; |
| 80 |
– |
struct Membership *ms; |
| 75 |
|
const char *from, *to; |
| 76 |
|
|
| 77 |
|
if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p)) |
| 85 |
|
to = source_p->name; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
< |
if ((p = strchr(parv[1], ',')) != NULL) |
| 95 |
< |
*p = '\0'; |
| 96 |
< |
|
| 97 |
< |
if (parv[1][0] == '\0') |
| 88 |
> |
if (EmptyString(parv[1])) |
| 89 |
|
{ |
| 90 |
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
| 91 |
|
from, to, "TOPIC"); |
| 95 |
|
if (MyClient(source_p) && !IsFloodDone(source_p)) |
| 96 |
|
flood_endgrace(source_p); |
| 97 |
|
|
| 98 |
< |
if (IsChanPrefix(*parv[1])) |
| 108 |
< |
{ |
| 109 |
< |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
| 110 |
< |
{ |
| 111 |
< |
/* if chptr isn't found locally, it =could= exist |
| 112 |
< |
* on the uplink. so forward reqeuest |
| 113 |
< |
*/ |
| 114 |
< |
if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL)) |
| 115 |
< |
{ |
| 116 |
< |
sendto_one(uplink, ":%s TOPIC %s %s", |
| 117 |
< |
ID_or_name(source_p, uplink), chptr->chname, |
| 118 |
< |
((parc > 2) ? parv[2] : "")); |
| 119 |
< |
return; |
| 120 |
< |
} |
| 121 |
< |
else |
| 122 |
< |
{ |
| 123 |
< |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
| 124 |
< |
from, to, parv[1]); |
| 125 |
< |
return; |
| 126 |
< |
} |
| 127 |
< |
} |
| 128 |
< |
|
| 129 |
< |
/* setting topic */ |
| 130 |
< |
if (parc > 2) |
| 131 |
< |
{ |
| 132 |
< |
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
| 133 |
< |
{ |
| 134 |
< |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), from, |
| 135 |
< |
to, parv[1]); |
| 136 |
< |
return; |
| 137 |
< |
} |
| 138 |
< |
if ((chptr->mode.mode & MODE_TOPICLIMIT) == 0 || |
| 139 |
< |
has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP)) |
| 140 |
< |
{ |
| 141 |
< |
char topic_info[USERHOST_REPLYLEN]; |
| 142 |
< |
ircsprintf(topic_info, "%s!%s@%s", |
| 143 |
< |
source_p->name, source_p->username, source_p->host); |
| 144 |
< |
set_channel_topic(chptr, parv[2], topic_info, CurrentTime); |
| 145 |
< |
|
| 146 |
< |
sendto_server(client_p, NULL, chptr, CAP_TS6, NOCAPS, NOFLAGS, |
| 147 |
< |
":%s TOPIC %s :%s", |
| 148 |
< |
ID(source_p), chptr->chname, |
| 149 |
< |
chptr->topic == NULL ? "" : chptr->topic); |
| 150 |
< |
sendto_server(client_p, NULL, chptr, NOCAPS, CAP_TS6, NOFLAGS, |
| 151 |
< |
":%s TOPIC %s :%s", |
| 152 |
< |
source_p->name, chptr->chname, |
| 153 |
< |
chptr->topic == NULL ? "" : chptr->topic); |
| 154 |
< |
sendto_channel_local(ALL_MEMBERS, NO, |
| 155 |
< |
chptr, ":%s!%s@%s TOPIC %s :%s", |
| 156 |
< |
source_p->name, |
| 157 |
< |
source_p->username, |
| 158 |
< |
source_p->host, |
| 159 |
< |
chptr->chname, chptr->topic == NULL ? |
| 160 |
< |
"" : chptr->topic); |
| 161 |
< |
} |
| 162 |
< |
else |
| 163 |
< |
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), |
| 164 |
< |
from, to, chptr->chname); |
| 165 |
< |
} |
| 166 |
< |
else /* only asking for topic */ |
| 167 |
< |
{ |
| 168 |
< |
if (!SecretChannel(chptr) || IsMember(source_p, chptr)) |
| 169 |
< |
{ |
| 170 |
< |
if (chptr->topic == NULL) |
| 171 |
< |
sendto_one(source_p, form_str(RPL_NOTOPIC), |
| 172 |
< |
from, to, chptr->chname); |
| 173 |
< |
else |
| 174 |
< |
{ |
| 175 |
< |
sendto_one(source_p, form_str(RPL_TOPIC), |
| 176 |
< |
from, to, |
| 177 |
< |
chptr->chname, chptr->topic); |
| 178 |
< |
|
| 179 |
< |
/* client on LL needing the topic - if we have serverhide, say |
| 180 |
< |
* its the actual LL server that set the topic, not us the |
| 181 |
< |
* uplink -- fl_ |
| 182 |
< |
*/ |
| 183 |
< |
if (ConfigServerHide.hide_servers && !MyClient(source_p) |
| 184 |
< |
&& IsCapable(client_p, CAP_LL) && ServerInfo.hub) |
| 185 |
< |
{ |
| 186 |
< |
sendto_one(source_p, form_str(RPL_TOPICWHOTIME), |
| 187 |
< |
from, to, chptr->chname, |
| 188 |
< |
client_p->name, chptr->topic_time); |
| 189 |
< |
} |
| 190 |
< |
else |
| 191 |
< |
{ |
| 192 |
< |
sendto_one(source_p, form_str(RPL_TOPICWHOTIME), |
| 193 |
< |
from, to, chptr->chname, |
| 194 |
< |
chptr->topic_info, |
| 195 |
< |
chptr->topic_time); |
| 196 |
< |
} |
| 197 |
< |
} |
| 198 |
< |
} |
| 199 |
< |
else |
| 200 |
< |
{ |
| 201 |
< |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
| 202 |
< |
from, to, chptr->chname); |
| 203 |
< |
return; |
| 204 |
< |
} |
| 205 |
< |
} |
| 206 |
< |
} |
| 207 |
< |
else |
| 98 |
> |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
| 99 |
|
{ |
| 100 |
|
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
| 101 |
|
from, to, parv[1]); |
| 211 |
– |
} |
| 212 |
– |
} |
| 213 |
– |
|
| 214 |
– |
/* |
| 215 |
– |
* ms_topic |
| 216 |
– |
* parv[0] = sender prefix |
| 217 |
– |
* parv[1] = channel name |
| 218 |
– |
* parv[2] = topic_info |
| 219 |
– |
* parv[3] = topic_info time |
| 220 |
– |
* parv[4] = new channel topic |
| 221 |
– |
* |
| 222 |
– |
* Let servers always set a topic |
| 223 |
– |
*/ |
| 224 |
– |
static void |
| 225 |
– |
ms_topic(struct Client *client_p, struct Client *source_p, |
| 226 |
– |
int parc, char *parv[]) |
| 227 |
– |
{ |
| 228 |
– |
struct Channel *chptr = NULL; |
| 229 |
– |
|
| 230 |
– |
if (!IsServer(source_p)) |
| 231 |
– |
{ |
| 232 |
– |
m_topic(client_p, source_p, parc, parv); |
| 102 |
|
return; |
| 103 |
|
} |
| 104 |
|
|
| 105 |
< |
if (parc < 5) |
| 106 |
< |
return; |
| 238 |
< |
|
| 239 |
< |
if (parv[1] && IsChanPrefix(*parv[1])) |
| 105 |
> |
/* setting topic */ |
| 106 |
> |
if (parc > 2) |
| 107 |
|
{ |
| 108 |
< |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
| 242 |
< |
return; |
| 108 |
> |
struct Membership *ms; |
| 109 |
|
|
| 110 |
< |
set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3])); |
| 110 |
> |
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
| 111 |
> |
{ |
| 112 |
> |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), from, |
| 113 |
> |
to, parv[1]); |
| 114 |
> |
return; |
| 115 |
> |
} |
| 116 |
|
|
| 117 |
< |
if (ConfigServerHide.hide_servers) |
| 117 |
> |
if (!(chptr->mode.mode & MODE_TOPICLIMIT) || |
| 118 |
> |
has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP)) |
| 119 |
|
{ |
| 120 |
< |
sendto_channel_local(ALL_MEMBERS, NO, |
| 249 |
< |
chptr, ":%s TOPIC %s :%s", |
| 250 |
< |
me.name, chptr->chname, |
| 251 |
< |
chptr->topic == NULL ? "" : chptr->topic); |
| 120 |
> |
char topic_info[USERHOST_REPLYLEN]; |
| 121 |
|
|
| 122 |
+ |
snprintf(topic_info, sizeof(topic_info), "%s!%s@%s", source_p->name, |
| 123 |
+ |
source_p->username, source_p->host); |
| 124 |
+ |
set_channel_topic(chptr, parv[2], topic_info, CurrentTime); |
| 125 |
+ |
|
| 126 |
+ |
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
| 127 |
+ |
":%s TOPIC %s :%s", |
| 128 |
+ |
ID(source_p), chptr->chname, |
| 129 |
+ |
chptr->topic); |
| 130 |
+ |
sendto_server(client_p, chptr, NOCAPS, CAP_TS6, |
| 131 |
+ |
":%s TOPIC %s :%s", |
| 132 |
+ |
source_p->name, chptr->chname, |
| 133 |
+ |
chptr->topic); |
| 134 |
+ |
sendto_channel_local(ALL_MEMBERS, 0, |
| 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); |
| 140 |
|
} |
| 141 |
|
else |
| 142 |
+ |
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), |
| 143 |
+ |
from, to, chptr->chname); |
| 144 |
+ |
} |
| 145 |
+ |
else /* only asking for topic */ |
| 146 |
+ |
{ |
| 147 |
+ |
if (!SecretChannel(chptr) || IsMember(source_p, chptr)) |
| 148 |
|
{ |
| 149 |
< |
sendto_channel_local(ALL_MEMBERS, NO, |
| 150 |
< |
chptr, ":%s TOPIC %s :%s", |
| 151 |
< |
source_p->name, |
| 152 |
< |
chptr->chname, chptr->topic == NULL ? "" : chptr->topic); |
| 149 |
> |
if (chptr->topic[0] == '\0') |
| 150 |
> |
sendto_one(source_p, form_str(RPL_NOTOPIC), |
| 151 |
> |
from, to, chptr->chname); |
| 152 |
> |
else |
| 153 |
> |
{ |
| 154 |
> |
sendto_one(source_p, form_str(RPL_TOPIC), |
| 155 |
> |
from, to, |
| 156 |
> |
chptr->chname, chptr->topic); |
| 157 |
> |
sendto_one(source_p, form_str(RPL_TOPICWHOTIME), |
| 158 |
> |
from, to, chptr->chname, |
| 159 |
> |
chptr->topic_info, |
| 160 |
> |
chptr->topic_time); |
| 161 |
> |
} |
| 162 |
|
} |
| 163 |
+ |
else |
| 164 |
+ |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
| 165 |
+ |
from, to, chptr->chname); |
| 166 |
|
} |
| 167 |
|
} |