execute mysql_check only if a query fails.
[NeonServV5.git] / cmd_neonserv_delban.c
1
2 /*
3 * argv[0]    nick|*auth|*!*@mask
4 */
5
6 static CMD_BIND(neonserv_cmd_delban) {
7     char hostmask_buffer[NICKLEN+USERLEN+HOSTLEN+3];
8     char *mask = make_banmask(argv[0], hostmask_buffer);
9     int matching_bans = 0;
10     MYSQL_RES *res;
11     MYSQL_ROW row;
12     //check if the provided mask is already banned by another ban
13     char *ban = getBanAffectingMask(chan, mask);
14     if(ban != NULL) {
15         reply(getTextBot(), user, "NS_DELBAN_BANNED_BY", mask, ban);
16         return;
17     }
18     //check if the provided mask affects any existing bans
19     printf_mysql_query("SELECT `ban_mask`, `ban_id` FROM `bans` WHERE `ban_channel` = '%d'", chan->channel_id);
20     res = mysql_use();
21     while ((row = mysql_fetch_row(res)) != NULL) {
22         if(!match(mask, row[0])) {
23             //remove the ban
24             printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", row[1]);
25             matching_bans++;
26         }
27     }
28     if(matching_bans) {
29         putsock(client, "MODE %s -b %s", chan->name, mask);
30         reply(getTextBot(), user, "NS_DELBAN_DONE", mask, chan->name);
31     } else
32         reply(getTextBot(), user, "NS_DELBAN_FAIL", mask);
33 }