Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_remove.c
blobf87eccce246107b3a2028a996e0fff8a6e8535ca
1 #include "stdinc.h"
2 #include "modules.h"
3 #include "client.h"
4 #include "ircd.h"
5 #include "send.h"
6 #include "numeric.h"
7 #include "s_serv.h"
8 #include "hash.h"
9 #include "channel.h"
10 #include "packet.h"
12 #define mg_remove {m_remove, 0}
14 static int m_remove (struct Client *client_p, struct Client *source_p, int parc, const char **parv);
16 /* {{{ struct Message remove_msgtab = { ... } */
17 struct Message remove_msgtab =
19 "REMOVE", 0, 0, 0, MFLG_SLOW,
21 mg_unreg,
22 mg_remove,
23 mg_remove,
24 mg_remove,
25 mg_ignore,
26 mg_remove,
29 /* }}} */
31 /* {{{ mapi_clist_av1 remove_clist[] = { ... } */
32 mapi_clist_av1 remove_clist[] =
34 &remove_msgtab,
35 NULL,
37 /* }}} */
39 /* {{{ DECLARE_MODULE_AV1(...) */
40 DECLARE_MODULE_AV1
42 remove,
43 NULL,
44 NULL,
45 remove_clist,
46 NULL,
47 NULL,
48 "$Revision$"
50 /* }}} */
52 /* {{{ static int m_remove()
54 * REMOVE <channel> <nick> [<reason>]
56 * parv[0] - prefix
57 * parv[1] - channel
58 * parv[2] - nick
59 * parv[3] - reason
62 static int
63 m_remove (struct Client *client_p, struct Client *source_p, int parc, const char **parv)
65 uint8_t have_reason = 0;
66 char reason_buf[REASONLEN + 1];
67 const char *p = NULL;
68 struct Channel *chptr = NULL;
69 struct membership *msptr = NULL;
70 struct Client *target_p = NULL;
71 int chasing = 0;
73 if (MyClient(source_p) && !IsFloodDone(source_p))
74 flood_endgrace(source_p);
76 if (parc < 3)
78 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "REMOVE");
79 return 0;
82 if (parc > 3 && *parv[3])
83 have_reason = 1;
85 ircsnprintf(reason_buf, sizeof(reason_buf), "requested by %s%s%s%s",
86 source_p->name,
87 !have_reason ? "" : ": \"",
88 !have_reason ? "" : parv[3],
89 !have_reason ? "" : "\"");
90 reason_buf[REASONLEN] = '\0';
92 p = strchr(parv[1], ',');
93 if (!p)
94 p = parv[1];
96 chptr = find_channel(p);
97 if (!p)
99 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), me.name, source_p->name, p);
100 return 0;
103 if (!IsServer(source_p) && !IsOverride(source_p))
105 msptr = find_channel_membership(chptr, source_p);
106 if (!msptr && MyConnect(source_p))
108 sendto_one(source_p, form_str(ERR_NOTONCHANNEL), me.name, source_p->name, p);
109 return 0;
113 * Nicked from m_kick.c; see that file for reasoning behind the
114 * code below...
117 if(!is_chanop(msptr))
119 if(MyConnect(source_p))
121 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
122 me.name, source_p->name, p);
123 return 0;
126 /* If its a TS 0 channel, do it the old way */
127 if(chptr->channelts == 0)
129 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
130 get_id(&me, source_p), get_id(source_p, source_p), p);
131 return 0;
136 p = strchr(parv[2], ',');
137 if (!p)
138 p = parv[2];
140 target_p = find_chasing(source_p, p, &chasing);
141 if (!target_p)
142 return 0;
144 msptr = find_channel_membership(chptr, target_p);
145 if (!msptr)
147 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, form_str(ERR_USERNOTINCHANNEL),
148 p, chptr->chname);
149 return 0;
152 if (MyClient(source_p))
154 if (IsService(target_p))
156 sendto_one(source_p, form_str(ERR_ISCHANSERVICE), me.name, source_p->name,
157 p, chptr->chname);
158 return 0;
160 else if (IsOverride(target_p))
162 sendto_one_numeric(source_p, ERR_ISCHANSERVICE,
163 "%s %s User is immune from kick", target_p->name, chptr->chname);
164 return 0;
168 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s",
169 target_p->name, target_p->username, target_p->host,
170 chptr->chname, reason_buf);
172 /* propagate to TS6 servers that support REMOVE. */
173 sendto_server(client_p, chptr, CAP_TS6 | CAP_REMOVE, NOCAPS,
174 ":%s REMOVE %s %s %s%s", use_id(source_p), chptr->chname, use_id(target_p),
175 !have_reason ? "" : ":",
176 !have_reason ? "" : parv[3]);
178 /* ...and to those that do not, translating to KICK. */
179 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
180 ":%s KICK %s %s %s%s",
181 use_id(source_p), chptr->chname, use_id(target_p),
182 !have_reason ? "" : ":",
183 !have_reason ? "" : parv[3]);
184 sendto_server(client_p, chptr, NOCAPS, CAP_TS6,
185 ":%s KICK %s %s %s%s",
186 source_p->name, chptr->chname, target_p->name,
187 !have_reason ? "" : ":",
188 !have_reason ? "" : parv[3]);
190 remove_user_from_channel(msptr);
192 return 0;
194 /* }}} */
197 * vim: ts=8 sw=8 noet fdm=marker tw=80