| 16 |
|
|
| 17 |
#include "common.h" |
#include "common.h" |
| 18 |
#include "io.h" |
#include "io.h" |
| 19 |
|
#include "lml.h" |
| 20 |
#include "log.h" |
#include "log.h" |
| 21 |
#include "login.h" |
#include "login.h" |
| 22 |
#include "screen.h" |
#include "screen.h" |
| 33 |
EXIT_LIST = 0, |
EXIT_LIST = 0, |
| 34 |
VIEW_USER, |
VIEW_USER, |
| 35 |
CHANGE_PAGE, |
CHANGE_PAGE, |
| 36 |
|
REFRESH_LIST, |
| 37 |
SHOW_HELP, |
SHOW_HELP, |
| 38 |
}; |
}; |
| 39 |
|
|
| 40 |
|
static int display_user_intro_key_handler(int *p_key, DISPLAY_CTX *p_ctx) |
| 41 |
|
{ |
| 42 |
|
return 0; |
| 43 |
|
} |
| 44 |
|
|
| 45 |
static int user_list_draw_screen(int online_user) |
static int user_list_draw_screen(int online_user) |
| 46 |
{ |
{ |
| 47 |
clearscr(); |
clearscr(); |
| 48 |
show_top((online_user ? "[在线用户]" : "[已注册用户]"), BBS_name, ""); |
show_top((online_user ? "[线上使用者]" : "[已注册用户]"), BBS_name, ""); |
| 49 |
moveto(2, 0); |
moveto(2, 0); |
| 50 |
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] " |
| 51 |
"查看[\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"); |
| 108 |
moveto(4 + i, 1); |
moveto(4 + i, 1); |
| 109 |
|
|
| 110 |
prints(" %6d %s%*s %s%*s %s", |
prints(" %6d %s%*s %s%*s %s", |
| 111 |
p_users[i].uid, |
p_users[i].id + 1, |
| 112 |
p_users[i].username, |
p_users[i].username, |
| 113 |
BBS_username_max_len - str_length(p_users[i].username, 1), |
BBS_username_max_len - str_length(p_users[i].username, 1), |
| 114 |
"", |
"", |
| 185 |
moveto(4 + i, 1); |
moveto(4 + i, 1); |
| 186 |
|
|
| 187 |
prints(" %6d %s%*s %s%*s %s%*s %s%*s %s", |
prints(" %6d %s%*s %s%*s %s%*s %s%*s %s", |
| 188 |
p_users[i].user_info.uid, |
p_users[i].id + 1, |
| 189 |
p_users[i].user_info.username, |
p_users[i].user_info.username, |
| 190 |
BBS_username_max_len - str_length(p_users[i].user_info.username, 1), |
BBS_username_max_len - str_length(p_users[i].user_info.username, 1), |
| 191 |
"", |
"", |
| 310 |
(*p_selected_index)++; |
(*p_selected_index)++; |
| 311 |
} |
} |
| 312 |
break; |
break; |
| 313 |
|
case KEY_F5: |
| 314 |
|
return REFRESH_LIST; |
| 315 |
case 'h': |
case 'h': |
| 316 |
return SHOW_HELP; |
return SHOW_HELP; |
| 317 |
default: |
default: |
| 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 |
|
|
| 420 |
{ |
{ |
| 421 |
case EXIT_LIST: |
case EXIT_LIST: |
| 422 |
return 0; |
return 0; |
| 423 |
|
case REFRESH_LIST: |
| 424 |
case CHANGE_PAGE: |
case CHANGE_PAGE: |
| 425 |
ret = query_user_list(page_id, users, &user_count, &page_count); |
if (online_user) |
|
if (ret < 0) |
|
| 426 |
{ |
{ |
| 427 |
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); |
| 428 |
return -2; |
if (ret < 0) |
| 429 |
|
{ |
| 430 |
|
log_error("query_user_online_list(page_id=%d) error\n", page_id); |
| 431 |
|
return -2; |
| 432 |
|
} |
| 433 |
|
} |
| 434 |
|
else |
| 435 |
|
{ |
| 436 |
|
ret = query_user_list(page_id, users, &user_count, &page_count); |
| 437 |
|
if (ret < 0) |
| 438 |
|
{ |
| 439 |
|
log_error("query_user_list(page_id=%d) error\n", page_id); |
| 440 |
|
return -2; |
| 441 |
|
} |
| 442 |
} |
} |
| 443 |
|
|
| 444 |
if (user_count == 0) // empty list |
if (user_count == 0) // empty list |
| 451 |
} |
} |
| 452 |
break; |
break; |
| 453 |
case VIEW_USER: |
case VIEW_USER: |
|
log_error("View user (uid=%d)\n", |
|
|
(online_user ? online_users[selected_index].user_info.uid : users[selected_index].uid)); |
|
| 454 |
clearscr(); |
clearscr(); |
| 455 |
press_any_key_ex("功能不可用,按任意键返回", 60); |
if (online_user) |
| 456 |
|
{ |
| 457 |
|
USER_ONLINE_INFO users[5]; |
| 458 |
|
int user_cnt = 5; |
| 459 |
|
ret = query_user_online_info_by_uid(online_users[selected_index].user_info.uid, users, &user_cnt, 0); |
| 460 |
|
if (ret <= 0) |
| 461 |
|
{ |
| 462 |
|
log_error("query_user_online_info_by_uid(uid=%d, cnt=%d) error: %d\n", |
| 463 |
|
online_users[selected_index].user_info.uid, user_cnt, ret); |
| 464 |
|
} |
| 465 |
|
else |
| 466 |
|
{ |
| 467 |
|
moveto(1, 1); |
| 468 |
|
prints("已选中用户 [%s] 会话 %d", online_users[selected_index].user_info.username, online_users[selected_index].id); |
| 469 |
|
|
| 470 |
|
for (int i = 0; i < user_cnt; i++) |
| 471 |
|
{ |
| 472 |
|
moveto(2 + i, 1); |
| 473 |
|
prints("会话%d", users[i].id); |
| 474 |
|
} |
| 475 |
|
} |
| 476 |
|
} |
| 477 |
|
else |
| 478 |
|
{ |
| 479 |
|
char intro_f[BBS_user_intro_max_len]; |
| 480 |
|
char profile_f[BUFSIZ]; |
| 481 |
|
long line_offsets[BBS_user_intro_max_line + 1]; |
| 482 |
|
long lines; |
| 483 |
|
|
| 484 |
|
lml_render(users[selected_index].intro, intro_f, sizeof(intro_f), 0); |
| 485 |
|
|
| 486 |
|
snprintf(profile_f, sizeof(profile_f), |
| 487 |
|
"已选中用户 [%s]\n发帖数:%d\n\n%s\n", |
| 488 |
|
users[selected_index].username, |
| 489 |
|
get_user_article_cnt(users[selected_index].uid), |
| 490 |
|
intro_f); |
| 491 |
|
|
| 492 |
|
lines = split_data_lines(profile_f, SCREEN_COLS, line_offsets, BBS_user_intro_max_line + 4, 1, NULL); |
| 493 |
|
display_data(profile_f, lines, line_offsets, 2, display_user_intro_key_handler, DATA_READ_HELP); |
| 494 |
|
} |
| 495 |
|
press_any_key(); |
| 496 |
user_list_draw_screen(online_user); |
user_list_draw_screen(online_user); |
| 497 |
break; |
break; |
| 498 |
case SHOW_HELP: |
case SHOW_HELP: |