| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
bbs_net.c - description |
bbs_net.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 18 2004 |
begin : Mon Oct 18 2004 |
| 5 |
copyright : (C) 2004 by Leaflet |
copyright : (C) 2004 by Leaflet |
| 6 |
email : leaflet@leafok.com |
email : leaflet@leafok.com |
| 7 |
***************************************************************************/ |
***************************************************************************/ |
| 8 |
|
|
| 9 |
/*************************************************************************** |
/*************************************************************************** |
| 17 |
|
|
| 18 |
#include "bbs.h" |
#include "bbs.h" |
| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
|
#include "log.h" |
| 21 |
#include "io.h" |
#include "io.h" |
| 22 |
|
#include "screen.h" |
| 23 |
#include "menu.h" |
#include "menu.h" |
| 24 |
#include "tcplib.h" |
#include "tcplib.h" |
| 25 |
#include <stdio.h> |
#include <stdio.h> |
| 32 |
#include <unistd.h> |
#include <unistd.h> |
| 33 |
#include <netdb.h> |
#include <netdb.h> |
| 34 |
|
|
| 35 |
#define TIME_OUT 15 |
#define TIME_OUT 15 |
| 36 |
#define MAX_PROCESS_BAR_LEN 30 |
#define MAX_PROCESS_BAR_LEN 30 |
| 37 |
#define MAXSTATION 26*2 |
#define MAXSTATION 26 * 2 |
| 38 |
#define STATION_PER_LINE 4 |
#define STATION_PER_LINE 4 |
| 39 |
|
|
| 40 |
struct _bbsnet_conf |
struct _bbsnet_conf |
| 41 |
{ |
{ |
| 42 |
char host1[20]; |
char host1[20]; |
| 43 |
char host2[40]; |
char host2[40]; |
| 44 |
char ip[40]; |
char ip[40]; |
| 45 |
int port; |
int port; |
| 46 |
} bbsnet_conf[MAXSTATION]; |
} bbsnet_conf[MAXSTATION]; |
| 47 |
|
|
| 48 |
MENU_SET bbsnet_menu; |
MENU_SET bbsnet_menu; |
| 49 |
|
|
| 50 |
int |
int load_bbsnet_conf(const char *file_config) |
|
load_bbsnet_conf (const char *file_config) |
|
| 51 |
{ |
{ |
| 52 |
FILE *fp; |
FILE *fp; |
| 53 |
MENU *p_menu; |
MENU *p_menu; |
| 54 |
MENU_ITEM *p_menuitem; |
MENU_ITEM *p_menuitem; |
| 55 |
char t[256], *t1, *t2, *t3, *t4; |
char t[256], *t1, *t2, *t3, *t4; |
| 56 |
int item_count = 0; |
int item_count = 0; |
| 57 |
|
|
| 58 |
fp = fopen (file_config, "r"); |
fp = fopen(file_config, "r"); |
| 59 |
if (fp == NULL) |
if (fp == NULL) |
| 60 |
return -1; |
return -1; |
| 61 |
|
|
| 62 |
p_menu = bbsnet_menu.p_menu[0] = malloc (sizeof (MENU)); |
p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU)); |
| 63 |
strcpy (p_menu->name, "BBSNET"); |
strcpy(p_menu->name, "BBSNET"); |
| 64 |
p_menu->title.show = 0; |
p_menu->title.show = 0; |
| 65 |
p_menu->screen.show = 0; |
p_menu->screen.show = 0; |
|
|
|
|
while (fgets (t, 255, fp) && item_count < MAXSTATION) |
|
|
{ |
|
|
t1 = strtok (t, " \t"); |
|
|
t2 = strtok (NULL, " \t\n"); |
|
|
t3 = strtok (NULL, " \t\n"); |
|
|
t4 = strtok (NULL, " \t\n"); |
|
|
|
|
|
if (t1[0] == '#' || t1[0] == '*' || t1 == NULL || t2 == NULL |
|
|
|| t3 == NULL) |
|
|
continue; |
|
|
strncpy (bbsnet_conf[item_count].host1, t2, 18); |
|
|
bbsnet_conf[item_count].host1[18] = 0; |
|
|
strncpy (bbsnet_conf[item_count].host2, t1, 36); |
|
|
bbsnet_conf[item_count].host2[36] = 0; |
|
|
strncpy (bbsnet_conf[item_count].ip, t3, 36); |
|
|
bbsnet_conf[item_count].ip[36] = 0; |
|
|
bbsnet_conf[item_count].port = t4 ? atoi (t4) : 23; |
|
|
|
|
|
p_menuitem = p_menu->items[item_count] = malloc (sizeof (MENU_ITEM)); |
|
|
p_menuitem->row = 2 + item_count / STATION_PER_LINE; |
|
|
p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20; |
|
|
sprintf (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] = |
|
|
(item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count); |
|
|
p_menuitem->name[1] = '\0'; |
|
|
sprintf (p_menuitem->text, "[1;36m%c.[m %s", |
|
|
p_menuitem->name[0], bbsnet_conf[item_count].host1); |
|
|
|
|
|
item_count++; |
|
|
} |
|
|
fclose (fp); |
|
|
|
|
|
p_menu->item_count = item_count; |
|
|
p_menu->item_cur_pos = 0; |
|
|
|
|
|
bbsnet_menu.menu_count = 1; |
|
|
bbsnet_menu.menu_select_depth = 0; |
|
|
bbsnet_menu.p_menu_select[0] = bbsnet_menu.p_menu[0]; |
|
| 66 |
|
|
| 67 |
return 0; |
while (fgets(t, 255, fp) && item_count < MAXSTATION) |
| 68 |
|
{ |
| 69 |
|
t1 = strtok(t, " \t"); |
| 70 |
|
t2 = strtok(NULL, " \t\n"); |
| 71 |
|
t3 = strtok(NULL, " \t\n"); |
| 72 |
|
t4 = strtok(NULL, " \t\n"); |
| 73 |
|
|
| 74 |
|
if (t1[0] == '#' || t1[0] == '*' || t1 == NULL || t2 == NULL || t3 == NULL) |
| 75 |
|
continue; |
| 76 |
|
strncpy(bbsnet_conf[item_count].host1, t2, 18); |
| 77 |
|
bbsnet_conf[item_count].host1[18] = 0; |
| 78 |
|
strncpy(bbsnet_conf[item_count].host2, t1, 36); |
| 79 |
|
bbsnet_conf[item_count].host2[36] = 0; |
| 80 |
|
strncpy(bbsnet_conf[item_count].ip, t3, 36); |
| 81 |
|
bbsnet_conf[item_count].ip[36] = 0; |
| 82 |
|
bbsnet_conf[item_count].port = t4 ? atoi(t4) : 23; |
| 83 |
|
|
| 84 |
|
p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM)); |
| 85 |
|
p_menuitem->row = 2 + item_count / STATION_PER_LINE; |
| 86 |
|
p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20; |
| 87 |
|
sprintf(p_menuitem->action, "%d", item_count); |
| 88 |
|
p_menuitem->submenu = 0; |
| 89 |
|
p_menuitem->priv = 0; |
| 90 |
|
p_menuitem->level = 0; |
| 91 |
|
p_menuitem->display = 0; |
| 92 |
|
p_menuitem->name[0] = |
| 93 |
|
(item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count); |
| 94 |
|
p_menuitem->name[1] = '\0'; |
| 95 |
|
sprintf(p_menuitem->text, "[1;36m%c.[m %s", |
| 96 |
|
p_menuitem->name[0], bbsnet_conf[item_count].host1); |
| 97 |
|
|
| 98 |
|
item_count++; |
| 99 |
|
} |
| 100 |
|
fclose(fp); |
| 101 |
|
|
| 102 |
|
p_menu->item_count = item_count; |
| 103 |
|
p_menu->item_cur_pos = 0; |
| 104 |
|
|
| 105 |
|
bbsnet_menu.menu_count = 1; |
| 106 |
|
bbsnet_menu.menu_select_depth = 0; |
| 107 |
|
bbsnet_menu.p_menu_select[0] = bbsnet_menu.p_menu[0]; |
| 108 |
|
|
| 109 |
|
return 0; |
| 110 |
} |
} |
| 111 |
|
|
| 112 |
static void |
static void |
| 113 |
process_bar (int n, int len) |
process_bar(int n, int len) |
| 114 |
{ |
{ |
| 115 |
char buf[256]; |
char buf[256]; |
| 116 |
char buf2[256]; |
char buf2[256]; |
| 117 |
char *ptr; |
char *ptr; |
| 118 |
char *ptr2; |
char *ptr2; |
| 119 |
char *ptr3; |
char *ptr3; |
| 120 |
|
|
| 121 |
moveto (4, 0); |
moveto(4, 0); |
| 122 |
prints ("┌───────────────┐\r\n"); |
prints("┌───────────────┐\r\n"); |
| 123 |
sprintf (buf2, " %3d%% ", n * 100 / len); |
sprintf(buf2, " %3d%% ", n * 100 / len); |
| 124 |
ptr = buf; |
ptr = buf; |
| 125 |
ptr2 = buf2; |
ptr2 = buf2; |
| 126 |
ptr3 = buf + n; |
ptr3 = buf + n; |
| 127 |
while (ptr != ptr3) |
while (ptr != ptr3) |
| 128 |
*ptr++ = *ptr2++; |
*ptr++ = *ptr2++; |
| 129 |
*ptr++ = '\x1b'; |
*ptr++ = '\x1b'; |
| 130 |
*ptr++ = '['; |
*ptr++ = '['; |
| 131 |
*ptr++ = '4'; |
*ptr++ = '4'; |
| 132 |
*ptr++ = '4'; |
*ptr++ = '4'; |
| 133 |
*ptr++ = 'm'; |
*ptr++ = 'm'; |
| 134 |
while (*ptr2 != '\0') |
while (*ptr2 != '\0') |
| 135 |
*ptr++ = *ptr2++; |
*ptr++ = *ptr2++; |
| 136 |
*ptr++ = '\0'; |
*ptr++ = '\0'; |
| 137 |
prints ("│\033[46m%s\033[m│\r\n", buf); |
prints("│\033[46m%s\033[m│\r\n", buf); |
| 138 |
prints ("└───────────────┘\r\n"); |
prints("└───────────────┘\r\n"); |
| 139 |
iflush (); |
iflush(); |
| 140 |
} |
} |
| 141 |
|
|
| 142 |
int |
int bbsnet_connect(int n) |
|
bbsnet_connect (int n) |
|
| 143 |
{ |
{ |
| 144 |
int sock, ch, result, len, loop; |
int sock, result, len, loop; |
| 145 |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
| 146 |
char buf[256]; |
char buf[256]; |
| 147 |
fd_set inputs, testfds; |
fd_set inputs, testfds; |
| 148 |
struct timeval timeout; |
struct timeval timeout; |
| 149 |
struct hostent *pHost = NULL; |
struct hostent *pHost = NULL; |
| 150 |
int rc, rv, tos = 020, i; |
int rv, tos = 020, i; |
| 151 |
char remote_addr[256]; |
char remote_addr[256]; |
| 152 |
int remote_port; |
int remote_port; |
| 153 |
time_t t_used; |
time_t t_used; |
| 154 |
struct tm *tm_used; |
struct tm *tm_used; |
| 155 |
|
|
| 156 |
clearscr (); |
clearscr(); |
| 157 |
|
|
| 158 |
moveto (0, 0); |
moveto(0, 0); |
| 159 |
prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n", |
prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n", |
| 160 |
bbsnet_conf[n].host1, bbsnet_conf[n].ip); |
bbsnet_conf[n].host1, bbsnet_conf[n].ip); |
| 161 |
prints ("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n", |
prints("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n", |
| 162 |
TIME_OUT); |
TIME_OUT); |
| 163 |
iflush (); |
iflush(); |
| 164 |
|
|
| 165 |
pHost = gethostbyname (bbsnet_conf[n].ip); |
pHost = gethostbyname(bbsnet_conf[n].ip); |
| 166 |
|
|
| 167 |
if (pHost == NULL) |
if (pHost == NULL) |
|
{ |
|
|
prints ("\033[1;31m查找主机名失败!\033[m\r\n"); |
|
|
press_any_key (); |
|
|
return -1; |
|
|
} |
|
|
|
|
|
sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); |
|
|
|
|
|
if (sock < 0) |
|
|
{ |
|
|
prints ("\033[1;31m无法创建socket!\033[m\r\n"); |
|
|
press_any_key (); |
|
|
return -1; |
|
|
} |
|
|
|
|
|
sin.sin_family = AF_INET; |
|
|
sin.sin_addr.s_addr = |
|
|
(strlen (hostaddr_server) > 0 ? inet_addr (hostaddr_server) : INADDR_ANY); |
|
|
sin.sin_port = 0; |
|
|
|
|
|
if (bind (sock, (struct sockaddr *) &sin, sizeof (sin)) < 0) |
|
|
{ |
|
|
log_error ("Bind address %s:%u failed\n", |
|
|
inet_ntoa (sin.sin_addr), ntohs (sin.sin_port)); |
|
|
return -2; |
|
|
} |
|
|
|
|
|
bzero (&sin, sizeof (sin)); |
|
|
sin.sin_family = AF_INET; |
|
|
sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0]; |
|
|
sin.sin_port = htons (bbsnet_conf[n].port); |
|
|
|
|
|
strcpy (remote_addr, inet_ntoa (sin.sin_addr)); |
|
|
remote_port = ntohs (sin.sin_port); |
|
|
|
|
|
prints ("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n"); |
|
|
process_bar (0, MAX_PROCESS_BAR_LEN); |
|
|
for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) |
|
|
{ |
|
|
if (i == 0) |
|
|
rv = |
|
|
NonBlockConnectEx (sock, (struct sockaddr *) &sin, sizeof (sin), |
|
|
500, 1); |
|
|
else |
|
|
rv = |
|
|
NonBlockConnectEx (sock, (struct sockaddr *) &sin, sizeof (sin), |
|
|
500, 0); |
|
|
if (rv == ERR_TCPLIB_TIMEOUT) |
|
| 168 |
{ |
{ |
| 169 |
process_bar (i + 1, MAX_PROCESS_BAR_LEN); |
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
| 170 |
continue; |
press_any_key(); |
| 171 |
|
return -1; |
| 172 |
} |
} |
| 173 |
else if (rv == 0) |
|
| 174 |
break; |
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 175 |
else |
|
| 176 |
|
if (sock < 0) |
| 177 |
{ |
{ |
| 178 |
prints ("\033[1;31m连接失败!\033[m\r\n"); |
prints("\033[1;31m无法创建socket!\033[m\r\n"); |
| 179 |
press_any_key (); |
press_any_key(); |
| 180 |
return -1; |
return -1; |
| 181 |
} |
} |
|
} |
|
|
if (i == MAX_PROCESS_BAR_LEN) |
|
|
{ |
|
|
prints ("\033[1;31m连接超时!\033[m\r\n"); |
|
|
press_any_key (); |
|
|
return -1; |
|
|
} |
|
|
setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int)); |
|
|
|
|
|
prints ("\033[1;31m连接成功!\033[m\r\n"); |
|
|
log_std ("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
|
|
|
|
|
FD_ZERO (&inputs); |
|
|
FD_SET (0, &inputs); |
|
|
FD_SET (sock, &inputs); |
|
|
|
|
|
BBS_last_access_tm = t_used = time (0); |
|
|
|
|
|
loop = 1; |
|
|
|
|
|
while (loop) |
|
|
{ |
|
|
testfds = inputs; |
|
|
timeout.tv_sec = TIME_OUT; |
|
|
timeout.tv_usec = 0; |
|
| 182 |
|
|
| 183 |
result = SignalSafeSelect (FD_SETSIZE, &testfds, (fd_set *) NULL, |
sin.sin_family = AF_INET; |
| 184 |
(fd_set *) NULL, &timeout); |
sin.sin_addr.s_addr = |
| 185 |
|
(strlen(hostaddr_server) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY); |
| 186 |
|
sin.sin_port = 0; |
| 187 |
|
|
| 188 |
|
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
| 189 |
|
{ |
| 190 |
|
log_error("Bind address %s:%u failed\n", |
| 191 |
|
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); |
| 192 |
|
return -2; |
| 193 |
|
} |
| 194 |
|
|
| 195 |
if (result == 0) |
bzero(&sin, sizeof(sin)); |
| 196 |
|
sin.sin_family = AF_INET; |
| 197 |
|
sin.sin_addr = *(struct in_addr *)pHost->h_addr_list[0]; |
| 198 |
|
sin.sin_port = htons(bbsnet_conf[n].port); |
| 199 |
|
|
| 200 |
|
strcpy(remote_addr, inet_ntoa(sin.sin_addr)); |
| 201 |
|
remote_port = ntohs(sin.sin_port); |
| 202 |
|
|
| 203 |
|
prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n"); |
| 204 |
|
process_bar(0, MAX_PROCESS_BAR_LEN); |
| 205 |
|
for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) |
| 206 |
{ |
{ |
| 207 |
if (time (0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (i == 0) |
| 208 |
{ |
rv = |
| 209 |
loop = 0; |
NonBlockConnectEx(sock, (struct sockaddr *)&sin, sizeof(sin), |
| 210 |
} |
500, 1); |
| 211 |
|
else |
| 212 |
|
rv = |
| 213 |
|
NonBlockConnectEx(sock, (struct sockaddr *)&sin, sizeof(sin), |
| 214 |
|
500, 0); |
| 215 |
|
if (rv == ERR_TCPLIB_TIMEOUT) |
| 216 |
|
{ |
| 217 |
|
process_bar(i + 1, MAX_PROCESS_BAR_LEN); |
| 218 |
|
continue; |
| 219 |
|
} |
| 220 |
|
else if (rv == 0) |
| 221 |
|
break; |
| 222 |
|
else |
| 223 |
|
{ |
| 224 |
|
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 225 |
|
press_any_key(); |
| 226 |
|
return -1; |
| 227 |
|
} |
| 228 |
} |
} |
| 229 |
if (result < 0) |
if (i == MAX_PROCESS_BAR_LEN) |
| 230 |
{ |
{ |
| 231 |
log_error ("select() error!\n"); |
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 232 |
loop = 0; |
press_any_key(); |
| 233 |
|
return -1; |
| 234 |
} |
} |
| 235 |
if (result > 0) |
setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(int)); |
| 236 |
|
|
| 237 |
|
prints("\033[1;31m连接成功!\033[m\r\n"); |
| 238 |
|
log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port); |
| 239 |
|
|
| 240 |
|
FD_ZERO(&inputs); |
| 241 |
|
FD_SET(0, &inputs); |
| 242 |
|
FD_SET(sock, &inputs); |
| 243 |
|
|
| 244 |
|
BBS_last_access_tm = t_used = time(0); |
| 245 |
|
|
| 246 |
|
loop = 1; |
| 247 |
|
|
| 248 |
|
while (loop) |
| 249 |
{ |
{ |
| 250 |
if (FD_ISSET (0, &testfds)) |
testfds = inputs; |
| 251 |
{ |
timeout.tv_sec = TIME_OUT; |
| 252 |
len = read (0, buf, 255); |
timeout.tv_usec = 0; |
| 253 |
if (len == 0) |
|
| 254 |
|
result = SignalSafeSelect(FD_SETSIZE, &testfds, (fd_set *)NULL, |
| 255 |
|
(fd_set *)NULL, &timeout); |
| 256 |
|
|
| 257 |
|
if (result == 0) |
| 258 |
|
{ |
| 259 |
|
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 260 |
|
{ |
| 261 |
|
loop = 0; |
| 262 |
|
} |
| 263 |
|
} |
| 264 |
|
if (result < 0) |
| 265 |
{ |
{ |
| 266 |
loop = 0; |
log_error("select() error (%d) !\n", result); |
| 267 |
|
loop = 0; |
| 268 |
} |
} |
| 269 |
write (sock, buf, len); |
if (result > 0) |
|
} |
|
|
if (FD_ISSET (sock, &testfds)) |
|
|
{ |
|
|
len = read (sock, buf, 255); |
|
|
if (len == 0) |
|
| 270 |
{ |
{ |
| 271 |
loop = 0; |
if (FD_ISSET(0, &testfds)) |
| 272 |
|
{ |
| 273 |
|
len = read(0, buf, 255); |
| 274 |
|
if (len == 0) |
| 275 |
|
{ |
| 276 |
|
loop = 0; |
| 277 |
|
} |
| 278 |
|
write(sock, buf, len); |
| 279 |
|
} |
| 280 |
|
if (FD_ISSET(sock, &testfds)) |
| 281 |
|
{ |
| 282 |
|
len = read(sock, buf, 255); |
| 283 |
|
if (len == 0) |
| 284 |
|
{ |
| 285 |
|
loop = 0; |
| 286 |
|
} |
| 287 |
|
write(1, buf, len); |
| 288 |
|
} |
| 289 |
|
BBS_last_access_tm = time(0); |
| 290 |
} |
} |
|
write (1, buf, len); |
|
|
} |
|
|
BBS_last_access_tm = time (0); |
|
| 291 |
} |
} |
|
} |
|
| 292 |
|
|
| 293 |
if (close (sock) == -1) |
if (close(sock) == -1) |
| 294 |
{ |
{ |
| 295 |
log_error ("Close socket failed\n"); |
log_error("Close socket failed\n"); |
| 296 |
} |
} |
| 297 |
|
|
| 298 |
t_used = time (0) - t_used; |
t_used = time(0) - t_used; |
| 299 |
tm_used = gmtime (&t_used); |
tm_used = gmtime(&t_used); |
| 300 |
|
|
| 301 |
log_std ("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
log_std("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
| 302 |
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, |
| 303 |
tm_used->tm_sec); |
tm_used->tm_sec); |
| 304 |
|
|
| 305 |
return 0; |
return 0; |
| 306 |
} |
} |
| 307 |
|
|
| 308 |
static int |
static int |
| 309 |
bbsnet_refresh () |
bbsnet_refresh() |
| 310 |
{ |
{ |
| 311 |
int i; |
int i; |
| 312 |
|
|
| 313 |
|
clearscr(); |
| 314 |
|
moveto(1, 0); |
| 315 |
|
prints("╭══════════════════════════════════════╮"); |
| 316 |
|
for (i = 2; i < 19; i++) |
| 317 |
|
{ |
| 318 |
|
moveto(i, 0); |
| 319 |
|
prints("║"); |
| 320 |
|
moveto(i, 79); |
| 321 |
|
prints("║"); |
| 322 |
|
} |
| 323 |
|
moveto(19, 0); |
| 324 |
|
prints("║——————————————————————————————————————║"); |
| 325 |
|
moveto(22, 0); |
| 326 |
|
prints("╰══════════════════════════════════════╯"); |
| 327 |
|
moveto(23, 0); |
| 328 |
|
prints(" [\x1b[1;32mCtrl+C\x1b[m]退出"); |
| 329 |
|
|
| 330 |
clearscr (); |
iflush(); |
|
moveto (1, 0); |
|
|
prints |
|
|
("?q?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?r"); |
|
|
for (i = 2; i < 19; i++) |
|
|
{ |
|
|
moveto (i, 0); |
|
|
prints ("?U"); |
|
|
moveto (i, 79); |
|
|
prints ("?U"); |
|
|
} |
|
|
moveto (19, 0); |
|
|
prints |
|
|
("?U——————————————————————————————————————?U"); |
|
|
moveto (22, 0); |
|
|
prints |
|
|
("?t?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?s"); |
|
|
moveto (23, 0); |
|
|
prints (" [\x1b[1;32mCtrl+C\x1b[m]退出"); |
|
|
iflush (); |
|
| 331 |
|
|
| 332 |
return 0; |
return 0; |
| 333 |
} |
} |
| 334 |
|
|
| 335 |
int |
int bbsnet_selchange(int new_pos) |
|
bbsnet_selchange (int new_pos) |
|
| 336 |
{ |
{ |
| 337 |
moveto (20, 0); |
moveto(20, 0); |
| 338 |
clrtoeol (); |
clrtoeol(); |
| 339 |
prints ("?U\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", |
| 340 |
bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1); |
bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1); |
| 341 |
moveto (20, 79); |
moveto(20, 79); |
| 342 |
prints ("?U"); |
prints("║"); |
| 343 |
moveto (21, 0); |
moveto(21, 0); |
| 344 |
clrtoeol (); |
clrtoeol(); |
| 345 |
prints ("?U\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip); |
prints("║\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip); |
| 346 |
if (bbsnet_conf[new_pos].port != 23) |
if (bbsnet_conf[new_pos].port != 23) |
| 347 |
prints (" %d", bbsnet_conf[new_pos].port); |
prints(" %d", bbsnet_conf[new_pos].port); |
| 348 |
prints ("\x1b[m"); |
prints("\x1b[m"); |
| 349 |
moveto (21, 79); |
moveto(21, 79); |
| 350 |
prints ("?U"); |
prints("║"); |
| 351 |
iflush (); |
iflush(); |
| 352 |
|
|
| 353 |
return 0; |
return 0; |
| 354 |
} |
} |
| 355 |
|
|
| 356 |
int |
int bbs_net() |
|
bbs_net () |
|
| 357 |
{ |
{ |
| 358 |
int ch, pos, i; |
int ch, pos, i; |
| 359 |
char file_config[256]; |
|
| 360 |
|
load_bbsnet_conf(CONF_BBSNET); |
| 361 |
|
|
| 362 |
strcpy (file_config, app_home_dir); |
BBS_last_access_tm = time(0); |
|
strcat (file_config, "conf/bbsnet.conf"); |
|
| 363 |
|
|
| 364 |
load_bbsnet_conf (file_config); |
clearscr(); |
| 365 |
|
bbsnet_refresh(); |
| 366 |
|
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 367 |
|
display_menu(get_menu(&bbsnet_menu, "BBSNET")); |
| 368 |
|
bbsnet_selchange(pos); |
| 369 |
|
|
| 370 |
BBS_last_access_tm = time (0); |
while (1) |
|
|
|
|
clearscr (); |
|
|
bbsnet_refresh (); |
|
|
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
|
|
display_menu (get_menu (&bbsnet_menu, "BBSNET")); |
|
|
bbsnet_selchange (pos); |
|
|
|
|
|
while (1) |
|
|
{ |
|
|
ch = igetch (); |
|
|
switch (ch) |
|
| 371 |
{ |
{ |
| 372 |
case KEY_NULL: |
ch = igetch(0); |
| 373 |
case Ctrl ('C'): |
switch (ch) |
| 374 |
return 0; |
{ |
| 375 |
case KEY_TIMEOUT: |
case KEY_NULL: |
| 376 |
if (time (0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
case Ctrl('C'): |
| 377 |
{ |
return 0; |
| 378 |
return -1; |
case KEY_TIMEOUT: |
| 379 |
} |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 380 |
continue; |
{ |
| 381 |
case CR: |
return -1; |
| 382 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
} |
| 383 |
bbsnet_connect (pos); |
continue; |
| 384 |
bbsnet_refresh (); |
case CR: |
| 385 |
display_current_menu (&bbsnet_menu); |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 386 |
bbsnet_selchange (pos); |
bbsnet_connect(pos); |
| 387 |
break; |
bbsnet_refresh(); |
| 388 |
case KEY_UP: |
display_current_menu(&bbsnet_menu); |
| 389 |
for (i = 0; i < STATION_PER_LINE; i++) |
bbsnet_selchange(pos); |
| 390 |
menu_control (&bbsnet_menu, KEY_UP); |
break; |
| 391 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
case KEY_UP: |
| 392 |
bbsnet_selchange (pos); |
for (i = 0; i < STATION_PER_LINE; i++) |
| 393 |
break; |
menu_control(&bbsnet_menu, KEY_UP); |
| 394 |
case KEY_DOWN: |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 395 |
for (i = 0; i < STATION_PER_LINE; i++) |
bbsnet_selchange(pos); |
| 396 |
menu_control (&bbsnet_menu, KEY_DOWN); |
break; |
| 397 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
case KEY_DOWN: |
| 398 |
bbsnet_selchange (pos); |
for (i = 0; i < STATION_PER_LINE; i++) |
| 399 |
break; |
menu_control(&bbsnet_menu, KEY_DOWN); |
| 400 |
case KEY_LEFT: |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 401 |
menu_control (&bbsnet_menu, KEY_UP); |
bbsnet_selchange(pos); |
| 402 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
break; |
| 403 |
bbsnet_selchange (pos); |
case KEY_LEFT: |
| 404 |
break; |
menu_control(&bbsnet_menu, KEY_UP); |
| 405 |
case KEY_RIGHT: |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 406 |
menu_control (&bbsnet_menu, KEY_DOWN); |
bbsnet_selchange(pos); |
| 407 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
break; |
| 408 |
bbsnet_selchange (pos); |
case KEY_RIGHT: |
| 409 |
break; |
menu_control(&bbsnet_menu, KEY_DOWN); |
| 410 |
default: |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 411 |
menu_control (&bbsnet_menu, ch); |
bbsnet_selchange(pos); |
| 412 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
break; |
| 413 |
bbsnet_selchange (pos); |
default: |
| 414 |
break; |
menu_control(&bbsnet_menu, ch); |
| 415 |
|
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 416 |
|
bbsnet_selchange(pos); |
| 417 |
|
break; |
| 418 |
|
} |
| 419 |
|
BBS_last_access_tm = time(0); |
| 420 |
} |
} |
|
BBS_last_access_tm = time (0); |
|
|
} |
|
| 421 |
|
|
| 422 |
return 0; |
return 0; |
| 423 |
} |
} |