/[LeafOK_CVS]/lbbs/src/menu_proc.c
ViewVC logotype

Diff of /lbbs/src/menu_proc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.36 by sysadm, Tue Oct 14 00:57:06 2025 UTC Revision 1.59 by sysadm, Wed Dec 17 03:47:00 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                                    menu_proc.c  -  description  /*
3                                                           -------------------   * menu_proc
4          Copyright            : (C) 2004-2025 by Leaflet   *   - handler functions of menu commands
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "article_cache.h"  #include "article_cache.h"
14    #include "article_favor_display.h"
15  #include "article_view_log.h"  #include "article_view_log.h"
16  #include "bbs.h"  #include "bbs.h"
17  #include "bbs_cmd.h"  #include "bbs_cmd.h"
18    #include "bbs_net.h"
19    #include "chicken.h"
20  #include "common.h"  #include "common.h"
21  #include "io.h"  #include "io.h"
22  #include "log.h"  #include "log.h"
# Line 25  Line 24 
24  #include "menu.h"  #include "menu.h"
25  #include "section_list_display.h"  #include "section_list_display.h"
26  #include "screen.h"  #include "screen.h"
27    #include "user_info_update.h"
28    #include "user_list_display.h"
29  #include "user_priv.h"  #include "user_priv.h"
30    #include <ctype.h>
31  #include <dlfcn.h>  #include <dlfcn.h>
32  #include <errno.h>  #include <errno.h>
33  #include <signal.h>  #include <signal.h>
# Line 42  int list_section(void *param) Line 44  int list_section(void *param)
44          return REDRAW;          return REDRAW;
45  }  }
46    
47    typedef union exec_handler_t
48    {
49            void *p;
50            int (*handler)();
51    } exec_handler;
52    
53  int exec_mbem(void *param)  int exec_mbem(void *param)
54  {  {
55          void *hdll;          void *hdll;
56          int (*func)();          exec_handler func;
57          char *c, *s;          char *c, *s;
58          char buf[FILE_PATH_LEN];          char buf[FILE_PATH_LEN];
59    
# Line 62  int exec_mbem(void *param) Line 70  int exec_mbem(void *param)
70                          c++;                          c++;
71                  }                  }
72    
73    #ifdef _ENABLE_SHARED
74                  hdll = dlopen(s + 5, RTLD_LAZY);                  hdll = dlopen(s + 5, RTLD_LAZY);
75    
76                  if (hdll)                  if (hdll)
77                  {                  {
78                          char *error;                          char *error;
79    
80                          if ((func = dlsym(hdll, c ? c : "mod_main")) != NULL)                          if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL)
81                                  func();                          {
82                                    func.handler();
83                            }
84                          else if ((error = dlerror()) != NULL)                          else if ((error = dlerror()) != NULL)
85                          {                          {
86                                  clearscr();                                  clearscr();
# Line 85  int exec_mbem(void *param) Line 96  int exec_mbem(void *param)
96                          prints("失败原因:%s\r\n", dlerror());                          prints("失败原因:%s\r\n", dlerror());
97                          press_any_key();                          press_any_key();
98                  }                  }
99    #else
100                    (void)hdll;
101                    (void)func;
102    
103                    if (strcasecmp(c, "bbs_net") == 0)
104                    {
105                            bbs_net();
106                    }
107                    else if (strcasecmp(c, "chicken_main") == 0)
108                    {
109                            chicken_main();
110                    }
111                    else
112                    {
113                            clearscr();
114                            prints("未知入口 [%s] !!\r\n", c);
115                            press_any_key();
116                    }
117    #endif
118          }          }
119    
120          return REDRAW;          return REDRAW;
# Line 95  int exit_bbs(void *param) Line 125  int exit_bbs(void *param)
125          return EXITBBS;          return EXITBBS;
126  }  }
127    
128    int eula(void *param)
129    {
130            display_file(DATA_EULA, 0);
131    
132            return REDRAW;
133    }
134    
135  int license(void *param)  int license(void *param)
136  {  {
137          display_file(DATA_LICENSE, 0);          display_file(DATA_LICENSE, 0);
# Line 109  int copyright(void *param) Line 146  int copyright(void *param)
146          return REDRAW;          return REDRAW;
147  }  }
148    
149    int version(void *param)
150    {
151            display_file(DATA_VERSION, 1);
152    
153            return REDRAW;
154    }
155    
156  int reload_bbs_conf(void *param)  int reload_bbs_conf(void *param)
157  {  {
158          clearscr();          clearscr();
# Line 131  int reload_bbs_conf(void *param) Line 175  int reload_bbs_conf(void *param)
175    
176  int shutdown_bbs(void *param)  int shutdown_bbs(void *param)
177  {  {
178          log_common("Notify main process to exit\n");          char buf[2] = "N";
179    
180            clearscr();
181            get_data(1, 1, "真的要关闭系统吗[y/N]? ", buf, sizeof(buf), 1);
182    
183          if (kill(getppid(), SIGTERM) < 0)          if (toupper(buf[0]) == 'Y')
184          {          {
185                  log_error("Send SIGTERM signal failed (%d)\n", errno);                  log_common("Notify main process to exit by [%s]\n", BBS_username);
186    
187                    if (kill(getppid(), SIGTERM) < 0)
188                    {
189                            log_error("Send SIGTERM signal failed (%d)\n", errno);
190                    }
191          }          }
192    
193          return REDRAW;          return REDRAW;
# Line 230  int show_top10_menu(void *param) Line 282  int show_top10_menu(void *param)
282  {  {
283          static int show_top10 = 0;          static int show_top10 = 0;
284          int ch = 0;          int ch = 0;
285            int loop;
286    
287          if (show_top10)          if (show_top10)
288          {          {
289                  return NOREDRAW;                  return NOREDRAW;
290          }          }
291          show_top10 = 1;          show_top10 = 1;
292            
293          clearscr();          clearscr();
294          show_top("", BBS_name, "");          show_top("", BBS_name, "");
295          show_bottom("");          show_bottom("");
296    
297          if (display_menu(&top10_menu) == 0)          if (display_menu(&top10_menu) == 0)
298          {          {
299                  while (!SYS_server_exit)                  for (loop = 1; !SYS_server_exit && loop;)
300                  {                  {
301                          iflush();                          iflush();
302                          ch = igetch(100);                          ch = igetch(100);
303    
304                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
305                            {
306                                    BBS_last_access_tm = time(NULL);
307                            }
308    
309                            if (user_online_update("TOP10_MENU") < 0)
310                            {
311                                    log_error("user_online_update(TOP10_MENU) error\n");
312                            }
313    
314                          switch (ch)                          switch (ch)
315                          {                          {
316                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
317                                  show_top10 = 0;  #ifdef _DEBUG
318                                  return 0;                                  log_error("KEY_NULL\n");
319    #endif
320                                    loop = 0;
321                                    break;
322                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
323                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
324                                  {                                  {
325                                          show_top10 = 0;                                          log_error("User input timeout\n");
326                                          return 0;                                          loop = 0;
327                                            break;
328                                  }                                  }
329                                  continue;                                  continue;
330                          case CR:                          case CR:
                                 igetch_reset();  
331                          default:                          default:
332                                  switch (menu_control(&top10_menu, ch))                                  switch (menu_control(&top10_menu, ch))
333                                  {                                  {
334                                  case EXITMENU:                                  case EXITMENU:
335                                          ch = EXITMENU;                                          loop = 0;
336                                          break;                                          break;
337                                  case REDRAW:                                  case REDRAW:
338                                          clearscr();                                          clearscr();
# Line 278  int show_top10_menu(void *param) Line 345  int show_top10_menu(void *param)
345                                          break;                                          break;
346                                  }                                  }
347                          }                          }
   
                         BBS_last_access_tm = time(NULL);  
   
                         if (ch == EXITMENU)  
                         {  
                                 break;  
                         }  
348                  }                  }
349          }          }
350            
351          show_top10 = 0;          show_top10 = 0;
352          return REDRAW;          return REDRAW;
353  }  }
# Line 316  int locate_article(void *param) Line 376  int locate_article(void *param)
376    
377  int favor_topic(void *param)  int favor_topic(void *param)
378  {  {
379          clearscr();          if (article_favor_display(&BBS_article_favor) < 0)
380          prints("此功能尚未实现");          {
381          press_any_key();                  log_error("article_favor_display() error\n");
382            }
383    
384            return REDRAW;
385    }
386    
387    int list_user(void *param)
388    {
389            if (user_list_display(0) < 0)
390            {
391                    log_error("user_list_display(all_user) error\n");
392            }
393    
394            return REDRAW;
395    }
396    
397    int list_online_user(void *param)
398    {
399            if (user_list_display(1) < 0)
400            {
401                    log_error("user_list_display(online_user) error\n");
402            }
403    
404            return REDRAW;
405    }
406    
407    int edit_intro(void *param)
408    {
409            if (user_intro_edit(BBS_priv.uid) < 0)
410            {
411                    log_error("user_intro_edit(%d) error\n", BBS_priv.uid);
412            }
413    
414            return REDRAW;
415    }
416    
417    int edit_sign(void *param)
418    {
419            if (user_sign_edit(BBS_priv.uid) < 0)
420            {
421                    log_error("user_sign_edit(%d) error\n", BBS_priv.uid);
422            }
423    
424          return REDRAW;          return REDRAW;
425  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1