/* * ================================================================= * Filename: m_rmtkl.c * Description: Command /rmtkl (Fixed Version) * Author: AngryWolf * Version: Unreal3.2 * ================================================================= */ #include "config.h" #include "struct.h" #include "common.h" #include "sys.h" #include "numeric.h" #include "msg.h" #include "channel.h" #include #include #include #include #include #ifdef _WIN32 #include #endif #include #include "h.h" #ifndef MODVAR #define MODVAR #endif #define IsParam(x) (parc > (x) && !BadPtr(parv[(x)])) #define IsNotParam(x) (parc <= (x) || BadPtr(parv[(x)])) #define DelCommand(x) if (x) CommandDel(x); x = NULL extern void sendto_one(aClient *to, char *pattern, ...); extern void sendto_serv_butone_token(aClient *one, char *prefix, char *command, char *token, char *pattern, ...); #ifdef TKLISTLEN extern MODVAR aTKline *tklines[TKLISTLEN]; #else extern aTKline *tklines; #endif static int m_rmtkl(aClient *cptr, aClient *sptr, int parc, char *parv[]); Command *CmdRmtkl = NULL; ModuleHeader MOD_HEADER(m_rmtkl) = { "rmtkl", "IRCops Olny", "Command /rmtkl - Author: AngryWolf - Globally clears all K/G/Z/Shun Lines", "3.2-b8-1", NULL }; DLLFUNC int MOD_INIT(m_rmtkl)(ModuleInfo *modinfo) { CmdRmtkl = CommandAdd(modinfo->handle, "RMTKL", NULL, m_rmtkl, 3, 0); return (CmdRmtkl ? MOD_SUCCESS : MOD_FAILED); } DLLFUNC int MOD_LOAD(m_rmtkl)(int module_load) { return MOD_SUCCESS; } DLLFUNC int MOD_UNLOAD(m_rmtkl)(int module_unload) { DelCommand(CmdRmtkl); return MOD_SUCCESS; } static void fixed_remove_shun(aTKline *tmp) { long i1, i; aClient *acptr; for (i1 = 0; i1 <= 5; i1++) { for (i = 0; i <= LastSlot; ++i) { if ((acptr = local[i])) { if (MyClient(acptr) && IsShunned(acptr)) { if (!match(tmp->hostmask, acptr->sockhost) && !match(tmp->usermask, acptr->user->username)) { ClearShunned(acptr); } } } } } } #ifdef TKLISTLEN void my_tkl_del_line(aTKline *p, int tklindex) { MyFree(p->hostmask); MyFree(p->reason); MyFree(p->setby); DelListItem(p, tklines[tklindex]); MyFree(p); } #endif static int dumpit(aClient *sptr, char **p) { for (; *p != NULL; p++) sendto_one(sptr, ":%s %03d %s :%s", me.name, RPL_TEXT, sptr->name, *p); return 0; } static char *rmtkl_help[] = { "*** Help on /rmtkl ***", "Syntax: /rmtkl [reason]", "Types: K, z, G, Z, s, *", NULL }; typedef struct { int type; char flag; char *txt; u_long oflag; } TKLType; TKLType tkl_types[] = { { TKL_KILL, 'K', "K:Line", OFLAG_KLINE }, { TKL_ZAP, 'z', "Z:Line", OFLAG_ZLINE }, { TKL_KILL|TKL_GLOBAL, 'G', "G:Line", OFLAG_TKL }, { TKL_ZAP|TKL_GLOBAL, 'Z', "GZ:Line", OFLAG_GZL }, { TKL_SHUN|TKL_GLOBAL, 's', "Shun", OFLAG_TKL }, { 0, 0, NULL, 0 } }; static TKLType *find_TKLType_by_flag(char flag) { TKLType *t; for (t = tkl_types; t->type; t++) if (t->flag == flag) return t; return NULL; } static int m_rmtkl(aClient *cptr, aClient *sptr, int parc, char *parv[]) { aTKline *tk, *next = NULL; TKLType *tkltype; char *types, *uhmask, *cmask, *p; int tklindex; if (!IsAnOper(sptr)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return -1; } if (IsNotParam(1)) return dumpit(sptr, rmtkl_help); if (IsNotParam(2)) return 0; types = parv[1]; uhmask = parv[2]; cmask = IsParam(3) ? parv[3] : NULL; if (strchr(types, '*')) types = "KzGZs"; for (p = types; *p; p++) { tkltype = find_TKLType_by_flag(*p); if (!tkltype) continue; tklindex = tkl_hash(tkltype->flag); for (tk = tklines[tklindex]; tk; tk = next) { next = tk->next; if (tk->type != tkltype->type) continue; if (match(uhmask, make_user_host(tk->usermask, tk->hostmask))) continue; if (cmask && match(cmask, tk->reason)) continue; sendto_snomask(SNO_TKL, "%s removed %s %s@%s", sptr->name, tkltype->txt, tk->usermask, tk->hostmask); if (tk->type & TKL_GLOBAL) sendto_serv_butone_token(&me, me.name, MSG_TKL, TOK_TKL, "- %c %s %s %s", tkltype->flag, tk->usermask, tk->hostmask, parv[0]); if (tk->type & TKL_SHUN) fixed_remove_shun(tk); my_tkl_del_line(tk, tklindex); } } return 0; }