+++ /dev/null
-/* cmd_neonserv_ban.c - NeonServ v5.3
- * Copyright (C) 2011-2012 Philipp Kreil (pk910)
- *
- * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include "cmd_neonserv.h"
-
-/*
-* argv[0-*] nick[,*auth[,*!*@mask[...]]]
-*/
-static USERLIST_CALLBACK(neonserv_cmd_ban_userlist_lookup);
-static void neonserv_cmd_ban_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *masks);
-
-struct neonserv_cmd_ban_cache {
- struct ClientSocket *client, *textclient;
- struct UserNode *user;
- struct Event *event;
- char *masks;
-};
-
-CMD_BIND(neonserv_cmd_ban) {
- struct neonserv_cmd_ban_cache *cache = malloc(sizeof(*cache));
- if (!cache) {
- perror("malloc() failed");
- return;
- }
- cache->client = client;
- cache->textclient = getTextBot();
- cache->user = user;
- cache->event = event;
- cache->masks = strdup(merge_argv_char(argv, 0, argc, ','));
- get_userlist_with_invisible(chan, neonserv_cmd_ban_userlist_lookup, cache);
-}
-
-static USERLIST_CALLBACK(neonserv_cmd_ban_userlist_lookup) {
- struct neonserv_cmd_ban_cache *cache = data;
- neonserv_cmd_ban_async1(cache->client, cache->textclient, cache->user, chan, cache->event, cache->masks);
- free(cache->masks);
- free(cache);
-}
-
-static void neonserv_cmd_ban_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *masks) {
- int done_masks = 0, provided_masks = 0, skip, match_count, total_match;
- char *mask, *nextmask;
- char hostmask_buffer[NICKLEN+USERLEN+HOSTLEN+3];
- char usermask[NICKLEN+USERLEN+HOSTLEN+3];
- struct UserNode *cuser;
- struct ChanUser *chanuser;
- struct ModeBuffer *modeBuf;
- modeBuf = initModeBuffer(client, chan);
- nextmask = masks;
- while((mask = nextmask)) {
- nextmask = strstr(mask, ",");
- if(nextmask) {
- *nextmask = '\0';
- nextmask++;
- }
- provided_masks++;
- skip = 0;
- match_count = 0;
- mask = make_banmask(mask, hostmask_buffer);
- for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
- cuser = chanuser->user;
- sprintf(usermask, "%s!%s@%s", cuser->nick, cuser->ident, cuser->host);
- if(!match(mask, usermask)) {
- cuser->flags |= USERFLAG_SCRIPTFLAG1; //we mark the user as 'matching'
- if(isNetworkService(chanuser->user)) {
- reply(textclient, user, "NS_SERVICE_IMMUNE", chanuser->user->nick);
- skip = 1;
- break;
- }
- if(cuser == user || ((cuser->flags & USERFLAG_ISAUTHED) && !stricmp(user->auth, cuser->auth))) {
- reply(textclient, user, "NS_YOU_PROTECTED");
- skip = 1;
- break;
- }
- if(isUserProtected(chan, cuser, user)) {
- reply(textclient, user, "NS_USER_PROTECTED", cuser->nick);
- skip = 1;
- break;
- }
- match_count++;
- if(match_count > 4 && (match_count * 3) > chan->usercount && !isGodMode(user)) {
- skip = 1;
- reply(textclient, user, "NS_LAME_MASK", mask);
- break;
- }
- }
- }
- if(!skip) {
- done_masks++;
- modeBufferBan(modeBuf, mask);
- }
- }
- total_match = 0; // count all users marked as 'matching'
- for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
- cuser = chanuser->user;
- if(cuser->flags & USERFLAG_SCRIPTFLAG1) {
- cuser->flags &= ~USERFLAG_SCRIPTFLAG1;
- total_match++;
- }
- }
- freeModeBuffer(modeBuf);
- if(done_masks == provided_masks)
- reply(getTextBot(), user, "NS_BAN_DONE", done_masks, chan->name, total_match);
- else
- reply(getTextBot(), user, "NS_BAN_FAIL", client->user->nick);
- if(done_masks)
- logEvent(event);
-}