| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
bbs_net.c - description |
/* |
| 3 |
------------------- |
* bbs_net |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - user interactive feature of site shuttle |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 by Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
|
/*************************************************************************** |
|
|
* * |
|
|
* This program is free software; you can redistribute it and/or modify * |
|
|
* it under the terms of the GNU General Public License as published by * |
|
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 8 |
|
|
| 9 |
#include "bbs.h" |
#include "bbs.h" |
| 10 |
#include "common.h" |
#include "common.h" |
|
#include "log.h" |
|
| 11 |
#include "io.h" |
#include "io.h" |
| 12 |
#include "screen.h" |
#include "log.h" |
| 13 |
|
#include "login.h" |
| 14 |
#include "menu.h" |
#include "menu.h" |
| 15 |
#include <stdio.h> |
#include "screen.h" |
|
#include <stdarg.h> |
|
| 16 |
#include <errno.h> |
#include <errno.h> |
|
#include <string.h> |
|
|
#include <stdlib.h> |
|
| 17 |
#include <fcntl.h> |
#include <fcntl.h> |
| 18 |
|
#include <netdb.h> |
| 19 |
|
#include <stdarg.h> |
| 20 |
|
#include <stdio.h> |
| 21 |
|
#include <stdlib.h> |
| 22 |
|
#include <string.h> |
| 23 |
#include <time.h> |
#include <time.h> |
| 24 |
#include <unistd.h> |
#include <unistd.h> |
| 25 |
#include <netdb.h> |
#include <arpa/inet.h> |
| 26 |
|
#include <libssh/libssh.h> |
| 27 |
|
#include <libssh/server.h> |
| 28 |
|
#include <libssh/callbacks.h> |
| 29 |
|
#include <netinet/in.h> |
| 30 |
|
#include <netinet/ip.h> |
| 31 |
#include <sys/select.h> |
#include <sys/select.h> |
| 32 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
| 33 |
#include <sys/socket.h> |
#include <sys/socket.h> |
| 34 |
#include <sys/epoll.h> |
#include <sys/epoll.h> |
|
#include <netinet/in.h> |
|
|
#include <netinet/ip.h> |
|
|
#include <arpa/inet.h> |
|
| 35 |
|
|
| 36 |
#define MENU_CONF_DELIM " \t\r\n" |
#define MENU_CONF_DELIM " \t\r\n" |
| 37 |
|
|
| 45 |
char host2[40]; |
char host2[40]; |
| 46 |
char ip[40]; |
char ip[40]; |
| 47 |
in_port_t port; |
in_port_t port; |
| 48 |
|
char charset[20]; |
| 49 |
} bbsnet_conf[MAXSTATION]; |
} bbsnet_conf[MAXSTATION]; |
| 50 |
|
|
| 51 |
MENU_SET bbsnet_menu; |
static MENU_SET bbsnet_menu; |
| 52 |
|
|
| 53 |
int load_bbsnet_conf(const char *file_config) |
static int load_bbsnet_conf(const char *file_config) |
| 54 |
{ |
{ |
| 55 |
FILE *fp; |
FILE *fp; |
| 56 |
MENU *p_menu; |
MENU *p_menu; |
| 57 |
MENU_ITEM *p_menuitem; |
MENU_ITEM *p_menu_item; |
| 58 |
char t[256], *t1, *t2, *t3, *t4, *saveptr; |
MENU_ITEM_ID menu_item_id; |
| 59 |
int item_count = 0; |
char t[256], *t1, *t2, *t3, *t4, *t5, *saveptr; |
| 60 |
|
|
| 61 |
fp = fopen(file_config, "r"); |
fp = fopen(file_config, "r"); |
| 62 |
if (fp == NULL) |
if (fp == NULL) |
| 64 |
return -1; |
return -1; |
| 65 |
} |
} |
| 66 |
|
|
| 67 |
p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU)); |
bbsnet_menu.p_menu_pool = calloc(1, sizeof(MENU)); |
| 68 |
|
if (bbsnet_menu.p_menu_pool == NULL) |
| 69 |
|
{ |
| 70 |
|
log_error("calloc(p_menu_pool) error\n"); |
| 71 |
|
return -3; |
| 72 |
|
} |
| 73 |
|
bbsnet_menu.menu_count = 1; |
| 74 |
|
|
| 75 |
|
bbsnet_menu.p_menu_item_pool = calloc(MAXSTATION, sizeof(MENU_ITEM)); |
| 76 |
|
if (bbsnet_menu.p_menu_item_pool == NULL) |
| 77 |
|
{ |
| 78 |
|
log_error("calloc(p_menu_item_pool) error\n"); |
| 79 |
|
return -3; |
| 80 |
|
} |
| 81 |
|
bbsnet_menu.menu_item_count = MAXSTATION; |
| 82 |
|
|
| 83 |
|
p_menu = (MENU *)get_menu_by_id(&bbsnet_menu, 0); |
| 84 |
|
|
| 85 |
strncpy(p_menu->name, "BBSNET", sizeof(p_menu->name) - 1); |
strncpy(p_menu->name, "BBSNET", sizeof(p_menu->name) - 1); |
| 86 |
p_menu->name[sizeof(p_menu->name) - 1] = '\0'; |
p_menu->name[sizeof(p_menu->name) - 1] = '\0'; |
| 87 |
p_menu->title.show = 0; |
p_menu->title.show = 0; |
| 88 |
p_menu->screen.show = 0; |
p_menu->screen_show = 0; |
| 89 |
|
|
| 90 |
while (fgets(t, 255, fp) && item_count < MAXSTATION) |
menu_item_id = 0; |
| 91 |
|
while (fgets(t, 255, fp) && menu_item_id < MAXSTATION) |
| 92 |
{ |
{ |
| 93 |
t1 = strtok_r(t, MENU_CONF_DELIM, &saveptr); |
t1 = strtok_r(t, MENU_CONF_DELIM, &saveptr); |
| 94 |
t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 95 |
t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 96 |
t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 97 |
|
t5 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 98 |
|
|
| 99 |
if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL || t[0] == '#' || t[0] == '*') |
if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL || t5 == NULL || t[0] == '#' || t[0] == '*') |
| 100 |
{ |
{ |
| 101 |
continue; |
continue; |
| 102 |
} |
} |
| 103 |
|
|
| 104 |
strncpy(bbsnet_conf[item_count].host1, t2, sizeof(bbsnet_conf[item_count].host1) - 1); |
strncpy(bbsnet_conf[menu_item_id].host1, t2, sizeof(bbsnet_conf[menu_item_id].host1) - 1); |
| 105 |
bbsnet_conf[item_count].host1[sizeof(bbsnet_conf[item_count].host1) - 1] = '\0'; |
bbsnet_conf[menu_item_id].host1[sizeof(bbsnet_conf[menu_item_id].host1) - 1] = '\0'; |
| 106 |
strncpy(bbsnet_conf[item_count].host2, t1, sizeof(bbsnet_conf[item_count].host2) - 1); |
strncpy(bbsnet_conf[menu_item_id].host2, t1, sizeof(bbsnet_conf[menu_item_id].host2) - 1); |
| 107 |
bbsnet_conf[item_count].host2[sizeof(bbsnet_conf[item_count].host2) - 1] = '\0'; |
bbsnet_conf[menu_item_id].host2[sizeof(bbsnet_conf[menu_item_id].host2) - 1] = '\0'; |
| 108 |
strncpy(bbsnet_conf[item_count].ip, t3, sizeof(bbsnet_conf[item_count].ip) - 1); |
strncpy(bbsnet_conf[menu_item_id].ip, t3, sizeof(bbsnet_conf[menu_item_id].ip) - 1); |
| 109 |
bbsnet_conf[item_count].ip[sizeof(bbsnet_conf[item_count].ip) - 1] = '\0'; |
bbsnet_conf[menu_item_id].ip[sizeof(bbsnet_conf[menu_item_id].ip) - 1] = '\0'; |
| 110 |
bbsnet_conf[item_count].port = (in_port_t)(t4 ? atoi(t4) : 23); |
bbsnet_conf[menu_item_id].port = (in_port_t)(t4 ? atoi(t4) : 23); |
| 111 |
|
strncpy(bbsnet_conf[menu_item_id].charset, t5, sizeof(bbsnet_conf[menu_item_id].charset) - 1); |
| 112 |
p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM)); |
bbsnet_conf[menu_item_id].charset[sizeof(bbsnet_conf[menu_item_id].charset) - 1] = '\0'; |
|
p_menuitem->row = 2 + item_count / STATION_PER_LINE; |
|
|
p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20; |
|
|
snprintf(p_menuitem->action, sizeof(p_menuitem->action), "%d", item_count); |
|
|
p_menuitem->submenu = 0; |
|
|
p_menuitem->priv = 0; |
|
|
p_menuitem->level = 0; |
|
|
p_menuitem->display = 0; |
|
|
p_menuitem->name[0] = |
|
|
(char)(item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count); |
|
|
p_menuitem->name[1] = '\0'; |
|
|
snprintf(p_menuitem->text, sizeof(p_menuitem->text), "[1;36m%c.[m %s", |
|
|
p_menuitem->name[0], bbsnet_conf[item_count].host1); |
|
| 113 |
|
|
| 114 |
item_count++; |
p_menu_item = get_menu_item_by_id(&bbsnet_menu, menu_item_id); |
| 115 |
} |
if (p_menu_item == NULL) |
| 116 |
fclose(fp); |
{ |
| 117 |
|
log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); |
| 118 |
|
return -1; |
| 119 |
|
} |
| 120 |
|
|
| 121 |
p_menu->item_count = item_count; |
p_menu_item->row = (int16_t)(2 + menu_item_id / STATION_PER_LINE); |
| 122 |
p_menu->item_cur_pos = 0; |
p_menu_item->col = (int16_t)(5 + menu_item_id % STATION_PER_LINE * 20); |
| 123 |
|
snprintf(p_menu_item->action, sizeof(p_menu_item->action), "%d", (int16_t)menu_item_id); |
| 124 |
|
p_menu_item->submenu = 0; |
| 125 |
|
p_menu_item->priv = 0; |
| 126 |
|
p_menu_item->level = 0; |
| 127 |
|
p_menu_item->name[0] = |
| 128 |
|
(char)(menu_item_id < MAXSTATION / 2 ? 'A' + menu_item_id : 'a' + menu_item_id); |
| 129 |
|
p_menu_item->name[1] = '\0'; |
| 130 |
|
snprintf(p_menu_item->text, sizeof(p_menu_item->text), "[1;36m%c.[m %s", |
| 131 |
|
p_menu_item->name[0], bbsnet_conf[menu_item_id].host1); |
| 132 |
|
|
| 133 |
|
p_menu->items[p_menu->item_count] = menu_item_id; |
| 134 |
|
p_menu->item_count++; |
| 135 |
|
menu_item_id++; |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
bbsnet_menu.menu_item_count = (int16_t)menu_item_id; |
| 139 |
|
bbsnet_menu.menu_id_path[0] = 0; |
| 140 |
|
bbsnet_menu.menu_item_pos[0] = 0; |
| 141 |
|
bbsnet_menu.choose_step = 0; |
| 142 |
|
|
| 143 |
bbsnet_menu.menu_count = 1; |
fclose(fp); |
|
bbsnet_menu.menu_select_depth = 0; |
|
|
bbsnet_menu.p_menu_select[0] = bbsnet_menu.p_menu[0]; |
|
| 144 |
|
|
| 145 |
return 0; |
return 0; |
| 146 |
} |
} |
| 147 |
|
|
| 148 |
|
static void unload_bbsnet_conf(void) |
| 149 |
|
{ |
| 150 |
|
bbsnet_menu.menu_count = 0; |
| 151 |
|
bbsnet_menu.menu_item_count = 0; |
| 152 |
|
|
| 153 |
|
free(bbsnet_menu.p_menu_pool); |
| 154 |
|
bbsnet_menu.p_menu_pool = NULL; |
| 155 |
|
free(bbsnet_menu.p_menu_item_pool); |
| 156 |
|
bbsnet_menu.p_menu_item_pool = NULL; |
| 157 |
|
} |
| 158 |
|
|
| 159 |
static void process_bar(int n, int len) |
static void process_bar(int n, int len) |
| 160 |
{ |
{ |
| 161 |
char buf[LINE_BUFFER_LEN]; |
char buf[LINE_BUFFER_LEN]; |
| 177 |
moveto(4, 0); |
moveto(4, 0); |
| 178 |
prints(" ------------------------------ \r\n"); |
prints(" ------------------------------ \r\n"); |
| 179 |
snprintf(buf, sizeof(buf), " %3d%% ", n * 100 / len); |
snprintf(buf, sizeof(buf), " %3d%% ", n * 100 / len); |
| 180 |
strncpy(buf2, buf, (size_t)n); |
memcpy(buf2, buf, (size_t)n); |
| 181 |
buf2[n] = '\0'; |
buf2[n] = '\0'; |
| 182 |
prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + n); |
prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + n); |
| 183 |
prints(" ------------------------------ \r\n"); |
prints(" ------------------------------ \r\n"); |
| 184 |
iflush(); |
iflush(); |
| 185 |
} |
} |
| 186 |
|
|
| 187 |
int bbsnet_connect(int n) |
static int bbsnet_connect(int n) |
| 188 |
{ |
{ |
| 189 |
int sock, ret, loop, error; |
int sock, ret, loop, error; |
| 190 |
int sock_connected = 0; |
int sock_connected = 0; |
| 199 |
int output_buf_len = 0; |
int output_buf_len = 0; |
| 200 |
int input_buf_offset = 0; |
int input_buf_offset = 0; |
| 201 |
int output_buf_offset = 0; |
int output_buf_offset = 0; |
| 202 |
|
char input_conv[LINE_BUFFER_LEN * 2]; |
| 203 |
|
char output_conv[LINE_BUFFER_LEN * 2]; |
| 204 |
|
int input_conv_len = 0; |
| 205 |
|
int output_conv_len = 0; |
| 206 |
|
int input_conv_offset = 0; |
| 207 |
|
int output_conv_offset = 0; |
| 208 |
|
iconv_t input_cd = NULL; |
| 209 |
|
iconv_t output_cd = NULL; |
| 210 |
|
char tocode[32]; |
| 211 |
struct epoll_event ev, events[MAX_EVENTS]; |
struct epoll_event ev, events[MAX_EVENTS]; |
| 212 |
int nfds, epollfd; |
int nfds, epollfd; |
| 213 |
int stdin_read_wait = 0; |
int stdin_read_wait = 0; |
| 218 |
int tos; |
int tos; |
| 219 |
char remote_addr[IP_ADDR_LEN]; |
char remote_addr[IP_ADDR_LEN]; |
| 220 |
int remote_port; |
int remote_port; |
| 221 |
time_t t_used; |
char local_addr[IP_ADDR_LEN]; |
| 222 |
|
int local_port; |
| 223 |
|
socklen_t sock_len; |
| 224 |
|
time_t t_used = time(NULL); |
| 225 |
struct tm *tm_used; |
struct tm *tm_used; |
| 226 |
int ch; |
int ch; |
| 227 |
|
|
| 228 |
|
if (user_online_update("BBS_NET") < 0) |
| 229 |
|
{ |
| 230 |
|
log_error("user_online_update(BBS_NET) error\n"); |
| 231 |
|
} |
| 232 |
|
|
| 233 |
clearscr(); |
clearscr(); |
| 234 |
|
|
| 235 |
moveto(0, 0); |
moveto(0, 0); |
| 236 |
prints("\033[1;32mڲ %s (%s) ӣԺ... \033[m\r\n", |
prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n", |
| 237 |
bbsnet_conf[n].host1, bbsnet_conf[n].ip); |
bbsnet_conf[n].host1, bbsnet_conf[n].ip); |
| 238 |
iflush(); |
iflush(); |
| 239 |
|
|
| 241 |
|
|
| 242 |
if (p_host == NULL) |
if (p_host == NULL) |
| 243 |
{ |
{ |
| 244 |
prints("\033[1;31mʧܣ\033[m\r\n"); |
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
| 245 |
press_any_key(); |
press_any_key(); |
| 246 |
return -1; |
return -1; |
| 247 |
} |
} |
| 250 |
|
|
| 251 |
if (sock < 0) |
if (sock < 0) |
| 252 |
{ |
{ |
| 253 |
prints("\033[1;31msocket\033[m\r\n"); |
prints("\033[1;31m无法创建socket!\033[m\r\n"); |
| 254 |
press_any_key(); |
press_any_key(); |
| 255 |
return -1; |
return -1; |
| 256 |
} |
} |
| 257 |
|
|
| 258 |
sin.sin_family = AF_INET; |
sin.sin_family = AF_INET; |
| 259 |
sin.sin_addr.s_addr = (hostaddr_server[0] != '\0' ? inet_addr(hostaddr_server) : INADDR_ANY); |
sin.sin_addr.s_addr = (BBS_address[0] != '\0' ? inet_addr(BBS_address) : INADDR_ANY); |
| 260 |
sin.sin_port = 0; |
sin.sin_port = 0; |
| 261 |
|
|
| 262 |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
| 266 |
return -2; |
return -2; |
| 267 |
} |
} |
| 268 |
|
|
| 269 |
bzero(&sin, sizeof(sin)); |
memset(&sin, 0, sizeof(sin)); |
| 270 |
sin.sin_family = AF_INET; |
sin.sin_family = AF_INET; |
| 271 |
sin.sin_addr = *(struct in_addr *)p_host->h_addr_list[0]; |
sin.sin_addr = *(struct in_addr *)p_host->h_addr_list[0]; |
| 272 |
sin.sin_port = htons(bbsnet_conf[n].port); |
sin.sin_port = htons(bbsnet_conf[n].port); |
| 275 |
remote_addr[sizeof(remote_addr) - 1] = '\0'; |
remote_addr[sizeof(remote_addr) - 1] = '\0'; |
| 276 |
remote_port = ntohs(sin.sin_port); |
remote_port = ntohs(sin.sin_port); |
| 277 |
|
|
| 278 |
prints("\033[1;32mʾǰʹõʱ䣬\033[1;33mCtrl+C\033[1;32mжϡ\033[m\r\n"); |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n"); |
| 279 |
process_bar(0, MAX_PROCESS_BAR_LEN); |
process_bar(0, MAX_PROCESS_BAR_LEN); |
| 280 |
|
|
| 281 |
// Set socket as non-blocking |
// Set socket as non-blocking |
| 295 |
return -1; |
return -1; |
| 296 |
} |
} |
| 297 |
|
|
| 298 |
ev.events = EPOLLOUT; |
ev.events = EPOLLOUT | EPOLLET; |
| 299 |
ev.data.fd = sock; |
ev.data.fd = sock; |
| 300 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1) |
| 301 |
{ |
{ |
| 303 |
goto cleanup; |
goto cleanup; |
| 304 |
} |
} |
| 305 |
|
|
| 306 |
ev.events = EPOLLIN; |
ev.events = EPOLLIN | EPOLLET; |
| 307 |
ev.data.fd = STDIN_FILENO; |
ev.data.fd = STDIN_FILENO; |
| 308 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1) |
| 309 |
{ |
{ |
| 330 |
{ |
{ |
| 331 |
log_error("connect(socket) error (%d)\n", errno); |
log_error("connect(socket) error (%d)\n", errno); |
| 332 |
|
|
| 333 |
prints("\033[1;31mʧܣ\033[m\r\n"); |
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 334 |
press_any_key(); |
press_any_key(); |
| 335 |
|
|
| 336 |
goto cleanup; |
goto cleanup; |
| 374 |
else if (events[i].data.fd == STDIN_FILENO) |
else if (events[i].data.fd == STDIN_FILENO) |
| 375 |
{ |
{ |
| 376 |
ch = igetch(0); |
ch = igetch(0); |
| 377 |
if (ch == Ctrl('C')) |
if (ch == Ctrl('C') || ch == KEY_ESC) |
| 378 |
{ |
{ |
| 379 |
goto cleanup; |
goto cleanup; |
| 380 |
} |
} |
| 388 |
} |
} |
| 389 |
if (!sock_connected) |
if (!sock_connected) |
| 390 |
{ |
{ |
| 391 |
prints("\033[1;31mʧܣ\033[m\r\n"); |
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 392 |
press_any_key(); |
press_any_key(); |
| 393 |
|
|
| 394 |
goto cleanup; |
goto cleanup; |
| 400 |
log_error("setsockopt IP_TOS=%d error (%d)\n", tos, errno); |
log_error("setsockopt IP_TOS=%d error (%d)\n", tos, errno); |
| 401 |
} |
} |
| 402 |
|
|
| 403 |
prints("\033[1;31mӳɹ\033[m\r\n"); |
sock_len = sizeof(sin); |
| 404 |
|
if (getsockname(sock, (struct sockaddr *)&sin, &sock_len) < 0) |
| 405 |
|
{ |
| 406 |
|
log_error("getsockname() error: %d", errno); |
| 407 |
|
goto cleanup; |
| 408 |
|
} |
| 409 |
|
|
| 410 |
|
strncpy(local_addr, inet_ntoa(sin.sin_addr), sizeof(local_addr) - 1); |
| 411 |
|
local_addr[sizeof(local_addr) - 1] = '\0'; |
| 412 |
|
local_port = ntohs(sin.sin_port); |
| 413 |
|
|
| 414 |
|
prints("\033[1;31m连接成功!\033[m\r\n"); |
| 415 |
iflush(); |
iflush(); |
| 416 |
log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
log_common("BBSNET connect to %s:%d from %s:%d by [%s]\n", |
| 417 |
|
remote_addr, remote_port, local_addr, local_port, BBS_username); |
| 418 |
|
|
| 419 |
|
snprintf(tocode, sizeof(tocode), "%s%s", bbsnet_conf[n].charset, |
| 420 |
|
(strcasecmp(stdio_charset, bbsnet_conf[n].charset) == 0 ? "" : "//IGNORE")); |
| 421 |
|
input_cd = iconv_open(tocode, stdio_charset); |
| 422 |
|
if (input_cd == (iconv_t)(-1)) |
| 423 |
|
{ |
| 424 |
|
log_error("iconv_open(%s->%s) error: %d\n", stdio_charset, tocode, errno); |
| 425 |
|
goto cleanup; |
| 426 |
|
} |
| 427 |
|
|
| 428 |
|
snprintf(tocode, sizeof(tocode), "%s%s", stdio_charset, |
| 429 |
|
(strcasecmp(bbsnet_conf[n].charset, stdio_charset) == 0 ? "" : "//TRANSLIT")); |
| 430 |
|
output_cd = iconv_open(tocode, bbsnet_conf[n].charset); |
| 431 |
|
if (output_cd == (iconv_t)(-1)) |
| 432 |
|
{ |
| 433 |
|
log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno); |
| 434 |
|
iconv_close(input_cd); |
| 435 |
|
goto cleanup; |
| 436 |
|
} |
| 437 |
|
|
| 438 |
ev.events = EPOLLIN | EPOLLOUT | EPOLLET; |
ev.events = EPOLLIN | EPOLLOUT | EPOLLET; |
| 439 |
ev.data.fd = sock; |
ev.data.fd = sock; |
| 443 |
goto cleanup; |
goto cleanup; |
| 444 |
} |
} |
| 445 |
|
|
| 446 |
ev.events = EPOLLOUT; |
ev.events = EPOLLOUT | EPOLLET; |
| 447 |
ev.data.fd = STDOUT_FILENO; |
ev.data.fd = STDOUT_FILENO; |
| 448 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1) |
| 449 |
{ |
{ |
| 451 |
goto cleanup; |
goto cleanup; |
| 452 |
} |
} |
| 453 |
|
|
| 454 |
BBS_last_access_tm = t_used = time(0); |
BBS_last_access_tm = t_used = time(NULL); |
| 455 |
loop = 1; |
loop = 1; |
| 456 |
|
|
| 457 |
while (loop && !SYS_server_exit) |
while (loop && !SYS_server_exit) |
| 458 |
{ |
{ |
| 459 |
|
if (SSH_v2 && ssh_channel_is_closed(SSH_channel)) |
| 460 |
|
{ |
| 461 |
|
log_error("SSH channel is closed\n"); |
| 462 |
|
loop = 0; |
| 463 |
|
break; |
| 464 |
|
} |
| 465 |
|
|
| 466 |
nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second |
nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second |
| 467 |
|
|
| 468 |
if (nfds < 0) |
if (nfds < 0) |
| 476 |
} |
} |
| 477 |
else if (nfds == 0) // timeout |
else if (nfds == 0) // timeout |
| 478 |
{ |
{ |
| 479 |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 480 |
{ |
{ |
| 481 |
break; |
break; |
| 482 |
} |
} |
|
continue; |
|
| 483 |
} |
} |
| 484 |
|
|
| 485 |
for (int i = 0; i < nfds; i++) |
for (int i = 0; i < nfds; i++) |
| 486 |
{ |
{ |
| 487 |
if (events[i].data.fd == STDIN_FILENO || stdin_read_wait) |
if (events[i].data.fd == STDIN_FILENO) |
| 488 |
{ |
{ |
| 489 |
stdin_read_wait = 1; |
stdin_read_wait = 1; |
| 490 |
while (input_buf_len < sizeof(input_buf) && !SYS_server_exit) |
} |
| 491 |
|
|
| 492 |
|
if (events[i].data.fd == sock) |
| 493 |
|
{ |
| 494 |
|
if (events[i].events & EPOLLIN) |
| 495 |
{ |
{ |
| 496 |
ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len); |
sock_read_wait = 1; |
| 497 |
if (ret < 0) |
} |
| 498 |
|
if (events[i].events & EPOLLOUT) |
| 499 |
|
{ |
| 500 |
|
sock_write_wait = 1; |
| 501 |
|
} |
| 502 |
|
} |
| 503 |
|
|
| 504 |
|
if (events[i].data.fd == STDOUT_FILENO) |
| 505 |
|
{ |
| 506 |
|
stdout_write_wait = 1; |
| 507 |
|
} |
| 508 |
|
} |
| 509 |
|
|
| 510 |
|
if (stdin_read_wait) |
| 511 |
|
{ |
| 512 |
|
while (input_buf_len < sizeof(input_buf) && !SYS_server_exit) |
| 513 |
|
{ |
| 514 |
|
if (SSH_v2) |
| 515 |
|
{ |
| 516 |
|
ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0); |
| 517 |
|
if (ret == SSH_ERROR) |
| 518 |
{ |
{ |
| 519 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session)); |
| 520 |
{ |
loop = 0; |
| 521 |
stdin_read_wait = 0; |
break; |
|
break; |
|
|
} |
|
|
else if (errno == EINTR) |
|
|
{ |
|
|
continue; |
|
|
} |
|
|
else |
|
|
{ |
|
|
log_error("read(STDIN) error (%d)\n", errno); |
|
|
loop = 0; |
|
|
break; |
|
|
} |
|
| 522 |
} |
} |
| 523 |
else if (ret == 0) // broken pipe |
else if (ret == SSH_EOF) |
| 524 |
{ |
{ |
|
log_std("read(STDIN) EOF\n"); |
|
| 525 |
stdin_read_wait = 0; |
stdin_read_wait = 0; |
| 526 |
loop = 0; |
loop = 0; |
| 527 |
break; |
break; |
| 528 |
} |
} |
| 529 |
else |
else if (ret == 0) |
| 530 |
|
{ |
| 531 |
|
// Send NO-OP to remote server |
| 532 |
|
input_buf[input_buf_len] = '\0'; |
| 533 |
|
input_buf_len++; |
| 534 |
|
BBS_last_access_tm = time(NULL); |
| 535 |
|
|
| 536 |
|
stdin_read_wait = 0; |
| 537 |
|
break; // Check whether channel is still open |
| 538 |
|
} |
| 539 |
|
} |
| 540 |
|
else |
| 541 |
|
{ |
| 542 |
|
ret = (int)read(STDIN_FILENO, input_buf + input_buf_len, sizeof(input_buf) - (size_t)input_buf_len); |
| 543 |
|
} |
| 544 |
|
if (ret < 0) |
| 545 |
|
{ |
| 546 |
|
if (errno == EAGAIN || errno == EWOULDBLOCK) |
| 547 |
|
{ |
| 548 |
|
stdin_read_wait = 0; |
| 549 |
|
break; |
| 550 |
|
} |
| 551 |
|
else if (errno == EINTR) |
| 552 |
{ |
{ |
|
input_buf_len += ret; |
|
|
BBS_last_access_tm = time(0); |
|
| 553 |
continue; |
continue; |
| 554 |
} |
} |
| 555 |
|
else |
| 556 |
|
{ |
| 557 |
|
log_error("read(STDIN) error (%d)\n", errno); |
| 558 |
|
loop = 0; |
| 559 |
|
break; |
| 560 |
|
} |
| 561 |
|
} |
| 562 |
|
else if (ret == 0) // broken pipe |
| 563 |
|
{ |
| 564 |
|
#ifdef _DEBUG |
| 565 |
|
log_error("read(STDIN) EOF\n"); |
| 566 |
|
#endif |
| 567 |
|
stdin_read_wait = 0; |
| 568 |
|
loop = 0; |
| 569 |
|
break; |
| 570 |
|
} |
| 571 |
|
else |
| 572 |
|
{ |
| 573 |
|
input_buf_len += ret; |
| 574 |
|
BBS_last_access_tm = time(NULL); |
| 575 |
|
|
| 576 |
|
// Refresh current action while user input |
| 577 |
|
if (user_online_update("BBS_NET") < 0) |
| 578 |
|
{ |
| 579 |
|
log_error("user_online_update(BBS_NET) error\n"); |
| 580 |
|
} |
| 581 |
|
|
| 582 |
|
continue; |
| 583 |
|
} |
| 584 |
|
} |
| 585 |
|
} |
| 586 |
|
|
| 587 |
|
if (sock_write_wait) |
| 588 |
|
{ |
| 589 |
|
if (input_buf_offset < input_buf_len) |
| 590 |
|
{ |
| 591 |
|
// For debug |
| 592 |
|
#ifdef _DEBUG |
| 593 |
|
for (int j = input_buf_offset; j < input_buf_len; j++) |
| 594 |
|
{ |
| 595 |
|
log_error("Debug input: <--[%u]\n", (input_buf[j] + 256) % 256); |
| 596 |
|
} |
| 597 |
|
#endif |
| 598 |
|
|
| 599 |
|
ret = io_buf_conv(input_cd, input_buf, &input_buf_len, &input_buf_offset, input_conv, sizeof(input_conv), &input_conv_len); |
| 600 |
|
if (ret < 0) |
| 601 |
|
{ |
| 602 |
|
log_error("io_buf_conv(input, %d, %d, %d) error\n", input_buf_len, input_buf_offset, input_conv_len); |
| 603 |
|
input_buf_len = input_buf_offset; // Discard invalid sequence |
| 604 |
|
} |
| 605 |
|
|
| 606 |
|
// For debug |
| 607 |
|
#ifdef _DEBUG |
| 608 |
|
for (int j = input_conv_offset; j < input_conv_len; j++) |
| 609 |
|
{ |
| 610 |
|
log_error("Debug input_conv: <--[%u]\n", (input_conv[j] + 256) % 256); |
| 611 |
} |
} |
| 612 |
|
#endif |
| 613 |
} |
} |
| 614 |
|
|
| 615 |
if (events[i].data.fd == sock || sock_write_wait) // EPOLLOUT |
while (input_conv_offset < input_conv_len && !SYS_server_exit) |
| 616 |
{ |
{ |
| 617 |
sock_write_wait = 1; |
ret = (int)write(sock, input_conv + input_conv_offset, (size_t)(input_conv_len - input_conv_offset)); |
| 618 |
while (input_buf_offset < input_buf_len && !SYS_server_exit) |
if (ret < 0) |
| 619 |
{ |
{ |
| 620 |
ret = (int)write(sock, input_buf + input_buf_offset, (size_t)(input_buf_len - input_buf_offset)); |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
| 621 |
if (ret < 0) |
{ |
| 622 |
|
sock_write_wait = 0; |
| 623 |
|
break; |
| 624 |
|
} |
| 625 |
|
else if (errno == EINTR) |
| 626 |
{ |
{ |
| 627 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
continue; |
|
{ |
|
|
sock_write_wait = 0; |
|
|
break; |
|
|
} |
|
|
else if (errno == EINTR) |
|
|
{ |
|
|
continue; |
|
|
} |
|
|
else |
|
|
{ |
|
|
log_error("write(socket) error (%d)\n", errno); |
|
|
loop = 0; |
|
|
break; |
|
|
} |
|
| 628 |
} |
} |
| 629 |
else if (ret == 0) // broken pipe |
else |
| 630 |
{ |
{ |
| 631 |
log_std("write(socket) EOF\n"); |
log_error("write(socket) error (%d)\n", errno); |
|
sock_write_wait = 0; |
|
| 632 |
loop = 0; |
loop = 0; |
| 633 |
break; |
break; |
| 634 |
} |
} |
| 635 |
else |
} |
| 636 |
|
else if (ret == 0) // broken pipe |
| 637 |
|
{ |
| 638 |
|
#ifdef _DEBUG |
| 639 |
|
log_error("write(socket) EOF\n"); |
| 640 |
|
#endif |
| 641 |
|
sock_write_wait = 0; |
| 642 |
|
loop = 0; |
| 643 |
|
break; |
| 644 |
|
} |
| 645 |
|
else |
| 646 |
|
{ |
| 647 |
|
input_conv_offset += ret; |
| 648 |
|
if (input_conv_offset >= input_conv_len) // Output buffer complete |
| 649 |
{ |
{ |
| 650 |
input_buf_offset += ret; |
input_conv_offset = 0; |
| 651 |
if (input_buf_offset >= input_buf_len) // Output buffer complete |
input_conv_len = 0; |
| 652 |
{ |
break; |
|
input_buf_offset = 0; |
|
|
input_buf_len = 0; |
|
|
break; |
|
|
} |
|
|
continue; |
|
| 653 |
} |
} |
| 654 |
|
continue; |
| 655 |
} |
} |
| 656 |
} |
} |
| 657 |
|
} |
| 658 |
|
|
| 659 |
if (events[i].data.fd == sock || sock_read_wait) // EPOLLIN |
if (sock_read_wait) |
| 660 |
|
{ |
| 661 |
|
while (output_buf_len < sizeof(output_buf) && !SYS_server_exit) |
| 662 |
{ |
{ |
| 663 |
sock_read_wait = 1; |
ret = (int)read(sock, output_buf + output_buf_len, sizeof(output_buf) - (size_t)output_buf_len); |
| 664 |
while (output_buf_len < sizeof(output_buf) && !SYS_server_exit) |
if (ret < 0) |
| 665 |
{ |
{ |
| 666 |
ret = (int)read(sock, output_buf + output_buf_len, sizeof(output_buf) - (size_t)output_buf_len); |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
|
if (ret < 0) |
|
| 667 |
{ |
{ |
|
if (errno == EAGAIN || errno == EWOULDBLOCK) |
|
|
{ |
|
|
sock_read_wait = 0; |
|
|
break; |
|
|
} |
|
|
else if (errno == EINTR) |
|
|
{ |
|
|
continue; |
|
|
} |
|
|
else |
|
|
{ |
|
|
log_error("read(socket) error (%d)\n", errno); |
|
|
loop = 0; |
|
|
break; |
|
|
} |
|
|
} |
|
|
else if (ret == 0) // broken pipe |
|
|
{ |
|
|
log_std("read(socket) EOF\n"); |
|
| 668 |
sock_read_wait = 0; |
sock_read_wait = 0; |
|
loop = 0; |
|
| 669 |
break; |
break; |
| 670 |
} |
} |
| 671 |
else |
else if (errno == EINTR) |
| 672 |
{ |
{ |
|
output_buf_len += ret; |
|
| 673 |
continue; |
continue; |
| 674 |
} |
} |
| 675 |
|
else |
| 676 |
|
{ |
| 677 |
|
log_error("read(socket) error (%d)\n", errno); |
| 678 |
|
loop = 0; |
| 679 |
|
break; |
| 680 |
|
} |
| 681 |
|
} |
| 682 |
|
else if (ret == 0) // broken pipe |
| 683 |
|
{ |
| 684 |
|
#ifdef _DEBUG |
| 685 |
|
log_error("read(socket) EOF\n"); |
| 686 |
|
#endif |
| 687 |
|
sock_read_wait = 0; |
| 688 |
|
loop = 0; |
| 689 |
|
break; |
| 690 |
|
} |
| 691 |
|
else |
| 692 |
|
{ |
| 693 |
|
output_buf_len += ret; |
| 694 |
|
continue; |
| 695 |
|
} |
| 696 |
|
} |
| 697 |
|
} |
| 698 |
|
|
| 699 |
|
if (stdout_write_wait) |
| 700 |
|
{ |
| 701 |
|
if (output_buf_offset < output_buf_len) |
| 702 |
|
{ |
| 703 |
|
ret = io_buf_conv(output_cd, output_buf, &output_buf_len, &output_buf_offset, output_conv, sizeof(output_conv), &output_conv_len); |
| 704 |
|
if (ret < 0) |
| 705 |
|
{ |
| 706 |
|
log_error("io_buf_conv(output, %d, %d, %d) error\n", output_buf_len, output_buf_offset, output_conv_len); |
| 707 |
|
output_buf_len = output_buf_offset; // Discard invalid sequence |
| 708 |
} |
} |
| 709 |
} |
} |
| 710 |
|
|
| 711 |
if (events[i].data.fd == STDOUT_FILENO || stdout_write_wait) |
while (output_conv_offset < output_conv_len && !SYS_server_exit) |
| 712 |
{ |
{ |
| 713 |
stdout_write_wait = 1; |
if (SSH_v2) |
|
while (output_buf_offset < output_buf_len && !SYS_server_exit) |
|
| 714 |
{ |
{ |
| 715 |
ret = (int)write(STDOUT_FILENO, output_buf + output_buf_offset, (size_t)(output_buf_len - output_buf_offset)); |
ret = ssh_channel_write(SSH_channel, output_conv + output_conv_offset, (uint32_t)(output_conv_len - output_conv_offset)); |
| 716 |
if (ret < 0) |
if (ret == SSH_ERROR) |
| 717 |
{ |
{ |
| 718 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); |
| 719 |
{ |
loop = 0; |
| 720 |
stdout_write_wait = 0; |
break; |
|
break; |
|
|
} |
|
|
else if (errno == EINTR) |
|
|
{ |
|
|
continue; |
|
|
} |
|
|
else |
|
|
{ |
|
|
log_error("write(STDOUT) error (%d)\n", errno); |
|
|
loop = 0; |
|
|
break; |
|
|
} |
|
| 721 |
} |
} |
| 722 |
else if (ret == 0) // broken pipe |
} |
| 723 |
|
else |
| 724 |
|
{ |
| 725 |
|
ret = (int)write(STDOUT_FILENO, output_conv + output_conv_offset, (size_t)(output_conv_len - output_conv_offset)); |
| 726 |
|
} |
| 727 |
|
if (ret < 0) |
| 728 |
|
{ |
| 729 |
|
if (errno == EAGAIN || errno == EWOULDBLOCK) |
| 730 |
{ |
{ |
|
log_std("write(STDOUT) EOF\n"); |
|
| 731 |
stdout_write_wait = 0; |
stdout_write_wait = 0; |
|
loop = 0; |
|
| 732 |
break; |
break; |
| 733 |
} |
} |
| 734 |
else |
else if (errno == EINTR) |
| 735 |
{ |
{ |
|
output_buf_offset += ret; |
|
|
if (output_buf_offset >= output_buf_len) // Output buffer complete |
|
|
{ |
|
|
output_buf_offset = 0; |
|
|
output_buf_len = 0; |
|
|
break; |
|
|
} |
|
| 736 |
continue; |
continue; |
| 737 |
} |
} |
| 738 |
|
else |
| 739 |
|
{ |
| 740 |
|
log_error("write(STDOUT) error (%d)\n", errno); |
| 741 |
|
loop = 0; |
| 742 |
|
break; |
| 743 |
|
} |
| 744 |
|
} |
| 745 |
|
else if (ret == 0) // broken pipe |
| 746 |
|
{ |
| 747 |
|
#ifdef _DEBUG |
| 748 |
|
log_error("write(STDOUT) EOF\n"); |
| 749 |
|
#endif |
| 750 |
|
stdout_write_wait = 0; |
| 751 |
|
loop = 0; |
| 752 |
|
break; |
| 753 |
|
} |
| 754 |
|
else |
| 755 |
|
{ |
| 756 |
|
output_conv_offset += ret; |
| 757 |
|
if (output_conv_offset >= output_conv_len) // Output buffer complete |
| 758 |
|
{ |
| 759 |
|
output_conv_offset = 0; |
| 760 |
|
output_conv_len = 0; |
| 761 |
|
break; |
| 762 |
|
} |
| 763 |
|
continue; |
| 764 |
} |
} |
| 765 |
} |
} |
| 766 |
} |
} |
| 767 |
} |
} |
| 768 |
|
|
| 769 |
|
iconv_close(input_cd); |
| 770 |
|
iconv_close(output_cd); |
| 771 |
|
|
| 772 |
cleanup: |
cleanup: |
| 773 |
if (close(epollfd) < 0) |
if (close(epollfd) < 0) |
| 774 |
{ |
{ |
| 787 |
log_error("Close socket failed\n"); |
log_error("Close socket failed\n"); |
| 788 |
} |
} |
| 789 |
|
|
| 790 |
t_used = time(0) - t_used; |
t_used = time(NULL) - t_used; |
| 791 |
tm_used = gmtime(&t_used); |
tm_used = gmtime(&t_used); |
| 792 |
|
|
| 793 |
log_std("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
| 794 |
tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, |
tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, |
| 795 |
tm_used->tm_sec); |
tm_used->tm_sec); |
| 796 |
|
|
| 797 |
|
BBS_last_access_tm = time(NULL); |
| 798 |
|
|
| 799 |
return 0; |
return 0; |
| 800 |
} |
} |
| 801 |
|
|
| 802 |
static int |
static int bbsnet_refresh() |
|
bbsnet_refresh() |
|
| 803 |
{ |
{ |
| 804 |
clearscr(); |
clearscr(); |
| 805 |
moveto(1, 0); |
moveto(1, 0); |
| 816 |
moveto(22, 0); |
moveto(22, 0); |
| 817 |
prints(" ----------------------------------------------------------------------------- "); |
prints(" ----------------------------------------------------------------------------- "); |
| 818 |
moveto(23, 0); |
moveto(23, 0); |
| 819 |
prints(" [\x1b[1;32mCtrl+C\x1b[m]˳"); |
prints(" [\x1b[1;32mCtrl+C\x1b[m]退出"); |
| 820 |
|
|
| 821 |
iflush(); |
iflush(); |
| 822 |
|
|
| 823 |
return 0; |
return 0; |
| 824 |
} |
} |
| 825 |
|
|
| 826 |
int bbsnet_selchange(int new_pos) |
static int bbsnet_selchange() |
| 827 |
{ |
{ |
| 828 |
|
int i = bbsnet_menu.menu_item_pos[0]; |
| 829 |
|
|
| 830 |
moveto(20, 0); |
moveto(20, 0); |
| 831 |
clrtoeol(); |
clrtoeol(); |
| 832 |
prints("|\x1b[1mλ:\x1b[1;33m%-18s\x1b[m վ:\x1b[1;33m%s\x1b[m", |
prints("|\x1b[1m单位:\x1b[1;33m%-18s\x1b[m 站名:\x1b[1;33m%s\x1b[m", |
| 833 |
bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1); |
bbsnet_conf[i].host2, bbsnet_conf[i].host1); |
| 834 |
moveto(20, 79); |
moveto(20, 79); |
| 835 |
prints("|"); |
prints("|"); |
| 836 |
moveto(21, 0); |
moveto(21, 0); |
| 837 |
clrtoeol(); |
clrtoeol(); |
| 838 |
prints("|\x1b[1m:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip); |
prints("|\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[i].ip); |
| 839 |
if (bbsnet_conf[new_pos].port != 23) |
if (bbsnet_conf[i].port != 23) |
| 840 |
{ |
{ |
| 841 |
prints(" %d", bbsnet_conf[new_pos].port); |
prints(" %d", bbsnet_conf[i].port); |
| 842 |
} |
} |
| 843 |
prints("\x1b[m"); |
prints("\x1b[m"); |
| 844 |
moveto(21, 79); |
moveto(21, 79); |
| 848 |
return 0; |
return 0; |
| 849 |
} |
} |
| 850 |
|
|
| 851 |
int bbs_net() |
extern int bbs_net() |
| 852 |
{ |
{ |
| 853 |
int ch, pos, i; |
int ch, i; |
| 854 |
|
|
| 855 |
load_bbsnet_conf(CONF_BBSNET); |
load_bbsnet_conf(CONF_BBSNET); |
| 856 |
|
|
|
BBS_last_access_tm = time(0); |
|
|
|
|
| 857 |
clearscr(); |
clearscr(); |
| 858 |
bbsnet_refresh(); |
bbsnet_refresh(); |
| 859 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
display_menu(&bbsnet_menu); |
| 860 |
display_menu(get_menu(&bbsnet_menu, "BBSNET")); |
bbsnet_selchange(); |
|
bbsnet_selchange(pos); |
|
| 861 |
|
|
| 862 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 863 |
{ |
{ |
| 864 |
ch = igetch(100); |
ch = igetch(100); |
| 865 |
|
|
| 866 |
|
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 867 |
|
{ |
| 868 |
|
BBS_last_access_tm = time(NULL); |
| 869 |
|
} |
| 870 |
|
|
| 871 |
switch (ch) |
switch (ch) |
| 872 |
{ |
{ |
| 873 |
case KEY_NULL: // broken pipe |
case KEY_NULL: // broken pipe |
| 874 |
case Ctrl('C'): // user cancel |
log_error("KEY_NULL\n"); |
| 875 |
return 0; |
goto cleanup; |
| 876 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 877 |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 878 |
{ |
{ |
| 879 |
return 0; |
log_error("User input timeout\n"); |
| 880 |
|
goto cleanup; |
| 881 |
} |
} |
| 882 |
continue; |
continue; |
| 883 |
|
case KEY_ESC: |
| 884 |
|
case Ctrl('C'): // user cancel |
| 885 |
|
goto cleanup; |
| 886 |
case CR: |
case CR: |
| 887 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
bbsnet_connect(bbsnet_menu.menu_item_pos[0]); |
|
bbsnet_connect(pos); |
|
| 888 |
bbsnet_refresh(); |
bbsnet_refresh(); |
| 889 |
display_current_menu(&bbsnet_menu); |
display_menu(&bbsnet_menu); |
| 890 |
bbsnet_selchange(pos); |
bbsnet_selchange(); |
| 891 |
break; |
break; |
| 892 |
case KEY_UP: |
case KEY_UP: |
| 893 |
for (i = 0; i < STATION_PER_LINE; i++) |
for (i = 0; i < STATION_PER_LINE; i++) |
| 894 |
{ |
{ |
| 895 |
menu_control(&bbsnet_menu, KEY_UP); |
menu_control(&bbsnet_menu, KEY_UP); |
| 896 |
} |
} |
| 897 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
bbsnet_selchange(); |
|
bbsnet_selchange(pos); |
|
| 898 |
break; |
break; |
| 899 |
case KEY_DOWN: |
case KEY_DOWN: |
| 900 |
for (i = 0; i < STATION_PER_LINE; i++) |
for (i = 0; i < STATION_PER_LINE; i++) |
| 901 |
{ |
{ |
| 902 |
menu_control(&bbsnet_menu, KEY_DOWN); |
menu_control(&bbsnet_menu, KEY_DOWN); |
| 903 |
} |
} |
| 904 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
bbsnet_selchange(); |
|
bbsnet_selchange(pos); |
|
| 905 |
break; |
break; |
| 906 |
case KEY_LEFT: |
case KEY_LEFT: |
| 907 |
menu_control(&bbsnet_menu, KEY_UP); |
menu_control(&bbsnet_menu, KEY_UP); |
| 908 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
bbsnet_selchange(); |
|
bbsnet_selchange(pos); |
|
| 909 |
break; |
break; |
| 910 |
case KEY_RIGHT: |
case KEY_RIGHT: |
| 911 |
menu_control(&bbsnet_menu, KEY_DOWN); |
menu_control(&bbsnet_menu, KEY_DOWN); |
| 912 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
bbsnet_selchange(); |
| 913 |
bbsnet_selchange(pos); |
break; |
| 914 |
|
case KEY_HOME: |
| 915 |
|
case KEY_PGUP: |
| 916 |
|
menu_control(&bbsnet_menu, KEY_PGUP); |
| 917 |
|
bbsnet_selchange(); |
| 918 |
|
break; |
| 919 |
|
case KEY_END: |
| 920 |
|
case KEY_PGDN: |
| 921 |
|
menu_control(&bbsnet_menu, KEY_PGDN); |
| 922 |
|
bbsnet_selchange(); |
| 923 |
break; |
break; |
| 924 |
default: |
default: |
| 925 |
menu_control(&bbsnet_menu, ch); |
menu_control(&bbsnet_menu, ch); |
| 926 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
bbsnet_selchange(); |
|
bbsnet_selchange(pos); |
|
| 927 |
break; |
break; |
| 928 |
} |
} |
|
BBS_last_access_tm = time(0); |
|
| 929 |
} |
} |
| 930 |
|
|
| 931 |
|
cleanup: |
| 932 |
|
unload_bbsnet_conf(); |
| 933 |
|
|
| 934 |
return 0; |
return 0; |
| 935 |
} |
} |