tried to reorder the program structure and build process
[NeonServV5.git] / src / event_neonserv_invite.c
1
2 static void neonserv_event_invite(struct ClientSocket *client, struct UserNode *user, char *channel) {
3     MYSQL_RES *res;
4     MYSQL_ROW row;
5     printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `channel_name` = '%s' AND `botclass` = '%d'", escape_string(channel), client->botid);
6     res = mysql_use();
7     if ((row = mysql_fetch_row(res)) == NULL) {
8         reply(client, user, "NS_INVITE_FAIL", channel, client->user->nick);
9         return;
10     }
11     int botid = atoi(row[0]);
12     struct ClientSocket *bot;
13     for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
14         if(bot->clientid == botid)
15             break;
16     }
17     if(bot) {
18         struct ChanNode *chan = getChanByName(channel);
19         if(chan && isUserOnChan(bot->user, chan)) {
20             reply(client, user, "NS_INVITE_ON_CHAN", bot->user->nick, chan->name);
21         } else
22             putsock(bot, "JOIN %s", channel);
23     }
24 }
25