主要修改有原来默认支持72个穿梭站点,修改后可以是无限个:)(不过不划算):P
修改#define MAXBBSNET ????即可改变穿梭数
目前白山使用的穿梭程序,希望大家多太意见
下在地址:
http://bbs.neu.edu.cn/bbsnet.c.gz/*bbsnet.c*/
// NJU bbsnet, preview version, zhch@dii.nju.edu.cn, 2000.3.23 //
// HIT bbsnet, Changed by Sunner, sun@bbs.hit.edu.cn, 2000.6.11
/* Telnet for FB3.0, zhch.bbs@bbs.nju.edu.cn, NJU Lily BBS, Dec 12, 2000
*/
// NEU bbsnet, Changed By ELM, elm@21cn.edu.cn, 2002.04.30
#include <stdio.h>
#include <termios.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
//#include <termio.h>
#include <fcntl.h>
#include <signal.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/telnet.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <math.h>
#include "bbs.h"
#define MAXBBSNET 250
char host1[MAXBBSNET][40], host2[MAXBBSNET][40], ip[MAXBBSNET][40];
int port[MAXBBSNET], counts= 0;
char str[]=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char datafile[80]= BBSHOME"/etc/bbsnet.ini";
char userid[80]= "unknown.";
init_data() {
FILE *fp;
char t[256], *t1, *t2, *t3, *t4;
fp= fopen(datafile, "r");
if(fp== NULL) return;
while(fgets(t, 255, fp)&& counts < MAXBBSNET) {
t1= strtok(t, " \t");
t2= strtok(NULL, " \t\n");
t3= strtok(NULL, " \t\n");
t4= strtok(NULL, " \t\n");
if(t1[0]== '#'|| t1== NULL|| t2== NULL|| t3== NULL) continue;
strncpy(host1[counts], t1, 16);
strncpy(host2[counts], t2, 36);
strncpy(ip[counts], t3, 36);
port[counts]= t4? atoi(t4): 23;
counts++;
}
fclose(fp);
}
sh(int n) {
static oldn= -1;
if(n>= counts) return;
if(oldn >=0 && (oldn/100)==(n/100)) {
locate(oldn%100);
printf(";32m %c.m%s", str[oldn%62], host2[oldn]);
}
else
show_all(n);
oldn= n;
printf("3;3H;37m单位: ;33m%s 3;
23H;37m 站名: ;33m%s \r\n", host1[n],
host2[n]);
printf(";37m3;41H连往: ;33m%-20.20s1;1H", ip[n]);
locate(n%100);
printf("[%c];42m%sm", str[n%62], host2[n]);
}
show_all(int p) {
int n;
printf("HJm");
printf( "┏━━━━━━━━━━━━━┫;35m白山黑水 ◇ 网路连线
m┣━━━━━━━━━━━━━┓\r\n");
for(n= 1; n< 20; n++){
printf("┃
┃\r\n");
}
printf("1;0H┃
┃\r\n");
printf( "2;0H┠─────────────────────────
─────────────┨\r\n");
printf("┃
;36m按;33mCtrl+C;36m退出m┃\r\n");
printf( "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━┛");
for(n= 0; ( (n< 100) && (n < counts-(p/100)*100)); n++) {
locate(n);
printf(";32m %c.m%s", str[((p/100)*100+n)%62],
host2[(p/100)*100+n]);
}
scroll(p);
}
locate(int n) {
int x, y;
char buf[20];
if(n>= counts) return;
y= n/5 + 2;
x= n % 5 * 15+ 4;
sprintf(buf, "%d;%dH", y, x);
printf(buf);
}
int getch()
{
int c, d, e;
static lastc= 0;
c= getchar();
if(c== 10&& lastc== 13) c=getchar();
lastc= c;
if(c!= 27) return c;
d= getchar();
e= getchar();
if(d== 27) return 27;
if(e== 'A') return 257;
if(e== 'B') return 258;
if(e== 'C') return 259;
if(e== 'D') return 260;
return 0;
}
void QuitTime()
{
reset_tty();
exit(0);
}
void SetQuitTime()
{
signal(SIGALRM, QuitTime);
alarm(60);
}
static void break_check() {
int i, result;
unsigned char buf[2048];
struct timeval tv;
fd_set readfds;
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&readfds) ;
FD_SET(0, &readfds);
result = select(1, &readfds, NULL, NULL, &tv);
if (FD_ISSET(0, &readfds)) {
result = read(0, buf, 80);
for(i=0; i<result; i++){
if(buf[i]==3 || buf[i]==4) {
printf("\r\nBreak\r\n");
QuitTime(0);
}
}
}
alarm(1);
}
main_loop() {
int p= 0;
int c, n;
L:
show_all(p);
sh(p);
fflush(stdout);
while(1) {
c= getch();
alarm(60);
if(c== 3|| c== 4|| c== 27|| c< 0) break;
if(c== 257) //向上
{
if (p < 5){
p += 5 * ( (counts -1)/5 - (p > ((counts -1)%5)));
} else p -= 5;
}
if(c== 258) //向下
{
if (p+5 > counts - 1) p %= 5;
else p += 5;
}
if(c== 259) //向右
{
p ++;
if(p > counts - 1) p = 0;
}
if(c== 260) //向左
{
p --;
if(p<0)p = counts -1;
}
if(c== 13|| c== 10) {
alarm(0);
bbsnet(p);
SetQuitTime();
goto L;
}
for(n=p+1; n< counts; n++) if(str[n%62]==c) {p= n; goto D; }
for(n=0; n< p+1; n++) if(str[n%62]== c) p= n;
D: sh(p);
fflush(stdout);
}
}
bbsnet(int n) {
if(n>= counts) return;
printf("HJ;32mo 连往: %s (%s)\r\n", host2[n], ip[n]);
printf("%s\r\n\r\nm", "o 连不上时请按 \'Ctrl+C\' 退出");
fflush(stdout);
telnet(host2[n],ip[n], port[n]);
}
main(int n, char* cmd[]) {
SetQuitTime();
get_tty();
init_tty();
if(n>= 2) strcpy(datafile, cmd[1]);
if(n>= 3) strcpy(userid, cmd[2]);
init_data();
main_loop();
printf("m");
reset_tty();
}
syslog(char* s) {
char buf[512], timestr[16], *thetime;
time_t dtime;
FILE *fp;
fp=fopen("reclog/bbsnet.log", "a");
if(!fp) return ;
time(&dtime);
thetime = (char*) ctime(&dtime);
strncpy(timestr, &(thetime[4]), 15);
timestr[15] = '\0';
sprintf(buf,"%s %s %s\n", userid, timestr, s) ;
fprintf(fp, buf);
fclose(fp);
}
#define stty(fd, data) tcsetattr( fd, TCSANOW, data )
#define gtty(fd, data) tcgetattr( fd, data )
struct termios tty_state, tty_new ;
get_tty()
{
if(gtty(1,&tty_state) < 0) return 0;
return 1 ;
}
init_tty()
{
long vdisable;
memcpy( &tty_new, &tty_state, sizeof(tty_new)) ;
tty_new.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ISIG);
tty_new.c_cflag &= ~CSIZE;
tty_new.c_cflag |= CS8;
tty_new.c_cc[ VMIN ] = 1;
tty_new.c_cc[ VTIME ] = 0;
if ((vdisable = fpathconf(STDIN_FILENO, _PC_VDISABLE)) >= 0) {
tty_new.c_cc[VSTART] = vdisable;
tty_new.c_cc[VSTOP] = vdisable;
tty_new.c_cc[VLNEXT] = vdisable;
}
tcsetattr(1, TCSANOW, &tty_new);
}
reset_tty()
{
stty(1,&tty_state) ;
}
telnet(char *hostname, char *server,int port)
{
int fd;
struct sockaddr_in blah;
struct hostent *he;
fd_set readfds;
struct timeval tv;
int result;
unsigned char buf[2048];
signal(SIGALRM, break_check);
alarm(1);
bzero((char *)&blah,sizeof(blah));
blah.sin_family=AF_INET;
blah.sin_addr.s_addr=inet_addr(server);
blah.sin_port=htons(port);
printf("正连接 %s,请稍候 ... \r\n", server);
fflush(stdout);
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if ((he = gethostbyname(server)) != NULL)
bcopy(he->h_addr, (char *)&blah.sin_addr, he->h_length);
else
if ((blah.sin_addr.s_addr = inet_addr(server)) < 0) return;
if(connect(fd,(struct sockaddr *)&blah,16)<0) return;
signal(SIGALRM, SIG_IGN);
sprintf(buf, "%s (%s)", hostname, server);
syslog(buf);
printf("已连上主机,按 \'Ctrl+]\' 快速退出。\r\n\r\n");
fflush(stdout);
while(1) {
tv.tv_sec = 2400;
tv.tv_usec = 0;
FD_ZERO(&readfds) ;
FD_SET(fd,&readfds);
FD_SET(0,&readfds);
result = select(fd + 1,&readfds,NULL,NULL,&tv);
if (result <= 0) break;
if (FD_ISSET(0,&readfds)) {
result = read(0,buf,2048);
if (result<=0) break;
if(result==1&&(buf[0]==10||buf[0]==13)){
buf[0]=13;
buf[1]=10;
result=2;
}
if(buf[0]==29){close(fd);return;}
write(fd,buf,result);
} else {
result=read(fd,buf,2048);
if (result<=0) break;
if(strchr(buf, 255)) telnetopt(fd, buf,result);
else write(0,buf,result);
}
}
}
int telnetopt(int fd, unsigned char *buf, int max) {
unsigned char c2, c3;
int i;
unsigned char tmp[30];
for(i=0; i<max; i++) {
if(buf[i]!=255) {
write(0, &buf[i], 1);
continue;
}
c2=buf[i+1];
c3=buf[i+2];
i+=2;
if(c2==253 && (c3==3 || c3==24)) {
sprintf(tmp, "%c%c%c", 255, 251, c3);
write(fd, tmp, 3);
continue;
}
if((c2==251 || c2==252) && (c3==1 || c3==3 || c3==24)) {
sprintf(tmp, "%c%c%c", 255, 253, c3);
write(fd, tmp, 3);
continue;
}
if(c2==251 || c2==252) {
sprintf(tmp, "%c%c%c", 255, 254, c3);
write(fd, tmp, 3);
continue;
}
if(c2==253 || c2==254) {
sprintf(tmp, "%c%c%c", 255, 252, c3);
write(fd, tmp, 3);
continue;
}
if(c2==250) {
while(c3!=240 && i<max) {
c3=buf[i];
i++;
}
sprintf(tmp, "%c%c%c%c%c%c%c%c%c%c",
255, 250, 24, 0, 65, 78, 83, 73 , 255, 240);
write(fd, tmp, 10);
}
}
fflush(stdout);
}
scroll(int p)
{
int num,i,min,max;
num = (counts < 100) ? 20 : (20 * (100. / counts));
for (i=0;i<20; i++) {
min = (p/100)*num;
max = (((p/100 + 1)*num)>20) ? 20: (p/100 + 1) * num;
printf("%d;78H%dm m",i+2,(i <= max && i >= min)? 43:42);
}
}
--
FROM ELM.neu.edu.cn