| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
bbs_net.c - description |
bbs_net.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 18 2004 |
Copyright : (C) 2004-2025 by Leaflet |
| 5 |
copyright : (C) 2004 by Leaflet |
Email : leaflet@leafok.com |
|
email : leaflet@leafok.com |
|
| 6 |
***************************************************************************/ |
***************************************************************************/ |
| 7 |
|
|
| 8 |
/*************************************************************************** |
/*************************************************************************** |
| 9 |
* * |
* * |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
| 11 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
| 12 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 3 of the License, or * |
| 13 |
* (at your option) any later version. * |
* (at your option) any later version. * |
| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 20 |
#include "io.h" |
#include "io.h" |
| 21 |
#include "screen.h" |
#include "screen.h" |
| 22 |
#include "menu.h" |
#include "menu.h" |
|
#include "tcplib.h" |
|
| 23 |
#include <stdio.h> |
#include <stdio.h> |
| 24 |
#include <stdarg.h> |
#include <stdarg.h> |
| 25 |
|
#include <errno.h> |
| 26 |
|
#include <string.h> |
| 27 |
|
#include <stdlib.h> |
| 28 |
|
#include <fcntl.h> |
| 29 |
|
#include <time.h> |
| 30 |
|
#include <unistd.h> |
| 31 |
|
#include <netdb.h> |
| 32 |
|
#include <sys/select.h> |
| 33 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
| 34 |
#include <sys/socket.h> |
#include <sys/socket.h> |
| 35 |
#include <netinet/in.h> |
#include <netinet/in.h> |
| 36 |
#include <arpa/inet.h> |
#include <arpa/inet.h> |
|
#include <time.h> |
|
|
#include <unistd.h> |
|
|
#include <netdb.h> |
|
| 37 |
|
|
| 38 |
#define TIME_OUT 15 |
#define MENU_CONF_DELIM " \t\r\n" |
| 39 |
|
|
| 40 |
#define MAX_PROCESS_BAR_LEN 30 |
#define MAX_PROCESS_BAR_LEN 30 |
| 41 |
#define MAXSTATION 26 * 2 |
#define MAXSTATION 26 * 2 |
| 42 |
#define STATION_PER_LINE 4 |
#define STATION_PER_LINE 4 |
| 46 |
char host1[20]; |
char host1[20]; |
| 47 |
char host2[40]; |
char host2[40]; |
| 48 |
char ip[40]; |
char ip[40]; |
| 49 |
int port; |
in_port_t port; |
| 50 |
} bbsnet_conf[MAXSTATION]; |
} bbsnet_conf[MAXSTATION]; |
| 51 |
|
|
| 52 |
MENU_SET bbsnet_menu; |
MENU_SET bbsnet_menu; |
| 61 |
|
|
| 62 |
fp = fopen(file_config, "r"); |
fp = fopen(file_config, "r"); |
| 63 |
if (fp == NULL) |
if (fp == NULL) |
| 64 |
|
{ |
| 65 |
return -1; |
return -1; |
| 66 |
|
} |
| 67 |
|
|
| 68 |
p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU)); |
p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU)); |
| 69 |
strcpy(p_menu->name, "BBSNET"); |
strncpy(p_menu->name, "BBSNET", sizeof(p_menu->name) - 1); |
| 70 |
|
p_menu->name[sizeof(p_menu->name) - 1] = '\0'; |
| 71 |
p_menu->title.show = 0; |
p_menu->title.show = 0; |
| 72 |
p_menu->screen.show = 0; |
p_menu->screen.show = 0; |
| 73 |
|
|
| 74 |
while (fgets(t, 255, fp) && item_count < MAXSTATION) |
while (fgets(t, 255, fp) && item_count < MAXSTATION) |
| 75 |
{ |
{ |
| 76 |
if (t[0] == '#' || t[0] == '*') |
t1 = strtok_r(t, MENU_CONF_DELIM, &saveptr); |
| 77 |
{ |
t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 78 |
continue; |
t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 79 |
} |
t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 80 |
|
|
| 81 |
t1 = strtok_r(t, " \t", &saveptr); |
if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL || t[0] == '#' || t[0] == '*') |
|
t2 = strtok_r(NULL, " \t\n", &saveptr); |
|
|
t3 = strtok_r(NULL, " \t\n", &saveptr); |
|
|
t4 = strtok_r(NULL, " \t\n", &saveptr); |
|
|
|
|
|
if (t1 == NULL || t2 == NULL || t3 == NULL) |
|
| 82 |
{ |
{ |
| 83 |
continue; |
continue; |
| 84 |
} |
} |
| 85 |
|
|
| 86 |
strncpy(bbsnet_conf[item_count].host1, t2, sizeof(bbsnet_conf[item_count].host1)); |
strncpy(bbsnet_conf[item_count].host1, t2, sizeof(bbsnet_conf[item_count].host1) - 1); |
| 87 |
strncpy(bbsnet_conf[item_count].host2, t1, sizeof(bbsnet_conf[item_count].host2)); |
bbsnet_conf[item_count].host1[sizeof(bbsnet_conf[item_count].host1) - 1] = '\0'; |
| 88 |
strncpy(bbsnet_conf[item_count].ip, t3, sizeof(bbsnet_conf[item_count].ip)); |
strncpy(bbsnet_conf[item_count].host2, t1, sizeof(bbsnet_conf[item_count].host2) - 1); |
| 89 |
bbsnet_conf[item_count].port = t4 ? atoi(t4) : 23; |
bbsnet_conf[item_count].host2[sizeof(bbsnet_conf[item_count].host2) - 1] = '\0'; |
| 90 |
|
strncpy(bbsnet_conf[item_count].ip, t3, sizeof(bbsnet_conf[item_count].ip) - 1); |
| 91 |
|
bbsnet_conf[item_count].ip[sizeof(bbsnet_conf[item_count].ip) - 1] = '\0'; |
| 92 |
|
bbsnet_conf[item_count].port = (in_port_t)(t4 ? atoi(t4) : 23); |
| 93 |
|
|
| 94 |
p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM)); |
p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM)); |
| 95 |
p_menuitem->row = 2 + item_count / STATION_PER_LINE; |
p_menuitem->row = 2 + item_count / STATION_PER_LINE; |
| 96 |
p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20; |
p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20; |
| 97 |
sprintf(p_menuitem->action, "%d", item_count); |
snprintf(p_menuitem->action, sizeof(p_menuitem->action), "%d", item_count); |
| 98 |
p_menuitem->submenu = 0; |
p_menuitem->submenu = 0; |
| 99 |
p_menuitem->priv = 0; |
p_menuitem->priv = 0; |
| 100 |
p_menuitem->level = 0; |
p_menuitem->level = 0; |
| 101 |
p_menuitem->display = 0; |
p_menuitem->display = 0; |
| 102 |
p_menuitem->name[0] = |
p_menuitem->name[0] = |
| 103 |
(item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count); |
(char)(item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count); |
| 104 |
p_menuitem->name[1] = '\0'; |
p_menuitem->name[1] = '\0'; |
| 105 |
snprintf(p_menuitem->text, sizeof(p_menuitem->text), "[1;36m%c.[m %s", |
snprintf(p_menuitem->text, sizeof(p_menuitem->text), "[1;36m%c.[m %s", |
| 106 |
p_menuitem->name[0], t2); |
p_menuitem->name[0], bbsnet_conf[item_count].host1); |
| 107 |
|
|
| 108 |
item_count++; |
item_count++; |
| 109 |
} |
} |
| 119 |
return 0; |
return 0; |
| 120 |
} |
} |
| 121 |
|
|
| 122 |
static void |
static void process_bar(int n, int len) |
|
process_bar(int n, int len) |
|
| 123 |
{ |
{ |
| 124 |
char buf[256]; |
char buf[LINE_BUFFER_LEN]; |
| 125 |
char buf2[256]; |
char buf2[LINE_BUFFER_LEN]; |
| 126 |
char *ptr; |
|
| 127 |
char *ptr2; |
if (len > LINE_BUFFER_LEN) |
| 128 |
char *ptr3; |
{ |
| 129 |
|
len = LINE_BUFFER_LEN - 1; |
| 130 |
|
} |
| 131 |
|
if (n < 0) |
| 132 |
|
{ |
| 133 |
|
n = 0; |
| 134 |
|
} |
| 135 |
|
else if (n > len) |
| 136 |
|
{ |
| 137 |
|
n = len; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
moveto(4, 0); |
moveto(4, 0); |
| 141 |
prints("┌───────────────┐\r\n"); |
prints(" ------------------------------ \r\n"); |
| 142 |
sprintf(buf2, " %3d%% ", n * 100 / len); |
snprintf(buf, sizeof(buf), " %3d%% ", n * 100 / len); |
| 143 |
ptr = buf; |
strncpy(buf2, buf, (size_t)n); |
| 144 |
ptr2 = buf2; |
buf2[n] = '\0'; |
| 145 |
ptr3 = buf + n; |
prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + n); |
| 146 |
while (ptr != ptr3) |
prints(" ------------------------------ \r\n"); |
|
*ptr++ = *ptr2++; |
|
|
*ptr++ = '\x1b'; |
|
|
*ptr++ = '['; |
|
|
*ptr++ = '4'; |
|
|
*ptr++ = '4'; |
|
|
*ptr++ = 'm'; |
|
|
while (*ptr2 != '\0') |
|
|
*ptr++ = *ptr2++; |
|
|
*ptr++ = '\0'; |
|
|
prints("│\033[46m%s\033[m│\r\n", buf); |
|
|
prints("└───────────────┘\r\n"); |
|
| 147 |
iflush(); |
iflush(); |
| 148 |
} |
} |
| 149 |
|
|
| 150 |
int bbsnet_connect(int n) |
int bbsnet_connect(int n) |
| 151 |
{ |
{ |
| 152 |
int sock, result, len, loop; |
int sock, flags, ret, loop, error; |
| 153 |
|
ssize_t len; |
| 154 |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
| 155 |
char buf[256]; |
char buf[LINE_BUFFER_LEN]; |
| 156 |
fd_set inputs, testfds; |
fd_set read_fds; |
| 157 |
|
fd_set write_fds; |
| 158 |
struct timeval timeout; |
struct timeval timeout; |
| 159 |
struct hostent *pHost = NULL; |
struct hostent *p_host = NULL; |
| 160 |
int rv, tos = 020, i; |
int tos = 020, i; |
| 161 |
char remote_addr[256]; |
char remote_addr[IP_ADDR_LEN]; |
| 162 |
int remote_port; |
int remote_port; |
| 163 |
time_t t_used; |
time_t t_used; |
| 164 |
struct tm *tm_used; |
struct tm *tm_used; |
| 165 |
|
int ch; |
| 166 |
|
|
| 167 |
clearscr(); |
clearscr(); |
| 168 |
|
|
| 169 |
moveto(0, 0); |
moveto(0, 0); |
| 170 |
prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n", |
prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n", |
| 171 |
bbsnet_conf[n].host1, bbsnet_conf[n].ip); |
bbsnet_conf[n].host1, bbsnet_conf[n].ip); |
|
prints("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n", |
|
|
TIME_OUT); |
|
| 172 |
iflush(); |
iflush(); |
| 173 |
|
|
| 174 |
pHost = gethostbyname(bbsnet_conf[n].ip); |
p_host = gethostbyname(bbsnet_conf[n].ip); |
| 175 |
|
|
| 176 |
if (pHost == NULL) |
if (p_host == NULL) |
| 177 |
{ |
{ |
| 178 |
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
| 179 |
press_any_key(); |
press_any_key(); |
| 191 |
|
|
| 192 |
sin.sin_family = AF_INET; |
sin.sin_family = AF_INET; |
| 193 |
sin.sin_addr.s_addr = |
sin.sin_addr.s_addr = |
| 194 |
(strlen(hostaddr_server) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY); |
(strnlen(hostaddr_server, sizeof(hostaddr_server)) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY); |
| 195 |
sin.sin_port = 0; |
sin.sin_port = 0; |
| 196 |
|
|
| 197 |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
| 203 |
|
|
| 204 |
bzero(&sin, sizeof(sin)); |
bzero(&sin, sizeof(sin)); |
| 205 |
sin.sin_family = AF_INET; |
sin.sin_family = AF_INET; |
| 206 |
sin.sin_addr = *(struct in_addr *)pHost->h_addr_list[0]; |
sin.sin_addr = *(struct in_addr *)p_host->h_addr_list[0]; |
| 207 |
sin.sin_port = htons(bbsnet_conf[n].port); |
sin.sin_port = htons(bbsnet_conf[n].port); |
| 208 |
|
|
| 209 |
strcpy(remote_addr, inet_ntoa(sin.sin_addr)); |
strncpy(remote_addr, inet_ntoa(sin.sin_addr), sizeof(remote_addr) - 1); |
| 210 |
|
remote_addr[sizeof(remote_addr) - 1] = '\0'; |
| 211 |
remote_port = ntohs(sin.sin_port); |
remote_port = ntohs(sin.sin_port); |
| 212 |
|
|
| 213 |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n"); |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n"); |
| 214 |
process_bar(0, MAX_PROCESS_BAR_LEN); |
process_bar(0, MAX_PROCESS_BAR_LEN); |
| 215 |
|
|
| 216 |
|
// Set socket as non-blocking |
| 217 |
|
flags = fcntl(sock, F_GETFL, 0); |
| 218 |
|
fcntl(sock, F_SETFL, flags | O_NONBLOCK); |
| 219 |
|
|
| 220 |
|
if ((ret = connect(sock, (struct sockaddr *)&sin, sizeof(sin))) < 0) |
| 221 |
|
{ |
| 222 |
|
if (errno != EINPROGRESS) |
| 223 |
|
{ |
| 224 |
|
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 225 |
|
press_any_key(); |
| 226 |
|
return -1; |
| 227 |
|
} |
| 228 |
|
} |
| 229 |
|
|
| 230 |
for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) |
for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) |
| 231 |
{ |
{ |
| 232 |
if (i == 0) |
ch = igetch(0); // 0.1 second |
| 233 |
rv = |
if (ch == Ctrl('C') || SYS_server_exit) |
| 234 |
NonBlockConnectEx(sock, (struct sockaddr *)&sin, sizeof(sin), |
{ |
| 235 |
500, 1); |
return 0; |
| 236 |
else |
} |
| 237 |
rv = |
|
| 238 |
NonBlockConnectEx(sock, (struct sockaddr *)&sin, sizeof(sin), |
FD_ZERO(&read_fds); |
| 239 |
500, 0); |
FD_SET(sock, &read_fds); |
| 240 |
if (rv == ERR_TCPLIB_TIMEOUT) |
|
| 241 |
|
FD_ZERO(&write_fds); |
| 242 |
|
FD_SET(sock, &write_fds); |
| 243 |
|
|
| 244 |
|
timeout.tv_sec = 0; |
| 245 |
|
timeout.tv_usec = 400 * 1000; // 0.4 second |
| 246 |
|
|
| 247 |
|
ret = select(sock + 1, &read_fds, &write_fds, NULL, &timeout); |
| 248 |
|
|
| 249 |
|
if (ret == 0) // Timeout |
| 250 |
{ |
{ |
| 251 |
process_bar(i + 1, MAX_PROCESS_BAR_LEN); |
process_bar(i + 1, MAX_PROCESS_BAR_LEN); |
|
continue; |
|
| 252 |
} |
} |
| 253 |
else if (rv == 0) |
else if (ret < 0) |
|
break; |
|
|
else |
|
| 254 |
{ |
{ |
| 255 |
prints("\033[1;31m连接失败!\033[m\r\n"); |
if (errno != EINTR) |
| 256 |
press_any_key(); |
{ |
| 257 |
return -1; |
log_error("select() error (%d) !\n", errno); |
| 258 |
|
return -1; |
| 259 |
|
} |
| 260 |
|
} |
| 261 |
|
// ret > 0 |
| 262 |
|
else if (FD_ISSET(sock, &read_fds) || FD_ISSET(sock, &write_fds)) |
| 263 |
|
{ |
| 264 |
|
len = sizeof(error); |
| 265 |
|
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&len) < 0) |
| 266 |
|
{ |
| 267 |
|
log_error("getsockopt() error (%d) !\n", error); |
| 268 |
|
return -1; |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
break; // connected |
| 272 |
} |
} |
| 273 |
} |
} |
| 274 |
if (i == MAX_PROCESS_BAR_LEN) |
if (i == MAX_PROCESS_BAR_LEN) |
| 277 |
press_any_key(); |
press_any_key(); |
| 278 |
return -1; |
return -1; |
| 279 |
} |
} |
| 280 |
|
|
| 281 |
|
fcntl(sock, F_SETFL, flags); /* restore file status flags */ |
| 282 |
setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(int)); |
setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(int)); |
| 283 |
|
|
| 284 |
prints("\033[1;31m连接成功!\033[m\r\n"); |
prints("\033[1;31m连接成功!\033[m\r\n"); |
| 285 |
log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
| 286 |
|
|
|
FD_ZERO(&inputs); |
|
|
FD_SET(0, &inputs); |
|
|
FD_SET(sock, &inputs); |
|
|
|
|
| 287 |
BBS_last_access_tm = t_used = time(0); |
BBS_last_access_tm = t_used = time(0); |
| 288 |
|
|
| 289 |
loop = 1; |
loop = 1; |
| 290 |
|
|
| 291 |
while (loop) |
while (loop && !SYS_server_exit) |
| 292 |
{ |
{ |
| 293 |
testfds = inputs; |
FD_ZERO(&read_fds); |
| 294 |
timeout.tv_sec = TIME_OUT; |
FD_SET(STDIN_FILENO, &read_fds); |
| 295 |
timeout.tv_usec = 0; |
FD_SET(sock, &read_fds); |
| 296 |
|
|
| 297 |
|
timeout.tv_sec = 0; |
| 298 |
|
timeout.tv_usec = 100 * 1000; // 0.1 second |
| 299 |
|
|
| 300 |
result = SignalSafeSelect(FD_SETSIZE, &testfds, (fd_set *)NULL, |
ret = select(FD_SETSIZE, &read_fds, NULL, NULL, &timeout); |
|
(fd_set *)NULL, &timeout); |
|
| 301 |
|
|
| 302 |
if (result == 0) |
if (ret == 0) // timeout |
| 303 |
{ |
{ |
| 304 |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 305 |
{ |
{ |
| 306 |
loop = 0; |
loop = 0; |
| 307 |
} |
} |
| 308 |
} |
} |
| 309 |
if (result < 0) |
else if (ret < 0) |
| 310 |
{ |
{ |
| 311 |
log_error("select() error (%d) !\n", result); |
if (errno != EINTR) |
| 312 |
loop = 0; |
{ |
| 313 |
|
log_error("select() error (%d) !\n", errno); |
| 314 |
|
loop = 0; |
| 315 |
|
} |
| 316 |
} |
} |
| 317 |
if (result > 0) |
else if (ret > 0) |
| 318 |
{ |
{ |
| 319 |
if (FD_ISSET(0, &testfds)) |
if (FD_ISSET(STDIN_FILENO, &read_fds)) |
| 320 |
{ |
{ |
| 321 |
len = read(0, buf, 255); |
len = read(STDIN_FILENO, buf, sizeof(buf)); |
| 322 |
if (len == 0) |
if (len == 0) |
| 323 |
{ |
{ |
| 324 |
loop = 0; |
loop = 0; |
| 325 |
} |
} |
| 326 |
write(sock, buf, len); |
write(sock, buf, (size_t)len); |
| 327 |
|
|
| 328 |
|
BBS_last_access_tm = time(0); |
| 329 |
} |
} |
| 330 |
if (FD_ISSET(sock, &testfds)) |
if (FD_ISSET(sock, &read_fds)) |
| 331 |
{ |
{ |
| 332 |
len = read(sock, buf, 255); |
len = read(sock, buf, sizeof(buf)); |
| 333 |
if (len == 0) |
if (len == 0) |
| 334 |
{ |
{ |
| 335 |
loop = 0; |
loop = 0; |
| 336 |
} |
} |
| 337 |
write(1, buf, len); |
write(STDOUT_FILENO, buf, (size_t)len); |
| 338 |
} |
} |
|
BBS_last_access_tm = time(0); |
|
| 339 |
} |
} |
| 340 |
} |
} |
| 341 |
|
|
| 357 |
static int |
static int |
| 358 |
bbsnet_refresh() |
bbsnet_refresh() |
| 359 |
{ |
{ |
|
int i; |
|
|
|
|
| 360 |
clearscr(); |
clearscr(); |
| 361 |
moveto(1, 0); |
moveto(1, 0); |
| 362 |
prints("╭══════════════════════════════════════╮"); |
prints(" ----------------------------------------------------------------------------- "); |
| 363 |
for (i = 2; i < 19; i++) |
for (int i = 2; i < 19; i++) |
| 364 |
{ |
{ |
| 365 |
moveto(i, 0); |
moveto(i, 0); |
| 366 |
prints("║"); |
prints("|"); |
| 367 |
moveto(i, 79); |
moveto(i, 79); |
| 368 |
prints("║"); |
prints("|"); |
| 369 |
} |
} |
| 370 |
moveto(19, 0); |
moveto(19, 0); |
| 371 |
prints("║——————————————————————————————————————║"); |
prints("|-----------------------------------------------------------------------------|"); |
| 372 |
moveto(22, 0); |
moveto(22, 0); |
| 373 |
prints("╰══════════════════════════════════════╯"); |
prints(" ----------------------------------------------------------------------------- "); |
| 374 |
moveto(23, 0); |
moveto(23, 0); |
| 375 |
prints(" [\x1b[1;32mCtrl+C\x1b[m]退出"); |
prints(" [\x1b[1;32mCtrl+C\x1b[m]退出"); |
| 376 |
|
|
| 383 |
{ |
{ |
| 384 |
moveto(20, 0); |
moveto(20, 0); |
| 385 |
clrtoeol(); |
clrtoeol(); |
| 386 |
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", |
| 387 |
bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1); |
bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1); |
| 388 |
moveto(20, 79); |
moveto(20, 79); |
| 389 |
prints("║"); |
prints("|"); |
| 390 |
moveto(21, 0); |
moveto(21, 0); |
| 391 |
clrtoeol(); |
clrtoeol(); |
| 392 |
prints("║\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip); |
prints("|\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip); |
| 393 |
if (bbsnet_conf[new_pos].port != 23) |
if (bbsnet_conf[new_pos].port != 23) |
| 394 |
|
{ |
| 395 |
prints(" %d", bbsnet_conf[new_pos].port); |
prints(" %d", bbsnet_conf[new_pos].port); |
| 396 |
|
} |
| 397 |
prints("\x1b[m"); |
prints("\x1b[m"); |
| 398 |
moveto(21, 79); |
moveto(21, 79); |
| 399 |
prints("║"); |
prints("|"); |
| 400 |
iflush(); |
iflush(); |
| 401 |
|
|
| 402 |
return 0; |
return 0; |
| 416 |
display_menu(get_menu(&bbsnet_menu, "BBSNET")); |
display_menu(get_menu(&bbsnet_menu, "BBSNET")); |
| 417 |
bbsnet_selchange(pos); |
bbsnet_selchange(pos); |
| 418 |
|
|
| 419 |
while (1) |
while (!SYS_server_exit) |
| 420 |
{ |
{ |
| 421 |
ch = igetch(0); |
ch = igetch(0); |
| 422 |
switch (ch) |
switch (ch) |
| 423 |
{ |
{ |
|
case KEY_NULL: |
|
| 424 |
case Ctrl('C'): |
case Ctrl('C'): |
| 425 |
return 0; |
return 0; |
| 426 |
|
case KEY_NULL: |
| 427 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 428 |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 429 |
{ |
{ |
| 430 |
return -1; |
return 0; |
| 431 |
} |
} |
| 432 |
continue; |
continue; |
| 433 |
case CR: |
case CR: |
| 439 |
break; |
break; |
| 440 |
case KEY_UP: |
case KEY_UP: |
| 441 |
for (i = 0; i < STATION_PER_LINE; i++) |
for (i = 0; i < STATION_PER_LINE; i++) |
| 442 |
|
{ |
| 443 |
menu_control(&bbsnet_menu, KEY_UP); |
menu_control(&bbsnet_menu, KEY_UP); |
| 444 |
|
} |
| 445 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 446 |
bbsnet_selchange(pos); |
bbsnet_selchange(pos); |
| 447 |
break; |
break; |
| 448 |
case KEY_DOWN: |
case KEY_DOWN: |
| 449 |
for (i = 0; i < STATION_PER_LINE; i++) |
for (i = 0; i < STATION_PER_LINE; i++) |
| 450 |
|
{ |
| 451 |
menu_control(&bbsnet_menu, KEY_DOWN); |
menu_control(&bbsnet_menu, KEY_DOWN); |
| 452 |
|
} |
| 453 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 454 |
bbsnet_selchange(pos); |
bbsnet_selchange(pos); |
| 455 |
break; |
break; |