--- lbbs/src/bbs_main.c 2025/07/02 04:17:33 1.76 +++ lbbs/src/bbs_main.c 2025/10/18 05:55:55 1.89 @@ -14,6 +14,7 @@ * * ***************************************************************************/ +#include "article_favor.h" #include "article_view_log.h" #include "bbs.h" #include "bbs_cmd.h" @@ -38,7 +39,7 @@ int bbs_info() { - prints("欢迎光临 \033[1;33m%s \033[32m[%s] \033[37m( %s )\r\n", + prints("欢迎光临 \033[1;33m%s \033[32m[%s] \033[37m( %s )\033[m\r\n", BBS_name, BBS_server, APP_INFO); return iflush(); @@ -180,16 +181,21 @@ int bbs_logout(void) return -1; } - if (user_online_del(db) < 0) + if (user_online_exp(db) < 0) { return -2; } + if (user_online_del(db) < 0) + { + return -3; + } + mysql_close(db); display_file(DATA_GOODBYE, 1); - log_common("User logout\n"); + log_common("User [%s] logout\n", BBS_username); return 0; } @@ -213,6 +219,11 @@ int bbs_center() { ch = igetch(100); + if (ch != KEY_NULL && ch != KEY_TIMEOUT) + { + BBS_last_access_tm = time(NULL); + } + if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10) { t_last_action = time(NULL); @@ -231,15 +242,16 @@ int bbs_center() switch (ch) { case KEY_NULL: // broken pipe + log_error("KEY_NULL\n"); return 0; case KEY_TIMEOUT: if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) { + log_error("User input timeout\n"); return 0; } continue; case CR: - igetch_reset(); default: switch (menu_control(&bbs_menu, ch)) { @@ -261,8 +273,42 @@ int bbs_center() } iflush(); } + } + + return 0; +} + +int bbs_charset_select() +{ + char msg[LINE_BUFFER_LEN]; + int ch; + + snprintf(msg, sizeof(msg), + "\rChoose character set in 5 seconds [UTF-8, GBK]: [U/g]"); - BBS_last_access_tm = time(NULL); + while (!SYS_server_exit) + { + ch = press_any_key_ex(msg, 5); + switch (ch) + { + case KEY_NULL: + return -1; + case KEY_TIMEOUT: + case CR: + case 'u': + case 'U': + return 0; + case 'g': + case 'G': + if (io_conv_init("GBK") < 0) + { + log_error("io_conv_init(%s) error\n", "GBK"); + return -1; + } + return 0; + default: + continue; + } } return 0; @@ -271,6 +317,7 @@ int bbs_center() int bbs_main() { struct sigaction act = {0}; + char msg[LINE_BUFFER_LEN]; // Set signal handler act.sa_handler = SIG_IGN; @@ -306,8 +353,18 @@ int bbs_main() goto cleanup; } + // Set default charset + if (io_conv_init(BBS_DEFAULT_CHARSET) < 0) + { + log_error("io_conv_init(%s) error\n", BBS_DEFAULT_CHARSET); + goto cleanup; + } + set_input_echo(0); + // Set user charset + bbs_charset_select(); + // System info if (bbs_info() < 0) { @@ -323,14 +380,14 @@ int bbs_main() // User login if (SSH_v2) { - prints("\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username); - iflush(); - igetch_t(MAX_DELAY_TIME); + snprintf(msg, sizeof(msg), "\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username); + press_any_key_ex(msg, 60); } else if (bbs_login() < 0) { goto cleanup; } + log_common("User [%s] login\n", BBS_username); // Load article view log if (article_view_log_load(BBS_priv.uid, &BBS_article_view_log, 0) < 0) @@ -339,6 +396,13 @@ int bbs_main() goto cleanup; } + // Load article favorite + if (article_favor_load(BBS_priv.uid, &BBS_article_favor, 0) < 0) + { + log_error("article_favor_load() error\n"); + goto cleanup; + } + // Init editor memory pool if (editor_memory_pool_init() < 0) { @@ -363,15 +427,28 @@ int bbs_main() log_error("article_view_log_save_inc() error\n"); } + // Save incremental article favorite + if (article_favor_save_inc(&BBS_article_favor) < 0) + { + log_error("article_favor_save_inc() error\n"); + } + cleanup: + // Cleanup iconv + io_conv_cleanup(); + // Cleanup editor memory pool editor_memory_pool_cleanup(); // Unload article view log article_view_log_unload(&BBS_article_view_log); + // Unload article favor + article_favor_unload(&BBS_article_favor); + // Detach menu in shared memory detach_menu_shm(&bbs_menu); + detach_menu_shm(&top10_menu); // Detach data pools shm detach_section_list_shm();