- for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
- if(bot == client) continue;
- for(chanuser = getUserChannels(bot->user, NULL); chanuser; chanuser = getUserChannels(bot->user, chanuser)) {
- if(isUserOnChan(user, chanuser->chan)) {
- return 0;
+ char do_rejoin = 1;
+ int botcount = 0;
+ int userbots = 0;
+ for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
+ if((chanuser->flags & CHANUSERFLAG_OPPED) || !(isBot(chanuser->user) || check_userbot_rejoin(chanuser->user))) {
+ do_rejoin = 0;
+ break;
+ }
+ botcount++;
+ if(!isBot(chanuser->user))
+ userbots++;
+ }
+ if(do_rejoin) {
+ struct OplessRejoinBot *rejoin_bot;
+ struct ClientSocket *bot, *chanbot = NULL;
+ chan->rejoin_bots = NULL;
+ for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+ if(!isUserOnChan(bot->user, chan))
+ continue;
+ if(!chanbot && ((bot->flags & SOCKET_FLAG_PREFERRED) || !getBots(SOCKET_FLAG_READY, bot)))
+ chanbot = bot;
+ else {
+ rejoin_bot = malloc(sizeof(*rejoin_bot));
+ rejoin_bot->is_client = 1;
+ rejoin_bot->bot.client = bot;
+ rejoin_bot->next = chan->rejoin_bots;
+ chan->rejoin_bots = rejoin_bot;
+ putsock(bot, "PART %s :rejoining", chan->name);
+ }
+ }
+ if(userbots) {
+ char tmp[MAXLEN];
+ int sourceid;
+ for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
+ if(check_userbot_rejoin(chanuser->user)) {
+ rejoin_bot = malloc(sizeof(*rejoin_bot));
+ rejoin_bot->is_client = 0;
+ rejoin_bot->bot.userbot = malloc(sizeof(struct OplessRejoinUserbot));
+ rejoin_bot->bot.userbot->nick = strdup(chanuser->user->nick);
+ rejoin_bot->bot.userbot->auth = strdup(chanuser->user->auth);
+ rejoin_bot->next = chan->rejoin_bots;
+ chan->rejoin_bots = rejoin_bot;
+ sprintf(tmp, "General.UserBots.%s.sourcebot", chanuser->user->auth);
+ if(get_string_field(tmp)) {
+ sourceid = resolve_botalias(get_string_field(tmp));
+ if(sourceid == -1)
+ sourceid = 0;
+ } else
+ sourceid = 0;
+ bot = getChannelBot(NULL, sourceid);
+ if(!bot)
+ bot = getChannelBot(NULL, 0);
+ sprintf(tmp, "General.UserBots.%s.opless_part", chanuser->user->auth);
+ putsock(bot, get_string_field(tmp), chanuser->user->nick, chan->name);
+ }