Beispiel #1
0
static void show_statuses(session_basic_info_t *res)
{
	if (session_basic_info_count(res) > 0)
		//% prints("目前状态如下:\n");
		prints("\xc4\xbf\xc7\xb0\xd7\xb4\xcc\xac\xc8\xe7\xcf\xc2\xa3\xba\n");

	for (int i = 0; i < session_basic_info_count(res); ++i) {
		bool visible = session_basic_info_visible(res, i);
		if (!visible && !HAS_PERM(PERM_SEECLOAK))
			continue;

		session_id_t sid = session_basic_info_sid(res, i);
		bool web = session_basic_info_web(res, i);
		int status = get_user_status(sid);
		int idle = (time(NULL) - session_get_idle(sid)) / 60;

		const char *color = session_status_color(status, visible, web);
		prints("\033[1m%s%s\033[m", color, session_status_descr(status));

		if (idle >= 1 && status != ST_BBSNET)
			prints("[%d] ", idle);
		else
			prints("    ");

		if ((i + 1) % 5 == 0)
			outc('\n');
	}
	outc('\n');
}
Beispiel #2
0
// Prevent too many logins of same account.
static int multi_user_check(void)
{
	int max = get_login_quota(&currentuser);
	if (max == INT_MAX)
		return 0;

	int logins = INT_MAX;
	session_basic_info_t *res = get_my_sessions();
	if (res) {
		logins = session_basic_info_count(res);
	}

	if (strcaseeq("guest", currentuser.userid) && logins >= max) {
		//% prints("\033[1;33m抱歉, 目前已有太多 \033[1;36mguest\033[33m, "
		prints("\033[1;33m\xb1\xa7\xc7\xb8, \xc4\xbf\xc7\xb0\xd2\xd1\xd3\xd0\xcc\xab\xb6\xe0 \033[1;36mguest\033[33m, "
				//% "请稍后再试。\033[m\n");
				"\xc7\xeb\xc9\xd4\xba\xf3\xd4\xd9\xca\xd4\xa1\xa3\033[m\n");
		session_basic_info_clear(res);
		return -1;
	}

	if (logins >= max) {
		//% prints("\033[1;32m为确保他人上站权益, "
		prints("\033[1;32m\xce\xaa\xc8\xb7\xb1\xa3\xcb\xfb\xc8\xcb\xc9\xcf\xd5\xbe\xc8\xa8\xd2\xe6, "
				//% "本站仅允许您用该帐号登录 %d 个。\n\033[m"
				"\xb1\xbe\xd5\xbe\xbd\xf6\xd4\xca\xd0\xed\xc4\xfa\xd3\xc3\xb8\xc3\xd5\xca\xba\xc5\xb5\xc7\xc2\xbc %d \xb8\xf6\xa1\xa3\n\033[m"
				//% "\033[1;36m您目前已经使用该帐号登录了 %d 个,"
				"\033[1;36m\xc4\xfa\xc4\xbf\xc7\xb0\xd2\xd1\xbe\xad\xca\xb9\xd3\xc3\xb8\xc3\xd5\xca\xba\xc5\xb5\xc7\xc2\xbc\xc1\xcb %d \xb8\xf6\xa3\xac"
				//% "您必须断开其他的连接方能进入本站!\n\033[m", max, logins);
				"\xc4\xfa\xb1\xd8\xd0\xeb\xb6\xcf\xbf\xaa\xc6\xe4\xcb\xfb\xb5\xc4\xc1\xac\xbd\xd3\xb7\xbd\xc4\xdc\xbd\xf8\xc8\xeb\xb1\xbe\xd5\xbe\xa3\xa1\n\033[m", max, logins);
		//% bool kick = askyn("您想删除重复的连接吗", false, false);
		bool kick = askyn("\xc4\xfa\xcf\xeb\xc9\xbe\xb3\xfd\xd6\xd8\xb8\xb4\xb5\xc4\xc1\xac\xbd\xd3\xc2\xf0", false, false);
		if (kick) {
			bbs_kill(session_basic_info_sid(res, 0),
					session_basic_info_pid(res, 0), SIGHUP);
			report("kicked (multi-login)", currentuser.userid);
			session_basic_info_clear(res);

			sleep(2);
			res = get_my_sessions();
			logins = session_basic_info_count(res);
		}

		session_basic_info_clear(res);
		if (logins >= max) {
			//% prints("\033[33m很抱歉,您已经用该帐号登录 %d 个,"
			prints("\033[33m\xba\xdc\xb1\xa7\xc7\xb8\xa3\xac\xc4\xfa\xd2\xd1\xbe\xad\xd3\xc3\xb8\xc3\xd5\xca\xba\xc5\xb5\xc7\xc2\xbc %d \xb8\xf6\xa3\xac"
					//% "所以,此连线将被取消。\033[m\n", logins);
					"\xcb\xf9\xd2\xd4\xa3\xac\xb4\xcb\xc1\xac\xcf\xdf\xbd\xab\xb1\xbb\xc8\xa1\xcf\xfb\xa1\xa3\033[m\n", logins);
			return -1;
		}
	}
	return 0;
}