/[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.77 by sysadm, Sat Jul 5 01:02:34 2025 UTC Revision 1.88 by sysadm, Sat Oct 18 05:30:01 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 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            return 0;
279    }
280    
281    int bbs_charset_select()
282    {
283            char msg[LINE_BUFFER_LEN];
284            int ch;
285    
286                  BBS_last_access_tm = time(NULL);          while (!SYS_server_exit)
287            {
288                    snprintf(msg, sizeof(msg),
289                                     "\rChoose character set in 5 seconds [UTF-8, GBK]: [U/g]");
290    
291                    ch = press_any_key_ex(msg, 5);
292                    switch (ch)
293                    {
294                    case KEY_TIMEOUT:
295                    case CR:
296                    case 'u':
297                    case 'U':
298                            return 0;
299                    case 'g':
300                    case 'G':
301                            if (io_conv_init("GBK") < 0)
302                            {
303                                    log_error("io_conv_init(%s) error\n", "GBK");
304                                    return -1;
305                            }
306                            return 0;
307                    default:
308                            continue;
309                    }
310          }          }
311    
312          return 0;          return 0;
# Line 271  int bbs_center() Line 315  int bbs_center()
315  int bbs_main()  int bbs_main()
316  {  {
317          struct sigaction act = {0};          struct sigaction act = {0};
318            char msg[LINE_BUFFER_LEN];
319    
320          // Set signal handler          // Set signal handler
321          act.sa_handler = SIG_IGN;          act.sa_handler = SIG_IGN;
# Line 306  int bbs_main() Line 351  int bbs_main()
351                  goto cleanup;                  goto cleanup;
352          }          }
353    
354            // Set default charset
355            if (io_conv_init(BBS_DEFAULT_CHARSET) < 0)
356            {
357                    log_error("io_conv_init(%s) error\n", BBS_DEFAULT_CHARSET);
358                    goto cleanup;
359            }
360    
361          set_input_echo(0);          set_input_echo(0);
362    
363            // Set user charset
364            bbs_charset_select();
365    
366          // System info          // System info
367          if (bbs_info() < 0)          if (bbs_info() < 0)
368          {          {
# Line 323  int bbs_main() Line 378  int bbs_main()
378          // User login          // User login
379          if (SSH_v2)          if (SSH_v2)
380          {          {
381                  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);
382                  iflush();                  press_any_key_ex(msg, 60);
                 igetch_t(MAX_DELAY_TIME);  
383          }          }
384          else if (bbs_login() < 0)          else if (bbs_login() < 0)
385          {          {
386                  goto cleanup;                  goto cleanup;
387          }          }
388            log_common("User [%s] login\n", BBS_username);
389    
390          // Load article view log          // Load article view log
391          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 394  int bbs_main()
394                  goto cleanup;                  goto cleanup;
395          }          }
396    
397            // Load article favorite
398            if (article_favor_load(BBS_priv.uid, &BBS_article_favor, 0) < 0)
399            {
400                    log_error("article_favor_load() error\n");
401                    goto cleanup;
402            }
403    
404          // Init editor memory pool          // Init editor memory pool
405          if (editor_memory_pool_init() < 0)          if (editor_memory_pool_init() < 0)
406          {          {
# Line 363  int bbs_main() Line 425  int bbs_main()
425                  log_error("article_view_log_save_inc() error\n");                  log_error("article_view_log_save_inc() error\n");
426          }          }
427    
428            // Save incremental article favorite
429            if (article_favor_save_inc(&BBS_article_favor) < 0)
430            {
431                    log_error("article_favor_save_inc() error\n");
432            }
433    
434  cleanup:  cleanup:
435            // Cleanup iconv
436            io_conv_cleanup();
437    
438          // Cleanup editor memory pool          // Cleanup editor memory pool
439          editor_memory_pool_cleanup();          editor_memory_pool_cleanup();
440    
441          // Unload article view log          // Unload article view log
442          article_view_log_unload(&BBS_article_view_log);          article_view_log_unload(&BBS_article_view_log);
443    
444            // Unload article favor
445            article_favor_unload(&BBS_article_favor);
446    
447          // Detach menu in shared memory          // Detach menu in shared memory
448          detach_menu_shm(&bbs_menu);          detach_menu_shm(&bbs_menu);
449            detach_menu_shm(&top10_menu);
450    
451          // Detach data pools shm          // Detach data pools shm
452          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