3 * argv[0-*] nick[,*auth[,*!*@mask[...]]]
5 static USERLIST_CALLBACK(neonserv_cmd_ban_userlist_lookup);
6 static void neonserv_cmd_ban_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *masks);
8 struct neonserv_cmd_ban_cache {
9 struct ClientSocket *client, *textclient;
10 struct UserNode *user;
14 static CMD_BIND(neonserv_cmd_ban) {
15 struct neonserv_cmd_ban_cache *cache = malloc(sizeof(*cache));
17 perror("malloc() failed");
20 cache->client = client;
21 cache->textclient = getTextBot();
23 cache->masks = strdup(merge_argv_char(argv, 0, argc, ','));
24 get_userlist(chan, neonserv_cmd_ban_userlist_lookup, cache);
27 static USERLIST_CALLBACK(neonserv_cmd_ban_userlist_lookup) {
28 struct neonserv_cmd_ban_cache *cache = data;
29 neonserv_cmd_ban_async1(cache->client, cache->textclient, cache->user, chan, cache->masks);
34 static void neonserv_cmd_ban_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *masks) {
35 int done_masks = 0, provided_masks = 0, skip, match_count, total_match;
36 char *mask, *nextmask;
37 char hostmask_buffer[NICKLEN+USERLEN+HOSTLEN+3];
38 char usermask[NICKLEN+USERLEN+HOSTLEN+3];
39 struct UserNode *cuser;
40 struct ChanUser *chanuser;
41 struct ModeBuffer *modeBuf;
42 modeBuf = initModeBuffer(client, chan);
44 while((mask = nextmask)) {
45 nextmask = strstr(mask, ",");
53 mask = make_banmask(mask, hostmask_buffer);
54 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
55 cuser = chanuser->user;
56 sprintf(usermask, "%s!%s@%s", cuser->nick, cuser->ident, cuser->host);
57 if(!match(mask, usermask)) {
58 cuser->flags |= USERFLAG_SCRIPTFLAG1; //we mark the user as 'matching'
59 if(isNetworkService(chanuser->user)) {
60 reply(textclient, user, "NS_SERVICE_IMMUNE", chanuser->user->nick);
64 if(isUserProtected(chan, cuser, user)) {
65 reply(textclient, user, "NS_USER_PROTECTED", cuser->nick);
70 if(match_count > 4 && (match_count * 3) > chan->usercount && !isGodMode(user)) {
72 reply(textclient, user, "NS_LAME_MASK", mask);
79 modeBufferBan(modeBuf, mask);
82 total_match = 0; // count all users marked as 'matching'
83 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
84 cuser = chanuser->user;
85 if(cuser->flags & USERFLAG_SCRIPTFLAG1) {
86 cuser->flags &= ~USERFLAG_SCRIPTFLAG1;
90 freeModeBuffer(modeBuf);
91 if(done_masks == provided_masks)
92 reply(getTextBot(), user, "NS_BAN_DONE", done_masks, chan->name, total_match);
94 reply(getTextBot(), user, "NS_BAN_FAIL", client->user->nick);