*/
CMD_BIND(neonserv_cmd_inviteme) {
- if(argc && !stricmp(argv[0], "all")) {
- //invite to all channels where autoinvite is enabled
- MYSQL_RES *res, *res2;
- MYSQL_ROW chanuserrow, defaultrow = NULL;
- printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags`, `channel_name`, `channel_getinvite` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `user_user` = '%s' AND `chanuser_flags` >= '%d'", escape_string(user->auth), DB_CHANUSER_AUTOINVITE);
- res = mysql_use();
- struct ChanUser *bchanuser;
- struct ClientSocket *bot;
- while((chanuserrow = mysql_fetch_row(res)) != NULL) {
- int userflags = atoi(chanuserrow[1]);
- if(!(userflags & DB_CHANUSER_AUTOINVITE)) continue;
- if(!(chan = getChanByName(chanuserrow[2]))) continue; //no bot is in the channel
- if((bchanuser = getChanUser(client->user, chan)) && (bchanuser->flags & CHANUSERFLAG_OPPED))
- bot = client;
- else {
- bot = getBotForChannel(chan);
- }
- if(getChanUser(user, chan)) continue; //user is already in the channel
- if(chanuserrow[3] == NULL && defaultrow == NULL) {
- printf_mysql_query("SELECT `channel_getinvite` FROM `channels` WHERE `channel_name` = 'defaults'");
- res2 = mysql_use();
- defaultrow = mysql_fetch_row(res2);
- }
- if(atoi(chanuserrow[0]) >= atoi((chanuserrow[3] ? chanuserrow[3] : defaultrow[0]))) {
- putsock(bot, "INVITE %s %s", user->nick, chan->name);
- reply(textclient, user, "NS_INVITEME_DONE", chan->name);
- }
- }
- } else {
- if(getChanUser(user, chan)) {
- reply(textclient, user, "NS_INVITEME_ON_CHAN", chan->name);
- /* BUG
- This check does not work if the user is invisible (CHMODE +D/+d)
- to fix this we'd need to request the full userlist...
- this is really senseless to invite a simple user so we simply mark this bug as unsolvable.
- */
- return;
- }
- putsock(client, "INVITE %s %s", user->nick, chan->name);
- reply(textclient, user, "NS_INVITEME_DONE", chan->name);
+ if(getChanUser(user, chan)) {
+ reply(textclient, user, "NS_INVITEME_ON_CHAN", chan->name);
+ /* BUG
+ This check does not work if the user is invisible (CHMODE +D/+d)
+ to fix this we'd need to request the full userlist...
+ this is really senseless to invite a simple user so we simply mark this bug as unsolvable.
+ */
+ return;
}
+ putsock(client, "INVITE %s %s", user->nick, chan->name);
+ reply(textclient, user, "NS_INVITEME_DONE", chan->name);
}