void hub_disconnect_user(struct hub_info* hub, struct hub_user* user, int reason) { struct event_data post; int need_notify = 0; /* is user already being disconnected ? */ if (user_is_disconnecting(user)) { return; } /* stop reading from user */ net_shutdown_r(net_con_get_sd(user->connection)); net_con_close(user->connection); user->connection = 0; LOG_TRACE("hub_disconnect_user(), user=%p, reason=%d, state=%d", user, reason, user->state); need_notify = user_is_logged_in(user) && hub->status == hub_status_running; user->quit_reason = reason; user_set_state(user, state_cleanup); if (need_notify) { memset(&post, 0, sizeof(post)); post.id = UHUB_EVENT_USER_QUIT; post.ptr = user; event_queue_post(hub->queue, &post); } else { hub_schedule_destroy_user(hub, user); } }
struct hub_user* user_create(struct hub_info* hub, struct net_connection* con, struct ip_addr_encap* addr) { struct hub_user* user = NULL; LOG_TRACE("user_create(), hub=%p, con[sd=%d]", hub, net_con_get_sd(con)); user = (struct hub_user*) hub_malloc_zero(sizeof(struct hub_user)); if (user == NULL) return NULL; /* OOM */ user->send_queue = ioq_send_create(); user->recv_queue = ioq_recv_create(); user->connection = con; net_con_reinitialize(user->connection, net_event, user, NET_EVENT_READ); memcpy(&user->id.addr, addr, sizeof(struct ip_addr_encap)); user_set_state(user, state_protocol); flood_control_reset(&user->flood_chat); flood_control_reset(&user->flood_connect); flood_control_reset(&user->flood_search); flood_control_reset(&user->flood_update); flood_control_reset(&user->flood_extras); user->hub = hub; return user; }
void hub_send_password_challenge(struct hub_info* hub, struct hub_user* u) { struct adc_message* igpa; igpa = adc_msg_construct(ADC_CMD_IGPA, 38); adc_msg_add_argument(igpa, acl_password_generate_challenge(hub, u)); user_set_state(u, state_verify); route_to_user(hub, u, igpa); adc_msg_free(igpa); }
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); } }
/* 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); /* 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); }
/* 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); }