--- lbbs/src/bbs_net.c 2025/12/18 07:58:23 1.97 +++ lbbs/src/bbs_net.c 2025/12/18 11:18:29 1.103 @@ -140,7 +140,7 @@ static int load_bbsnet_conf(const char * port = strtol(t4, &endptr, 10); if (*endptr != '\0' || port <= 0 || port > 65535) { - log_error("Invalid port value %d of menu item %d\n", port, menu_item_id); + log_error("Invalid port value %ld of menu item %d\n", port, menu_item_id); fclose(fp); unload_bbsnet_conf(); return -3; @@ -212,13 +212,13 @@ static void progress_bar(int percent, in char buf2[LINE_BUFFER_LEN]; int pos; - if (len <= 0) + if (len < 4) { - len = 1; + len = 4; } - else if (len > LINE_BUFFER_LEN) + else if (len + 2 > LINE_BUFFER_LEN) { - len = LINE_BUFFER_LEN - 1; + len = LINE_BUFFER_LEN - 3; } if (percent < 0) { @@ -531,9 +531,9 @@ static int bbsnet_connect(int n) } ts_now = ts_begin; - while ((ts_now.tv_sec - ts_begin.tv_sec) + - (ts_now.tv_nsec - ts_begin.tv_nsec) / 1000 / 1000 / 1000 < - REMOTE_CONNECT_TIMEOUT && + while ((ts_now.tv_sec - ts_begin.tv_sec) * 1000 + + (ts_now.tv_nsec - ts_begin.tv_nsec) / 1000 / 1000 < + REMOTE_CONNECT_TIMEOUT * 1000 && !sock_connected && !SYS_server_exit) { #ifdef HAVE_SYS_EPOLL_H @@ -573,6 +573,14 @@ static int bbsnet_connect(int n) (ts_now.tv_nsec - ts_begin.tv_nsec) / 1000 / 1000) / REMOTE_CONNECT_TIMEOUT / 10 + 1; + if (progress < 0) + { + progress = 0; + } + if (progress > 100) + { + progress = 100; + } if (progress > progress_last) { @@ -956,6 +964,7 @@ static int bbsnet_connect(int n) { if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { + log_debug("User input timeout\n"); break; } } @@ -1313,7 +1322,7 @@ static int bbsnet_connect(int n) ret = 1; // Normal disconnect BBS_last_access_tm = time(NULL); t_used = BBS_last_access_tm - t_begin; - log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", + log_common("BBSNET disconnect, %ld days %ld hours %ld minutes %ld seconds used\n", t_used / 86400, t_used % 86400 / 3600, t_used % 3600 / 60, t_used % 60); cleanup: @@ -1364,7 +1373,7 @@ cleanup: if (sock != -1 && close(sock) == -1) { - log_error("Close socket failed\n"); + log_error("close(socket) error (%d)\n", errno); } if (res) @@ -1425,7 +1434,7 @@ static int bbsnet_selchange() int bbs_net() { - int ch, i; + int ch; if (load_bbsnet_conf(CONF_BBSNET) < 0) { @@ -1457,7 +1466,7 @@ int bbs_net() case KEY_TIMEOUT: if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - log_error("User input timeout\n"); + log_debug("User input timeout\n"); goto cleanup; } continue; @@ -1465,7 +1474,10 @@ int bbs_net() case Ctrl('C'): // user cancel goto cleanup; case CR: - bbsnet_connect(bbsnet_menu.menu_item_pos[0]); + if (bbsnet_connect(bbsnet_menu.menu_item_pos[0]) < 0) + { + log_debug("bbsnet_connect() error\n"); + } // Force cleanup anything remaining in the output buffer clearscr(); iflush(); @@ -1475,14 +1487,14 @@ int bbs_net() bbsnet_selchange(); break; case KEY_UP: - for (i = 0; i < STATION_PER_LINE; i++) + for (int i = 0; i < STATION_PER_LINE; i++) { menu_control(&bbsnet_menu, KEY_UP); } bbsnet_selchange(); break; case KEY_DOWN: - for (i = 0; i < STATION_PER_LINE; i++) + for (int i = 0; i < STATION_PER_LINE; i++) { menu_control(&bbsnet_menu, KEY_DOWN); }