void hchannel_remove_inactive_users(void) { hchannel *hchan = hchannels; for (;hchan;hchan = hchan->next) { if (hchan->flags & H_ANTI_IDLE && !(hchan->flags & H_PASSIVE)) { hchannel_user **hchanuser = &hchan->channel_users; while (*hchanuser) { if ( (huser_get_level((*hchanuser)->husr) == H_PEON) && (time(NULL) - huser_on_channel((*hchanuser)->husr,hchan)->last_activity >= hchan->max_idle) && !(on_queue((*hchanuser)->husr, huser_on_channel((*hchanuser)->husr, hchan))) && !IsSetHost((*hchanuser)->husr->real_user) ) { if (huser_on_channel((*hchanuser)->husr, hchan)->flags & H_IDLE_WARNING) { const char *banmask = hban_ban_string((*hchanuser)->husr->real_user, HBAN_HOST); int bantime = 10; helpmod_setban(hchan, banmask, time(NULL) + bantime * HDEF_m, MCB_ADD, HLAZY); helpmod_kick(hchan, (*hchanuser)->husr, "Please do not idle in %s (%dmin anti-idle tempban). If you still require assistance, please try again later.", hchannel_get_name(hchan), bantime); continue; } else { helpmod_reply((*hchanuser)->husr, NULL, "You are currently idle in %s. Please part the channel if you have nothing to do there", hchannel_get_name(hchan)); huser_on_channel((*hchanuser)->husr, hchan)->flags |= H_IDLE_WARNING; } } /*hcommit_modes();*/ hchanuser = &(*hchanuser)->next; } hcommit_modes(); } /* Additionally, test if the channel has queue but no idle opers / staff */ if (hchan->flags & H_QUEUE && hchan->flags & H_QUEUE_TIMEOUT) { hchannel_user *tmp; for (tmp = hchan->channel_users;tmp;tmp = tmp->next) if (huser_get_level(tmp->husr) >= H_TRIAL) { huser_channel *huserchan = huser_on_channel(tmp->husr, hchan); if ((time(NULL) - huserchan->last_activity < HELPMOD_QUEUE_TIMEOUT) && (huserchan->last_activity != tmp->time_joined)) break; } if (!tmp) { hchan->flags &= ~H_QUEUE; if (hchan->flags & H_REPORT && hchannel_is_valid(hchan->report_to)) helpmod_message_channel(hchan->report_to, "%s: Channel queue deactivated because of inactivity", hchannel_get_name(hchan)); hchannel_conf_change(hchan, hchan->flags | H_QUEUE); } } } }
void helpmod_queue_handler (huser *sender, channel* returntype, hchannel *hchan, int hqueue_action, char* ostr, int argc, char *argv[]) { if (hchan == NULL) { helpmod_reply(sender, returntype, "Can not handle queue: Channel not defined or not found"); return; } switch (hqueue_action) /* easy ones */ { case HQ_ON: if (hchan->flags & H_QUEUE) helpmod_reply(sender, returntype, "Can not activate queue: Queue is already active on channel %s", hchannel_get_name(hchan)); else { hchan->flags |= H_QUEUE; helpmod_reply(sender, returntype, "Queue activated for channel %s", hchannel_get_name(hchan)); hchannel_conf_change(hchan, hchan->flags & ~(H_QUEUE)); hchan->autoqueue = 0; } return; case HQ_OFF: if (!(hchan->flags & H_QUEUE)) helpmod_reply(sender, returntype, "Can not deactive queue: Queue is not active on %s", hchannel_get_name(hchan)); else { hchan->flags &= ~H_QUEUE; helpmod_reply(sender, returntype, "Queue deactivated for channel %s", hchannel_get_name(hchan)); hchannel_conf_change(hchan, hchan->flags | H_QUEUE); hchan->autoqueue = 0; { /* devoice all users of level H_PEON */ hchannel_user *hchanuser; huser_channel *huserchan; for (hchanuser = hchan->channel_users;hchanuser != NULL;hchanuser = hchanuser->next) { huserchan = huser_on_channel(hchanuser->husr, hchan); if (huser_get_level(hchanuser->husr) == H_PEON && huserchan->flags & HCUMODE_VOICE) helpmod_channick_modes(hchanuser->husr, hchan, MC_DEVOICE, HLAZY); } } } return; } if (!(hchan->flags & H_QUEUE)) { helpmod_reply(sender, returntype, "Can not handle queue: Queue not active on channel %s", hchannel_get_name(hchan)); return; } /* now to the real deal */ switch (hqueue_action) { case HQ_DONE: { int i; if (argc == 0) { helpmod_reply(sender, returntype, "Can not advance queue: User not specified"); return; } if (argc > H_CMD_MAX_ARGS) argc = H_CMD_MAX_ARGS; for (i=0;i<argc;i++) { huser *husr = huser_get(getnickbynick(argv[i])); if (husr == NULL) { helpmod_reply(sender, returntype, "Can not advance queue: User %s not found", argv[i]); continue; } helpmod_channick_modes(husr, hchan, MC_DEVOICE, HLAZY); } hqueue_handle_queue(hchan, sender); } return; case HQ_NEXT: { int nnext = 1; if (argc > 0) { if (!sscanf(argv[0], "%d", &nnext) || nnext <= 0 || nnext > 25 /* magic number */) { helpmod_reply(sender, returntype, "Can not advance queue: Integer [1, 25] expected"); return; } } hqueue_advance(hchan, sender, nnext); } return; case HQ_MAINTAIN: { int tmp; if (argc == 0) { helpmod_reply(sender, returntype, "Autoqueue for channel %s is currently %d (%s)", hchannel_get_name(hchan), hchan->autoqueue, hchannel_get_state(hchan, H_QUEUE_MAINTAIN)); return; } if (!sscanf(argv[0], "%d", &tmp) || tmp < 0 || tmp > 25) { helpmod_reply(sender, returntype, "Can not set auto queue: Integer [0, 20] expected"); return; } hchan->autoqueue = tmp; if (tmp == 0) { if (hchan->flags & H_QUEUE_MAINTAIN) { hchan->flags &= ~(H_QUEUE_MAINTAIN); helpmod_reply(sender, returntype, "Autoqueue is now disabled for channel %s", hchannel_get_name(hchan)); } else helpmod_reply(sender, returntype, "Autoqueue is not enabled for channel %s", hchannel_get_name(hchan)); } else if (!(hchan->flags & H_QUEUE_MAINTAIN)) { hchan->flags |= H_QUEUE_MAINTAIN; helpmod_reply(sender, returntype, "Autoqueue for channel %s activated and set to %d succesfully", hchannel_get_name(hchan), hchan->autoqueue); } else helpmod_reply(sender, returntype, "Autoqueue for channel %s set to %d succesfully", hchannel_get_name(hchan), hchan->autoqueue); hqueue_handle_queue(hchan, sender); } return; case HQ_LIST: { int count = hqueue_count_in_queue(hchan); hqueue_entry *hqueue = hqueue_get_next(hchan); char buffer[512]; buffer[0] = '\0'; helpmod_reply(sender, returntype, "Channel %s has following users in queue (%d user%s total):", hchannel_get_name(hchan), count, (count==1)?"":"s"); for (;hqueue;hqueue = hqueue_get_next(NULL)) { if (strlen(buffer) >= 250) { helpmod_reply(sender, returntype, "%s", buffer); buffer[0] = '\0'; } if (hqueue_on_queue(hqueue)) sprintf(buffer+strlen(buffer) /* :) */, "%s (%s@%s) [%s] ", huser_get_nick(hqueue->hchanuser->husr), huser_get_ident(hqueue->hchanuser->husr), huser_get_host(hqueue->hchanuser->husr), helpmod_strtime(time(NULL) - hqueue->hchanuser->time_joined)); } if (buffer[0]) helpmod_reply(sender, returntype, "%s", buffer); } return; case HQ_NONE: /* if no parameters are given print the summary */ case HQ_SUMMARY: { int count_on = hqueue_count_in_queue(hchan); int count_off = hqueue_count_off_queue(hchan); int average = hqueue_average_time(hchan); helpmod_reply(sender, returntype, "Channel %s has %d user%s in queue, %d user%s being helped, average time in queue %s", hchannel_get_name(hchan), count_on, (count_on==1)?"":"s", count_off, (count_off==1)?"":"s", helpmod_strtime(average)); } return; case HQ_RESET: { hchannel_user *hchanuser = hchan->channel_users; for (;hchanuser;hchanuser = hchanuser->next) { if (huser_get_level(hchanuser->husr) == H_PEON) { huser_channel *huserchan = huser_on_channel(hchanuser->husr, hchan); assert (huserchan != NULL); if (huserchan->flags & HCUMODE_VOICE) helpmod_channick_modes(hchanuser->husr, hchan, MC_DEVOICE, HLAZY); huserchan->flags &= ~(HQUEUE_DONE | H_IDLE_WARNING); } } if (!IsModerated(hchan->real_channel)) helpmod_simple_modes(hchan, CHANMODE_MODERATE, 0, 0); helpmod_message_channel(hchan, "Channel queue has been reset"); helpmod_reply(sender, returntype, "Queue for channel %s has been reset", hchannel_get_name(hchan)); } return; } }