示例#1
0
int hchannel_highlight_detection(hchannel *hchan, const char *message)
{
    char buffer[512], *buffer_ptr = buffer, *ptr = buffer;
    int i, matches = 0;

    strcpy(buffer, message);

    /* remove commas */
    for (i=0;i<512 && buffer[i] != '\0';i++)
	if (buffer[i] == ',')
	    buffer[i] = ' ';

    /* reset i for loop */
    i = 0;
    do
    {
	nick *tmp;
	huser *tmp_huser;
	huser_channel *tmp_huserchan;

	if (i++ > 6)
            break;

	while (*buffer_ptr && isspace(*buffer_ptr))
	    buffer_ptr++;

	if (*buffer_ptr == '@')
            buffer_ptr++;

	if (*buffer_ptr)
	{
	    ptr = strchr(buffer_ptr, ' ');
	    if (ptr)
	    {
                *ptr = '\0';
		ptr++;
	    }
	    if ((tmp = getnickbynick(buffer_ptr)))
		if ((tmp_huser = huser_get(tmp)))
		    if ((tmp_huserchan = huser_on_channel(tmp_huser, hchan)))
			if ((tmp_huserchan->flags & HCUMODE_OP) && strlen(huser_get_nick(tmp_huser)) > 1)
			    matches++;
	}
	if (ptr == NULL)
	    break;
	else
	    buffer_ptr = ptr;
    } while (*ptr);

    if (matches > 2)
	return 1;
    else
	return 0;
}
示例#2
0
hchannel *hchannel_add(const char *cname)
{
    channel *cp;
    hchannel *hchan;

    cp = findchannel((char*)cname);
    if (!cp)
    {
        localcreatechannel(helpmodnick, (char*)cname);
        cp = findchannel((char*)cname);
    }
    else
    {
        localjoinchannel(helpmodnick, cp);
        localgetops(helpmodnick, cp);
    }

    hchan = (hchannel*)malloc(sizeof(hchannel));

    hchan->welcome[0] = '\0';
    hchan->real_channel = cp;
    hchan->flags = H_CHANFLAGS_DEFAULT;
    hchan->channel_users = NULL;
    hchan->channel_hterms = NULL;
    hchan->max_idle = 5 * HDEF_m;
    hchan->topic = NULL;
    hchan->report_to = NULL;

    hchan->autoqueue = 0;
    hchan->jf_control = time(NULL);
    hchan->lc_profile = NULL;
    hchan->censor = NULL;

    hchan->htickets = NULL;
    hchan->ticket_message = NULL;

    hchan->last_activity = time(NULL);
    hchan->last_staff_activity = time(NULL);
    hchan->stats = get_hstat_channel();

    hchan->next = hchannels;
    hchannels = hchan;

    {
        int i;
        nick *nck;
        huser *husr;
        huser_channel *tmp;
        for (i=0;i < hchan->real_channel->users->hashsize;i++)
        {
            nck = getnickbynumeric(hchan->real_channel->users->content[i]);
            if (!nck) /* it's a hash, not an array */
                continue;

            if ((husr = huser_get(nck)) == NULL)
                husr = huser_add(nck);

	    tmp = huser_add_channel(husr, hchan);
            hchannel_add_user(hchan, husr);

            if (hchan->real_channel->users->content[i] & CUMODE_OP)
                tmp->flags |= HCUMODE_OP;
            if (hchan->real_channel->users->content[i] & CUMODE_VOICE)
                tmp->flags |= HCUMODE_VOICE;
        }
    }
    return hchan;
}
示例#3
0
文件: hqueue.c 项目: quakenet/newserv
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;
    }
}