--- lbbs/src/bbs_main.c 2025/06/21 02:15:18 1.73 +++ lbbs/src/bbs_main.c 2025/10/17 01:25:08 1.84 @@ -14,6 +14,7 @@ * * ***************************************************************************/ +#include "article_favor.h" #include "article_view_log.h" #include "bbs.h" #include "bbs_cmd.h" @@ -29,6 +30,8 @@ #include "section_list.h" #include "trie_dict.h" #include "user_priv.h" +#include +#include #include #include #include @@ -36,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(); @@ -155,11 +158,11 @@ int bbs_welcome(void) display_file(DATA_WELCOME, 2); // Display welcome message - prints("\r\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n" - "\033[32m目前上站人数 [\033[36m%d/%d\033[32m] " - "匿名游客[\033[36m%d\033[32m] " - "注册用户数[\033[36m%d/%d\033[32m]\r\n" - "从 [\033[36m%s\033[32m] 起,累计访问人次:[\033[36m%d\033[32m]\033[m\r\n", + prints("\r\033[1;35m娆㈣繋鍏変复\033[33m 銆 %s 銆 \033[35mBBS\r\n" + "\033[32m鐩墠涓婄珯浜烘暟 [\033[36m%d/%d\033[32m] " + "鍖垮悕娓稿[\033[36m%d\033[32m] " + "娉ㄥ唽鐢ㄦ埛鏁癧\033[36m%d/%d\033[32m]\r\n" + "浠 [\033[36m%s\033[32m] 璧凤紝绱璁块棶浜烘锛歔\033[36m%d\033[32m]\033[m\r\n", BBS_name, u_online, BBS_max_client, u_anonymous, u_total, BBS_max_user, BBS_start_dt, u_login_count); @@ -178,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; } @@ -204,20 +212,25 @@ int bbs_center() show_top("", BBS_name, ""); show_active_board(); show_bottom(""); - display_menu(p_bbs_menu); + display_menu(&bbs_menu); iflush(); while (!SYS_server_exit) { ch = igetch(100); - if (p_bbs_menu->choose_step == 0 && time(NULL) - t_last_action >= 10) + 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); show_active_board(); show_bottom(""); - display_menu_cursor(p_bbs_menu, 1); + display_menu_cursor(&bbs_menu, 1); iflush(); } @@ -229,19 +242,21 @@ 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(p_bbs_menu, ch)) + switch (menu_control(&bbs_menu, ch)) { case EXITBBS: + case EXITMENU: return 0; case REDRAW: t_last_action = time(NULL); @@ -249,7 +264,7 @@ int bbs_center() show_top("", BBS_name, ""); show_active_board(); show_bottom(""); - display_menu(p_bbs_menu); + display_menu(&bbs_menu); break; case NOREDRAW: case UNKNOWN_CMD: @@ -258,8 +273,6 @@ int bbs_center() } iflush(); } - - BBS_last_access_tm = time(NULL); } return 0; @@ -267,6 +280,22 @@ int bbs_center() int bbs_main() { + struct sigaction act = {0}; + + // Set signal handler + act.sa_handler = SIG_IGN; + if (sigaction(SIGHUP, &act, NULL) == -1) + { + log_error("set signal action of SIGHUP error: %d\n", errno); + goto cleanup; + } + act.sa_handler = SIG_DFL; + if (sigaction(SIGCHLD, &act, NULL) == -1) + { + log_error("set signal action of SIGCHLD error: %d\n", errno); + goto cleanup; + } + // Set data pools in shared memory readonly if (set_trie_dict_shm_readonly() < 0) { @@ -282,7 +311,7 @@ int bbs_main() } // Load menu in shared memory - if (set_menu_shm_readonly(p_bbs_menu) < 0) + if (set_menu_shm_readonly(&bbs_menu) < 0) { goto cleanup; } @@ -304,14 +333,16 @@ int bbs_main() // User login if (SSH_v2) { - prints("\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username); + prints("\033[1m%s 娆㈣繋浣跨敤ssh鏂瑰紡璁块棶 \033[1;33m鎸変换鎰忛敭缁х画...\033[m", BBS_username); iflush(); + igetch_reset(); igetch_t(MAX_DELAY_TIME); } 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) @@ -320,6 +351,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) { @@ -344,6 +382,12 @@ 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 editor memory pool editor_memory_pool_cleanup(); @@ -351,10 +395,12 @@ 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(p_bbs_menu); - free(p_bbs_menu); - p_bbs_menu = NULL; + detach_menu_shm(&bbs_menu); + detach_menu_shm(&top10_menu); // Detach data pools shm detach_section_list_shm();