Example #1
0
hchannel_user *hchannel_add_user(hchannel *hchan, struct huser_struct *husr)
{
    hchannel_user **tmp = &(hchan->channel_users);
    assert(hchannel_on_channel(hchan, husr) == NULL);

    for (;*tmp;tmp = &(*tmp)->next);

    *tmp = (hchannel_user*)malloc(sizeof(hchannel_user));
    (*tmp)->husr = husr;
    (*tmp)->time_joined = time(NULL);
    (*tmp)->next = NULL;

    assert(hchannel_on_channel(hchan, husr) != NULL);

    return *tmp;
}
Example #2
0
hchannel_user *hchannel_del_user(hchannel *hchan, struct huser_struct *husr)
{
    hchannel_user **tmp = &(hchan->channel_users);
    assert(hchannel_on_channel(hchan, husr) != NULL);

    for (;*tmp;tmp = &(*tmp)->next)
        if ((*tmp)->husr == husr)
        {
            hchannel_user *ptr = (*tmp)->next;
            free(*tmp);
            *tmp = ptr;

            assert(hchannel_on_channel(hchan, husr) == NULL);
            return NULL;
        }
    return NULL;
}
Example #3
0
int hqueue_get_position(hchannel *hchan, huser *target)
{
    int position;
    hqueue_entry *hqueue = hqueue_get_next(hchan);

    if (hchannel_on_channel(hchan, target) == NULL)
        return -1;

    if (!(hchan->flags & H_QUEUE))
        return -1;

    for (position = 0;hqueue;hqueue = hqueue_get_next(NULL))
    {
        if (hqueue_on_queue(hqueue))
        {
            position++;
            if (hqueue->hchanuser->husr == target)
                return position;
        }
    }
    return -1;
}