/[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.52 by sysadm, Mon May 19 06:55:06 2025 UTC Revision 1.55 by sysadm, Tue May 27 00:54:01 2025 UTC
# Line 25  Line 25 
25  #include "screen.h"  #include "screen.h"
26  #include "menu.h"  #include "menu.h"
27  #include "bbs_cmd.h"  #include "bbs_cmd.h"
28    #include "section_list.h"
29    #include "trie_dict.h"
30  #include <unistd.h>  #include <unistd.h>
31  #include <time.h>  #include <time.h>
32  #include <string.h>  #include <string.h>
33    #include <stdlib.h>
34    
35  int bbs_info()  int bbs_info()
36  {  {
# Line 57  int bbs_welcome(MYSQL *db) Line 60  int bbs_welcome(MYSQL *db)
60                           BBS_user_off_line);                           BBS_user_off_line);
61          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
62          {          {
63                  log_error("Query user_online failed\n");                  log_error("Query user_online error: %s\n", mysql_error(db));
64                  return -2;                  return -2;
65          }          }
66          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
# Line 78  int bbs_welcome(MYSQL *db) Line 81  int bbs_welcome(MYSQL *db)
81                           BBS_user_off_line);                           BBS_user_off_line);
82          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
83          {          {
84                  log_error("Query user_online failed\n");                  log_error("Query user_online error: %s\n", mysql_error(db));
85                  return -2;                  return -2;
86          }          }
87          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
# Line 95  int bbs_welcome(MYSQL *db) Line 98  int bbs_welcome(MYSQL *db)
98          snprintf(sql, sizeof(sql), "SELECT COUNT(UID) AS cc FROM user_list WHERE enable");          snprintf(sql, sizeof(sql), "SELECT COUNT(UID) AS cc FROM user_list WHERE enable");
99          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
100          {          {
101                  log_error("Query user_list failed\n");                  log_error("Query user_list error: %s\n", mysql_error(db));
102                  return -2;                  return -2;
103          }          }
104          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
# Line 112  int bbs_welcome(MYSQL *db) Line 115  int bbs_welcome(MYSQL *db)
115          snprintf(sql, sizeof(sql), "SELECT ID FROM user_login_log ORDER BY ID LIMIT 1");          snprintf(sql, sizeof(sql), "SELECT ID FROM user_login_log ORDER BY ID LIMIT 1");
116          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
117          {          {
118                  log_error("Query user_login_log failed\n");                  log_error("Query user_login_log error: %s\n", mysql_error(db));
119                  return -2;                  return -2;
120          }          }
121          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
# Line 248  int bbs_center() Line 251  int bbs_center()
251    
252  int bbs_main()  int bbs_main()
253  {  {
254          MYSQL *db;          MYSQL *db = NULL;
255    
256            // Set data pools in shared memory readonly
257            if (set_trie_dict_shm_readonly() < 0)
258            {
259                    goto cleanup;
260            }
261            if (set_article_block_shm_readonly() < 0)
262            {
263                    goto cleanup;
264            }
265            if (set_section_list_shm_readonly() < 0)
266            {
267                    goto cleanup;
268            }
269    
270            // Load menu in shared memory
271            if (set_menu_shm_readonly(p_bbs_menu) < 0)
272            {
273                    goto cleanup;
274            }
275    
276          set_input_echo(0);          set_input_echo(0);
277    
278          // System info          // System info
279          if (bbs_info() < 0)          if (bbs_info() < 0)
280          {          {
281                  return -1;                  goto cleanup;
282          }          }
283    
284          db = db_open();          db = db_open();
285          if (db == NULL)          if (db == NULL)
286          {          {
287                  prints("无法连接数据库\n");                  prints("无法连接数据库\n");
288                  return -2;                  goto cleanup;
289          }          }
290    
291          // Welcome          // Welcome
292          if (bbs_welcome(db) < 0)          if (bbs_welcome(db) < 0)
293          {          {
294                  mysql_close(db);                  mysql_close(db);
295                  return -3;                  goto cleanup;
296          }          }
297    
298          // User login          // User login
299          if (bbs_login(db) < 0)          if (bbs_login(db) < 0)
300          {          {
301                  mysql_close(db);                  mysql_close(db);
302                  return -4;                  goto cleanup;
303          }          }
304          clearscr();          clearscr();
305    
306          // BBS Top 10          // BBS Top 10
307          display_file_ex(VAR_BBS_TOP, 1, 1);          display_file_ex(VAR_BBS_TOP, 1, 1);
308    
         // Load menu in shared memory  
         if (load_menu_shm(p_bbs_menu) < 0)  
         {  
                 return -5;  
         }  
   
309          // Main          // Main
310          bbs_center();          bbs_center();
311    
         // Unload menu in shared memory  
         unload_menu_shm(p_bbs_menu);  
         free(p_bbs_menu);  
         p_bbs_menu = NULL;  
   
312          // Logout          // Logout
313          bbs_logout(db);          bbs_logout(db);
314    
315          mysql_close(db);  cleanup:
316            if (db != NULL)
317            {
318                    mysql_close(db);
319            }
320    
321            // Detach menu in shared memory
322            detach_menu_shm(p_bbs_menu);
323            free(p_bbs_menu);
324            p_bbs_menu = NULL;
325    
326            // Detach data pools shm
327            detach_section_list_shm();
328            detach_article_block_shm();
329            detach_trie_dict_shm();
330    
331          return 0;          return 0;
332  }  }


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

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