00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdinc.h"
00026 #include "tools.h"
00027 #include "handlers.h"
00028 #include "channel.h"
00029 #include "channel_mode.h"
00030 #include "client.h"
00031 #include "ircd.h"
00032 #include "numeric.h"
00033 #include "s_log.h"
00034 #include "s_serv.h"
00035 #include "send.h"
00036 #include "irc_string.h"
00037 #include "sprintf_irc.h"
00038 #include "hash.h"
00039 #include "msg.h"
00040 #include "parse.h"
00041 #include "modules.h"
00042 #include "list.h"
00043 #include "s_conf.h"
00044 #include "common.h"
00045
00046 static void mo_clearchan(struct Client *, struct Client *, int, char *[]);
00047 static void kick_list(struct Client *, struct Channel *);
00048 static void remove_our_modes(struct Channel *);
00049 static void remove_a_mode(struct Channel *, int, char);
00050
00051 struct Message clearchan_msgtab = {
00052 "CLEARCHAN", 0, 0, 2, 0, MFLG_SLOW, 0,
00053 { m_unregistered, m_not_oper, m_ignore, m_ignore, mo_clearchan, m_ignore }
00054 };
00055
00056 #ifndef STATIC_MODULES
00057 void
00058 _modinit(void)
00059 {
00060 mod_add_cmd(&clearchan_msgtab);
00061 }
00062
00063 void
00064 _moddeinit(void)
00065 {
00066 mod_del_cmd(&clearchan_msgtab);
00067 }
00068
00069 const char *_version = "$Revision: 616 $";
00070 #endif
00071
00072
00073
00074
00075
00076
00077 static void
00078 mo_clearchan(struct Client *client_p, struct Client *source_p,
00079 int parc, char *parv[])
00080 {
00081 struct Channel *chptr = NULL;
00082
00083
00084 if (!IsAdmin(source_p))
00085 {
00086 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
00087 me.name, source_p->name);
00088 return;
00089 }
00090
00091
00092
00093 if ((chptr = hash_find_channel(parv[1])) == NULL)
00094 {
00095 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
00096 me.name, source_p->name, parv[1]);
00097 return;
00098 }
00099
00100 if (IsMember(source_p, chptr))
00101 {
00102 sendto_one(source_p, ":%s NOTICE %s :*** Please part %s before using CLEARCHAN",
00103 me.name, source_p->name, chptr->chname);
00104 return;
00105 }
00106
00107 sendto_wallops_flags(UMODE_WALLOP, &me, "CLEARCHAN called for [%s] by %s!%s@%s",
00108 chptr->chname, source_p->name, source_p->username, source_p->host);
00109 sendto_server(NULL, source_p, NULL, NOCAPS, NOCAPS, LL_ICLIENT,
00110 ":%s WALLOPS :CLEARCHAN called for [%s] by %s!%s@%s",
00111 me.name, chptr->chname, source_p->name, source_p->username,
00112 source_p->host);
00113 ilog(L_NOTICE, "CLEARCHAN called for [%s] by %s!%s@%s",
00114 chptr->chname, source_p->name, source_p->username, source_p->host);
00115
00116
00117
00118
00119 remove_our_modes(chptr);
00120
00121
00122 sendto_server(client_p, source_p, chptr, CAP_TS6, NOCAPS, LL_ICLIENT,
00123 ":%s JOIN %lu %s +ntsi",
00124 source_p->id, (unsigned long)(chptr->channelts - 1),
00125 chptr->chname);
00126 sendto_server(client_p, source_p, chptr, NOCAPS, CAP_TS6,
00127 LL_ICLIENT, ":%s SJOIN %lu %s +ntsi :@%s",
00128 me.name, (unsigned long)(chptr->channelts - 1),
00129 chptr->chname, source_p->name);
00130 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s JOIN %s",
00131 source_p->name, source_p->username,
00132 source_p->host, chptr->chname);
00133 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s MODE %s +o %s",
00134 me.name, chptr->chname, source_p->name);
00135
00136
00137
00138
00139 if (chptr->channelts)
00140 --chptr->channelts;
00141
00142 chptr->mode.mode = MODE_SECRET | MODE_TOPICLIMIT |
00143 MODE_INVITEONLY | MODE_NOPRIVMSGS;
00144 free_topic(chptr);
00145 chptr->mode.key[0] = '\0';
00146
00147
00148 kick_list(source_p, chptr);
00149 }
00150
00151 static void
00152 kick_list(struct Client *source_p, struct Channel *chptr)
00153 {
00154 dlink_node *ptr = NULL, *ptr_next = NULL;
00155 struct Membership *ms = NULL;
00156
00157 DLINK_FOREACH(ptr, chptr->members.head)
00158 {
00159 ms = ptr->data;
00160
00161 sendto_channel_local(ALL_MEMBERS, NO, chptr,
00162 ":%s!%s@%s KICK %s %s CLEARCHAN",
00163 source_p->name, source_p->username,
00164 source_p->host, chptr->chname, ms->client_p->name);
00165 sendto_server(NULL, source_p, chptr, NOCAPS, NOCAPS, LL_ICLIENT,
00166 ":%s KICK %s %s :CLEARCHAN", source_p->name,
00167 chptr->chname, ms->client_p->name);
00168 }
00169
00170 add_user_to_channel(chptr, source_p, CHFL_CHANOP, NO);
00171
00172 DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
00173 {
00174 ms = ptr->data;
00175
00176 if (ms->client_p != source_p)
00177 remove_user_from_channel(ms);
00178 }
00179
00180
00181
00182
00183
00184 sendto_one(source_p, ":%s!%s@%s JOIN %s",
00185 source_p->name, source_p->username,
00186 source_p->host, chptr->chname);
00187 channel_member_names(source_p, chptr, 1);
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 static void
00200 remove_our_modes(struct Channel *chptr)
00201 {
00202 remove_a_mode(chptr, CHFL_CHANOP, 'o');
00203 #ifdef HALFOPS
00204 remove_a_mode(chptr, CHFL_HALFOP, 'h');
00205 #endif
00206 remove_a_mode(chptr, CHFL_VOICE, 'v');
00207
00208
00209 free_channel_list(&chptr->banlist);
00210 free_channel_list(&chptr->exceptlist);
00211 free_channel_list(&chptr->invexlist);
00212 }
00213
00214
00215
00216
00217
00218
00219
00220 static void
00221 remove_a_mode(struct Channel *chptr, int mask, char flag)
00222 {
00223 const dlink_node *ptr = NULL;
00224 char lmodebuf[MODEBUFLEN];
00225 const char *lpara[4] = { "", "", "", "" };
00226 char *mbuf = lmodebuf;
00227 int count = 0;
00228
00229 *mbuf++ = '-';
00230
00231 DLINK_FOREACH(ptr, chptr->members.head)
00232 {
00233 struct Membership *ms = ptr->data;
00234 if ((ms->flags & mask) == 0)
00235 continue;
00236
00237 ms->flags &= ~mask;
00238
00239 lpara[count++] = ms->client_p->name;
00240
00241 *mbuf++ = flag;
00242
00243 if (count == 4)
00244 {
00245 *mbuf = '\0';
00246 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s MODE %s %s %s %s %s %s",
00247 me.name, chptr->chname, lmodebuf, lpara[0],
00248 lpara[1], lpara[2], lpara[3]);
00249
00250 mbuf = lmodebuf;
00251 *mbuf++ = '-';
00252 count = 0;
00253 lpara[0] = lpara[1] = lpara[2] = lpara[3] = "";
00254 }
00255 }
00256
00257 if (count != 0)
00258 {
00259 *mbuf = '\0';
00260 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s MODE %s %s %s %s %s %s",
00261 me.name, chptr->chname, lmodebuf, lpara[0],
00262 lpara[1], lpara[2], lpara[3]);
00263 }
00264 }