Exemplo n.º 1
0
int uman_send_user_list(struct hub_info* hub, struct hub_user* target)
{
	int ret = 1;
	struct hub_user* user;
	user_flag_set(target, flag_user_list);
	user = (struct hub_user*) list_get_first(hub->users->list); /* iterate users - only on INF or PAS msg */
	while (user)
	{
		if (user_is_logged_in(user))
		{
			ret = route_to_user(hub, target, user->info);
			if (!ret)
				break;
		}
		user = (struct hub_user*) list_get_next(hub->users->list);
	}

#if 0
	FIXME: FIXME FIXME handle send queue excess
	if (!target->send_queue_size)
	{
	    user_flag_unset(target, flag_user_list);
	}
#endif
	return ret;
}
Exemplo n.º 2
0
Arquivo: hub.c Projeto: imobilis/uhub
void hub_send_handshake(struct hub_info* hub, struct hub_user* u)
{
	user_flag_set(u, flag_pipeline);
	hub_send_support(hub, u);
	hub_send_sid(hub, u);
	hub_send_hubinfo(hub, u);
	route_flush_pipeline(hub, u);

	if (!user_is_disconnecting(u))
	{
		user_set_state(u, state_identify);
	}
}
Exemplo n.º 3
0
Arquivo: hub.c Projeto: imobilis/uhub
void hub_send_flood_warning(struct hub_info* hub, struct hub_user* u, const char* message)
{
	struct adc_message* msg;
	char* tmp;

	if (user_flag_get(u, flag_flood))
		return;

	msg = adc_msg_construct(ADC_CMD_ISTA, 128);
	if (msg)
	{
		tmp = adc_msg_escape(message);
		adc_msg_add_argument(msg, "110");
		adc_msg_add_argument(msg, tmp);
		hub_free(tmp);

		route_to_user(hub, u, msg);
		user_flag_set(u, flag_flood);
		adc_msg_free(msg);
	}
}
Exemplo n.º 4
0
/* Notify plugins, etc */
void on_login_success(struct hub_info* hub, struct hub_user* u)
{
	/* Send user list of all existing users */
	if (!uman_send_user_list(hub, hub->users, u))
		return;

	/* Mark as being in the normal state, and add user to the user list */
	user_set_state(u, state_normal);
	uman_add(hub->users, u);

	// Make operators receive hub notifications by default.
	if (user_is_protected(u))
		user_flag_set(u, flag_opnotify);

	/* Announce new user to all connected users */
	if (user_is_logged_in(u))
		route_info_message(hub, u);

	plugin_log_user_login_success(hub, u);

	/* reset timeout */
	net_con_clear_timeout(u->connection);
}
Exemplo n.º 5
0
int handle_net_read(struct hub_user* user)
{
    static char buf[MAX_RECV_BUF];
    struct hub_recvq* q = user->recv_queue;
    size_t buf_size = hub_recvq_get(q, buf, MAX_RECV_BUF);
    ssize_t size;

    if (user_flag_get(user, flag_maxbuf))
        buf_size = 0;
    size = net_con_recv(user->connection, buf + buf_size, MAX_RECV_BUF - buf_size);

    if (size > 0)
        buf_size += size;

    if (size < 0)
    {
        if (size == -1)
            return quit_disconnected;
        else
            return quit_socket_error;
    }
    else if (size == 0)
    {
        return 0;
    }
    else
    {
        char* lastPos = 0;
        char* start = buf;
        char* pos = 0;
        size_t remaining = buf_size;

        while ((pos = memchr(start, '\n', remaining)))
        {
            lastPos = pos;
            pos[0] = '\0';

#ifdef DEBUG_SENDQ
            LOG_DUMP("PROC: \"%s\" (%d)\n", start, (int) (pos - start));
#endif

            if (user_flag_get(user, flag_maxbuf))
            {
                user_flag_unset(user, flag_maxbuf);
            }
            else
            {
                if (((pos - start) > 0) && g_hub->config->max_recv_buffer > (pos - start))
                {
                    if (hub_handle_message(g_hub, user, start, (pos - start)) == -1)
                    {
                        return quit_protocol_error;
                    }
                }
            }

            pos[0] = '\n'; /* FIXME: not needed */
            pos ++;
            remaining -= (pos - start);
            start = pos;
        }

        if (lastPos || remaining)
        {
            if (remaining < g_hub->config->max_recv_buffer)
            {
                hub_recvq_set(q, lastPos ? lastPos : buf, remaining);
            }
            else
            {
                hub_recvq_set(q, 0, 0);
                user_flag_set(user, flag_maxbuf);
                LOG_WARN("Received message past max_recv_buffer, dropping message.");
            }
        }
        else
        {
            hub_recvq_set(q, 0, 0);
        }
    }
    return 0;
}
Exemplo n.º 6
0
Arquivo: user.c Projeto: junaidk/uhub
void user_set_nat_override(struct hub_user* user)
{
	user_flag_set(user, flag_nat);
}