| 35 |
SHOW_HELP, |
SHOW_HELP, |
| 36 |
}; |
}; |
| 37 |
|
|
| 38 |
static int user_list_draw_screen() |
static int user_list_draw_screen(int online_user) |
| 39 |
{ |
{ |
| 40 |
clearscr(); |
clearscr(); |
| 41 |
show_top("[已注册用户]", BBS_name, ""); |
show_top((online_user ? "[在线用户]" : "[已注册用户]"), BBS_name, ""); |
| 42 |
moveto(2, 0); |
moveto(2, 0); |
| 43 |
prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] " |
prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] " |
| 44 |
"查看[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m"); |
"查看[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m"); |
| 45 |
moveto(3, 0); |
moveto(3, 0); |
| 46 |
prints("\033[44;37m \033[1;37m 编 号 用户名 昵称 上次登陆距今 \033[m"); |
|
| 47 |
|
if (online_user) |
| 48 |
|
{ |
| 49 |
|
prints("\033[44;37m \033[1;37m 编 号 用户名 昵称 在线时长 空闲 最后活动 \033[m"); |
| 50 |
|
} |
| 51 |
|
else |
| 52 |
|
{ |
| 53 |
|
prints("\033[44;37m \033[1;37m 编 号 用户名 昵称 上次登陆距今 \033[m"); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
return 0; |
return 0; |
| 57 |
} |
} |
| 58 |
|
|
| 59 |
static int user_list_draw_items(int page_id, USER_INFO *p_users, |
static int user_list_draw_items(int page_id, USER_INFO *p_users, int user_count) |
|
int user_count) |
|
| 60 |
{ |
{ |
| 61 |
char str_time[LINE_BUFFER_LEN]; |
char str_time_login[LINE_BUFFER_LEN]; |
| 62 |
time_t tm_now; |
time_t tm_now; |
| 63 |
time_t tm_duration; |
time_t tm_duration; |
| 64 |
struct tm *p_tm; |
struct tm *p_tm; |
| 72 |
{ |
{ |
| 73 |
tm_duration = tm_now - p_users[i].last_login_dt; |
tm_duration = tm_now - p_users[i].last_login_dt; |
| 74 |
p_tm = gmtime(&tm_duration); |
p_tm = gmtime(&tm_duration); |
| 75 |
if (p_tm->tm_year > 70) |
if (p_tm == NULL) |
| 76 |
{ |
{ |
| 77 |
snprintf(str_time, sizeof(str_time), |
log_error("Invalid time duration\n"); |
| 78 |
|
str_time_login[0] = '\0'; |
| 79 |
|
} |
| 80 |
|
else if (p_tm->tm_year > 70) |
| 81 |
|
{ |
| 82 |
|
snprintf(str_time_login, sizeof(str_time_login), |
| 83 |
"%d年", p_tm->tm_year - 70); |
"%d年", p_tm->tm_year - 70); |
| 84 |
} |
} |
| 85 |
else if (p_tm->tm_yday > 1) |
else if (p_tm->tm_yday > 0) |
| 86 |
{ |
{ |
| 87 |
snprintf(str_time, sizeof(str_time), |
snprintf(str_time_login, sizeof(str_time_login), |
| 88 |
"%d天", p_tm->tm_yday); |
"%d天", p_tm->tm_yday); |
| 89 |
} |
} |
| 90 |
else if (p_tm->tm_hour > 0) |
else if (p_tm->tm_hour > 0) |
| 91 |
{ |
{ |
| 92 |
snprintf(str_time, sizeof(str_time), |
snprintf(str_time_login, sizeof(str_time_login), |
| 93 |
"%d时%d分", p_tm->tm_hour, p_tm->tm_min); |
"%d时%d分", p_tm->tm_hour, p_tm->tm_min); |
| 94 |
} |
} |
| 95 |
else |
else |
| 96 |
{ |
{ |
| 97 |
snprintf(str_time, sizeof(str_time), |
snprintf(str_time_login, sizeof(str_time_login), |
| 98 |
"%d分%d秒", p_tm->tm_min, p_tm->tm_sec); |
"%d分%d秒", p_tm->tm_min, p_tm->tm_sec); |
| 99 |
} |
} |
| 100 |
|
|
| 101 |
moveto(4 + i, 1); |
moveto(4 + i, 1); |
| 102 |
|
|
| 103 |
prints(" %7d %s%*s %s%*s %s", |
prints(" %6d %s%*s %s%*s %s", |
| 104 |
p_users[i].uid, |
p_users[i].uid, |
| 105 |
p_users[i].username, |
p_users[i].username, |
| 106 |
BBS_username_max_len - str_length(p_users[i].username, 1), |
BBS_username_max_len - str_length(p_users[i].username, 1), |
| 108 |
p_users[i].nickname, |
p_users[i].nickname, |
| 109 |
BBS_nickname_max_len / 2 - str_length(p_users[i].nickname, 1), |
BBS_nickname_max_len / 2 - str_length(p_users[i].nickname, 1), |
| 110 |
"", |
"", |
| 111 |
str_time); |
str_time_login); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
return 0; |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
static int user_online_list_draw_items(int page_id, USER_ONLINE_INFO *p_users, int user_count) |
| 118 |
|
{ |
| 119 |
|
char str_time_login[LINE_BUFFER_LEN]; |
| 120 |
|
char str_time_idle[LINE_BUFFER_LEN]; |
| 121 |
|
const char *p_action_title; |
| 122 |
|
time_t tm_now; |
| 123 |
|
time_t tm_duration; |
| 124 |
|
struct tm *p_tm; |
| 125 |
|
int i; |
| 126 |
|
|
| 127 |
|
clrline(4, 23); |
| 128 |
|
|
| 129 |
|
time(&tm_now); |
| 130 |
|
|
| 131 |
|
for (i = 0; i < user_count; i++) |
| 132 |
|
{ |
| 133 |
|
tm_duration = tm_now - p_users[i].login_tm; |
| 134 |
|
p_tm = gmtime(&tm_duration); |
| 135 |
|
if (p_tm == NULL) |
| 136 |
|
{ |
| 137 |
|
log_error("Invalid time duration\n"); |
| 138 |
|
str_time_login[0] = '\0'; |
| 139 |
|
} |
| 140 |
|
else if (p_tm->tm_yday > 0) |
| 141 |
|
{ |
| 142 |
|
snprintf(str_time_login, sizeof(str_time_login), |
| 143 |
|
"%d天%d时", p_tm->tm_yday, p_tm->tm_hour); |
| 144 |
|
} |
| 145 |
|
else if (p_tm->tm_hour > 0) |
| 146 |
|
{ |
| 147 |
|
snprintf(str_time_login, sizeof(str_time_login), |
| 148 |
|
"%d时%d分", p_tm->tm_hour, p_tm->tm_min); |
| 149 |
|
} |
| 150 |
|
else |
| 151 |
|
{ |
| 152 |
|
snprintf(str_time_login, sizeof(str_time_login), |
| 153 |
|
"%d\'%d\"", p_tm->tm_min, p_tm->tm_sec); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
tm_duration = tm_now - p_users[i].last_tm; |
| 157 |
|
p_tm = gmtime(&tm_duration); |
| 158 |
|
if (p_tm == NULL) |
| 159 |
|
{ |
| 160 |
|
log_error("Invalid time duration\n"); |
| 161 |
|
str_time_idle[0] = '\0'; |
| 162 |
|
} |
| 163 |
|
else if (p_tm->tm_min > 0) |
| 164 |
|
{ |
| 165 |
|
snprintf(str_time_idle, sizeof(str_time_idle), |
| 166 |
|
"%d\'%d\"", p_tm->tm_min, p_tm->tm_sec); |
| 167 |
|
} |
| 168 |
|
else |
| 169 |
|
{ |
| 170 |
|
snprintf(str_time_idle, sizeof(str_time_idle), |
| 171 |
|
"%d\"", p_tm->tm_sec); |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
p_action_title = (p_users[i].current_action_title != NULL |
| 175 |
|
? p_users[i].current_action_title |
| 176 |
|
: p_users[i].current_action); |
| 177 |
|
|
| 178 |
|
moveto(4 + i, 1); |
| 179 |
|
|
| 180 |
|
prints(" %6d %s%*s %s%*s %s%*s %s%*s %s", |
| 181 |
|
p_users[i].user_info.uid, |
| 182 |
|
p_users[i].user_info.username, |
| 183 |
|
BBS_username_max_len - str_length(p_users[i].user_info.username, 1), |
| 184 |
|
"", |
| 185 |
|
p_users[i].user_info.nickname, |
| 186 |
|
BBS_nickname_max_len / 2 - str_length(p_users[i].user_info.nickname, 1), |
| 187 |
|
"", |
| 188 |
|
str_time_login, |
| 189 |
|
8 - str_length(str_time_login, 1), |
| 190 |
|
"", |
| 191 |
|
str_time_idle, |
| 192 |
|
6 - str_length(str_time_idle, 1), |
| 193 |
|
"", |
| 194 |
|
p_action_title); |
| 195 |
} |
} |
| 196 |
|
|
| 197 |
return 0; |
return 0; |
| 335 |
return EXIT_LIST; |
return EXIT_LIST; |
| 336 |
} |
} |
| 337 |
|
|
| 338 |
int user_list_display(void) |
int user_list_display(int online_user) |
| 339 |
{ |
{ |
| 340 |
char page_info_str[LINE_BUFFER_LEN]; |
char page_info_str[LINE_BUFFER_LEN]; |
| 341 |
USER_INFO users[BBS_user_limit_per_page]; |
USER_INFO users[BBS_user_limit_per_page]; |
| 342 |
|
USER_ONLINE_INFO online_users[BBS_user_limit_per_page]; |
| 343 |
int user_count; |
int user_count; |
| 344 |
int page_count; |
int page_count; |
| 345 |
int page_id = 0; |
int page_id = 0; |
| 346 |
int selected_index = 0; |
int selected_index = 0; |
| 347 |
int ret; |
int ret; |
| 348 |
|
|
| 349 |
user_list_draw_screen(); |
user_list_draw_screen(online_user); |
| 350 |
|
|
| 351 |
ret = query_user_list(page_id, users, &user_count, &page_count); |
if (online_user) |
|
if (ret < 0) |
|
| 352 |
{ |
{ |
| 353 |
log_error("query_user_list(page_id=%d) error\n", page_id); |
ret = query_user_online_list(page_id, online_users, &user_count, &page_count); |
| 354 |
return -2; |
if (ret < 0) |
| 355 |
|
{ |
| 356 |
|
log_error("query_user_online_list(page_id=%d) error\n", page_id); |
| 357 |
|
return -2; |
| 358 |
|
} |
| 359 |
|
} |
| 360 |
|
else |
| 361 |
|
{ |
| 362 |
|
ret = query_user_list(page_id, users, &user_count, &page_count); |
| 363 |
|
if (ret < 0) |
| 364 |
|
{ |
| 365 |
|
log_error("query_user_list(page_id=%d) error\n", page_id); |
| 366 |
|
return -2; |
| 367 |
|
} |
| 368 |
} |
} |
| 369 |
|
|
| 370 |
if (user_count == 0) // empty list |
if (user_count == 0) // empty list |
| 374 |
|
|
| 375 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 376 |
{ |
{ |
| 377 |
ret = user_list_draw_items(page_id, users, user_count); |
if (online_user) |
|
if (ret < 0) |
|
| 378 |
{ |
{ |
| 379 |
log_error("user_list_draw_items(page_id=%d) error\n", page_id); |
ret = user_online_list_draw_items(page_id, online_users, user_count); |
| 380 |
return -3; |
if (ret < 0) |
| 381 |
|
{ |
| 382 |
|
log_error("user_online_list_draw_items(page_id=%d) error\n", page_id); |
| 383 |
|
return -3; |
| 384 |
|
} |
| 385 |
|
} |
| 386 |
|
else |
| 387 |
|
{ |
| 388 |
|
ret = user_list_draw_items(page_id, users, user_count); |
| 389 |
|
if (ret < 0) |
| 390 |
|
{ |
| 391 |
|
log_error("user_list_draw_items(page_id=%d) error\n", page_id); |
| 392 |
|
return -3; |
| 393 |
|
} |
| 394 |
} |
} |
| 395 |
|
|
| 396 |
snprintf(page_info_str, sizeof(page_info_str), |
snprintf(page_info_str, sizeof(page_info_str), |
| 400 |
show_bottom(page_info_str); |
show_bottom(page_info_str); |
| 401 |
iflush(); |
iflush(); |
| 402 |
|
|
| 403 |
if (user_online_update("USER_LIST") < 0) |
if (user_online_update(online_user ? "USER_ONLINE" : "USER_LIST") < 0) |
| 404 |
{ |
{ |
| 405 |
log_error("user_online_update(USER_LIST) error\n"); |
log_error("user_online_update(%s) error\n", |
| 406 |
|
(online_user ? "USER_ONLINE" : "USER_LIST")); |
| 407 |
} |
} |
| 408 |
|
|
| 409 |
ret = user_list_select(page_count, user_count, &page_id, &selected_index); |
ret = user_list_select(page_count, user_count, &page_id, &selected_index); |
| 429 |
} |
} |
| 430 |
break; |
break; |
| 431 |
case VIEW_USER: |
case VIEW_USER: |
| 432 |
|
log_error("View user (uid=%d)\n", |
| 433 |
|
(online_user ? online_users[selected_index].user_info.uid : users[selected_index].uid)); |
| 434 |
clearscr(); |
clearscr(); |
| 435 |
press_any_key_ex("功能不可用,按任意键返回", 60); |
press_any_key_ex("功能不可用,按任意键返回", 60); |
| 436 |
user_list_draw_screen(); |
user_list_draw_screen(online_user); |
| 437 |
break; |
break; |
| 438 |
case SHOW_HELP: |
case SHOW_HELP: |
| 439 |
// Display help information |
// Display help information |
| 440 |
display_file(DATA_READ_HELP, 1); |
display_file(DATA_READ_HELP, 1); |
| 441 |
user_list_draw_screen(); |
user_list_draw_screen(online_user); |
| 442 |
break; |
break; |
| 443 |
default: |
default: |
| 444 |
log_error("Unknown command %d\n", ret); |
log_error("Unknown command %d\n", ret); |