/[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.76 by sysadm, Wed Jul 2 04:17:33 2025 UTC Revision 1.87 by sysadm, Sat Oct 18 05:02:15 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #include "article_favor.h"
18  #include "article_view_log.h"  #include "article_view_log.h"
19  #include "bbs.h"  #include "bbs.h"
20  #include "bbs_cmd.h"  #include "bbs_cmd.h"
# Line 38  Line 39 
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_INFO);                     BBS_name, BBS_server, APP_INFO);
44    
45          return iflush();          return iflush();
# Line 180  int bbs_logout(void) Line 181  int bbs_logout(void)
181                  return -1;                  return -1;
182          }          }
183    
184          if (user_online_del(db) < 0)          if (user_online_exp(db) < 0)
185          {          {
186                  return -2;                  return -2;
187          }          }
188    
189            if (user_online_del(db) < 0)
190            {
191                    return -3;
192            }
193    
194          mysql_close(db);          mysql_close(db);
195    
196          display_file(DATA_GOODBYE, 1);          display_file(DATA_GOODBYE, 1);
197    
198          log_common("User logout\n");          log_common("User [%s] logout\n", BBS_username);
199    
200          return 0;          return 0;
201  }  }
# Line 213  int bbs_center() Line 219  int bbs_center()
219          {          {
220                  ch = igetch(100);                  ch = igetch(100);
221    
222                    if (ch != KEY_NULL && ch != KEY_TIMEOUT)
223                    {
224                            BBS_last_access_tm = time(NULL);
225                    }
226    
227                  if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10)                  if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10)
228                  {                  {
229                          t_last_action = time(NULL);                          t_last_action = time(NULL);
# Line 231  int bbs_center() Line 242  int bbs_center()
242                  switch (ch)                  switch (ch)
243                  {                  {
244                  case KEY_NULL: // broken pipe                  case KEY_NULL: // broken pipe
245                            log_error("KEY_NULL\n");
246                          return 0;                          return 0;
247                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
248                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
249                          {                          {
250                                    log_error("User input timeout\n");
251                                  return 0;                                  return 0;
252                          }                          }
253                          continue;                          continue;
254                  case CR:                  case CR:
                         igetch_reset();  
255                  default:                  default:
256                          switch (menu_control(&bbs_menu, ch))                          switch (menu_control(&bbs_menu, ch))
257                          {                          {
# Line 261  int bbs_center() Line 273  int bbs_center()
273                          }                          }
274                          iflush();                          iflush();
275                  }                  }
276            }
277    
278                  BBS_last_access_tm = time(NULL);          return 0;
279    }
280    
281    int bbs_charset_select()
282    {
283            char msg[LINE_BUFFER_LEN];
284            int ch;
285    
286            snprintf(msg, sizeof(msg),
287                             "\rChoose character set in 5 seconds [UTF-8, GBK]: [U/g]");
288    
289            ch = press_any_key_ex(msg, 5);
290            switch (ch)
291            {
292            case 'g':
293            case 'G':
294                    if (io_conv_init("GBK") < 0)
295                    {
296                            log_error("io_conv_init(%s) error\n", "GBK");
297                            return -1;
298                    }
299                    break;
300            default:
301                    log_error("Debug: %d\n", ch);
302          }          }
303    
304            prints("\r\n");
305            iflush();
306    
307          return 0;          return 0;
308  }  }
309    
310  int bbs_main()  int bbs_main()
311  {  {
312          struct sigaction act = {0};          struct sigaction act = {0};
313            char msg[LINE_BUFFER_LEN];
314    
315          // Set signal handler          // Set signal handler
316          act.sa_handler = SIG_IGN;          act.sa_handler = SIG_IGN;
# Line 306  int bbs_main() Line 346  int bbs_main()
346                  goto cleanup;                  goto cleanup;
347          }          }
348    
349            // Set default charset
350            if (io_conv_init(BBS_DEFAULT_CHARSET) < 0)
351            {
352                    log_error("io_conv_init(%s) error\n", BBS_DEFAULT_CHARSET);
353                    goto cleanup;
354            }
355    
356          set_input_echo(0);          set_input_echo(0);
357    
358            // Set user charset
359            bbs_charset_select();
360    
361          // System info          // System info
362          if (bbs_info() < 0)          if (bbs_info() < 0)
363          {          {
# Line 323  int bbs_main() Line 373  int bbs_main()
373          // User login          // User login
374          if (SSH_v2)          if (SSH_v2)
375          {          {
376                  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);
377                  iflush();                  press_any_key_ex(msg, 60);
                 igetch_t(MAX_DELAY_TIME);  
378          }          }
379          else if (bbs_login() < 0)          else if (bbs_login() < 0)
380          {          {
381                  goto cleanup;                  goto cleanup;
382          }          }
383            log_common("User [%s] login\n", BBS_username);
384    
385          // Load article view log          // Load article view log
386          if (article_view_log_load(BBS_priv.uid, &BBS_article_view_log, 0) < 0)          if (article_view_log_load(BBS_priv.uid, &BBS_article_view_log, 0) < 0)
# Line 339  int bbs_main() Line 389  int bbs_main()
389                  goto cleanup;                  goto cleanup;
390          }          }
391    
392            // Load article favorite
393            if (article_favor_load(BBS_priv.uid, &BBS_article_favor, 0) < 0)
394            {
395                    log_error("article_favor_load() error\n");
396                    goto cleanup;
397            }
398    
399          // Init editor memory pool          // Init editor memory pool
400          if (editor_memory_pool_init() < 0)          if (editor_memory_pool_init() < 0)
401          {          {
# Line 363  int bbs_main() Line 420  int bbs_main()
420                  log_error("article_view_log_save_inc() error\n");                  log_error("article_view_log_save_inc() error\n");
421          }          }
422    
423            // Save incremental article favorite
424            if (article_favor_save_inc(&BBS_article_favor) < 0)
425            {
426                    log_error("article_favor_save_inc() error\n");
427            }
428    
429  cleanup:  cleanup:
430            // Cleanup iconv
431            io_conv_cleanup();
432    
433          // Cleanup editor memory pool          // Cleanup editor memory pool
434          editor_memory_pool_cleanup();          editor_memory_pool_cleanup();
435    
436          // Unload article view log          // Unload article view log
437          article_view_log_unload(&BBS_article_view_log);          article_view_log_unload(&BBS_article_view_log);
438    
439            // Unload article favor
440            article_favor_unload(&BBS_article_favor);
441    
442          // Detach menu in shared memory          // Detach menu in shared memory
443          detach_menu_shm(&bbs_menu);          detach_menu_shm(&bbs_menu);
444            detach_menu_shm(&top10_menu);
445    
446          // Detach data pools shm          // Detach data pools shm
447          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