a9fbc0025a606e342d70a6209bfa92277a6d9049
[NeonServV5.git] / src / cmd_neonserv_up.c
1 /* cmd_neonserv_up.c - NeonServ v5.1
2  * Copyright (C) 2011  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17
18 #include "cmd_neonserv.h"
19
20 /*
21 * no arguments
22 */
23
24 CMD_BIND(neonserv_cmd_up) {
25     struct ChanUser *chanuser = getChanUser(user, chan);
26     if(!chanuser) {
27         reply(getTextBot(), user, "NS_NOT_ON_CHANNEL_YOU", chan->name);
28         return;
29     }
30     check_mysql();
31     loadChannelSettings(chan);
32     MYSQL_RES *res, *default_res;
33     MYSQL_ROW row, default_row;
34     int chan_getop, chan_getvoice, caccess;
35     printf_mysql_query("SELECT `channel_getop`, `channel_getvoice` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
36     res = mysql_use();
37     if ((row = mysql_fetch_row(res)) == NULL) return;
38     if(!row[0] || !row[1]) {
39         printf_mysql_query("SELECT `channel_getop`, `channel_getvoice` FROM `channels` WHERE `channel_name` = 'defaults'");
40         default_res = mysql_use();
41         if ((default_row = mysql_fetch_row(default_res)) == NULL) return;
42         chan_getop = (row[0] ? atoi(row[0]) : atoi(default_row[0]));
43         chan_getvoice = (row[1] ? atoi(row[1]) : atoi(default_row[1]));
44     } else {
45         chan_getop = atoi(row[0]);
46         chan_getvoice = atoi(row[1]);
47     }
48     caccess = getChannelAccess(user, chan, 1);
49     if(caccess >= chan_getop) {
50         if(!(chanuser->flags & CHANUSERFLAG_OPPED)) {
51             putsock(client, "MODE %s +o %s", chan->name, user->nick);
52             logEvent(event);
53         } else
54             reply(getTextBot(), user, "NS_UP_ALREADY_OP", chan->name);
55     } else if(caccess >= chan_getvoice) {
56         if(!(chanuser->flags & CHANUSERFLAG_VOICED)) {
57             putsock(client, "MODE %s +v %s", chan->name, user->nick);
58             logEvent(event);
59         } else
60             reply(getTextBot(), user, "NS_UP_ALREADY_VOICE", chan->name);
61     } else
62         reply(getTextBot(), user, "NS_NOT_ON_USERLIST_YOU", chan->name);
63 }