|
@@ -598,8 +598,6 @@ getin_request(char *botnick, char *code, char *par)
|
|
|
|
|
|
|
|
if (what[0] != 'K') {
|
|
if (what[0] != 'K') {
|
|
|
if (!(channel_pending(chan) || channel_active(chan))) {
|
|
if (!(channel_pending(chan) || channel_active(chan))) {
|
|
|
- putlog(LOG_GETIN, "*", "%sreq from %s/%s %s %s - I'm not on %s right now.", type, botnick, nick, desc,
|
|
|
|
|
- chan->dname, chan->dname);
|
|
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -722,6 +720,27 @@ getin_request(char *botnick, char *code, char *par)
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Should I respond to this request?
|
|
|
|
|
+ // If there's 18 eligible bots in the channel, and in-bots is 2, I have a 2/18 chance of replying.
|
|
|
|
|
+ int eligible_bots = 0;
|
|
|
|
|
+ for (memberlist* m = chan->channel.member; m && m->nick[0]; m = m->next) {
|
|
|
|
|
+ if (chan_hasop(m)) {
|
|
|
|
|
+ member_getuser(m, 0);
|
|
|
|
|
+ if (m->user && m->user->bot) {
|
|
|
|
|
+ ++eligible_bots;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!eligible_bots) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!((randint(eligible_bots) + 1) <= static_cast<unsigned int>(in_bots))) {
|
|
|
|
|
+ // Not my turn
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
bool sendi = 0;
|
|
bool sendi = 0;
|
|
|
|
|
|
|
|
if (chan->channel.maxmembers) {
|
|
if (chan->channel.maxmembers) {
|
|
@@ -816,8 +835,10 @@ getin_request(char *botnick, char *code, char *par)
|
|
|
static void
|
|
static void
|
|
|
request_op(struct chanset_t *chan)
|
|
request_op(struct chanset_t *chan)
|
|
|
{
|
|
{
|
|
|
- if (!chan || (chan && (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan) || me_op(chan))))
|
|
|
|
|
|
|
+ if (!chan || (chan && (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan) || me_op(chan)))) {
|
|
|
|
|
+ chan->channel.do_opreq = 0;
|
|
|
return;
|
|
return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (chan->channel.no_op) {
|
|
if (chan->channel.no_op) {
|
|
|
if (chan->channel.no_op > now) /* dont op until this time has passed */
|
|
if (chan->channel.no_op > now) /* dont op until this time has passed */
|
|
@@ -826,7 +847,6 @@ request_op(struct chanset_t *chan)
|
|
|
chan->channel.no_op = 0;
|
|
chan->channel.no_op = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- chan->channel.do_opreq = 0;
|
|
|
|
|
/* check server lag */
|
|
/* check server lag */
|
|
|
if (server_lag > lag_threshold) {
|
|
if (server_lag > lag_threshold) {
|
|
|
putlog(LOG_GETIN, "*", "Not asking for ops on %s - I'm too lagged", chan->dname);
|
|
putlog(LOG_GETIN, "*", "Not asking for ops on %s - I'm too lagged", chan->dname);
|
|
@@ -986,15 +1006,17 @@ request_in(struct chanset_t *chan)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int foundBots = 0;
|
|
int foundBots = 0;
|
|
|
- char* botops[MAX_BOTS];
|
|
|
|
|
|
|
+// char* botops[MAX_BOTS];
|
|
|
|
|
|
|
|
for (tand_t* bot = tandbot; bot && (foundBots < MAX_BOTS); bot = bot->next) {
|
|
for (tand_t* bot = tandbot; bot && (foundBots < MAX_BOTS); bot = bot->next) {
|
|
|
if (bot->hub || !bot->u)
|
|
if (bot->hub || !bot->u)
|
|
|
continue;
|
|
continue;
|
|
|
|
|
|
|
|
get_user_flagrec(bot->u, &fr, chan->dname, chan);
|
|
get_user_flagrec(bot->u, &fr, chan->dname, chan);
|
|
|
- if (bot_shouldjoin(bot->u, &fr, chan) && chk_op(fr, chan))
|
|
|
|
|
- botops[foundBots++] = bot->bot;
|
|
|
|
|
|
|
+ if (bot_shouldjoin(bot->u, &fr, chan) && chk_op(fr, chan)) {
|
|
|
|
|
+ ++foundBots;
|
|
|
|
|
+// botops[foundBots++] = bot->bot;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!foundBots) {
|
|
if (!foundBots) {
|
|
@@ -1002,23 +1024,9 @@ request_in(struct chanset_t *chan)
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- int cnt = foundBots < in_bots ? foundBots : in_bots;
|
|
|
|
|
- char s[255] = "";
|
|
|
|
|
- char l[1024] = "";
|
|
|
|
|
- size_t len = 0;
|
|
|
|
|
-
|
|
|
|
|
- simple_snprintf(s, sizeof(s), "gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip);
|
|
|
|
|
-
|
|
|
|
|
- shuffleArray(botops, foundBots);
|
|
|
|
|
- for (int n = 0; n < cnt; ++n) {
|
|
|
|
|
- putbot(botops[n], s);
|
|
|
|
|
-
|
|
|
|
|
- if (l[0])
|
|
|
|
|
- len += strlcpy(l + len, ", ", sizeof(l) - len);
|
|
|
|
|
- len += strlcpy(l + len, botops[n], sizeof(l) - len);
|
|
|
|
|
- }
|
|
|
|
|
- l[len] = 0;
|
|
|
|
|
- putlog(LOG_GETIN, "*", "Requested help to join %s from %s", chan->dname, l);
|
|
|
|
|
|
|
+ bd::String request(bd::String::printf("gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip));
|
|
|
|
|
+ putallbots(request.c_str());
|
|
|
|
|
+ putlog(LOG_GETIN, "*", "Requested help to join %s", chan->dname);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1276,21 +1284,6 @@ killmember(struct chanset_t *chan, char *nick)
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/* Check if I am a chanop. Returns boolean 1 or 0.
|
|
|
|
|
- */
|
|
|
|
|
-bool
|
|
|
|
|
-me_op(const struct chanset_t *chan)
|
|
|
|
|
-{
|
|
|
|
|
- memberlist *mx = ismember(chan, botname);
|
|
|
|
|
-
|
|
|
|
|
- if (!mx)
|
|
|
|
|
- return 0;
|
|
|
|
|
- if (chan_hasop(mx))
|
|
|
|
|
- return 1;
|
|
|
|
|
- else
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/* Check whether I'm voice. Returns boolean 1 or 0.
|
|
/* Check whether I'm voice. Returns boolean 1 or 0.
|
|
|
*/
|
|
*/
|
|
|
bool
|
|
bool
|
|
@@ -1423,8 +1416,6 @@ check_lonely_channel(struct chanset_t *chan)
|
|
|
!shouldjoin(chan) || (chan->channel.mode & CHANANON))
|
|
!shouldjoin(chan) || (chan->channel.mode & CHANANON))
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
- memberlist *m = NULL;
|
|
|
|
|
- char s[UHOSTLEN] = "";
|
|
|
|
|
static int whined = 0;
|
|
static int whined = 0;
|
|
|
|
|
|
|
|
if ((chan->channel.members - chan->channel.splitmembers) == 1 && channel_cycle(chan) && !channel_stop_cycle(chan)) {
|
|
if ((chan->channel.members - chan->channel.splitmembers) == 1 && channel_cycle(chan) && !channel_stop_cycle(chan)) {
|
|
@@ -1436,15 +1427,10 @@ check_lonely_channel(struct chanset_t *chan)
|
|
|
}
|
|
}
|
|
|
} else if (any_ops(chan)) {
|
|
} else if (any_ops(chan)) {
|
|
|
whined = 0;
|
|
whined = 0;
|
|
|
- request_op(chan);
|
|
|
|
|
-/* need: op */
|
|
|
|
|
} else {
|
|
} else {
|
|
|
/* Other people here, but none are ops. If there are other bots make
|
|
/* Other people here, but none are ops. If there are other bots make
|
|
|
* them LEAVE!
|
|
* them LEAVE!
|
|
|
*/
|
|
*/
|
|
|
- bool ok = 1;
|
|
|
|
|
- struct userrec *u = NULL;
|
|
|
|
|
-
|
|
|
|
|
if (!whined) {
|
|
if (!whined) {
|
|
|
/* + is opless. Complaining about no ops when without special
|
|
/* + is opless. Complaining about no ops when without special
|
|
|
* help(services), we cant get them - Raist
|
|
* help(services), we cant get them - Raist
|
|
@@ -1453,10 +1439,14 @@ check_lonely_channel(struct chanset_t *chan)
|
|
|
putlog(LOG_MISC, "*", "%s is active but has no ops :(", chan->dname);
|
|
putlog(LOG_MISC, "*", "%s is active but has no ops :(", chan->dname);
|
|
|
whined = 1;
|
|
whined = 1;
|
|
|
}
|
|
}
|
|
|
|
|
+#ifdef disabled
|
|
|
|
|
+ memberlist *m = NULL;
|
|
|
|
|
+ bool ok = 1;
|
|
|
|
|
+
|
|
|
for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
|
|
for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
|
|
|
- simple_snprintf(s, sizeof(s), "%s!%s", m->nick, m->userhost);
|
|
|
|
|
- u = get_user_by_host(s);
|
|
|
|
|
- if (!m->is_me && (!u || !u->bot)) {
|
|
|
|
|
|
|
+ member_getuser(m, 0);
|
|
|
|
|
+
|
|
|
|
|
+ if (!m->is_me && (!m->user || !m->user->bot)) {
|
|
|
ok = 0;
|
|
ok = 0;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -1468,11 +1458,8 @@ check_lonely_channel(struct chanset_t *chan)
|
|
|
if (!m->is_me)
|
|
if (!m->is_me)
|
|
|
dprintf(DP_SERVER, "PRIVMSG %s :go %s\n", m->nick, chan->dname);
|
|
dprintf(DP_SERVER, "PRIVMSG %s :go %s\n", m->nick, chan->dname);
|
|
|
*/
|
|
*/
|
|
|
- } else {
|
|
|
|
|
- /* Some humans on channel, but still op-less */
|
|
|
|
|
- request_op(chan);
|
|
|
|
|
-/* need: op */
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1622,10 +1609,11 @@ check_expired_chanstuff(struct chanset_t *chan)
|
|
|
}
|
|
}
|
|
|
} /* me_op */
|
|
} /* me_op */
|
|
|
|
|
|
|
|
-// for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
|
|
|
|
|
- int splitmembers = 0;
|
|
|
|
|
|
|
+ size_t splitmembers = 0, bot_ops = 0;
|
|
|
|
|
+ const bool im_opped = me_op(chan);
|
|
|
for (m = chan->channel.member; m && m->nick[0]; m = n) {
|
|
for (m = chan->channel.member; m && m->nick[0]; m = n) {
|
|
|
n = m->next;
|
|
n = m->next;
|
|
|
|
|
+ // Update split members
|
|
|
if (m->split) {
|
|
if (m->split) {
|
|
|
++splitmembers;
|
|
++splitmembers;
|
|
|
if (now - m->split > wait_split) {
|
|
if (now - m->split > wait_split) {
|
|
@@ -1648,7 +1636,7 @@ check_expired_chanstuff(struct chanset_t *chan)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (me_op(chan)) {
|
|
|
|
|
|
|
+ if (im_opped) {
|
|
|
if (dovoice(chan) && !loading) { /* autovoice of +v users if bot is +y */
|
|
if (dovoice(chan) && !loading) { /* autovoice of +v users if bot is +y */
|
|
|
if (!chan_hasop(m) && !chan_hasvoice(m) && !chan_sentvoice(m)) {
|
|
if (!chan_hasop(m) && !chan_hasvoice(m) && !chan_sentvoice(m)) {
|
|
|
member_getuser(m, 1);
|
|
member_getuser(m, 1);
|
|
@@ -1673,11 +1661,17 @@ check_expired_chanstuff(struct chanset_t *chan)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (m->user && m->user->bot) {
|
|
|
|
|
+ ++bot_ops;
|
|
|
|
|
+ }
|
|
|
m = n;
|
|
m = n;
|
|
|
}
|
|
}
|
|
|
// Update minutely
|
|
// Update minutely
|
|
|
chan->channel.splitmembers = splitmembers;
|
|
chan->channel.splitmembers = splitmembers;
|
|
|
check_lonely_channel(chan);
|
|
check_lonely_channel(chan);
|
|
|
|
|
+ if (bot_ops && !im_opped) {
|
|
|
|
|
+ request_op(chan);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1801,23 +1795,10 @@ static cmd_t irc_bot[] = {
|
|
|
{NULL, NULL, NULL, NULL, 0}
|
|
{NULL, NULL, NULL, NULL, 0}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-static void
|
|
|
|
|
-getin_5secondly()
|
|
|
|
|
-{
|
|
|
|
|
- if (!server_online)
|
|
|
|
|
- return;
|
|
|
|
|
-
|
|
|
|
|
- for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
|
|
|
|
|
- if ((!channel_pending(chan) && channel_active(chan)) && !me_op(chan))
|
|
|
|
|
- request_op(chan);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
void
|
|
void
|
|
|
irc_init()
|
|
irc_init()
|
|
|
{
|
|
{
|
|
|
timer_create_secs(60, "irc_minutely", (Function) irc_minutely);
|
|
timer_create_secs(60, "irc_minutely", (Function) irc_minutely);
|
|
|
- timer_create_secs(5, "getin_5secondly", (Function) getin_5secondly);
|
|
|
|
|
|
|
|
|
|
/* Add our commands to the imported tables. */
|
|
/* Add our commands to the imported tables. */
|
|
|
add_builtins("dcc", irc_dcc);
|
|
add_builtins("dcc", irc_dcc);
|