/[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.84 by sysadm, Fri Oct 17 01:25:08 2025 UTC Revision 1.95 by sysadm, Sun Nov 2 04:30:29 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 47  int bbs_info() Line 48  int bbs_info()
48    
49  int bbs_welcome(void)  int bbs_welcome(void)
50  {  {
51          char sql[SQL_BUFFER_LEN];          int u_online = 0;
52            int u_anonymous = 0;
53            int u_total = 0;
54            int u_login_count = 0;
55    
56          u_int32_t u_online = 0;          if (get_user_online_list_count(&u_online, &u_anonymous) < 0)
         u_int32_t u_anonymous = 0;  
         u_int32_t u_total = 0;  
         u_int32_t u_login_count = 0;  
   
         MYSQL *db;  
         MYSQL_RES *rs;  
         MYSQL_ROW row;  
   
         db = db_open();  
         if (db == NULL)  
         {  
                 return -1;  
         }  
   
         snprintf(sql, sizeof(sql),  
                          "SELECT COUNT(*) AS cc FROM "  
                          "(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)  
57          {          {
58                  log_error("Query user_online error: %s\n", mysql_error(db));                  log_error("get_user_online_list_count() error\n");
59                  mysql_close(db);                  u_online = 0;
                 return -2;  
60          }          }
61          if ((rs = mysql_store_result(db)) == NULL)          u_online += u_anonymous;
62            u_online++; // current user
63            if (BBS_priv.uid == 0)
64          {          {
65                  log_error("Get user_online data failed\n");                  u_anonymous++;
                 mysql_close(db);  
                 return -2;  
66          }          }
         if ((row = mysql_fetch_row(rs)))  
         {  
                 u_online = (u_int32_t)atoi(row[0]);  
         }  
         mysql_free_result(rs);  
67    
68          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)  
69          {          {
70                  log_error("Query user_online error: %s\n", mysql_error(db));                  log_error("get_user_list_count() error\n");
71                  mysql_close(db);                  u_total = 0;
                 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_anonymous = (u_int32_t)atoi(row[0]);  
         }  
         mysql_free_result(rs);  
73    
74          snprintf(sql, sizeof(sql), "SELECT COUNT(UID) AS cc FROM user_list WHERE enable");          if (get_user_login_count(&u_login_count) < 0)
         if (mysql_query(db, sql) != 0)  
75          {          {
76                  log_error("Query user_list error: %s\n", mysql_error(db));                  log_error("get_user_login_count() error\n");
77                  mysql_close(db);                  u_login_count = 0;
                 return -2;  
         }  
         if ((rs = mysql_store_result(db)) == NULL)  
         {  
                 log_error("Get user_list data failed\n");  
                 mysql_close(db);  
                 return -2;  
78          }          }
         if ((row = mysql_fetch_row(rs)))  
         {  
                 u_total = (u_int32_t)atoi(row[0]);  
         }  
         mysql_free_result(rs);  
   
         snprintf(sql, sizeof(sql), "SELECT ID FROM user_login_log ORDER BY ID LIMIT 1");  
         if (mysql_query(db, sql) != 0)  
         {  
                 log_error("Query user_login_log error: %s\n", mysql_error(db));  
                 mysql_close(db);  
                 return -2;  
         }  
         if ((rs = mysql_store_result(db)) == NULL)  
         {  
                 log_error("Get user_login_log data failed\n");  
                 mysql_close(db);  
                 return -2;  
         }  
         if ((row = mysql_fetch_row(rs)))  
         {  
                 u_login_count = (u_int32_t)atoi(row[0]);  
         }  
         mysql_free_result(rs);  
   
         mysql_close(db);  
   
         // Count current user before login  
         u_online++;  
         u_anonymous++;  
79    
80          // Display logo          // Display logo
81          display_file(DATA_WELCOME, 2);          display_file(DATA_WELCOME, 2);
# Line 164  int bbs_welcome(void) Line 87  int bbs_welcome(void)
87                     "注册用户数[\033[36m%d/%d\033[32m]\r\n"                     "注册用户数[\033[36m%d/%d\033[32m]\r\n"
88                     "从 [\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",
89                     BBS_name, u_online, BBS_max_client, u_anonymous, u_total,                     BBS_name, u_online, BBS_max_client, u_anonymous, u_total,
90                     BBS_max_user, BBS_start_dt, u_login_count);                     BBS_max_user_count, BBS_start_dt, u_login_count);
91    
92          iflush();          iflush();
93    
# Line 195  int bbs_logout(void) Line 118  int bbs_logout(void)
118    
119          display_file(DATA_GOODBYE, 1);          display_file(DATA_GOODBYE, 1);
120    
121          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);
122    
123          return 0;          return 0;
124  }  }
# Line 219  int bbs_center() Line 142  int bbs_center()
142          {          {
143                  ch = igetch(100);                  ch = igetch(100);
144    
145          if (ch != KEY_NULL && ch != KEY_TIMEOUT)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
146          {                  {
147              BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
148          }                  }
149    
150                  if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10)                  if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10)
151                  {                  {
# Line 278  int bbs_center() Line 201  int bbs_center()
201          return 0;          return 0;
202  }  }
203    
204    int bbs_charset_select()
205    {
206            char msg[LINE_BUFFER_LEN];
207            int ch;
208    
209            snprintf(msg, sizeof(msg),
210                             "\rChoose character set in 5 seconds [UTF-8, GBK]: [U/g]");
211    
212            while (!SYS_server_exit)
213            {
214                    ch = press_any_key_ex(msg, 5);
215                    switch (ch)
216                    {
217                    case KEY_NULL:
218                            return -1;
219                    case KEY_TIMEOUT:
220                    case CR:
221                    case 'u':
222                    case 'U':
223                            return 0;
224                    case 'g':
225                    case 'G':
226                            if (io_conv_init("GBK") < 0)
227                            {
228                                    log_error("io_conv_init(%s) error\n", "GBK");
229                                    return -1;
230                            }
231                            return 0;
232                    default:
233                            continue;
234                    }
235            }
236    
237            return 0;
238    }
239    
240  int bbs_main()  int bbs_main()
241  {  {
242          struct sigaction act = {0};          struct sigaction act = {0};
243            char msg[LINE_BUFFER_LEN];
244    
245          // Set signal handler          // Set signal handler
246          act.sa_handler = SIG_IGN;          act.sa_handler = SIG_IGN;
# Line 309  int bbs_main() Line 269  int bbs_main()
269          {          {
270                  goto cleanup;                  goto cleanup;
271          }          }
272            if (set_user_list_pool_shm_readonly() < 0)
273            {
274                    goto cleanup;
275            }
276    
277          // Load menu in shared memory          // Load menu in shared memory
278          if (set_menu_shm_readonly(&bbs_menu) < 0)          if (set_menu_shm_readonly(&bbs_menu) < 0)
# Line 316  int bbs_main() Line 280  int bbs_main()
280                  goto cleanup;                  goto cleanup;
281          }          }
282    
283            // Set default charset
284            if (io_conv_init(BBS_DEFAULT_CHARSET) < 0)
285            {
286                    log_error("io_conv_init(%s) error\n", BBS_DEFAULT_CHARSET);
287                    goto cleanup;
288            }
289    
290          set_input_echo(0);          set_input_echo(0);
291    
292            // Set user charset
293            bbs_charset_select();
294    
295          // System info          // System info
296          if (bbs_info() < 0)          if (bbs_info() < 0)
297          {          {
# Line 333  int bbs_main() Line 307  int bbs_main()
307          // User login          // User login
308          if (SSH_v2)          if (SSH_v2)
309          {          {
310                  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);
311                  iflush();                  press_any_key_ex(msg, 60);
                 igetch_reset();  
                 igetch_t(MAX_DELAY_TIME);  
312          }          }
313          else if (bbs_login() < 0)          else if (bbs_login() < 0)
314          {          {
# Line 389  int bbs_main() Line 361  int bbs_main()
361          }          }
362    
363  cleanup:  cleanup:
364            // Cleanup iconv
365            io_conv_cleanup();
366    
367          // Cleanup editor memory pool          // Cleanup editor memory pool
368          editor_memory_pool_cleanup();          editor_memory_pool_cleanup();
369    
# Line 403  cleanup: Line 378  cleanup:
378          detach_menu_shm(&top10_menu);          detach_menu_shm(&top10_menu);
379    
380          // Detach data pools shm          // Detach data pools shm
381            detach_user_list_pool_shm();
382          detach_section_list_shm();          detach_section_list_shm();
383          detach_article_block_shm();          detach_article_block_shm();
384          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