Ejemplo n.º 1
0
void
userlist_update_mode (session * sess, char *name, char mode, char sign)
{
    int access;
    int offset = 0;
    int level;
    int pos;
    char prefix;
    struct User *user;

    user = userlist_find (sess, name);
    if (!user)
        return;

    /* remove from binary trees, before we loose track of it */
    tree_remove (sess->usertree, user, &pos);
    tree_remove (sess->usertree_alpha, user, &pos);

    /* which bit number is affected? */
    access = mode_access (sess->server, mode, &prefix);

    if (sign == '+')
    {
        level = TRUE;
        if (!(user->access & (1 << access)))
        {
            offset = 1;
            user->access |= (1 << access);
        }
    }
    else
    {
        level = FALSE;
        if (user->access & (1 << access))
        {
            offset = -1;
            user->access &= ~(1 << access);
        }
    }

    /* now what is this users highest prefix? e.g. @ for ops */
    user->prefix[0] = get_nick_prefix (sess->server, user->access);

    /* update the various counts using the CHANGED prefix only */
    update_counts (sess, user, prefix, level, offset);

    /* insert it back into its new place */
    tree_insert (sess->usertree_alpha, user);
    pos = tree_insert (sess->usertree, user);

    /* let GTK move it too */
    fe_userlist_move (sess, user, pos);
    fe_userlist_numbers (sess);
}
Ejemplo n.º 2
0
void
userlist_update_mode (session *sess, const char name[], char mode, char sign)
{
	auto result = std::find_if(
		sess->usertree.begin(),
		sess->usertree.end(),
		[sess, name](const std::unique_ptr<User> &u){
		return sess->server->compare(name, u->nick) == 0;
	});
	if (result == sess->usertree.end())
		return;

	User * user = result->get();

	/* which bit number is affected? */
	char prefix;
	auto access = mode_access (sess->server, mode, &prefix);
	bool level = false;
	int offset = 0;
	if (sign == '+')
	{
		level = true;
		if (!(user->access & (1 << access)))
		{
			offset = 1;
			user->access |= (1 << access);
		}
	} else
	{
		level = false;
		if (user->access & (1 << access))
		{
			offset = -1;
			user->access &= ~(1 << access);
		}
	}

	/* now what is this users highest prefix? e.g. @ for ops */
	user->prefix[0] = get_nick_prefix (sess->server, user->access);

	/* update the various counts using the CHANGED prefix only */
	update_counts (sess, user, prefix, level, offset);
	
	int pos = userlist_resort(*sess, user->nick);

	/* let GTK move it too */
	fe_userlist_move (sess, user, pos);
	fe_userlist_numbers (*sess);
}