Anyway, this module is a port of the /remove command used on freenode with a few tweaks. It hasn't been tested on networks with multiple servers simply because I don't have a test network to do that, but it has been well-tested on a single-server network (running services, of course). If you feel like testing it on a network with multiple servers for me, pm me so I can send you my test cases.
This module is licensed under the GPL and uses code from m_sapart.c (the /sapart command), and m_kick.c (the /kick command).
Features:
- Forces a user to part a channel, preventing auto-rejoin
- Requires +o or above to use
- Channel hierarchy is maintained (+o and +a cannot remove +aq or services)
- OperOverride allows opers to remove any user from any channel (including channels they have not joined)
- Part reason is prefixed with "Requested by nick", where the nick is the user issuing the command
- Works for multiple users and multiple channels in one command
/REMOVE #channel User => * User has left #channel (Requested by Skizzerz)
/REMOVE #channel User insert reason here => * User has left #channel (Requested by Skizzerz: insert reason here)
m_remove.c:
Code: Select all
/*
* remove command by Skizzerz, modified from m_sapart.c and m_kick.c
* Allows Channel Operators (chmode +o) or above to force a user (or users) to part the channel(s)
* The part reason is prefixed with "Requested by name", where name is the user who issued the command
* Usage: /remove <channel> <nick> [reason]
* Multiple users/channels may be specified as a comma-seperated list (no spaces!)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "proto.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif
DLLFUNC int m_remove(aClient *cptr, aClient *sptr, int parc, char *parv[]);
#define MSG_REMOVE "REMOVE"
#define TOK_REMOVE "BY"
#ifdef PREFIX_AQ
#define CHFL_ISOP (CHFL_CHANOWNER|CHFL_CHANPROT|CHFL_CHANOP)
#else
#define CHFL_ISOP (CHFL_CHANOP)
#endif
ModuleHeader MOD_HEADER(m_remove)
= {
"m_remove",
"$Id: m_remove.c,v 1.0 2008/11/10 17:26:00 skizzerz Exp $",
"command /remove",
"3.2-b8-1",
NULL
};
DLLFUNC int MOD_INIT(m_remove)(ModuleInfo *modinfo)
{
add_Command(MSG_REMOVE, TOK_REMOVE, m_remove, 3);
return MOD_SUCCESS;
}
DLLFUNC int MOD_LOAD(m_remove)(int module_load)
{
return MOD_SUCCESS;
}
DLLFUNC int MOD_UNLOAD(m_remove)(int module_unload)
{
if (del_Command(MSG_REMOVE, TOK_REMOVE, m_remove) < 0)
{
sendto_realops("Failed to delete commands when unloading %s",
MOD_HEADER(m_remove).name);
}
return MOD_SUCCESS;
}
/* m_remove() - Lamego - Wed Jul 21 20:04:48 1999
Copied off PTlink IRCd (C) PTlink coders team.
Coded for Sadmin by Stskeeps
also Modified by NiQuiL ([email protected])
further modified by Skizzerz ([email protected])
parv[0] - sender
parv[1] - channel(s) to part
parv[2] - nick to make part
parv[3] - comment
*/
DLLFUNC CMD_FUNC(m_remove)
{
aClient *acptr;
aChannel *chptr;
Membership *lp;
char *name = NULL, *user = NULL, *p = NULL, *p2 = NULL;
char *comment = (parc > 3 && parv[3] ? parv[3] : NULL);
char commentx[512] = {0};
char errbuf[NICKLEN+30] = {0};
long acptr_flags = 0;
long sptr_flags = 0;
char *temp = parv[2]; //holds parv[2] so that we can work off the same list of users on multiple channels
char *args[3] = {0}; //args for passing to the PART command so we don't overwrite parv
if (parc < 3)
{
sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "REMOVE");
return 0;
}
if (MyClient(sptr))
{
for (; (name = strtoken(&p, parv[1], ",")); parv[1] = NULL)
{
sptr_flags = 0;
if (!(chptr = get_channel(sptr, name, !CREATE)))
{
sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], name);
continue;
}
/* Store "sptr" access flags */
if (IsPerson(sptr))
sptr_flags = get_access(sptr, chptr);
if (!IsServer(cptr) && !IsULine(sptr) && !op_can_override(sptr) && !(sptr_flags & CHFL_ISOP))
{
sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED), me.name, parv[0], chptr->chname);
continue;
}
temp = parv[2];
for (; (user = strtoken(&p2, temp, ",")); temp = NULL)
{
acptr_flags = 0;
if (!(acptr = find_person(user, NULL)))
{
sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], user);
continue;
}
if (!acptr->user)
continue;
if (!(lp = find_membership_link(acptr->user->channel, chptr)))
{
sendto_one(sptr, err_str(ERR_USERNOTINCHANNEL), me.name, parv[0], chptr, name);
continue;
}
if (IsULine(sptr) || IsServer(sptr))
goto remove; //U-lines/servers get through all the checks
// removing self == ok
if (sptr == acptr)
goto remove;
acptr_flags = get_access(acptr, chptr);
/*
* is this an OperOverride? Checks for the following:
* are we not opped on the channel?
* is the target +a/+q/services and we aren't +q?
*/
if (op_can_override(sptr)
&& (!(sptr_flags & CHFL_ISOP)
|| (((acptr_flags & (CHFL_CHANOWNER|CHFL_CHANPROT)) || IsServices(acptr))
&& !(sptr_flags & CHFL_CHANOWNER))))
{
if (comment)
{
sendto_snomask(SNO_EYES,
"*** OperOverride -- %s (%s@%s) REMOVE %s %s (%s)",
sptr->name, sptr->user->username, sptr->user->realhost,
chptr->chname, acptr->name, comment);
ircd_log(LOG_OVERRIDE,"OVERRIDE: %s (%s@%s) REMOVE %s %s (%s)",
sptr->name, sptr->user->username, sptr->user->realhost,
chptr->chname, acptr->name, comment);
}
else
{
sendto_snomask(SNO_EYES,
"*** OperOverride -- %s (%s@%s) REMOVE %s %s",
sptr->name, sptr->user->username, sptr->user->realhost,
chptr->chname, acptr->name);
ircd_log(LOG_OVERRIDE,"OVERRIDE: %s (%s@%s) REMOVE %s %s",
sptr->name, sptr->user->username, sptr->user->realhost,
chptr->chname, acptr->name);
}
goto remove;
}
// is the target user +a/+q/services and we aren't +q?
if ((acptr_flags & (CHFL_CHANOWNER|CHFL_CHANPROT) || IsServices(acptr))
&& !(sptr_flags & CHFL_CHANOWNER))
{
if (acptr_flags & CHFL_CHANOWNER)
{
strncpy(errbuf, acptr->name, sizeof(errbuf));
strncat(errbuf, " is a channel owner", sizeof(errbuf));
}
else if (acptr_flags & CHFL_CHANPROT)
{
strncpy(errbuf, acptr->name, sizeof(errbuf));
strncat(errbuf, " is a channel admin", sizeof(errbuf));
}
else
{
strncpy(errbuf, acptr->name, sizeof(errbuf));
strncat(errbuf, " is a network service", sizeof(errbuf));
}
sendto_one(sptr, err_str(ERR_CANNOTDOCOMMAND), me.name, sptr->name, "REMOVE", errbuf);
continue;
}
remove:
if (comment)
{
strncpy(commentx, "Requested by ", sizeof(commentx));
strncat(commentx, sptr->name, sizeof(commentx));
strncat(commentx, ": ", sizeof(commentx));
strncat(commentx, comment, sizeof(commentx));
}
else
{
strncpy(commentx, "Requested by ", sizeof(commentx));
strncat(commentx, sptr->name, sizeof(commentx));
}
args[0] = acptr->name; // nick
args[1] = chptr->chname; // chan
args[2] = commentx; // comment
do_cmd(acptr, acptr, "PART", 3, args);
} // end of user loop
} // end of channel loop
}
else
{
if (comment)
{
sendto_one(acptr, ":%s REMOVE %s %s :%s", parv[0], parv[1], parv[2], comment);
}
else
{
sendto_one(acptr, ":%s REMOVE %s %s", parv[0], parv[1], parv[2]);
}
}
return 0;
}