/[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.14 by sysadm, Sun May 11 01:54:00 2025 UTC Revision 1.43 by sysadm, Wed Oct 22 04:48:53 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #include "article_cache.h"
18    #include "article_favor_display.h"
19    #include "article_view_log.h"
20  #include "bbs.h"  #include "bbs.h"
21  #include "bbs_cmd.h"  #include "bbs_cmd.h"
22  #include "common.h"  #include "common.h"
 #include "log.h"  
23  #include "io.h"  #include "io.h"
24  #include "screen.h"  #include "log.h"
25    #include "login.h"
26  #include "menu.h"  #include "menu.h"
27    #include "section_list_display.h"
28    #include "screen.h"
29    #include "user_list_display.h"
30    #include "user_priv.h"
31  #include <dlfcn.h>  #include <dlfcn.h>
32  #include <errno.h>  #include <errno.h>
33  #include <signal.h>  #include <signal.h>
34    #include <stdlib.h>
35  #include <string.h>  #include <string.h>
 #include <sys/types.h>  
36  #include <time.h>  #include <time.h>
37  #include <unistd.h>  #include <unistd.h>
38    #include <sys/types.h>
39    
40    int list_section(void *param)
41    {
42            section_list_display(param, 0);
43    
44  int exec_mbem(const char *str)          return REDRAW;
45    }
46    
47    typedef union exec_handler_t{
48            void *p;
49            int (*handler)();
50    } exec_handler;
51    
52    int exec_mbem(void *param)
53  {  {
54          void *hdll;          void *hdll;
55          int (*func)();          exec_handler func;
56          char *c, *s;          char *c, *s;
57          char buf[FILE_PATH_LEN];          char buf[FILE_PATH_LEN];
58    
59          strncpy(buf, str, sizeof(buf) - 1);          strncpy(buf, (const char *)param, sizeof(buf) - 1);
60          buf[sizeof(buf) - 1] = '\0';          buf[sizeof(buf) - 1] = '\0';
61    
62          s = strstr(buf, "@mod:");          s = strstr(buf, "@mod:");
# Line 55  int exec_mbem(const char *str) Line 75  int exec_mbem(const char *str)
75                  {                  {
76                          char *error;                          char *error;
77    
78                          if ((func = dlsym(hdll, c ? c : "mod_main")) != NULL)                          if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL)
79                                  func();                          {
80                                    func.handler();
81                            }
82                          else if ((error = dlerror()) != NULL)                          else if ((error = dlerror()) != NULL)
83                          {                          {
84                                  clearscr();                                  clearscr();
# Line 68  int exec_mbem(const char *str) Line 90  int exec_mbem(const char *str)
90                  else                  else
91                  {                  {
92                          clearscr();                          clearscr();
93                          prints("ؿļ [%s] ʧ!!\r\n", s + 5);                          prints("加载库文件 [%s] 失败!!\r\n", s + 5);
94                          prints("ʧԭ:%s\r\n", dlerror());                          prints("失败原因:%s\r\n", dlerror());
95                          press_any_key();                          press_any_key();
96                  }                  }
97          }          }
# Line 77  int exec_mbem(const char *str) Line 99  int exec_mbem(const char *str)
99          return REDRAW;          return REDRAW;
100  }  }
101    
102  int exitbbs(const char *s)  int exit_bbs(void *param)
103  {  {
104          return EXITBBS;          return EXITBBS;
105  }  }
106    
107  int license(const char *s)  int license(void *param)
108  {  {
109          display_file_ex(DATA_LICENSE, 1, 1);          display_file(DATA_LICENSE, 0);
110    
111          return REDRAW;          return REDRAW;
112  }  }
113    
114  int copyright(const char *s)  int copyright(void *param)
115  {  {
116          display_file_ex(DATA_COPYRIGHT, 1, 1);          display_file(DATA_COPYRIGHT, 1);
117    
118          return REDRAW;          return REDRAW;
119  }  }
120    
121  int reloadbbsmenu(const char *s)  int version(void *param)
122  {  {
123          MENU_SET new_menu;          display_file(DATA_VERSION, 1);
124    
125            return REDRAW;
126    }
127    
128    int reload_bbs_conf(void *param)
129    {
130          clearscr();          clearscr();
131    
132          if (load_menu(&new_menu, CONF_MENU) < 0)          if (kill(getppid(), SIGHUP) < 0)
133          {          {
134                  log_error("Reload menu failed\n");                  log_error("Send SIGHUP signal failed (%d)\n", errno);
135    
136                  unload_menu(&new_menu);                  prints("发送指令失败\r\n");
   
                 prints("˵Уʧ\r\n");  
137          }          }
138          else          else
139          {          {
140                  unload_menu(&new_menu);                  prints("已发送指令\r\n");
   
                 if (kill(getppid(), SIGHUP) < 0)  
                 {  
                         log_error("Send SIGHUP signal failed (%d)\n", errno);  
           
                         prints("ָʧ\r\n");  
                 }  
                 else  
                 {  
                         prints("ѷָ\r\n");  
                 }  
141          }          }
142    
143          press_any_key();          press_any_key();
# Line 131  int reloadbbsmenu(const char *s) Line 145  int reloadbbsmenu(const char *s)
145          return REDRAW;          return REDRAW;
146  }  }
147    
148  int shutdownbbs(const char *s)  int shutdown_bbs(void *param)
149  {  {
150          log_std("Notify main process to exit\n");          log_common("Notify main process to exit\n");
151    
152          if (kill(getppid(), SIGTERM) < 0)          if (kill(getppid(), SIGTERM) < 0)
153          {          {
# Line 141  int shutdownbbs(const char *s) Line 155  int shutdownbbs(const char *s)
155          }          }
156    
157          return REDRAW;          return REDRAW;
158    }
159    
160    int favor_section_filter(void *param)
161    {
162            MENU_ITEM *p_menu_item = param;
163    
164            return (is_favor(&BBS_priv, p_menu_item->priv) && checklevel2(&BBS_priv, p_menu_item->level));
165    }
166    
167    static int display_ex_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
168    {
169            switch (*p_key)
170            {
171            case 0: // Set msg
172                    snprintf(p_ctx->msg, sizeof(p_ctx->msg),
173                                     "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
174                                     "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "
175                                     "帮助[\033[32mh\033[33m] |");
176                    break;
177            }
178    
179            return 0;
180    }
181    
182    int view_ex_article(void *param)
183    {
184            ARTICLE_CACHE cache;
185            ARTICLE *p_article;
186            int32_t aid = atoi(param);
187            int ret;
188    
189            (void)ret;
190    
191            p_article = article_block_find_by_aid(aid);
192            if (p_article == NULL)
193            {
194                    log_error("article_block_find_by_aid(%d) error\n", aid);
195                    return NOREDRAW;
196            }
197    
198            if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
199            {
200                    log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
201                    return NOREDRAW;
202            }
203    
204            if (user_online_update("VIEW_ARTICLE") < 0)
205            {
206                    log_error("user_online_update(VIEW_ARTICLE) error\n");
207            }
208    
209            ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
210                                               display_ex_article_key_handler, DATA_READ_HELP);
211    
212            if (article_cache_unload(&cache) < 0)
213            {
214                    log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
215            }
216    
217            // Update article_view_log
218            if (article_view_log_set_viewed(p_article->aid, &BBS_article_view_log) < 0)
219            {
220                    log_error("article_view_log_set_viewed(aid=%d) error\n", p_article->aid);
221            }
222    
223            return REDRAW;
224    }
225    
226    int list_ex_section(void *param)
227    {
228            SECTION_LIST *p_section;
229    
230            p_section = section_list_find_by_name(param);
231            if (p_section == NULL)
232            {
233                    log_error("Section %s not found\n", (const char *)param);
234                    return -1;
235            }
236    
237            if (section_list_ex_dir_display(p_section) < 0)
238            {
239                    log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);
240            }
241    
242            return REDRAW;
243    }
244    
245    int show_top10_menu(void *param)
246    {
247            static int show_top10 = 0;
248            int ch = 0;
249    
250            if (show_top10)
251            {
252                    return NOREDRAW;
253            }
254            show_top10 = 1;
255    
256            clearscr();
257            show_top("", BBS_name, "");
258            show_bottom("");
259    
260            if (display_menu(&top10_menu) == 0)
261            {
262                    while (!SYS_server_exit)
263                    {
264                            iflush();
265                            ch = igetch(100);
266    
267                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
268                            {
269                                    BBS_last_access_tm = time(NULL);
270                            }
271    
272                            switch (ch)
273                            {
274                            case KEY_NULL: // broken pipe
275                                    log_error("KEY_NULL\n");
276                                    show_top10 = 0;
277                                    return 0;
278                            case KEY_TIMEOUT:
279                                    if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
280                                    {
281                                            log_error("User input timeout\n");
282                                            show_top10 = 0;
283                                            return 0;
284                                    }
285                                    continue;
286                            case CR:
287                            default:
288                                    switch (menu_control(&top10_menu, ch))
289                                    {
290                                    case EXITMENU:
291                                            ch = EXITMENU;
292                                            break;
293                                    case REDRAW:
294                                            clearscr();
295                                            show_bottom("");
296                                            display_menu(&top10_menu);
297                                            break;
298                                    case NOREDRAW:
299                                    case UNKNOWN_CMD:
300                                    default:
301                                            break;
302                                    }
303                            }
304    
305                            if (ch == EXITMENU)
306                            {
307                                    break;
308                            }
309                    }
310            }
311    
312            show_top10 = 0;
313            return REDRAW;
314    }
315    
316    int locate_article(void *param)
317    {
318            char buf[MAX_MENUITEM_NAME_LENGTH];
319            char *sname, *aid, *saveptr;
320    
321            strncpy(buf, param, sizeof(buf) - 1);
322            buf[sizeof(buf) - 1] = '\0';
323    
324            sname = strtok_r(buf, "|", &saveptr);
325            aid = strtok_r(NULL, "|", &saveptr);
326    
327            if (sname == NULL || aid == NULL)
328            {
329                    log_error("top10_locate(%s) error: invalid parameter\n", param);
330                    return NOREDRAW;
331            }
332    
333            section_list_display(sname, atoi(aid));
334    
335            return REDRAW;
336    }
337    
338    int favor_topic(void *param)
339    {
340            if (article_favor_display(&BBS_article_favor) < 0)
341            {
342                    log_error("article_favor_display() error\n");
343            }
344    
345            return REDRAW;
346    }
347    
348    int list_user(void *param)
349    {
350            if (user_list_display(0) < 0)
351            {
352                    log_error("user_list_display(all_user) error\n");
353            }
354    
355            return REDRAW;
356    }
357    
358    int list_online_user(void *param)
359    {
360            if (user_list_display(1) < 0)
361            {
362                    log_error("user_list_display(online_user) error\n");
363            }
364    
365            return REDRAW;
366  }  }


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

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