tried to reorder the program structure and build process
[NeonServV5.git] / src / cmd_neonserv_upall.c
1
2 #include "cmd_neonserv.h"
3
4 /*
5 * no arguments
6 */
7
8 CMD_BIND(neonserv_cmd_upall) {
9     MYSQL_RES *res, *default_res;
10     MYSQL_ROW row, default_row;
11     struct ChanUser *chanuser;
12     int userid, chan_getop, chan_getvoice, caccess;
13     printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", user->auth);
14     res = mysql_use();
15     if ((row = mysql_fetch_row(res)) == NULL)
16         return;
17     userid = atoi(row[0]);
18     printf_mysql_query("SELECT `chanuser_access`, `channel_getop`, `channel_getvoice`, `channel_name`, `channel_id` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` WHERE `chanuser_uid` = '%d'", userid);
19     res = mysql_use();
20     while ((row = mysql_fetch_row(res)) != NULL) {
21         chan = getChanByName(row[3]);
22         if(!chan) continue;
23         printf_mysql_query("SELECT `botid` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` WHERE `chanid` = '%s' AND `botclass` = '%d'", row[4], client->botid);
24         if (mysql_fetch_row(mysql_use()) == NULL) continue;
25         if(!(chanuser = getChanUser(user, chan))) continue;
26         if(!row[1] || !row[2]) {
27             printf_mysql_query("SELECT `channel_getop`, `channel_getvoice` FROM `channels` WHERE `channel_name` = 'defaults'");
28             default_res = mysql_use();
29             if ((default_row = mysql_fetch_row(default_res)) == NULL) return;
30             chan_getop = (row[1] ? atoi(row[1]) : atoi(default_row[0]));
31             chan_getvoice = (row[2] ? atoi(row[2]) : atoi(default_row[1]));
32         } else {
33             chan_getop = atoi(row[1]);
34             chan_getvoice = atoi(row[2]);
35         }
36         caccess = atoi(row[0]);
37         int done = 0;
38         if(caccess >= chan_getop) {
39             if(!(chanuser->flags & CHANUSERFLAG_OPPED)) {
40                 putsock(client, "MODE %s +o %s", chan->name, user->nick);
41                 done = 1;
42             }
43         } else if(caccess >= chan_getvoice) {
44             if(!(chanuser->flags & CHANUSERFLAG_VOICED)) {
45                 putsock(client, "MODE %s +v %s", chan->name, user->nick);
46                 done = 1;
47             }
48         }
49         if(done) {
50             event->chan = chan;
51             logEvent(event);
52         }
53     }
54 }