/[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.27 by sysadm, Sat Jun 21 02:15:18 2025 UTC Revision 1.40 by sysadm, Fri Oct 17 12:23:01 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"
23  #include "io.h"  #include "io.h"
24  #include "log.h"  #include "log.h"
25    #include "login.h"
26  #include "menu.h"  #include "menu.h"
27  #include "section_list_display.h"  #include "section_list_display.h"
28  #include "screen.h"  #include "screen.h"
# Line 26  Line 30 
30  #include <dlfcn.h>  #include <dlfcn.h>
31  #include <errno.h>  #include <errno.h>
32  #include <signal.h>  #include <signal.h>
33    #include <stdlib.h>
34  #include <string.h>  #include <string.h>
35  #include <time.h>  #include <time.h>
36  #include <unistd.h>  #include <unistd.h>
# Line 33  Line 38 
38    
39  int list_section(void *param)  int list_section(void *param)
40  {  {
41          section_list_display(param);          section_list_display(param, 0);
42    
43          return REDRAW;          return REDRAW;
44  }  }
# Line 77  int exec_mbem(void *param) Line 82  int exec_mbem(void *param)
82                  else                  else
83                  {                  {
84                          clearscr();                          clearscr();
85                          prints("ؿļ [%s] ʧ!!\r\n", s + 5);                          prints("加载库文件 [%s] 失败!!\r\n", s + 5);
86                          prints("ʧԭ:%s\r\n", dlerror());                          prints("失败原因:%s\r\n", dlerror());
87                          press_any_key();                          press_any_key();
88                  }                  }
89          }          }
# Line 105  int copyright(void *param) Line 110  int copyright(void *param)
110          return REDRAW;          return REDRAW;
111  }  }
112    
113    int version(void *param)
114    {
115            display_file(DATA_VERSION, 1);
116    
117            return REDRAW;
118    }
119    
120  int reload_bbs_conf(void *param)  int reload_bbs_conf(void *param)
121  {  {
122          clearscr();          clearscr();
# Line 113  int reload_bbs_conf(void *param) Line 125  int reload_bbs_conf(void *param)
125          {          {
126                  log_error("Send SIGHUP signal failed (%d)\n", errno);                  log_error("Send SIGHUP signal failed (%d)\n", errno);
127    
128                  prints("ָʧ\r\n");                  prints("发送指令失败\r\n");
129          }          }
130          else          else
131          {          {
132                  prints("ѷָ\r\n");                  prints("已发送指令\r\n");
133          }          }
134    
135          press_any_key();          press_any_key();
# Line 137  int shutdown_bbs(void *param) Line 149  int shutdown_bbs(void *param)
149          return REDRAW;          return REDRAW;
150  }  }
151    
152  int favour_section_filter(void *param)  int favor_section_filter(void *param)
153  {  {
154          MENU_ITEM *p_menu_item = param;          MENU_ITEM *p_menu_item = param;
155    
156          return (is_favor(&BBS_priv, p_menu_item->priv) && checklevel2(&BBS_priv, p_menu_item->level));          return (is_favor(&BBS_priv, p_menu_item->priv) && checklevel2(&BBS_priv, p_menu_item->level));
157  }  }
158    
159    static int display_ex_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
160    {
161            switch (*p_key)
162            {
163            case 0: // Set msg
164                    snprintf(p_ctx->msg, sizeof(p_ctx->msg),
165                                     "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
166                                     "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "
167                                     "帮助[\033[32mh\033[33m] |");
168                    break;
169            }
170    
171            return 0;
172    }
173    
174    int view_ex_article(void *param)
175    {
176            ARTICLE_CACHE cache;
177            ARTICLE *p_article;
178            int32_t aid = atoi(param);
179            int ret;
180    
181            (void)ret;
182    
183            p_article = article_block_find_by_aid(aid);
184            if (p_article == NULL)
185            {
186                    log_error("article_block_find_by_aid(%d) error\n", aid);
187                    return NOREDRAW;
188            }
189    
190            if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
191            {
192                    log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
193                    return NOREDRAW;
194            }
195    
196            if (user_online_update("VIEW_ARTICLE") < 0)
197            {
198                    log_error("user_online_update(VIEW_ARTICLE) error\n");
199            }
200    
201            ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
202                                               display_ex_article_key_handler, DATA_READ_HELP);
203    
204            if (article_cache_unload(&cache) < 0)
205            {
206                    log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
207            }
208    
209            // Update article_view_log
210            if (article_view_log_set_viewed(p_article->aid, &BBS_article_view_log) < 0)
211            {
212                    log_error("article_view_log_set_viewed(aid=%d) error\n", p_article->aid);
213            }
214    
215            return REDRAW;
216    }
217    
218    int list_ex_section(void *param)
219    {
220            SECTION_LIST *p_section;
221    
222            p_section = section_list_find_by_name(param);
223            if (p_section == NULL)
224            {
225                    log_error("Section %s not found\n", (const char *)param);
226                    return -1;
227            }
228    
229            if (section_list_ex_dir_display(p_section) < 0)
230            {
231                    log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);
232            }
233    
234            return REDRAW;
235    }
236    
237    int show_top10_menu(void *param)
238    {
239            static int show_top10 = 0;
240            int ch = 0;
241    
242            if (show_top10)
243            {
244                    return NOREDRAW;
245            }
246            show_top10 = 1;
247    
248            clearscr();
249            show_top("", BBS_name, "");
250            show_bottom("");
251    
252            if (display_menu(&top10_menu) == 0)
253            {
254                    while (!SYS_server_exit)
255                    {
256                            iflush();
257                            ch = igetch(100);
258    
259                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
260                            {
261                                    BBS_last_access_tm = time(NULL);
262                            }
263    
264                            switch (ch)
265                            {
266                            case KEY_NULL: // broken pipe
267                                    log_error("KEY_NULL\n");
268                                    show_top10 = 0;
269                                    return 0;
270                            case KEY_TIMEOUT:
271                                    if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
272                                    {
273                                            log_error("User input timeout\n");
274                                            show_top10 = 0;
275                                            return 0;
276                                    }
277                                    continue;
278                            case CR:
279                            default:
280                                    switch (menu_control(&top10_menu, ch))
281                                    {
282                                    case EXITMENU:
283                                            ch = EXITMENU;
284                                            break;
285                                    case REDRAW:
286                                            clearscr();
287                                            show_bottom("");
288                                            display_menu(&top10_menu);
289                                            break;
290                                    case NOREDRAW:
291                                    case UNKNOWN_CMD:
292                                    default:
293                                            break;
294                                    }
295                            }
296    
297                            if (ch == EXITMENU)
298                            {
299                                    break;
300                            }
301                    }
302            }
303    
304            show_top10 = 0;
305            return REDRAW;
306    }
307    
308    int locate_article(void *param)
309    {
310            char buf[MAX_MENUITEM_NAME_LENGTH];
311            char *sname, *aid, *saveptr;
312    
313            strncpy(buf, param, sizeof(buf) - 1);
314            buf[sizeof(buf) - 1] = '\0';
315    
316            sname = strtok_r(buf, "|", &saveptr);
317            aid = strtok_r(NULL, "|", &saveptr);
318    
319            if (sname == NULL || aid == NULL)
320            {
321                    log_error("top10_locate(%s) error: invalid parameter\n", param);
322                    return NOREDRAW;
323            }
324    
325            section_list_display(sname, atoi(aid));
326    
327            return REDRAW;
328    }
329    
330    int favor_topic(void *param)
331    {
332            if (article_favor_display(&BBS_article_favor) < 0)
333            {
334                    log_error("article_favor_display() error\n");
335            }
336    
337            return REDRAW;
338    }


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

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