| 22 |
#include "str_process.h" |
#include "str_process.h" |
| 23 |
#include "user_list.h" |
#include "user_list.h" |
| 24 |
#include "user_priv.h" |
#include "user_priv.h" |
| 25 |
|
#include "user_info_display.h" |
| 26 |
#include "user_list_display.h" |
#include "user_list_display.h" |
| 27 |
|
#include <ctype.h> |
| 28 |
#include <string.h> |
#include <string.h> |
| 29 |
#include <time.h> |
#include <time.h> |
| 30 |
#include <sys/param.h> |
#include <sys/param.h> |
| 36 |
CHANGE_PAGE, |
CHANGE_PAGE, |
| 37 |
REFRESH_LIST, |
REFRESH_LIST, |
| 38 |
SHOW_HELP, |
SHOW_HELP, |
| 39 |
|
SEARCH_USER, |
| 40 |
}; |
}; |
| 41 |
|
|
| 42 |
static int user_list_draw_screen(int online_user) |
static int user_list_draw_screen(int online_user) |
| 43 |
{ |
{ |
| 44 |
clearscr(); |
clearscr(); |
| 45 |
show_top((online_user ? "[在线用户]" : "[已注册用户]"), BBS_name, ""); |
show_top((online_user ? "[线上使用者]" : "[已注册用户]"), BBS_name, ""); |
| 46 |
moveto(2, 0); |
moveto(2, 0); |
| 47 |
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] " |
| 48 |
"查看[\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;32ms\033[0;37m] " |
| 49 |
|
"帮助[\033[1;32mh\033[0;37m]\033[m"); |
| 50 |
moveto(3, 0); |
moveto(3, 0); |
| 51 |
|
|
| 52 |
if (online_user) |
if (online_user) |
| 85 |
else if (p_tm->tm_year > 70) |
else if (p_tm->tm_year > 70) |
| 86 |
{ |
{ |
| 87 |
snprintf(str_time_login, sizeof(str_time_login), |
snprintf(str_time_login, sizeof(str_time_login), |
| 88 |
"%d年", p_tm->tm_year - 70); |
"%d年%d天", p_tm->tm_year - 70, p_tm->tm_yday); |
| 89 |
} |
} |
| 90 |
else if (p_tm->tm_yday > 0) |
else if (p_tm->tm_yday > 0) |
| 91 |
{ |
{ |
| 95 |
else if (p_tm->tm_hour > 0) |
else if (p_tm->tm_hour > 0) |
| 96 |
{ |
{ |
| 97 |
snprintf(str_time_login, sizeof(str_time_login), |
snprintf(str_time_login, sizeof(str_time_login), |
| 98 |
"%d时%d分", p_tm->tm_hour, p_tm->tm_min); |
"%d:%.2d", p_tm->tm_hour, p_tm->tm_min); |
| 99 |
} |
} |
| 100 |
else |
else |
| 101 |
{ |
{ |
| 102 |
snprintf(str_time_login, sizeof(str_time_login), |
snprintf(str_time_login, sizeof(str_time_login), |
| 103 |
"%d分%d秒", p_tm->tm_min, p_tm->tm_sec); |
"%d\'%.2d\"", p_tm->tm_min, p_tm->tm_sec); |
| 104 |
} |
} |
| 105 |
|
|
| 106 |
moveto(4 + i, 1); |
moveto(4 + i, 1); |
| 145 |
else if (p_tm->tm_yday > 0) |
else if (p_tm->tm_yday > 0) |
| 146 |
{ |
{ |
| 147 |
snprintf(str_time_login, sizeof(str_time_login), |
snprintf(str_time_login, sizeof(str_time_login), |
| 148 |
"%d天%d时", p_tm->tm_yday, p_tm->tm_hour); |
"%dd%dh", p_tm->tm_yday, p_tm->tm_hour); |
| 149 |
} |
} |
| 150 |
else if (p_tm->tm_hour > 0) |
else if (p_tm->tm_hour > 0) |
| 151 |
{ |
{ |
| 152 |
snprintf(str_time_login, sizeof(str_time_login), |
snprintf(str_time_login, sizeof(str_time_login), |
| 153 |
"%d时%d分", p_tm->tm_hour, p_tm->tm_min); |
"%d:%.2d", p_tm->tm_hour, p_tm->tm_min); |
| 154 |
} |
} |
| 155 |
else |
else |
| 156 |
{ |
{ |
| 157 |
snprintf(str_time_login, sizeof(str_time_login), |
snprintf(str_time_login, sizeof(str_time_login), |
| 158 |
"%d\'%d\"", p_tm->tm_min, p_tm->tm_sec); |
"%d\'%.2d\"", p_tm->tm_min, p_tm->tm_sec); |
| 159 |
} |
} |
| 160 |
|
|
| 161 |
tm_duration = tm_now - p_users[i].last_tm; |
tm_duration = tm_now - p_users[i].last_tm; |
| 308 |
(*p_selected_index)++; |
(*p_selected_index)++; |
| 309 |
} |
} |
| 310 |
break; |
break; |
| 311 |
|
case 's': |
| 312 |
|
return SEARCH_USER; |
| 313 |
case KEY_F5: |
case KEY_F5: |
| 314 |
return REFRESH_LIST; |
return REFRESH_LIST; |
| 315 |
case 'h': |
case 'h': |
| 349 |
char page_info_str[LINE_BUFFER_LEN]; |
char page_info_str[LINE_BUFFER_LEN]; |
| 350 |
USER_INFO users[BBS_user_limit_per_page]; |
USER_INFO users[BBS_user_limit_per_page]; |
| 351 |
USER_ONLINE_INFO online_users[BBS_user_limit_per_page]; |
USER_ONLINE_INFO online_users[BBS_user_limit_per_page]; |
| 352 |
int user_count; |
int user_count = 0; |
| 353 |
int page_count; |
int page_count = 0; |
| 354 |
int page_id = 0; |
int page_id = 0; |
| 355 |
int selected_index = 0; |
int selected_index = 0; |
| 356 |
int ret; |
int ret = 0; |
| 357 |
|
|
| 358 |
user_list_draw_screen(online_user); |
user_list_draw_screen(online_user); |
| 359 |
|
|
| 451 |
} |
} |
| 452 |
break; |
break; |
| 453 |
case VIEW_USER: |
case VIEW_USER: |
| 454 |
clearscr(); |
user_info_display(online_user ? &(online_users[selected_index].user_info) : &(users[selected_index])); |
| 455 |
prints("已选中用户 [%s]\n", online_user |
user_list_draw_screen(online_user); |
| 456 |
? online_users[selected_index].user_info.username |
break; |
| 457 |
: users[selected_index].username); |
case SEARCH_USER: |
| 458 |
press_any_key(); |
user_list_search(); |
| 459 |
user_list_draw_screen(online_user); |
user_list_draw_screen(online_user); |
| 460 |
break; |
break; |
| 461 |
case SHOW_HELP: |
case SHOW_HELP: |
| 468 |
} |
} |
| 469 |
} |
} |
| 470 |
|
|
| 471 |
|
return 0; |
| 472 |
|
} |
| 473 |
|
|
| 474 |
|
int user_list_search(void) |
| 475 |
|
{ |
| 476 |
|
const int users_per_line = 5; |
| 477 |
|
const int max_user_lines = 20; |
| 478 |
|
const int max_user_cnt = users_per_line * max_user_lines + 1; |
| 479 |
|
|
| 480 |
|
char username[BBS_username_max_len + 1]; |
| 481 |
|
int32_t uid_list[max_user_cnt]; |
| 482 |
|
char username_list[max_user_cnt][BBS_username_max_len + 1]; |
| 483 |
|
int ret; |
| 484 |
|
int i; |
| 485 |
|
USER_INFO user_info; |
| 486 |
|
char user_intro[BBS_user_intro_max_len]; |
| 487 |
|
int ok; |
| 488 |
|
|
| 489 |
|
username[0] = '\0'; |
| 490 |
|
|
| 491 |
|
clearscr(); |
| 492 |
|
|
| 493 |
|
while (!SYS_server_exit) |
| 494 |
|
{ |
| 495 |
|
get_data(2, 1, "查找谁: ", username, sizeof(username), BBS_username_max_len); |
| 496 |
|
|
| 497 |
|
if (username[0] == '\0') |
| 498 |
|
{ |
| 499 |
|
return 0; |
| 500 |
|
} |
| 501 |
|
|
| 502 |
|
// Verify format |
| 503 |
|
for (i = 0, ok = 1; ok && username[i] != '\0'; i++) |
| 504 |
|
{ |
| 505 |
|
if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_')))) |
| 506 |
|
{ |
| 507 |
|
ok = 0; |
| 508 |
|
} |
| 509 |
|
} |
| 510 |
|
if (ok && i > BBS_username_max_len) |
| 511 |
|
{ |
| 512 |
|
ok = 0; |
| 513 |
|
} |
| 514 |
|
if (!ok) |
| 515 |
|
{ |
| 516 |
|
moveto(3, 1); |
| 517 |
|
clrtoeol(); |
| 518 |
|
prints("用户名格式非法"); |
| 519 |
|
continue; |
| 520 |
|
} |
| 521 |
|
|
| 522 |
|
clrline(3, SCREEN_ROWS); |
| 523 |
|
|
| 524 |
|
ret = query_user_info_by_username(username, max_user_cnt, uid_list, username_list); |
| 525 |
|
|
| 526 |
|
if (ret < 0) |
| 527 |
|
{ |
| 528 |
|
log_error("query_user_info_by_username(%s) error\n", username); |
| 529 |
|
return -1; |
| 530 |
|
} |
| 531 |
|
else if (ret > 1) |
| 532 |
|
{ |
| 533 |
|
moveto(3, 1); |
| 534 |
|
prints("存在多个匹配的用户,[S]精确查找,[L]列出全部? [L]"); |
| 535 |
|
iflush(); |
| 536 |
|
igetch_reset(); |
| 537 |
|
|
| 538 |
|
switch (igetch_t(MAX_DELAY_TIME)) |
| 539 |
|
{ |
| 540 |
|
case KEY_NULL: |
| 541 |
|
case KEY_TIMEOUT: |
| 542 |
|
return -1; |
| 543 |
|
case KEY_ESC: |
| 544 |
|
return 0; |
| 545 |
|
case 'S': |
| 546 |
|
case 's': |
| 547 |
|
ret = (strcasecmp(username_list[0], username) == 0 ? 1 : 0); |
| 548 |
|
break; |
| 549 |
|
case 'L': |
| 550 |
|
case 'l': |
| 551 |
|
case CR: |
| 552 |
|
for (i = 0; i < MIN(ret, users_per_line * max_user_lines); i++) |
| 553 |
|
{ |
| 554 |
|
moveto(4 + i / users_per_line, 3 + i % users_per_line * (BBS_username_max_len + 3)); |
| 555 |
|
prints("%s", username_list[i]); |
| 556 |
|
} |
| 557 |
|
moveto(SCREEN_ROWS, 1); |
| 558 |
|
if (ret > users_per_line * max_user_lines) |
| 559 |
|
{ |
| 560 |
|
prints("还有更多..."); |
| 561 |
|
} |
| 562 |
|
continue; |
| 563 |
|
default: |
| 564 |
|
moveto(3, 1); |
| 565 |
|
clrtoeol(); |
| 566 |
|
continue; |
| 567 |
|
} |
| 568 |
|
} |
| 569 |
|
|
| 570 |
|
if (ret == 0) |
| 571 |
|
{ |
| 572 |
|
moveto(3, 1); |
| 573 |
|
clrtoeol(); |
| 574 |
|
prints("没有找到符合条件的用户"); |
| 575 |
|
press_any_key(); |
| 576 |
|
return 0; |
| 577 |
|
} |
| 578 |
|
else // ret == 1 |
| 579 |
|
{ |
| 580 |
|
if (query_user_info_by_uid(uid_list[0], &user_info, user_intro, sizeof(user_intro)) <= 0) |
| 581 |
|
{ |
| 582 |
|
log_error("query_user_info_by_uid(uid=%d) error\n", uid_list[0]); |
| 583 |
|
return -2; |
| 584 |
|
} |
| 585 |
|
else if (user_info_display(&user_info) < 0) |
| 586 |
|
{ |
| 587 |
|
log_error("user_info_display(uid=%d) error\n", uid_list[0]); |
| 588 |
|
return -3; |
| 589 |
|
} |
| 590 |
|
return 1; |
| 591 |
|
} |
| 592 |
|
} |
| 593 |
|
|
| 594 |
return 0; |
return 0; |
| 595 |
} |
} |