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

Contents of /lbbs/src/menu_proc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.42 - (show annotations)
Tue Oct 21 11:11:28 2025 UTC (4 months, 3 weeks ago) by sysadm
Branch: MAIN
Changes since 1.41: +11 -0 lines
Content type: text/x-csrc
Add user_list_display

1 /***************************************************************************
2 menu_proc.c - description
3 -------------------
4 Copyright : (C) 2004-2025 by Leaflet
5 Email : leaflet@leafok.com
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 3 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17 #include "article_cache.h"
18 #include "article_favor_display.h"
19 #include "article_view_log.h"
20 #include "bbs.h"
21 #include "bbs_cmd.h"
22 #include "common.h"
23 #include "io.h"
24 #include "log.h"
25 #include "login.h"
26 #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>
32 #include <errno.h>
33 #include <signal.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <time.h>
37 #include <unistd.h>
38 #include <sys/types.h>
39
40 int list_section(void *param)
41 {
42 section_list_display(param, 0);
43
44 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;
55 exec_handler func;
56 char *c, *s;
57 char buf[FILE_PATH_LEN];
58
59 strncpy(buf, (const char *)param, sizeof(buf) - 1);
60 buf[sizeof(buf) - 1] = '\0';
61
62 s = strstr(buf, "@mod:");
63 if (s)
64 {
65 c = strstr(s + 5, "#");
66 if (c)
67 {
68 *c = 0;
69 c++;
70 }
71
72 hdll = dlopen(s + 5, RTLD_LAZY);
73
74 if (hdll)
75 {
76 char *error;
77
78 if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL)
79 {
80 func.handler();
81 }
82 else if ((error = dlerror()) != NULL)
83 {
84 clearscr();
85 prints("%s\r\n", error);
86 press_any_key();
87 }
88 dlclose(hdll);
89 }
90 else
91 {
92 clearscr();
93 prints("加载库文件 [%s] 失败!!\r\n", s + 5);
94 prints("失败原因:%s\r\n", dlerror());
95 press_any_key();
96 }
97 }
98
99 return REDRAW;
100 }
101
102 int exit_bbs(void *param)
103 {
104 return EXITBBS;
105 }
106
107 int license(void *param)
108 {
109 display_file(DATA_LICENSE, 0);
110
111 return REDRAW;
112 }
113
114 int copyright(void *param)
115 {
116 display_file(DATA_COPYRIGHT, 1);
117
118 return REDRAW;
119 }
120
121 int version(void *param)
122 {
123 display_file(DATA_VERSION, 1);
124
125 return REDRAW;
126 }
127
128 int reload_bbs_conf(void *param)
129 {
130 clearscr();
131
132 if (kill(getppid(), SIGHUP) < 0)
133 {
134 log_error("Send SIGHUP signal failed (%d)\n", errno);
135
136 prints("发送指令失败\r\n");
137 }
138 else
139 {
140 prints("已发送指令\r\n");
141 }
142
143 press_any_key();
144
145 return REDRAW;
146 }
147
148 int shutdown_bbs(void *param)
149 {
150 log_common("Notify main process to exit\n");
151
152 if (kill(getppid(), SIGTERM) < 0)
153 {
154 log_error("Send SIGTERM signal failed (%d)\n", errno);
155 }
156
157 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 user_list(void *param)
349 {
350 if (user_list_display() < 0)
351 {
352 log_error("user_list_display() error\n");
353 }
354
355 return REDRAW;
356 }

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