/[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.64 by sysadm, Thu Jun 5 05:24:56 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  {  {
37          prints("欢迎光临 \033[1;33m%s \033[32m[%s]  \033[37m( %s )\r\n",          prints("欢迎光临 \033[1;33m%s \033[32m[%s]  \033[37m( %s )\r\n",
38                     BBS_name, BBS_server, app_version);                     BBS_name, BBS_server, APP_NAME_VER);
39    
40          return iflush();          return iflush();
41  }  }
# 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 150  int bbs_welcome(MYSQL *db) Line 153  int bbs_welcome(MYSQL *db)
153          u_anonymous++;          u_anonymous++;
154    
155          // Display logo          // Display logo
156          display_file_ex(DATA_WELCOME, 1, 0);          display_file(DATA_WELCOME, 1, 2);
157    
158          // Display welcome message          // Display welcome message
159          prints("\r\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n"          prints("\r\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n"
# Line 158  int bbs_welcome(MYSQL *db) Line 161  int bbs_welcome(MYSQL *db)
161                     "匿名游客[\033[36m%d\033[32m] "                     "匿名游客[\033[36m%d\033[32m] "
162                     "注册用户数[\033[36m%d/%d\033[32m]\r\n"                     "注册用户数[\033[36m%d/%d\033[32m]\r\n"
163                     "从 [\033[36m%s\033[32m] 起,最高人数记录:"                     "从 [\033[36m%s\033[32m] 起,最高人数记录:"
164                     "[\033[36m%d\033[32m],累计访问人次:[\033[36m%d\033[32m]\r\n",                     "[\033[36m%d\033[32m],累计访问人次:[\033[36m%d\033[32m]\033[m\r\n",
165                     BBS_name, u_online, BBS_max_client, u_anonymous, u_total,                     BBS_name, u_online, BBS_max_client, u_anonymous, u_total,
166                     BBS_max_user, BBS_start_dt, max_u_online, u_login_count);                     BBS_max_user, BBS_start_dt, max_u_online, u_login_count);
167    
168            iflush();
169    
170          return 0;          return 0;
171  }  }
172    
# Line 172  int bbs_logout(MYSQL *db) Line 177  int bbs_logout(MYSQL *db)
177                  return -1;                  return -1;
178          }          }
179    
180          display_file_ex(DATA_GOODBYE, 1, 1);          display_file(DATA_GOODBYE, 1, 1);
181    
182          log_std("User logout\n");          log_common("User logout\n");
183    
184          return 0;          return 0;
185  }  }
# Line 188  int bbs_center() Line 193  int bbs_center()
193    
194          clearscr();          clearscr();
195    
196          show_top("");          show_top("", BBS_name, "");
197          show_active_board();          show_active_board();
198          show_bottom("");          show_bottom("");
199          display_menu(p_bbs_menu);          display_menu(p_bbs_menu);
# Line 204  int bbs_center() Line 209  int bbs_center()
209    
210                          show_active_board();                          show_active_board();
211                          show_bottom("");                          show_bottom("");
212                            display_menu_cursor(p_bbs_menu, 1);
213                          iflush();                          iflush();
214                  }                  }
215    
# Line 227  int bbs_center() Line 233  int bbs_center()
233                          case REDRAW:                          case REDRAW:
234                                  t_last_action = time(0);                                  t_last_action = time(0);
235                                  clearscr();                                  clearscr();
236                                  show_top("");                                  show_top("", BBS_name, "");
237                                  show_active_board();                                  show_active_board();
238                                  show_bottom("");                                  show_bottom("");
239                                  display_menu(p_bbs_menu);                                  display_menu(p_bbs_menu);
# Line 248  int bbs_center() Line 254  int bbs_center()
254    
255  int bbs_main()  int bbs_main()
256  {  {
257          MYSQL *db;          MYSQL *db = NULL;
258    
259            // Set data pools in shared memory readonly
260            if (set_trie_dict_shm_readonly() < 0)
261            {
262                    goto cleanup;
263            }
264            if (set_article_block_shm_readonly() < 0)
265            {
266                    goto cleanup;
267            }
268            if (set_section_list_shm_readonly() < 0)
269            {
270                    goto cleanup;
271            }
272    
273            // Load menu in shared memory
274            if (set_menu_shm_readonly(p_bbs_menu) < 0)
275            {
276                    goto cleanup;
277            }
278    
279          set_input_echo(0);          set_input_echo(0);
280    
281          // System info          // System info
282          if (bbs_info() < 0)          if (bbs_info() < 0)
283          {          {
284                  return -1;                  goto cleanup;
285          }          }
286    
287          db = db_open();          db = db_open();
288          if (db == NULL)          if (db == NULL)
289          {          {
290                  prints("无法连接数据库\n");                  prints("无法连接数据库\n");
291                  return -2;                  goto cleanup;
292          }          }
293    
294          // Welcome          // Welcome
295          if (bbs_welcome(db) < 0)          if (bbs_welcome(db) < 0)
296          {          {
297                  mysql_close(db);                  goto cleanup;
                 return -3;  
298          }          }
299    
300          // User login          // User login
301          if (bbs_login(db) < 0)          if (SSH_v2)
302          {          {
303                  mysql_close(db);                  prints("\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username);
304                  return -4;                  iflush();
305                    igetch_t(MAX_DELAY_TIME);
306          }          }
307            else if (bbs_login(db) < 0)
308            {
309                    goto cleanup;
310            }
311    
312          clearscr();          clearscr();
313    
314          // BBS Top 10          // BBS Top 10
315          display_file_ex(VAR_BBS_TOP, 1, 1);          display_file(VAR_BBS_TOP, 1, 1);
   
         // Load menu in shared memory  
         if (load_menu_shm(p_bbs_menu) < 0)  
         {  
                 return -5;  
         }  
316    
317          // Main          // Main
318          bbs_center();          bbs_center();
319    
         // Unload menu in shared memory  
         unload_menu_shm(p_bbs_menu);  
         free(p_bbs_menu);  
         p_bbs_menu = NULL;  
   
320          // Logout          // Logout
321          bbs_logout(db);          bbs_logout(db);
322    
323          mysql_close(db);  cleanup:
324            if (db != NULL)
325            {
326                    mysql_close(db);
327            }
328    
329            // Detach menu in shared memory
330            detach_menu_shm(p_bbs_menu);
331            free(p_bbs_menu);
332            p_bbs_menu = NULL;
333    
334            // Detach data pools shm
335            detach_section_list_shm();
336            detach_article_block_shm();
337            detach_trie_dict_shm();
338    
339          return 0;          return 0;
340  }  }


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

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