Пример #1
0
void
sv_core_httpd(void)
{
	int sv;

	if (chdir(MY_BBS_HOME)) 
		return;
	signal(SIGPIPE, dopipesig);
	signal(SIGBUS, dosigbus);
/*
	shm_utmp = (struct UTMPFILE *) get_old_shm(UTMP_SHMKEY, sizeof (struct UTMPFILE));
	if (shm_utmp == NULL) {
		printf("shm_utmp error ");
		exit(-1);
	}
 */		
	if ((sv = bindport(SERVER_PORT)) == -1) 
		return;
	while (1) {
		int maxfd;
		fd_set rfs, wfs;
		FD_ZERO(&rfs);
		FD_ZERO(&wfs);
		FD_SET(sv, &rfs);

		maxfd = conn_cullselect(&rfs, &wfs);
		if (sv > maxfd)
			maxfd = sv;

		if (select(maxfd + 1, &rfs, &wfs, NULL, NULL) == -1) {
			if (errno == EINTR)
				continue;
			break;
		}
		if (FD_ISSET(sv, &rfs)) {
			int cl;

			if ((cl = getcl(sv)) == -1)
				break;
			if (fcntl(cl, F_SETFL, O_NONBLOCK) >= 0)
				conn_insert(cl);
			else
				close(cl);
		}
		conn_upkeep(&rfs, &wfs);
	}
	return;
}
Пример #2
0
int input_login(DESC_DATA *d, const char *data, int plen)
{
	const int	PACKET_LENGTH = 4;

	if (plen < PACKET_LENGTH)
		return 0;

	DWORD	account_id = decode_4bytes((const BYTE*)data);

//	sys_log("LOGIN: %u", account_id);

	/* 기존 정보가 있으면 접속을 끊으라고 알려줌 */
	CONN_DATA	*conn = conn_find(account_id);
	if (conn)
	{
		send_force_logout(conn);
		//conn_delete(GET_ID(conn));

		// 새로운 접속자도 접속을 끊는다.
		{
			PACKET_DATA	*buf = &d->packet_buffer;

			packet_header(buf, HEADER_TG_FORCE_LOGOUT, d->desc_num);
			packet(buf, GET_LOGIN(conn), MAX_LOGIN_LEN);
		}
		return PACKET_LENGTH;
	}

	conn = (CONN_DATA*) calloc(1, sizeof(CONN_DATA));
	GET_ID(conn)	= account_id;
	GET_DESC(conn)	= d;
	GET_EVENT(conn)	= NULL;


	int login_succ = FALSE;
	if (teen_all_flag)
		login_succ = account_login_teen_all(account_id, conn);
	else
		login_succ = account_login(account_id, conn);

	if (FALSE==login_succ)
	{
		//conn_delete(GET_ID(conn));
		SAFE_FREE(conn);
		return PACKET_LENGTH;
	}

	conn_insert(conn);

	if (YES==GET_TEENAGE(conn))
	{
		conn_event_info	*info = (conn_event_info*) calloc(1, sizeof(conn_event_info));
		info->conn = conn;
		GET_EVENT(conn) = event_create(conn_event_func, info, (CHECK_TIME_SEC * PASSES_PER_SEC));
	}
	else
	{
		GET_EVENT(conn) = NULL;
	}

	if (YES==GET_TEENAGE(conn))
	{
		send_login_notice(conn);
		set_notice_step(conn);
		send_notice(conn);
	}

	sys_log("CONN_INSERT : %u, %s", GET_ID(conn), GET_LOGIN(conn));

	return PACKET_LENGTH;
} /* end of input_login() */