/[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.65 by sysadm, Sat Jun 7 08:33:08 2025 UTC Revision 1.78 by sysadm, Mon Oct 13 00:46:03 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 "log.h"  #include "editor.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 <unistd.h>  #include "user_priv.h"
33  #include <time.h>  #include <errno.h>
34  #include <string.h>  #include <signal.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 47  int bbs_welcome(void) Line 52  int bbs_welcome(void)
52          u_int32_t u_online = 0;          u_int32_t u_online = 0;
53          u_int32_t u_anonymous = 0;          u_int32_t u_anonymous = 0;
54          u_int32_t u_total = 0;          u_int32_t u_total = 0;
         u_int32_t max_u_online = 0;  
55          u_int32_t u_login_count = 0;          u_int32_t u_login_count = 0;
56    
57          MYSQL *db;          MYSQL *db;
# Line 146  int bbs_welcome(void) Line 150  int bbs_welcome(void)
150    
151          mysql_close(db);          mysql_close(db);
152    
         // Log max user_online  
         FILE *fin, *fout;  
         if ((fin = fopen(VAR_MAX_USER_ONLINE, "r")) != NULL)  
         {  
                 fscanf(fin, "%d", &max_u_online);  
                 fclose(fin);  
         }  
         if (u_online > max_u_online)  
         {  
                 max_u_online = u_online;  
                 if ((fout = fopen(VAR_MAX_USER_ONLINE, "w")) == NULL)  
                 {  
                         log_error("Open max_user_online.dat failed\n");  
                         return -3;  
                 }  
                 fprintf(fout, "%d\n", max_u_online);  
                 fclose(fout);  
         }  
   
153          // Count current user before login          // Count current user before login
154          u_online++;          u_online++;
155          u_anonymous++;          u_anonymous++;
156    
157          // Display logo          // Display logo
158          display_file(DATA_WELCOME, 1, 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%s\033[32m] 起,累计访问人次:[\033[36m%d\033[32m]\033[m\r\n",
                    "[\033[36m%d\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, max_u_online, u_login_count);                     BBS_max_user, BBS_start_dt, u_login_count);
168    
169          iflush();          iflush();
170    
# Line 204  int bbs_logout(void) Line 188  int bbs_logout(void)
188    
189          mysql_close(db);          mysql_close(db);
190    
191          display_file(DATA_GOODBYE, 1, 1);          display_file(DATA_GOODBYE, 1);
192    
193          log_common("User logout\n");          log_common("User logout\n");
194    
# Line 216  int bbs_center() Line 200  int bbs_center()
200          int ch;          int ch;
201          time_t t_last_action;          time_t t_last_action;
202    
203          BBS_last_access_tm = t_last_action = time(0);          BBS_last_access_tm = t_last_action = time(NULL);
204    
205          clearscr();          clearscr();
206    
207          show_top("", BBS_name, "");          show_top("", BBS_name, "");
208          show_active_board();          show_active_board();
209          show_bottom("");          show_bottom("");
210          display_menu(p_bbs_menu);          display_menu(&bbs_menu);
211          iflush();          iflush();
212    
213          while (!SYS_server_exit)          while (!SYS_server_exit)
214          {          {
215                  ch = igetch(100);                  ch = igetch(100);
216    
217                  if (p_bbs_menu->choose_step == 0 && time(0) - t_last_action >= 10)                  if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10)
218                  {                  {
219                          t_last_action = time(0);                          t_last_action = time(NULL);
220    
221                          show_active_board();                          show_active_board();
222                          show_bottom("");                          show_bottom("");
223                          display_menu_cursor(p_bbs_menu, 1);                          display_menu_cursor(&bbs_menu, 1);
224                          iflush();                          iflush();
225                  }                  }
226    
227                    if (user_online_update("MENU") < 0)
228                    {
229                            log_error("user_online_update(MENU) error\n");
230                    }
231    
232                  switch (ch)                  switch (ch)
233                  {                  {
234                  case KEY_NULL: // broken pipe                  case KEY_NULL: // broken pipe
235                          return 0;                          return 0;
236                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
237                          if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
238                          {                          {
239                                  return 0;                                  return 0;
240                          }                          }
# Line 253  int bbs_center() Line 242  int bbs_center()
242                  case CR:                  case CR:
243                          igetch_reset();                          igetch_reset();
244                  default:                  default:
245                          switch (menu_control(p_bbs_menu, ch))                          switch (menu_control(&bbs_menu, ch))
246                          {                          {
247                          case EXITBBS:                          case EXITBBS:
248                            case EXITMENU:
249                                  return 0;                                  return 0;
250                          case REDRAW:                          case REDRAW:
251                                  t_last_action = time(0);                                  t_last_action = time(NULL);
252                                  clearscr();                                  clearscr();
253                                  show_top("", BBS_name, "");                                  show_top("", BBS_name, "");
254                                  show_active_board();                                  show_active_board();
255                                  show_bottom("");                                  show_bottom("");
256                                  display_menu(p_bbs_menu);                                  display_menu(&bbs_menu);
257                                  break;                                  break;
258                          case NOREDRAW:                          case NOREDRAW:
259                          case UNKNOWN_CMD:                          case UNKNOWN_CMD:
# Line 273  int bbs_center() Line 263  int bbs_center()
263                          iflush();                          iflush();
264                  }                  }
265    
266                  BBS_last_access_tm = time(0);                  BBS_last_access_tm = time(NULL);
267          }          }
268    
269          return 0;          return 0;
# Line 281  int bbs_center() Line 271  int bbs_center()
271    
272  int bbs_main()  int bbs_main()
273  {  {
274            struct sigaction act = {0};
275    
276            // Set signal handler
277            act.sa_handler = SIG_IGN;
278            if (sigaction(SIGHUP, &act, NULL) == -1)
279            {
280                    log_error("set signal action of SIGHUP error: %d\n", errno);
281                    goto cleanup;
282            }
283            act.sa_handler = SIG_DFL;
284            if (sigaction(SIGCHLD, &act, NULL) == -1)
285            {
286                    log_error("set signal action of SIGCHLD error: %d\n", errno);
287                    goto cleanup;
288            }
289    
290          // Set data pools in shared memory readonly          // Set data pools in shared memory readonly
291          if (set_trie_dict_shm_readonly() < 0)          if (set_trie_dict_shm_readonly() < 0)
292          {          {
# Line 296  int bbs_main() Line 302  int bbs_main()
302          }          }
303    
304          // Load menu in shared memory          // Load menu in shared memory
305          if (set_menu_shm_readonly(p_bbs_menu) < 0)          if (set_menu_shm_readonly(&bbs_menu) < 0)
306          {          {
307                  goto cleanup;                  goto cleanup;
308          }          }
# Line 318  int bbs_main() Line 324  int bbs_main()
324          // User login          // User login
325          if (SSH_v2)          if (SSH_v2)
326          {          {
327                  prints("\033[1m%s ӭʹsshʽ \033[1;33m...\033[m", BBS_username);                  prints("\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username);
328                  iflush();                  iflush();
329                  igetch_t(MAX_DELAY_TIME);                  igetch_t(MAX_DELAY_TIME);
330          }          }
# Line 327  int bbs_main() Line 333  int bbs_main()
333                  goto cleanup;                  goto cleanup;
334          }          }
335    
336          // Load article_view_log          // Load article view log
337            if (article_view_log_load(BBS_priv.uid, &BBS_article_view_log, 0) < 0)
338            {
339                    log_error("article_view_log_load() error\n");
340                    goto cleanup;
341            }
342    
343            // Load article favorite
344            if (article_favor_load(BBS_priv.uid, &BBS_article_favor, 0) < 0)
345            {
346                    log_error("article_favor_load() error\n");
347                    goto cleanup;
348            }
349    
350            // Init editor memory pool
351            if (editor_memory_pool_init() < 0)
352            {
353                    log_error("editor_memory_pool_init() error\n");
354                    goto cleanup;
355            }
356    
357          clearscr();          clearscr();
358    
359          // BBS Top 10          // BBS Top 10
360          display_file(VAR_BBS_TOP, 1, 1);          display_file(VAR_BBS_TOP, 1);
361    
362          // Main          // Main
363          bbs_center();          bbs_center();
# Line 340  int bbs_main() Line 365  int bbs_main()
365          // Logout          // Logout
366          bbs_logout();          bbs_logout();
367    
368            // Save incremental article view log
369            if (article_view_log_save_inc(&BBS_article_view_log) < 0)
370            {
371                    log_error("article_view_log_save_inc() error\n");
372            }
373    
374            // Save incremental article favorite
375            if (article_favor_save_inc(&BBS_article_favor) < 0)
376            {
377                    log_error("article_favor_save_inc() error\n");
378            }
379    
380  cleanup:  cleanup:
381            // Cleanup editor memory pool
382            editor_memory_pool_cleanup();
383    
384            // Unload article view log
385            article_view_log_unload(&BBS_article_view_log);
386    
387            // Unload article favor
388            article_favor_unload(&BBS_article_favor);
389    
390          // Detach menu in shared memory          // Detach menu in shared memory
391          detach_menu_shm(p_bbs_menu);          detach_menu_shm(&bbs_menu);
         free(p_bbs_menu);  
         p_bbs_menu = NULL;  
392    
393          // Detach data pools shm          // Detach data pools shm
394          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