tried to reorder the program structure and build process
[NeonServV5.git] / src / cmd_neonserv_delban.c
1
2 #include "cmd_neonserv.h"
3
4 /*
5 * argv[0]    nick|*auth|*!*@mask
6 */
7
8 CMD_BIND(neonserv_cmd_delban) {
9     char hostmask_buffer[NICKLEN+USERLEN+HOSTLEN+3];
10     char *mask = make_banmask(argv[0], hostmask_buffer);
11     int matching_bans = 0;
12     MYSQL_RES *res;
13     MYSQL_ROW row;
14     //check if the provided mask is already banned by another ban
15     char *ban = getBanAffectingMask(chan, mask);
16     if(ban != NULL) {
17         reply(getTextBot(), user, "NS_DELBAN_BANNED_BY", mask, ban);
18         return;
19     }
20     //check if the provided mask affects any existing bans
21     char nameBuf[20];
22     printf_mysql_query("SELECT `ban_mask`, `ban_id`, `ban_timeout` FROM `bans` WHERE `ban_channel` = '%d'", chan->channel_id);
23     res = mysql_use();
24     while ((row = mysql_fetch_row(res)) != NULL) {
25         if(!match(mask, row[0])) {
26             //remove the ban
27             if(strcmp(row[2], "0")) {
28                 sprintf(nameBuf, "ban_%s", row[1]);
29                 timeq_del_name(nameBuf);
30             }
31             printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", row[1]);
32             matching_bans++;
33         }
34     }
35     if(matching_bans) {
36         putsock(client, "MODE %s -b %s", chan->name, mask);
37         reply(getTextBot(), user, "NS_DELBAN_DONE", mask, chan->name);
38         logEvent(event);
39     } else
40         reply(getTextBot(), user, "NS_DELBAN_FAIL", mask);
41 }