/********************************************************************* * IRCd-ratbox * m_sanick: change a user's nick: ops only * * Copyright (C) 2005 ASO Development Team * * Bob Krouse * NoUse * * 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 "stdinc.h" #include "modules.h" #include "msg.h" #include "hook.h" #include "client.h" #include "ircd.h" #include "send.h" #include "tools.h" #include "channel.h" #include "client.h" #include "irc_string.h" #include "numeric.h" #include "msg.h" #include "parse.h" #include "hash.h" #include "packet.h" #include "s_serv.h" #include "s_newconf.h" extern void change_local_nick(struct Client *client_p, struct Client *source_p, char *nick); /* #define __EVIL_SANICK */ /* Evil Sanick is NoUse's funny way of teaching non-opers to leave it alone */ #ifdef __EVIL_SANICK static int munreg_sanick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); static int mclient_sanick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); static int mserver_sanick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); static int mrclient_sanick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); #endif /* __EVIL_SANICK */ static int moper_sanick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); struct Message sanick_msgtab = { "sanick", 0,0,0,MFLG_SLOW, { #ifdef __EVIL_SANICK {munreg_sanick, 0}, /* unreg -NoUse */ {mclient_sanick, 0}, /* local -NoUse */ mg_ignore, /* remote -lovepump */ mg_ignore, /* server -lovepump */ mg_ignore, /* ENCAP */ #else mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, #endif /* __EVIL_SANICK */ {moper_sanick, 2} /* ops -lovepump */ } }; mapi_clist_av1 sanick_clist[] = { &sanick_msgtab, NULL }; DECLARE_MODULE_AV1( sanick, NULL, NULL, sanick_clist, NULL, NULL, "$Revision: 0.01 $"); static int validate_nick(char *nick) { if(nick == NULL) return 0; if(nick[0] == '-' || IsDigit(*nick) || strlen(nick) == 0) return 0; while(*nick != NULL) { if(!IsNickChar(nick)) return 0; nick++; } return 1; } #ifdef __EVIL_SANICK /* unreg */ static int munreg_sanick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { struct Channel *chptr; struct membership *msptr; chptr = find_channel(source_p->name); msptr = find_channel_membership(chptr, client_p); sendto_one(source_p, ":%s NOTICE %s :You are unregistered, goodbye (_)_):::D", me.name, source_p->name); sendto_channel_local(ALL_MEMBERS, chptr, ":%s KICK %s %s :%s",me.name, chptr->chname, source_p->name, "Fuck off!"); sendto_server(&me, chptr, NOCAPS, NOCAPS, ":%s KICK %s %s :%s", me.name, chptr->chname, source_p->name, "Fuck off!"); remove_user_from_channel(msptr); return 0; } /* local non op */ static int mclient_sanick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { struct Channel *chptr; struct membership *msptr; chptr = find_channel(source_p->name); msptr = find_channel_membership(chptr, client_p); sendto_one(source_p, ":%s NOTICE %s :You are unregistered, goodbye (_)_):::D", me.name, source_p->name); sendto_channel_local(ALL_MEMBERS, chptr, ":%s KICK %s %s :%s",me.name, chptr->chname, source_p->name, "Fuck off!"); sendto_server(&me, chptr, NOCAPS, NOCAPS, ":%s KICK %s %s :%s", me.name, chptr->chname, source_p->name, "Fuck off!"); remove_user_from_channel(msptr); return 0; } #endif static int moper_sanick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { struct Client *target_p; char new_nick[NICKLEN]; if(parc < 2) { sendto_one(source_p, ":%s ERROR %s : Incorrect Syntax.", me.name, source_p->name); return 0; } /* Ensure source is an oper */ if(!IsOperAdmin(source_p)) { sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "sanick"); return 0; } /* Valid target nick? If not, quit */ if((target_p = find_client(parv[1])) == NULL) { sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]); return 0; } strlcpy(new_nick, parv[2], sizeof(new_nick)); if(!validate_nick(new_nick)) { sendto_one(source_p, ":%s NOTICE %s: Invalid Target Nick %s", me.name, source_p->name, new_nick); return 0; } /* Now make sure the new nick is not a duplicate of an existing nick */ if(find_client(new_nick) != NULL) { sendto_one(source_p, ":%s NOTICE %s : *** Notice, nick %s is in use.", me.name, source_p->name, parv[2]); return 0; } change_local_nick(target_p, target_p, new_nick); return 0; }