Example #1
0
int helpmod_config_write_ticket(FILE *out, hticket *htick, hchannel *hchan)
{
    fprintf(out, "\t%s\n", hchannel_get_name(hchan));
    fprintf(out, "\t%s\n", htick->authname);
    fprintf(out, "\t%u\n", (unsigned int)htick->time_expiration);
    if (htick->message)
	fprintf(out, "\t%s\n", htick->message->content);
    else
        fprintf(out, "\n");

    return 0;
}
Example #2
0
int helpmod_config_write_stats(FILE *out, hstat_account *hs_acc)
{
    int i;
    hstat_account_entry *entry;

    fprintf(out, "\t%s\n", hchannel_get_name(hs_acc->hchan));

    for (i=0;i<17;i++)
    {
        if (i < 7) /* days */
            entry = &hs_acc->week[(hstat_day() + i) % 7];
        else /* weeks */
            entry = &hs_acc->longterm[(hstat_week() + (i-7)) % 10];

        fprintf(out, "\t%d %d %d %d\n", entry->time_spent, entry->prime_time_spent, entry->lines, entry->words);
    }
    return 0;
}
Example #3
0
int helpmod_config_write_channel(FILE *out, hchannel *target)
{
    fprintf(out, "\t%s\n", hchannel_get_name(target));
    fprintf(out, "\t%x\n", target->flags & 0x0FFFFFF);
    fprintf(out, "\t%s\n", target->welcome);
    if (target->lc_profile == NULL)
        fprintf(out, "\t(null)\n");
    else
	fprintf(out, "\t%s\n", target->lc_profile->name->content);

    fprintf(out, "\t%d\n", target->max_idle);

    if (target->ticket_message == NULL)
	fprintf(out, "\t(null)\n");
    else
	fprintf(out, "\t%s\n", target->ticket_message->content);

    fprintf(out, "\t%d %% censor\n", hcensor_count(target->censor));
    {
        hcensor *hcens = target->censor;
        for (;hcens;hcens = hcens->next)
	{
            fprintf(out, "\t\t%d\n", hcens->type);
            fprintf(out, "\t\t%s\n", hcens->pattern->content);
	    fprintf(out, "\t\t%s\n", hcens->reason?hcens->reason->content:"");
        }
    }

    fprintf(out, "\t%d %% terms\n", hterm_count(target->channel_hterms));
    {
        hterm *tmp = target->channel_hterms;
        for (;tmp;tmp = tmp->next)
        {
            helpmod_config_write_term(out, tmp);
        }
    }

    helpmod_config_write_chanstats(out, target->stats);

    return 0;
}
Example #4
0
void hchannel_report(void)
{
    hchannel *hchan = hchannels;
    for (;hchan;hchan = hchan->next)
        if (hchan->flags & H_REPORT && !(hchan->flags & H_PASSIVE) && hchannel_is_valid(hchan->report_to))
        {
            int total = hchannel_count_users(hchan, H_ANY);
            int peons = hchannel_count_users(hchan, H_PEON);
            int services = hchannel_count_users(hchan, H_SERVICE);

            if (peons == 0)
                return;

            if (hchan->flags & H_QUEUE)
            {
                int peons_queue = hchannel_count_queue(hchan);
                helpmod_message_channel(hchan->report_to, "%s: %d user%s in queue and %d user%s currently receiving support. %d Non-user%s. Average queue time %s", hchannel_get_name(hchan), peons_queue, (peons_queue==1)?"":"s", peons - peons_queue, (peons - peons_queue == 1)?"":"s", total-peons-services, (total-peons-services == 1)?"":"s", helpmod_strtime(hqueue_average_time(hchan)));
            }
            else
                helpmod_message_channel(hchan->report_to, "%s: %d user%s and %d non-user%s", hchannel_get_name(hchan), peons, (peons == 1)?"":"s",  total-peons-services, (total-peons-services == 1)?"":"s");
        }
}
Example #5
0
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);
            }
        }
    }
}
Example #6
0
int helpmod_config_write_report(FILE *out, hchannel *hchan)
{
    fprintf(out, "\t%s\n", hchannel_get_name(hchan));
    fprintf(out, "\t%s\n", hchannel_get_name(hchan->report_to));
    return 0;
}
Example #7
0
void hqueue_report_positions(hchannel *hchan)
{
    int count;
    hqueue_entry *tmp = hqueue_get_next(hchan);

    for (count = 1;tmp;tmp = hqueue_get_next(NULL))
    {
        if (hqueue_on_queue(tmp) && ((count <= 5) || !(count % 5)))
            helpmod_reply(tmp->hchanuser->husr, hchan->real_channel, "You now have queue position #%d for channel %s", count, hchannel_get_name(hchan));
        if (hqueue_on_queue(tmp))
            count++;
    }
}
Example #8
0
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;
    }
}
Example #9
0
void hqueue_advance(hchannel *hchan, huser *oper, int nadv)
{
    char buffer[512];
    int counter = nadv;
    huser_channel *huserchan;

    if (hchan == NULL) return;

    hchannel_user *hchanuser = hchan->channel_users;

    buffer[0] = '\0';

    if (counter < 0 || counter > 25)
        return;

    if (!huser_valid(oper) || !huser_on_channel(oper, hchan) || (time(NULL) - huser_on_channel(oper,hchan)->last_activity > HELPMOD_QUEUE_TIMEOUT))
        oper = NULL;

    while (counter)
    {
        if (hchanuser == NULL) /* out of users */
        {
            if (counter == nadv)
            {
                helpmod_message_channel(hchan, "There are no users in the queue");
                return;
            }
            else
                break; /* we got something, print the message on channel */
        }
        huserchan = huser_on_channel(hchanuser->husr, hchan);

        assert(huserchan != NULL);

        if (huserchan->flags & HQUEUE_DONE || huser_get_level(hchanuser->husr) > H_PEON)
        {
            hchanuser = hchanuser->next; /* user was not in queue, proceed to next one */
            continue;
        }

        huserchan->flags |= HQUEUE_DONE;

        counter--;

        strcat(buffer, huser_get_nick(hchanuser->husr));
        strcat(buffer, " ");

        if (hchan->flags & H_DO_STATS)
            hstat_add_queue(hchan, 1);

        if ((hchan->flags & H_QUEUE_SPAMMY) && (oper != NULL))
        {
	    helpmod_reply(hchanuser->husr, hchan->real_channel, "It is now your time to state your problem. Please do so on channel %s and direct your questions to %s %s",  hchannel_get_name(hchan), hlevel_title(huser_get_level(oper)), huser_get_nick(oper));
            if (!(huser_get_account_flags(oper) & H_NOSPAM))
                helpmod_reply(oper, hchan->real_channel, "User %s (%s@%s) is yours, he has been in queue for %s", huser_get_nick(hchanuser->husr), huser_get_ident(hchanuser->husr), huser_get_host(hchanuser->husr), helpmod_strtime(time(NULL) - hchanuser->time_joined));
        }

        helpmod_channick_modes(hchanuser->husr, hchan, MC_VOICE, HLAZY);
        huserchan->responsible_oper = oper;

        hchanuser = hchanuser->next;
    }
    if (oper != NULL)
        helpmod_message_channel(hchan, "user%s %s: Please state your questions on this channel and direct them to %s %s", (nadv - counter == 1)?"":"s", buffer, hlevel_title(huser_get_level(oper)), huser_get_nick(oper));
    else
        helpmod_message_channel(hchan, "user%s %s: Please state your questions on this channel", (nadv - counter == 1)?"":"s", buffer);

    if (hchan->flags & H_QUEUE_SPAMMY)
        hqueue_report_positions(hchan);
}