--- lbbs/src/menu_proc.c 2025/10/13 07:13:39 1.34 +++ lbbs/src/menu_proc.c 2025/11/23 04:28:24 1.56 @@ -1,23 +1,22 @@ -/*************************************************************************** - menu_proc.c - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * menu_proc + * - handler functions of menu commands + * + * Copyright (C) 2004-2025 Leaflet + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "article_cache.h" +#include "article_favor_display.h" #include "article_view_log.h" #include "bbs.h" #include "bbs_cmd.h" +#include "bbs_net.h" +#include "chicken.h" #include "common.h" #include "io.h" #include "log.h" @@ -25,7 +24,10 @@ #include "menu.h" #include "section_list_display.h" #include "screen.h" +#include "user_info_update.h" +#include "user_list_display.h" #include "user_priv.h" +#include #include #include #include @@ -42,10 +44,16 @@ int list_section(void *param) return REDRAW; } +typedef union exec_handler_t +{ + void *p; + int (*handler)(); +} exec_handler; + int exec_mbem(void *param) { void *hdll; - int (*func)(); + exec_handler func; char *c, *s; char buf[FILE_PATH_LEN]; @@ -62,14 +70,17 @@ int exec_mbem(void *param) c++; } +#ifdef _ENABLE_SHARED hdll = dlopen(s + 5, RTLD_LAZY); if (hdll) { char *error; - if ((func = dlsym(hdll, c ? c : "mod_main")) != NULL) - func(); + if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL) + { + func.handler(); + } else if ((error = dlerror()) != NULL) { clearscr(); @@ -85,6 +96,25 @@ int exec_mbem(void *param) prints("失败原因:%s\r\n", dlerror()); press_any_key(); } +#else + (void)hdll; + (void)func; + + if (strcasecmp(c, "bbs_net") == 0) + { + bbs_net(); + } + else if (strcasecmp(c, "chicken_main") == 0) + { + chicken_main(); + } + else + { + clearscr(); + prints("未知入口 [%s] !!\r\n", c); + press_any_key(); + } +#endif } return REDRAW; @@ -109,6 +139,13 @@ int copyright(void *param) return REDRAW; } +int version(void *param) +{ + display_file(DATA_VERSION, 1); + + return REDRAW; +} + int reload_bbs_conf(void *param) { clearscr(); @@ -131,11 +168,19 @@ int reload_bbs_conf(void *param) int shutdown_bbs(void *param) { - log_common("Notify main process to exit\n"); + char buf[2] = "N"; + + clearscr(); + get_data(1, 1, "真的要关闭系统吗[y/N]? ", buf, sizeof(buf), 1); - if (kill(getppid(), SIGTERM) < 0) + if (toupper(buf[0]) == 'Y') { - log_error("Send SIGTERM signal failed (%d)\n", errno); + log_common("Notify main process to exit by [%s]\n", BBS_username); + + if (kill(getppid(), SIGTERM) < 0) + { + log_error("Send SIGTERM signal failed (%d)\n", errno); + } } return REDRAW; @@ -211,7 +256,7 @@ int list_ex_section(void *param) { SECTION_LIST *p_section; - p_section = section_list_find_by_name(param, NULL); + p_section = section_list_find_by_name(param); if (p_section == NULL) { log_error("Section %s not found\n", (const char *)param); @@ -228,7 +273,15 @@ int list_ex_section(void *param) int show_top10_menu(void *param) { + static int show_top10 = 0; int ch = 0; + int loop; + + if (show_top10) + { + return NOREDRAW; + } + show_top10 = 1; clearscr(); show_top("", BBS_name, ""); @@ -236,27 +289,36 @@ int show_top10_menu(void *param) if (display_menu(&top10_menu) == 0) { - while (!SYS_server_exit) + for (loop = 1; !SYS_server_exit && loop;) { iflush(); ch = igetch(100); + + if (ch != KEY_NULL && ch != KEY_TIMEOUT) + { + BBS_last_access_tm = time(NULL); + } + switch (ch) { case KEY_NULL: // broken pipe - return 0; + log_error("KEY_NULL\n"); + loop = 0; + break; case KEY_TIMEOUT: - if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) + if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - return 0; + log_error("User input timeout\n"); + loop = 0; + break; } continue; case CR: - igetch_reset(); default: switch (menu_control(&top10_menu, ch)) { case EXITMENU: - ch = EXITMENU; + loop = 0; break; case REDRAW: clearscr(); @@ -269,16 +331,10 @@ int show_top10_menu(void *param) break; } } - - BBS_last_access_tm = time(NULL); - - if (ch == EXITMENU) - { - break; - } } } - + + show_top10 = 0; return REDRAW; } @@ -306,9 +362,50 @@ int locate_article(void *param) int favor_topic(void *param) { - clearscr(); - prints("此功能尚未实现"); - press_any_key(); + if (article_favor_display(&BBS_article_favor) < 0) + { + log_error("article_favor_display() error\n"); + } + + return REDRAW; +} + +int list_user(void *param) +{ + if (user_list_display(0) < 0) + { + log_error("user_list_display(all_user) error\n"); + } + + return REDRAW; +} + +int list_online_user(void *param) +{ + if (user_list_display(1) < 0) + { + log_error("user_list_display(online_user) error\n"); + } + + return REDRAW; +} + +int edit_intro(void *param) +{ + if (user_intro_edit(BBS_priv.uid) < 0) + { + log_error("user_intro_edit(%d) error\n", BBS_priv.uid); + } + + return REDRAW; +} + +int edit_sign(void *param) +{ + if (user_sign_edit(BBS_priv.uid) < 0) + { + log_error("user_sign_edit(%d) error\n", BBS_priv.uid); + } return REDRAW; }