| 42 |
char host1[20]; |
char host1[20]; |
| 43 |
char host2[40]; |
char host2[40]; |
| 44 |
char ip[40]; |
char ip[40]; |
| 45 |
int port; |
in_port_t port; |
| 46 |
} bbsnet_conf[MAXSTATION]; |
} bbsnet_conf[MAXSTATION]; |
| 47 |
|
|
| 48 |
MENU_SET bbsnet_menu; |
MENU_SET bbsnet_menu; |
| 57 |
|
|
| 58 |
fp = fopen(file_config, "r"); |
fp = fopen(file_config, "r"); |
| 59 |
if (fp == NULL) |
if (fp == NULL) |
| 60 |
|
{ |
| 61 |
return -1; |
return -1; |
| 62 |
|
} |
| 63 |
|
|
| 64 |
p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU)); |
p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU)); |
| 65 |
strcpy(p_menu->name, "BBSNET"); |
strncpy(p_menu->name, "BBSNET", sizeof(p_menu->name) - 1); |
| 66 |
|
p_menu->name[sizeof(p_menu->name) - 1] = '\0'; |
| 67 |
p_menu->title.show = 0; |
p_menu->title.show = 0; |
| 68 |
p_menu->screen.show = 0; |
p_menu->screen.show = 0; |
| 69 |
|
|
| 70 |
while (fgets(t, 255, fp) && item_count < MAXSTATION) |
while (fgets(t, 255, fp) && item_count < MAXSTATION) |
| 71 |
{ |
{ |
|
if (t[0] == '#' || t[0] == '*') |
|
|
{ |
|
|
continue; |
|
|
} |
|
|
|
|
| 72 |
t1 = strtok_r(t, " \t", &saveptr); |
t1 = strtok_r(t, " \t", &saveptr); |
| 73 |
t2 = strtok_r(NULL, " \t\n", &saveptr); |
t2 = strtok_r(NULL, " \t\n", &saveptr); |
| 74 |
t3 = strtok_r(NULL, " \t\n", &saveptr); |
t3 = strtok_r(NULL, " \t\n", &saveptr); |
| 75 |
t4 = strtok_r(NULL, " \t\n", &saveptr); |
t4 = strtok_r(NULL, " \t\n", &saveptr); |
| 76 |
|
|
| 77 |
if (t1 == NULL || t2 == NULL || t3 == NULL) |
if (t1 == NULL || t2 == NULL || t3 == NULL || t[0] == '#' || t[0] == '*') |
| 78 |
{ |
{ |
| 79 |
continue; |
continue; |
| 80 |
} |
} |
| 81 |
|
|
| 82 |
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); |
| 83 |
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'; |
| 84 |
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); |
| 85 |
bbsnet_conf[item_count].port = t4 ? atoi(t4) : 23; |
bbsnet_conf[item_count].host2[sizeof(bbsnet_conf[item_count].host2) - 1] = '\0'; |
| 86 |
|
strncpy(bbsnet_conf[item_count].ip, t3, sizeof(bbsnet_conf[item_count].ip) - 1); |
| 87 |
|
bbsnet_conf[item_count].ip[sizeof(bbsnet_conf[item_count].ip) - 1] = '\0'; |
| 88 |
|
bbsnet_conf[item_count].port = (in_port_t)(t4 ? atoi(t4) : 23); |
| 89 |
|
|
| 90 |
p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM)); |
p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM)); |
| 91 |
p_menuitem->row = 2 + item_count / STATION_PER_LINE; |
p_menuitem->row = 2 + item_count / STATION_PER_LINE; |
| 92 |
p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20; |
p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20; |
| 93 |
sprintf(p_menuitem->action, "%d", item_count); |
snprintf(p_menuitem->action, sizeof(p_menuitem->action), "%d", item_count); |
| 94 |
p_menuitem->submenu = 0; |
p_menuitem->submenu = 0; |
| 95 |
p_menuitem->priv = 0; |
p_menuitem->priv = 0; |
| 96 |
p_menuitem->level = 0; |
p_menuitem->level = 0; |
| 97 |
p_menuitem->display = 0; |
p_menuitem->display = 0; |
| 98 |
p_menuitem->name[0] = |
p_menuitem->name[0] = |
| 99 |
(item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count); |
(char)(item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count); |
| 100 |
p_menuitem->name[1] = '\0'; |
p_menuitem->name[1] = '\0'; |
| 101 |
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", |
| 102 |
p_menuitem->name[0], t2); |
p_menuitem->name[0], bbsnet_conf[item_count].host1); |
| 103 |
|
|
| 104 |
item_count++; |
item_count++; |
| 105 |
} |
} |
| 115 |
return 0; |
return 0; |
| 116 |
} |
} |
| 117 |
|
|
| 118 |
static void |
static void process_bar(int n, int len) |
|
process_bar(int n, int len) |
|
| 119 |
{ |
{ |
| 120 |
char buf[256]; |
char buf[256]; |
| 121 |
char buf2[256]; |
char buf2[256]; |
| 124 |
char *ptr3; |
char *ptr3; |
| 125 |
|
|
| 126 |
moveto(4, 0); |
moveto(4, 0); |
| 127 |
prints("┌──────────────────────────────┐\r\n"); |
prints(" ------------------------------ \r\n"); |
| 128 |
sprintf(buf2, " %3d%% ", n * 100 / len); |
snprintf(buf2, sizeof(buf2), " %3d%% ", n * 100 / len); |
| 129 |
ptr = buf; |
ptr = buf; |
| 130 |
ptr2 = buf2; |
ptr2 = buf2; |
| 131 |
ptr3 = buf + n; |
ptr3 = buf + n; |
| 139 |
while (*ptr2 != '\0') |
while (*ptr2 != '\0') |
| 140 |
*ptr++ = *ptr2++; |
*ptr++ = *ptr2++; |
| 141 |
*ptr++ = '\0'; |
*ptr++ = '\0'; |
| 142 |
prints("│\033[46m%s\033[m│\r\n", buf); |
prints("|\033[46m%s\033[m|\r\n", buf); |
| 143 |
prints("└──────────────────────────────┘\r\n"); |
prints(" ------------------------------ \r\n"); |
| 144 |
iflush(); |
iflush(); |
| 145 |
} |
} |
| 146 |
|
|
| 147 |
int bbsnet_connect(int n) |
int bbsnet_connect(int n) |
| 148 |
{ |
{ |
| 149 |
int sock, result, len, loop; |
int sock, result, loop; |
| 150 |
|
ssize_t len; |
| 151 |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
| 152 |
char buf[256]; |
char buf[256]; |
| 153 |
fd_set inputs, testfds; |
fd_set inputs, testfds; |
| 188 |
|
|
| 189 |
sin.sin_family = AF_INET; |
sin.sin_family = AF_INET; |
| 190 |
sin.sin_addr.s_addr = |
sin.sin_addr.s_addr = |
| 191 |
(strlen(hostaddr_server) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY); |
(strnlen(hostaddr_server, sizeof(hostaddr_server)) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY); |
| 192 |
sin.sin_port = 0; |
sin.sin_port = 0; |
| 193 |
|
|
| 194 |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
| 203 |
sin.sin_addr = *(struct in_addr *)pHost->h_addr_list[0]; |
sin.sin_addr = *(struct in_addr *)pHost->h_addr_list[0]; |
| 204 |
sin.sin_port = htons(bbsnet_conf[n].port); |
sin.sin_port = htons(bbsnet_conf[n].port); |
| 205 |
|
|
| 206 |
strcpy(remote_addr, inet_ntoa(sin.sin_addr)); |
strncpy(remote_addr, inet_ntoa(sin.sin_addr), sizeof(remote_addr) - 1); |
| 207 |
|
remote_addr[sizeof(remote_addr) - 1] = '\0'; |
| 208 |
remote_port = ntohs(sin.sin_port); |
remote_port = ntohs(sin.sin_port); |
| 209 |
|
|
| 210 |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n"); |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n"); |
| 225 |
continue; |
continue; |
| 226 |
} |
} |
| 227 |
else if (rv == 0) |
else if (rv == 0) |
| 228 |
|
{ |
| 229 |
break; |
break; |
| 230 |
|
} |
| 231 |
else |
else |
| 232 |
{ |
{ |
| 233 |
prints("\033[1;31m连接失败!\033[m\r\n"); |
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 284 |
{ |
{ |
| 285 |
loop = 0; |
loop = 0; |
| 286 |
} |
} |
| 287 |
write(sock, buf, len); |
write(sock, buf, (size_t)len); |
| 288 |
} |
} |
| 289 |
if (FD_ISSET(sock, &testfds)) |
if (FD_ISSET(sock, &testfds)) |
| 290 |
{ |
{ |
| 293 |
{ |
{ |
| 294 |
loop = 0; |
loop = 0; |
| 295 |
} |
} |
| 296 |
write(1, buf, len); |
write(1, buf, (size_t)len); |
| 297 |
} |
} |
| 298 |
BBS_last_access_tm = time(0); |
BBS_last_access_tm = time(0); |
| 299 |
} |
} |
| 317 |
static int |
static int |
| 318 |
bbsnet_refresh() |
bbsnet_refresh() |
| 319 |
{ |
{ |
|
int i; |
|
|
|
|
| 320 |
clearscr(); |
clearscr(); |
| 321 |
moveto(1, 0); |
moveto(1, 0); |
| 322 |
prints("╭═════════════════════════════════════════════════════════════════════════════╮"); |
prints(" ----------------------------------------------------------------------------- "); |
| 323 |
for (i = 2; i < 19; i++) |
for (int i = 2; i < 19; i++) |
| 324 |
{ |
{ |
| 325 |
moveto(i, 0); |
moveto(i, 0); |
| 326 |
prints("║"); |
prints("|"); |
| 327 |
moveto(i, 79); |
moveto(i, 79); |
| 328 |
prints("║"); |
prints("|"); |
| 329 |
} |
} |
| 330 |
moveto(19, 0); |
moveto(19, 0); |
| 331 |
prints("║—————————————————————————————————————————————————————————————————————————————║"); |
prints("|-----------------------------------------------------------------------------|"); |
| 332 |
moveto(22, 0); |
moveto(22, 0); |
| 333 |
prints("╰═════════════════════════════════════════════════════════════════════════════╯"); |
prints(" ----------------------------------------------------------------------------- "); |
| 334 |
moveto(23, 0); |
moveto(23, 0); |
| 335 |
prints(" [\x1b[1;32mCtrl+C\x1b[m]退出"); |
prints(" [\x1b[1;32mCtrl+C\x1b[m]退出"); |
| 336 |
|
|
| 343 |
{ |
{ |
| 344 |
moveto(20, 0); |
moveto(20, 0); |
| 345 |
clrtoeol(); |
clrtoeol(); |
| 346 |
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", |
| 347 |
bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1); |
bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1); |
| 348 |
moveto(20, 79); |
moveto(20, 79); |
| 349 |
prints("║"); |
prints("|"); |
| 350 |
moveto(21, 0); |
moveto(21, 0); |
| 351 |
clrtoeol(); |
clrtoeol(); |
| 352 |
prints("║\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip); |
prints("|\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip); |
| 353 |
if (bbsnet_conf[new_pos].port != 23) |
if (bbsnet_conf[new_pos].port != 23) |
| 354 |
|
{ |
| 355 |
prints(" %d", bbsnet_conf[new_pos].port); |
prints(" %d", bbsnet_conf[new_pos].port); |
| 356 |
|
} |
| 357 |
prints("\x1b[m"); |
prints("\x1b[m"); |
| 358 |
moveto(21, 79); |
moveto(21, 79); |
| 359 |
prints("║"); |
prints("|"); |
| 360 |
iflush(); |
iflush(); |
| 361 |
|
|
| 362 |
return 0; |
return 0; |
| 399 |
break; |
break; |
| 400 |
case KEY_UP: |
case KEY_UP: |
| 401 |
for (i = 0; i < STATION_PER_LINE; i++) |
for (i = 0; i < STATION_PER_LINE; i++) |
| 402 |
|
{ |
| 403 |
menu_control(&bbsnet_menu, KEY_UP); |
menu_control(&bbsnet_menu, KEY_UP); |
| 404 |
|
} |
| 405 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 406 |
bbsnet_selchange(pos); |
bbsnet_selchange(pos); |
| 407 |
break; |
break; |
| 408 |
case KEY_DOWN: |
case KEY_DOWN: |
| 409 |
for (i = 0; i < STATION_PER_LINE; i++) |
for (i = 0; i < STATION_PER_LINE; i++) |
| 410 |
|
{ |
| 411 |
menu_control(&bbsnet_menu, KEY_DOWN); |
menu_control(&bbsnet_menu, KEY_DOWN); |
| 412 |
|
} |
| 413 |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
pos = bbsnet_menu.p_menu[0]->item_cur_pos; |
| 414 |
bbsnet_selchange(pos); |
bbsnet_selchange(pos); |
| 415 |
break; |
break; |