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

Diff of /lbbs/src/bbs_main.c

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

Revision 1.70 by sysadm, Tue Jun 17 02:06:48 2025 UTC Revision 1.80 by sysadm, Thu Oct 16 05:24:52 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "bbs_main.h"  #include "article_favor.h"
18    #include "article_view_log.h"
19  #include "bbs.h"  #include "bbs.h"
20  #include "login.h"  #include "bbs_cmd.h"
21  #include "user_priv.h"  #include "bbs_main.h"
22  #include "common.h"  #include "common.h"
23  #include "database.h"  #include "database.h"
24  #include "article_view_log.h"  #include "editor.h"
 #include "log.h"  
25  #include "io.h"  #include "io.h"
26  #include "screen.h"  #include "log.h"
27    #include "login.h"
28  #include "menu.h"  #include "menu.h"
29  #include "bbs_cmd.h"  #include "screen.h"
30  #include "section_list.h"  #include "section_list.h"
31  #include "trie_dict.h"  #include "trie_dict.h"
32  #include "editor.h"  #include "user_priv.h"
33  #include <unistd.h>  #include <errno.h>
34  #include <time.h>  #include <signal.h>
 #include <string.h>  
35  #include <stdlib.h>  #include <stdlib.h>
36    #include <string.h>
37    #include <time.h>
38    #include <unistd.h>
39    
40  int bbs_info()  int bbs_info()
41  {  {
42          prints("ӭ \033[1;33m%s \033[32m[%s]  \033[37m( %s )\r\n",          prints("欢迎光临 \033[1;33m%s \033[32m[%s]  \033[37m( %s )\033[m\r\n",
43                     BBS_name, BBS_server, APP_NAME_VER);                     BBS_name, BBS_server, APP_INFO);
44    
45          return iflush();          return iflush();
46  }  }
# Line 155  int bbs_welcome(void) Line 158  int bbs_welcome(void)
158          display_file(DATA_WELCOME, 2);          display_file(DATA_WELCOME, 2);
159    
160          // Display welcome message          // Display welcome message
161          prints("\r\033[1;35mӭ\033[33m %s \033[35mBBS\r\n"          prints("\r\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n"
162                     "\033[32mĿǰվ [\033[36m%d/%d\033[32m] "                     "\033[32m目前上站人数 [\033[36m%d/%d\033[32m] "
163                     "ο[\033[36m%d\033[32m] "                     "匿名游客[\033[36m%d\033[32m] "
164                     "עû[\033[36m%d/%d\033[32m]\r\n"                     "注册用户数[\033[36m%d/%d\033[32m]\r\n"
165                     " [\033[36m%s\033[32m] ۼƷ˴Σ[\033[36m%d\033[32m]\033[m\r\n",                     "从 [\033[36m%s\033[32m] 起,累计访问人次:[\033[36m%d\033[32m]\033[m\r\n",
166                     BBS_name, u_online, BBS_max_client, u_anonymous, u_total,                     BBS_name, u_online, BBS_max_client, u_anonymous, u_total,
167                     BBS_max_user, BBS_start_dt, u_login_count);                     BBS_max_user, BBS_start_dt, u_login_count);
168    
# Line 178  int bbs_logout(void) Line 181  int bbs_logout(void)
181                  return -1;                  return -1;
182          }          }
183    
184          if (user_online_del(db) < 0)          if (user_online_exp(db) < 0)
185          {          {
186                  return -2;                  return -2;
187          }          }
188    
189            if (user_online_del(db) < 0)
190            {
191                    return -3;
192            }
193    
194          mysql_close(db);          mysql_close(db);
195    
196          display_file(DATA_GOODBYE, 1);          display_file(DATA_GOODBYE, 1);
# Line 204  int bbs_center() Line 212  int bbs_center()
212          show_top("", BBS_name, "");          show_top("", BBS_name, "");
213          show_active_board();          show_active_board();
214          show_bottom("");          show_bottom("");
215          display_menu(p_bbs_menu);          display_menu(&bbs_menu);
216          iflush();          iflush();
217    
218          while (!SYS_server_exit)          while (!SYS_server_exit)
219          {          {
220                  ch = igetch(100);                  ch = igetch(100);
221    
222                  if (p_bbs_menu->choose_step == 0 && time(NULL) - t_last_action >= 10)                  if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10)
223                  {                  {
224                          t_last_action = time(NULL);                          t_last_action = time(NULL);
225    
226                          show_active_board();                          show_active_board();
227                          show_bottom("");                          show_bottom("");
228                          display_menu_cursor(p_bbs_menu, 1);                          display_menu_cursor(&bbs_menu, 1);
229                          iflush();                          iflush();
230                  }                  }
231    
232                    if (user_online_update("MENU") < 0)
233                    {
234                            log_error("user_online_update(MENU) error\n");
235                    }
236    
237                  switch (ch)                  switch (ch)
238                  {                  {
239                  case KEY_NULL: // broken pipe                  case KEY_NULL: // broken pipe
# Line 234  int bbs_center() Line 247  int bbs_center()
247                  case CR:                  case CR:
248                          igetch_reset();                          igetch_reset();
249                  default:                  default:
250                          switch (menu_control(p_bbs_menu, ch))                          switch (menu_control(&bbs_menu, ch))
251                          {                          {
252                          case EXITBBS:                          case EXITBBS:
253                            case EXITMENU:
254                                  return 0;                                  return 0;
255                          case REDRAW:                          case REDRAW:
256                                  t_last_action = time(NULL);                                  t_last_action = time(NULL);
# Line 244  int bbs_center() Line 258  int bbs_center()
258                                  show_top("", BBS_name, "");                                  show_top("", BBS_name, "");
259                                  show_active_board();                                  show_active_board();
260                                  show_bottom("");                                  show_bottom("");
261                                  display_menu(p_bbs_menu);                                  display_menu(&bbs_menu);
262                                  break;                                  break;
263                          case NOREDRAW:                          case NOREDRAW:
264                          case UNKNOWN_CMD:                          case UNKNOWN_CMD:
# Line 262  int bbs_center() Line 276  int bbs_center()
276    
277  int bbs_main()  int bbs_main()
278  {  {
279            struct sigaction act = {0};
280    
281            // Set signal handler
282            act.sa_handler = SIG_IGN;
283            if (sigaction(SIGHUP, &act, NULL) == -1)
284            {
285                    log_error("set signal action of SIGHUP error: %d\n", errno);
286                    goto cleanup;
287            }
288            act.sa_handler = SIG_DFL;
289            if (sigaction(SIGCHLD, &act, NULL) == -1)
290            {
291                    log_error("set signal action of SIGCHLD error: %d\n", errno);
292                    goto cleanup;
293            }
294    
295          // Set data pools in shared memory readonly          // Set data pools in shared memory readonly
296          if (set_trie_dict_shm_readonly() < 0)          if (set_trie_dict_shm_readonly() < 0)
297          {          {
# Line 277  int bbs_main() Line 307  int bbs_main()
307          }          }
308    
309          // Load menu in shared memory          // Load menu in shared memory
310          if (set_menu_shm_readonly(p_bbs_menu) < 0)          if (set_menu_shm_readonly(&bbs_menu) < 0)
311          {          {
312                  goto cleanup;                  goto cleanup;
313          }          }
# Line 299  int bbs_main() Line 329  int bbs_main()
329          // User login          // User login
330          if (SSH_v2)          if (SSH_v2)
331          {          {
332                  prints("\033[1m%s ӭʹsshʽ \033[1;33m...\033[m", BBS_username);                  prints("\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username);
333                  iflush();                  iflush();
334                  igetch_t(MAX_DELAY_TIME);                  igetch_t(MAX_DELAY_TIME);
335          }          }
# Line 315  int bbs_main() Line 345  int bbs_main()
345                  goto cleanup;                  goto cleanup;
346          }          }
347    
348            // Load article favorite
349            if (article_favor_load(BBS_priv.uid, &BBS_article_favor, 0) < 0)
350            {
351                    log_error("article_favor_load() error\n");
352                    goto cleanup;
353            }
354    
355          // Init editor memory pool          // Init editor memory pool
356          if (editor_memory_pool_init() < 0)          if (editor_memory_pool_init() < 0)
357          {          {
# Line 339  int bbs_main() Line 376  int bbs_main()
376                  log_error("article_view_log_save_inc() error\n");                  log_error("article_view_log_save_inc() error\n");
377          }          }
378    
379            // Save incremental article favorite
380            if (article_favor_save_inc(&BBS_article_favor) < 0)
381            {
382                    log_error("article_favor_save_inc() error\n");
383            }
384    
385  cleanup:  cleanup:
386          // Cleanup editor memory pool          // Cleanup editor memory pool
387          editor_memory_pool_cleanup();          editor_memory_pool_cleanup();
388            
389          // Unload article view log          // Unload article view log
390          article_view_log_unload(&BBS_article_view_log);          article_view_log_unload(&BBS_article_view_log);
391    
392            // Unload article favor
393            article_favor_unload(&BBS_article_favor);
394    
395          // Detach menu in shared memory          // Detach menu in shared memory
396          detach_menu_shm(p_bbs_menu);          detach_menu_shm(&bbs_menu);
397          free(p_bbs_menu);          detach_menu_shm(&top10_menu);
         p_bbs_menu = NULL;  
398    
399          // Detach data pools shm          // Detach data pools shm
400          detach_section_list_shm();          detach_section_list_shm();


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

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