| 32 |
EXIT_LIST = 0, |
EXIT_LIST = 0, |
| 33 |
VIEW_USER, |
VIEW_USER, |
| 34 |
CHANGE_PAGE, |
CHANGE_PAGE, |
| 35 |
|
REFRESH_LIST, |
| 36 |
SHOW_HELP, |
SHOW_HELP, |
| 37 |
}; |
}; |
| 38 |
|
|
| 39 |
static int user_list_draw_screen() |
static int user_list_draw_screen(int online_user) |
| 40 |
{ |
{ |
| 41 |
clearscr(); |
clearscr(); |
| 42 |
show_top("[已注册用户]", BBS_name, ""); |
show_top((online_user ? "[线上使用者]" : "[已注册用户]"), BBS_name, ""); |
| 43 |
moveto(2, 0); |
moveto(2, 0); |
| 44 |
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] " |
| 45 |
"查看[\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"); |
| 46 |
moveto(3, 0); |
moveto(3, 0); |
| 47 |
prints("\033[44;37m \033[1;37m 编 号 用户名 昵称 上次登陆距今 \033[m"); |
|
| 48 |
|
if (online_user) |
| 49 |
|
{ |
| 50 |
|
prints("\033[44;37m \033[1;37m 编 号 用户名 昵称 在线时长 空闲 最后活动 \033[m"); |
| 51 |
|
} |
| 52 |
|
else |
| 53 |
|
{ |
| 54 |
|
prints("\033[44;37m \033[1;37m 编 号 用户名 昵称 上次登陆距今 \033[m"); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
return 0; |
return 0; |
| 58 |
} |
} |
| 59 |
|
|
| 60 |
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) |
|
| 61 |
{ |
{ |
| 62 |
char str_time[LINE_BUFFER_LEN]; |
char str_time_login[LINE_BUFFER_LEN]; |
| 63 |
time_t tm_now; |
time_t tm_now; |
| 64 |
time_t tm_duration; |
time_t tm_duration; |
| 65 |
struct tm *p_tm; |
struct tm *p_tm; |
| 73 |
{ |
{ |
| 74 |
tm_duration = tm_now - p_users[i].last_login_dt; |
tm_duration = tm_now - p_users[i].last_login_dt; |
| 75 |
p_tm = gmtime(&tm_duration); |
p_tm = gmtime(&tm_duration); |
| 76 |
if (p_tm->tm_year > 70) |
if (p_tm == NULL) |
| 77 |
|
{ |
| 78 |
|
log_error("Invalid time duration\n"); |
| 79 |
|
str_time_login[0] = '\0'; |
| 80 |
|
} |
| 81 |
|
else if (p_tm->tm_year > 70) |
| 82 |
{ |
{ |
| 83 |
snprintf(str_time, sizeof(str_time), |
snprintf(str_time_login, sizeof(str_time_login), |
| 84 |
"%d年", p_tm->tm_year - 70); |
"%d年", p_tm->tm_year - 70); |
| 85 |
} |
} |
| 86 |
else if (p_tm->tm_yday > 1) |
else if (p_tm->tm_yday > 0) |
| 87 |
{ |
{ |
| 88 |
snprintf(str_time, sizeof(str_time), |
snprintf(str_time_login, sizeof(str_time_login), |
| 89 |
"%d天", p_tm->tm_yday); |
"%d天", p_tm->tm_yday); |
| 90 |
} |
} |
| 91 |
else if (p_tm->tm_hour > 0) |
else if (p_tm->tm_hour > 0) |
| 92 |
{ |
{ |
| 93 |
snprintf(str_time, sizeof(str_time), |
snprintf(str_time_login, sizeof(str_time_login), |
| 94 |
"%d时%d分", p_tm->tm_hour, p_tm->tm_min); |
"%d时%d分", p_tm->tm_hour, p_tm->tm_min); |
| 95 |
} |
} |
| 96 |
else |
else |
| 97 |
{ |
{ |
| 98 |
snprintf(str_time, sizeof(str_time), |
snprintf(str_time_login, sizeof(str_time_login), |
| 99 |
"%d分%d秒", p_tm->tm_min, p_tm->tm_sec); |
"%d分%d秒", p_tm->tm_min, p_tm->tm_sec); |
| 100 |
} |
} |
| 101 |
|
|
| 102 |
moveto(4 + i, 1); |
moveto(4 + i, 1); |
| 103 |
|
|
| 104 |
prints(" %7d %s%*s %s%*s %s", |
prints(" %6d %s%*s %s%*s %s", |
| 105 |
p_users[i].uid, |
p_users[i].id + 1, |
| 106 |
p_users[i].username, |
p_users[i].username, |
| 107 |
BBS_username_max_len - str_length(p_users[i].username, 1), |
BBS_username_max_len - str_length(p_users[i].username, 1), |
| 108 |
"", |
"", |
| 109 |
p_users[i].nickname, |
p_users[i].nickname, |
| 110 |
BBS_nickname_max_len / 2 - str_length(p_users[i].nickname, 1), |
BBS_nickname_max_len / 2 - str_length(p_users[i].nickname, 1), |
| 111 |
"", |
"", |
| 112 |
str_time); |
str_time_login); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
return 0; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
static int user_online_list_draw_items(int page_id, USER_ONLINE_INFO *p_users, int user_count) |
| 119 |
|
{ |
| 120 |
|
char str_time_login[LINE_BUFFER_LEN]; |
| 121 |
|
char str_time_idle[LINE_BUFFER_LEN]; |
| 122 |
|
const char *p_action_title; |
| 123 |
|
time_t tm_now; |
| 124 |
|
time_t tm_duration; |
| 125 |
|
struct tm *p_tm; |
| 126 |
|
int i; |
| 127 |
|
|
| 128 |
|
clrline(4, 23); |
| 129 |
|
|
| 130 |
|
time(&tm_now); |
| 131 |
|
|
| 132 |
|
for (i = 0; i < user_count; i++) |
| 133 |
|
{ |
| 134 |
|
tm_duration = tm_now - p_users[i].login_tm; |
| 135 |
|
p_tm = gmtime(&tm_duration); |
| 136 |
|
if (p_tm == NULL) |
| 137 |
|
{ |
| 138 |
|
log_error("Invalid time duration\n"); |
| 139 |
|
str_time_login[0] = '\0'; |
| 140 |
|
} |
| 141 |
|
else if (p_tm->tm_yday > 0) |
| 142 |
|
{ |
| 143 |
|
snprintf(str_time_login, sizeof(str_time_login), |
| 144 |
|
"%d天%d时", p_tm->tm_yday, p_tm->tm_hour); |
| 145 |
|
} |
| 146 |
|
else if (p_tm->tm_hour > 0) |
| 147 |
|
{ |
| 148 |
|
snprintf(str_time_login, sizeof(str_time_login), |
| 149 |
|
"%d时%d分", p_tm->tm_hour, p_tm->tm_min); |
| 150 |
|
} |
| 151 |
|
else |
| 152 |
|
{ |
| 153 |
|
snprintf(str_time_login, sizeof(str_time_login), |
| 154 |
|
"%d\'%d\"", p_tm->tm_min, p_tm->tm_sec); |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
tm_duration = tm_now - p_users[i].last_tm; |
| 158 |
|
p_tm = gmtime(&tm_duration); |
| 159 |
|
if (p_tm == NULL) |
| 160 |
|
{ |
| 161 |
|
log_error("Invalid time duration\n"); |
| 162 |
|
str_time_idle[0] = '\0'; |
| 163 |
|
} |
| 164 |
|
else if (p_tm->tm_min > 0) |
| 165 |
|
{ |
| 166 |
|
snprintf(str_time_idle, sizeof(str_time_idle), |
| 167 |
|
"%d\'%d\"", p_tm->tm_min, p_tm->tm_sec); |
| 168 |
|
} |
| 169 |
|
else |
| 170 |
|
{ |
| 171 |
|
snprintf(str_time_idle, sizeof(str_time_idle), |
| 172 |
|
"%d\"", p_tm->tm_sec); |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
p_action_title = (p_users[i].current_action_title != NULL |
| 176 |
|
? p_users[i].current_action_title |
| 177 |
|
: p_users[i].current_action); |
| 178 |
|
|
| 179 |
|
moveto(4 + i, 1); |
| 180 |
|
|
| 181 |
|
prints(" %6d %s%*s %s%*s %s%*s %s%*s %s", |
| 182 |
|
p_users[i].id + 1, |
| 183 |
|
p_users[i].user_info.username, |
| 184 |
|
BBS_username_max_len - str_length(p_users[i].user_info.username, 1), |
| 185 |
|
"", |
| 186 |
|
p_users[i].user_info.nickname, |
| 187 |
|
BBS_nickname_max_len / 2 - str_length(p_users[i].user_info.nickname, 1), |
| 188 |
|
"", |
| 189 |
|
str_time_login, |
| 190 |
|
8 - str_length(str_time_login, 1), |
| 191 |
|
"", |
| 192 |
|
str_time_idle, |
| 193 |
|
6 - str_length(str_time_idle, 1), |
| 194 |
|
"", |
| 195 |
|
p_action_title); |
| 196 |
} |
} |
| 197 |
|
|
| 198 |
return 0; |
return 0; |
| 304 |
(*p_selected_index)++; |
(*p_selected_index)++; |
| 305 |
} |
} |
| 306 |
break; |
break; |
| 307 |
|
case KEY_F5: |
| 308 |
|
return REFRESH_LIST; |
| 309 |
case 'h': |
case 'h': |
| 310 |
return SHOW_HELP; |
return SHOW_HELP; |
| 311 |
default: |
default: |
| 338 |
return EXIT_LIST; |
return EXIT_LIST; |
| 339 |
} |
} |
| 340 |
|
|
| 341 |
int user_list_display(void) |
int user_list_display(int online_user) |
| 342 |
{ |
{ |
| 343 |
char page_info_str[LINE_BUFFER_LEN]; |
char page_info_str[LINE_BUFFER_LEN]; |
| 344 |
USER_INFO users[BBS_user_limit_per_page]; |
USER_INFO users[BBS_user_limit_per_page]; |
| 345 |
USER_INFO user_info; |
USER_ONLINE_INFO online_users[BBS_user_limit_per_page]; |
| 346 |
int user_count; |
int user_count = 0; |
| 347 |
int page_count; |
int page_count = 0; |
| 348 |
int page_id = 0; |
int page_id = 0; |
| 349 |
int selected_index = 0; |
int selected_index = 0; |
| 350 |
int ret; |
int ret = 0; |
| 351 |
|
|
| 352 |
user_list_draw_screen(); |
user_list_draw_screen(online_user); |
| 353 |
|
|
| 354 |
ret = query_user_list(page_id, users, &user_count, &page_count); |
if (online_user) |
|
if (ret < 0) |
|
| 355 |
{ |
{ |
| 356 |
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); |
| 357 |
return -2; |
if (ret < 0) |
| 358 |
|
{ |
| 359 |
|
log_error("query_user_online_list(page_id=%d) error\n", page_id); |
| 360 |
|
return -2; |
| 361 |
|
} |
| 362 |
|
} |
| 363 |
|
else |
| 364 |
|
{ |
| 365 |
|
ret = query_user_list(page_id, users, &user_count, &page_count); |
| 366 |
|
if (ret < 0) |
| 367 |
|
{ |
| 368 |
|
log_error("query_user_list(page_id=%d) error\n", page_id); |
| 369 |
|
return -2; |
| 370 |
|
} |
| 371 |
} |
} |
| 372 |
|
|
| 373 |
if (user_count == 0) // empty list |
if (user_count == 0) // empty list |
| 377 |
|
|
| 378 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 379 |
{ |
{ |
| 380 |
ret = user_list_draw_items(page_id, users, user_count); |
if (online_user) |
|
if (ret < 0) |
|
| 381 |
{ |
{ |
| 382 |
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); |
| 383 |
return -3; |
if (ret < 0) |
| 384 |
|
{ |
| 385 |
|
log_error("user_online_list_draw_items(page_id=%d) error\n", page_id); |
| 386 |
|
return -3; |
| 387 |
|
} |
| 388 |
|
} |
| 389 |
|
else |
| 390 |
|
{ |
| 391 |
|
ret = user_list_draw_items(page_id, users, user_count); |
| 392 |
|
if (ret < 0) |
| 393 |
|
{ |
| 394 |
|
log_error("user_list_draw_items(page_id=%d) error\n", page_id); |
| 395 |
|
return -3; |
| 396 |
|
} |
| 397 |
} |
} |
| 398 |
|
|
| 399 |
snprintf(page_info_str, sizeof(page_info_str), |
snprintf(page_info_str, sizeof(page_info_str), |
| 403 |
show_bottom(page_info_str); |
show_bottom(page_info_str); |
| 404 |
iflush(); |
iflush(); |
| 405 |
|
|
| 406 |
if (user_online_update("USER_LIST") < 0) |
if (user_online_update(online_user ? "USER_ONLINE" : "USER_LIST") < 0) |
| 407 |
{ |
{ |
| 408 |
log_error("user_online_update(USER_LIST) error\n"); |
log_error("user_online_update(%s) error\n", |
| 409 |
|
(online_user ? "USER_ONLINE" : "USER_LIST")); |
| 410 |
} |
} |
| 411 |
|
|
| 412 |
ret = user_list_select(page_count, user_count, &page_id, &selected_index); |
ret = user_list_select(page_count, user_count, &page_id, &selected_index); |
| 414 |
{ |
{ |
| 415 |
case EXIT_LIST: |
case EXIT_LIST: |
| 416 |
return 0; |
return 0; |
| 417 |
|
case REFRESH_LIST: |
| 418 |
case CHANGE_PAGE: |
case CHANGE_PAGE: |
| 419 |
ret = query_user_list(page_id, users, &user_count, &page_count); |
if (online_user) |
|
if (ret < 0) |
|
| 420 |
{ |
{ |
| 421 |
log_error("query_favor_articles(page_id=%d) error\n", page_id); |
ret = query_user_online_list(page_id, online_users, &user_count, &page_count); |
| 422 |
return -2; |
if (ret < 0) |
| 423 |
|
{ |
| 424 |
|
log_error("query_user_online_list(page_id=%d) error\n", page_id); |
| 425 |
|
return -2; |
| 426 |
|
} |
| 427 |
|
} |
| 428 |
|
else |
| 429 |
|
{ |
| 430 |
|
ret = query_user_list(page_id, users, &user_count, &page_count); |
| 431 |
|
if (ret < 0) |
| 432 |
|
{ |
| 433 |
|
log_error("query_user_list(page_id=%d) error\n", page_id); |
| 434 |
|
return -2; |
| 435 |
|
} |
| 436 |
} |
} |
| 437 |
|
|
| 438 |
if (user_count == 0) // empty list |
if (user_count == 0) // empty list |
| 445 |
} |
} |
| 446 |
break; |
break; |
| 447 |
case VIEW_USER: |
case VIEW_USER: |
| 448 |
if ((ret = query_user_info(users[selected_index].uid, &user_info)) < 0) |
clearscr(); |
| 449 |
|
if (online_user) |
| 450 |
{ |
{ |
| 451 |
log_error("query_user_info(uid=%d) error: %d\n", users[selected_index].uid, ret); |
prints("已选中用户 [%s] 会话 %d", online_users[selected_index].user_info.username, online_users[selected_index].id); |
| 452 |
} |
|
| 453 |
else if (ret == 0) |
USER_ONLINE_INFO users[5]; |
| 454 |
{ |
int user_cnt = 5; |
| 455 |
log_error("query_user_info(uid=%d) error: user not found\n", users[selected_index].uid); |
ret = query_user_online_info_by_uid(online_users[selected_index].user_info.uid, users, &user_cnt, 0); |
| 456 |
} |
if (ret <= 0) |
| 457 |
else if (users[selected_index].uid != user_info.uid) |
{ |
| 458 |
{ |
log_error("query_user_online_info_by_uid(uid=%d, cnt=%d) error: %d\n", |
| 459 |
log_error("query_user_info(uid=%d) error: inconsistent uid=%d\n", users[selected_index].uid, user_info.uid); |
online_users[selected_index].user_info.uid, user_cnt, ret); |
| 460 |
|
} |
| 461 |
|
else |
| 462 |
|
{ |
| 463 |
|
for (int i = 0; i < user_cnt; i++) |
| 464 |
|
{ |
| 465 |
|
moveto(2 + i, 1); |
| 466 |
|
prints("会话%d", users[i].id); |
| 467 |
|
} |
| 468 |
|
} |
| 469 |
} |
} |
| 470 |
else |
else |
| 471 |
{ |
{ |
| 472 |
clearscr(); |
prints("已选中用户 [%s]", users[selected_index].username); |
|
press_any_key_ex("功能不可用,按任意键返回", 60); |
|
|
user_list_draw_screen(); |
|
| 473 |
} |
} |
| 474 |
|
press_any_key(); |
| 475 |
|
user_list_draw_screen(online_user); |
| 476 |
break; |
break; |
| 477 |
case SHOW_HELP: |
case SHOW_HELP: |
| 478 |
// Display help information |
// Display help information |
| 479 |
display_file(DATA_READ_HELP, 1); |
display_file(DATA_READ_HELP, 1); |
| 480 |
user_list_draw_screen(); |
user_list_draw_screen(online_user); |
| 481 |
break; |
break; |
| 482 |
default: |
default: |
| 483 |
log_error("Unknown command %d\n", ret); |
log_error("Unknown command %d\n", ret); |