/[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.85 by sysadm, Fri Oct 17 07:07:55 2025 UTC Revision 1.94 by sysadm, Sat Nov 1 10:35:42 2025 UTC
# Line 29  Line 29 
29  #include "screen.h"  #include "screen.h"
30  #include "section_list.h"  #include "section_list.h"
31  #include "trie_dict.h"  #include "trie_dict.h"
32    #include "user_list.h"
33  #include "user_priv.h"  #include "user_priv.h"
34  #include <errno.h>  #include <errno.h>
35  #include <signal.h>  #include <signal.h>
# Line 49  int bbs_welcome(void) Line 50  int bbs_welcome(void)
50  {  {
51          char sql[SQL_BUFFER_LEN];          char sql[SQL_BUFFER_LEN];
52    
53          u_int32_t u_online = 0;          int u_online = 0;
54          u_int32_t u_anonymous = 0;          int u_anonymous = 0;
55          u_int32_t u_total = 0;          int u_total = 0;
56          u_int32_t u_login_count = 0;          int u_login_count = 0;
57    
58          MYSQL *db;          MYSQL *db;
59          MYSQL_RES *rs;          MYSQL_RES *rs;
60          MYSQL_ROW row;          MYSQL_ROW row;
61    
62          db = db_open();          if (get_user_online_list_count(&u_online, &u_anonymous) < 0)
         if (db == NULL)  
63          {          {
64                  return -1;                  log_error("get_user_online_list_count() error\n");
65                    u_online = 0;
66          }          }
67            u_online += u_anonymous;
68          snprintf(sql, sizeof(sql),          u_online++; // current user
69                           "SELECT COUNT(*) AS cc FROM "          if (BBS_priv.uid == 0)
                          "(SELECT DISTINCT SID FROM user_online "  
                          "WHERE last_tm >= SUBDATE(NOW(), INTERVAL %d SECOND)) AS t1",  
                          BBS_user_off_line);  
         if (mysql_query(db, sql) != 0)  
70          {          {
71                  log_error("Query user_online error: %s\n", mysql_error(db));                  u_anonymous++;
                 mysql_close(db);  
                 return -2;  
72          }          }
         if ((rs = mysql_store_result(db)) == NULL)  
         {  
                 log_error("Get user_online data failed\n");  
                 mysql_close(db);  
                 return -2;  
         }  
         if ((row = mysql_fetch_row(rs)))  
         {  
                 u_online = (u_int32_t)atoi(row[0]);  
         }  
         mysql_free_result(rs);  
73    
74          snprintf(sql, sizeof(sql),          if (get_user_list_count(&u_total) < 0)
                          "SELECT COUNT(*) AS cc FROM "  
                          "(SELECT DISTINCT SID FROM user_online "  
                          "WHERE UID = 0 AND last_tm >= SUBDATE(NOW(), INTERVAL %d SECOND)) AS t1",  
                          BBS_user_off_line);  
         if (mysql_query(db, sql) != 0)  
         {  
                 log_error("Query user_online error: %s\n", mysql_error(db));  
                 mysql_close(db);  
                 return -2;  
         }  
         if ((rs = mysql_store_result(db)) == NULL)  
         {  
                 log_error("Get user_online data failed\n");  
                 mysql_close(db);  
                 return -2;  
         }  
         if ((row = mysql_fetch_row(rs)))  
75          {          {
76                  u_anonymous = (u_int32_t)atoi(row[0]);                  log_error("get_user_list_count() error\n");
77                    u_total = 0;
78          }          }
         mysql_free_result(rs);  
79    
80          snprintf(sql, sizeof(sql), "SELECT COUNT(UID) AS cc FROM user_list WHERE enable");          db = db_open();
81          if (mysql_query(db, sql) != 0)          if (db == NULL)
         {  
                 log_error("Query user_list error: %s\n", mysql_error(db));  
                 mysql_close(db);  
                 return -2;  
         }  
         if ((rs = mysql_store_result(db)) == NULL)  
         {  
                 log_error("Get user_list data failed\n");  
                 mysql_close(db);  
                 return -2;  
         }  
         if ((row = mysql_fetch_row(rs)))  
82          {          {
83                  u_total = (u_int32_t)atoi(row[0]);                  return -1;
84          }          }
         mysql_free_result(rs);  
85    
86          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");
87          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
# Line 144  int bbs_welcome(void) Line 98  int bbs_welcome(void)
98          }          }
99          if ((row = mysql_fetch_row(rs)))          if ((row = mysql_fetch_row(rs)))
100          {          {
101                  u_login_count = (u_int32_t)atoi(row[0]);                  u_login_count = atoi(row[0]);
102          }          }
103          mysql_free_result(rs);          mysql_free_result(rs);
104    
105          mysql_close(db);          mysql_close(db);
106    
         // Count current user before login  
         u_online++;  
         u_anonymous++;  
   
107          // Display logo          // Display logo
108          display_file(DATA_WELCOME, 2);          display_file(DATA_WELCOME, 2);
109    
# Line 164  int bbs_welcome(void) Line 114  int bbs_welcome(void)
114                     "注册用户数[\033[36m%d/%d\033[32m]\r\n"                     "注册用户数[\033[36m%d/%d\033[32m]\r\n"
115                     "从 [\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",
116                     BBS_name, u_online, BBS_max_client, u_anonymous, u_total,                     BBS_name, u_online, BBS_max_client, u_anonymous, u_total,
117                     BBS_max_user, BBS_start_dt, u_login_count);                     BBS_max_user_count, BBS_start_dt, u_login_count);
118    
119          iflush();          iflush();
120    
# Line 195  int bbs_logout(void) Line 145  int bbs_logout(void)
145    
146          display_file(DATA_GOODBYE, 1);          display_file(DATA_GOODBYE, 1);
147    
148          log_common("User [%s] logout\n", BBS_username);          log_common("User [%s] logout, idle for %ld seconds since last input\n", BBS_username, time(NULL) - BBS_last_access_tm);
149    
150          return 0;          return 0;
151  }  }
# Line 278  int bbs_center() Line 228  int bbs_center()
228          return 0;          return 0;
229  }  }
230    
231    int bbs_charset_select()
232    {
233            char msg[LINE_BUFFER_LEN];
234            int ch;
235    
236            snprintf(msg, sizeof(msg),
237                             "\rChoose character set in 5 seconds [UTF-8, GBK]: [U/g]");
238    
239            while (!SYS_server_exit)
240            {
241                    ch = press_any_key_ex(msg, 5);
242                    switch (ch)
243                    {
244                    case KEY_NULL:
245                            return -1;
246                    case KEY_TIMEOUT:
247                    case CR:
248                    case 'u':
249                    case 'U':
250                            return 0;
251                    case 'g':
252                    case 'G':
253                            if (io_conv_init("GBK") < 0)
254                            {
255                                    log_error("io_conv_init(%s) error\n", "GBK");
256                                    return -1;
257                            }
258                            return 0;
259                    default:
260                            continue;
261                    }
262            }
263    
264            return 0;
265    }
266    
267  int bbs_main()  int bbs_main()
268  {  {
269          struct sigaction act = {0};          struct sigaction act = {0};
270            char msg[LINE_BUFFER_LEN];
271    
272          // Set signal handler          // Set signal handler
273          act.sa_handler = SIG_IGN;          act.sa_handler = SIG_IGN;
# Line 309  int bbs_main() Line 296  int bbs_main()
296          {          {
297                  goto cleanup;                  goto cleanup;
298          }          }
299            if (set_user_list_pool_shm_readonly() < 0)
300            {
301                    goto cleanup;
302            }
303    
304          // Load menu in shared memory          // Load menu in shared memory
305          if (set_menu_shm_readonly(&bbs_menu) < 0)          if (set_menu_shm_readonly(&bbs_menu) < 0)
# Line 316  int bbs_main() Line 307  int bbs_main()
307                  goto cleanup;                  goto cleanup;
308          }          }
309    
310            // Set default charset
311            if (io_conv_init(BBS_DEFAULT_CHARSET) < 0)
312            {
313                    log_error("io_conv_init(%s) error\n", BBS_DEFAULT_CHARSET);
314                    goto cleanup;
315            }
316    
317          set_input_echo(0);          set_input_echo(0);
318    
319            // Set user charset
320            bbs_charset_select();
321    
322          // System info          // System info
323          if (bbs_info() < 0)          if (bbs_info() < 0)
324          {          {
# Line 333  int bbs_main() Line 334  int bbs_main()
334          // User login          // User login
335          if (SSH_v2)          if (SSH_v2)
336          {          {
337                  prints("\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username);                  snprintf(msg, sizeof(msg), "\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username);
338                  iflush();                  press_any_key_ex(msg, 60);
                 igetch_reset();  
                 while (!SYS_server_exit && igetch_t(MAX_DELAY_TIME) == 0)  
                         ;  
339          }          }
340          else if (bbs_login() < 0)          else if (bbs_login() < 0)
341          {          {
# Line 390  int bbs_main() Line 388  int bbs_main()
388          }          }
389    
390  cleanup:  cleanup:
391            // Cleanup iconv
392            io_conv_cleanup();
393    
394          // Cleanup editor memory pool          // Cleanup editor memory pool
395          editor_memory_pool_cleanup();          editor_memory_pool_cleanup();
396    
# Line 404  cleanup: Line 405  cleanup:
405          detach_menu_shm(&top10_menu);          detach_menu_shm(&top10_menu);
406    
407          // Detach data pools shm          // Detach data pools shm
408            detach_user_list_pool_shm();
409          detach_section_list_shm();          detach_section_list_shm();
410          detach_article_block_shm();          detach_article_block_shm();
411          detach_trie_dict_shm();          detach_trie_dict_shm();


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

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