3 * argv[0] nick[,*auth[,*!*@mask[...]]]
6 static USERLIST_CALLBACK(neonserv_cmd_ban_userlist_lookup);
7 static void neonserv_cmd_ban_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *masks);
9 struct neonserv_cmd_ban_cache {
10 struct ClientSocket *client, *textclient;
11 struct UserNode *user;
15 static CMD_BIND(neonserv_cmd_ban) {
16 struct neonserv_cmd_ban_cache *cache = malloc(sizeof(*cache));
18 perror("malloc() failed");
21 cache->client = client;
22 cache->textclient = getTextBot();
24 cache->masks = strdup(merge_argv_char(argv, 0, argc, ','));
25 get_userlist(chan, neonserv_cmd_ban_userlist_lookup, cache);
28 static USERLIST_CALLBACK(neonserv_cmd_ban_userlist_lookup) {
29 struct neonserv_cmd_ban_cache *cache = data;
30 neonserv_cmd_ban_async1(cache->client, cache->textclient, cache->user, chan, cache->masks);
35 static void neonserv_cmd_ban_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *masks) {
36 int done_masks = 0, provided_masks = 0, skip, match_count, total_match;
37 char *mask, *nextmask;
38 char hostmask_buffer[NICKLEN+USERLEN+HOSTLEN+3];
39 char usermask[NICKLEN+USERLEN+HOSTLEN+3];
40 struct UserNode *cuser;
41 struct ChanUser *chanuser;
42 struct ModeBuffer *modeBuf;
43 modeBuf = initModeBuffer(client, chan);
46 while((mask = nextmask)) {
47 nextmask = strstr(mask, ",");
55 mask = make_banmask(mask, hostmask_buffer);
56 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
57 cuser = chanuser->user;
58 sprintf(usermask, "%s!%s@%s", cuser->nick, cuser->ident, cuser->host);
59 if(!match(mask, usermask)) {
60 cuser->flags |= USERFLAG_SCRIPTFLAG1; //we mark the user as 'matching'
61 if(isNetworkService(chanuser->user)) {
62 reply(textclient, user, "NS_SERVICE_IMMUNE", chanuser->user->nick);
66 if(isUserProtected(chan, cuser, user)) {
67 reply(textclient, user, "NS_USER_PROTECTED", cuser->nick);
72 if(match_count > 4 && (match_count * 3) > chan->usercount && !isGodMode(user)) {
74 reply(textclient, user, "NS_LAME_MASK", mask);
81 modeBufferBan(modeBuf, mask);
84 total_match = 0; // count all users marked as 'matching'
85 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
86 cuser = chanuser->user;
87 if(cuser->flags & USERFLAG_SCRIPTFLAG1) {
88 cuser->flags &= ~USERFLAG_SCRIPTFLAG1;
92 freeModeBuffer(modeBuf);
93 if(done_masks == provided_masks)
94 reply(getTextBot(), user, "NS_BAN_DONE", done_masks, chan->name, total_match);
96 reply(getTextBot(), user, "NS_BAN_FAIL", client->user->nick);