--- lbbs/src/menu_proc.c 2025/10/13 05:39:45 1.33 +++ lbbs/src/menu_proc.c 2025/11/05 01:04:06 1.46 @@ -1,20 +1,13 @@ -/*************************************************************************** - 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 + */ #include "article_cache.h" +#include "article_favor_display.h" #include "article_view_log.h" #include "bbs.h" #include "bbs_cmd.h" @@ -25,6 +18,7 @@ #include "menu.h" #include "section_list_display.h" #include "screen.h" +#include "user_list_display.h" #include "user_priv.h" #include #include @@ -42,10 +36,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]; @@ -68,8 +68,10 @@ int exec_mbem(void *param) { 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(); @@ -109,6 +111,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(); @@ -211,7 +220,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); @@ -226,21 +235,91 @@ int list_ex_section(void *param) return REDRAW; } -int top10_menu(void *param) +int show_top10_menu(void *param) { + static int show_top10 = 0; + int ch = 0; + + if (show_top10) + { + return NOREDRAW; + } + show_top10 = 1; + + clearscr(); + show_top("", BBS_name, ""); + show_bottom(""); + + if (display_menu(&top10_menu) == 0) + { + while (!SYS_server_exit) + { + iflush(); + ch = igetch(100); + + if (ch != KEY_NULL && ch != KEY_TIMEOUT) + { + BBS_last_access_tm = time(NULL); + } + + switch (ch) + { + case KEY_NULL: // broken pipe + log_error("KEY_NULL\n"); + show_top10 = 0; + return 0; + case KEY_TIMEOUT: + if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) + { + log_error("User input timeout\n"); + show_top10 = 0; + return 0; + } + continue; + case CR: + default: + switch (menu_control(&top10_menu, ch)) + { + case EXITMENU: + ch = EXITMENU; + break; + case REDRAW: + clearscr(); + show_bottom(""); + display_menu(&top10_menu); + break; + case NOREDRAW: + case UNKNOWN_CMD: + default: + break; + } + } + + if (ch == EXITMENU) + { + break; + } + } + } + + show_top10 = 0; return REDRAW; } int locate_article(void *param) { + char buf[MAX_MENUITEM_NAME_LENGTH]; char *sname, *aid, *saveptr; - sname = strtok_r(param, " ", &saveptr); - aid = strtok_r(NULL, " ", &saveptr); + strncpy(buf, param, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; + + sname = strtok_r(buf, "|", &saveptr); + aid = strtok_r(NULL, "|", &saveptr); if (sname == NULL || aid == NULL) { - log_error("top10_locate() error: invalid parameter\n", (const char *)param); + log_error("top10_locate(%s) error: invalid parameter\n", param); return NOREDRAW; } @@ -251,9 +330,30 @@ 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; }