Skip to content
Snippets Groups Projects
term.c 36 KiB
Newer Older
deuce's avatar
deuce committed

			if(j!=-1 && fpick.files>=1)
				loadfont(fpick.selected[0]);
			filepick_free(&fpick);
		}
		else
			setfont(i,FALSE);
	uifcbail();
	puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf);
	window(txtinfo.winleft,txtinfo.wintop,txtinfo.winright,txtinfo.winbottom);
	textattr(txtinfo.attribute);
	gotoxy(txtinfo.curx,txtinfo.cury);
}

void capture_control(struct bbslist *bbs)
{
	char *buf;
	struct	text_info txtinfo;
	int i,j;

	if(safe_mode)
		return;
   	gettextinfo(&txtinfo);
	buf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2);
	gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf);
	init_uifc(FALSE, FALSE);

	if(!cterm.log) {
		struct file_pick fpick;
		char *opts[3]={
						 "ASCII"
						,"Raw"
						,""
					  };

		i=0;
		uifc.helpbuf="`Capture Type`\n\n"
					"~ ASCII ~ Strips out ANSI sequences\n"
					"~ Raw ~   Leaves ANSI sequences in\n\n"
					"Raw is usefull for stealing ANSI screens from other systems.\n"
					"Don't do that though.  :-)";
		if(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,NULL,"Capture Type",opts)!=-1) {
			j=filepick(&uifc, "Capture File", &fpick, bbs->dldir, NULL, UIFC_FP_ALLOWENTRY);

				cterm_openlog(fpick.selected[0], i?CTERM_LOG_RAW:CTERM_LOG_ASCII);
			filepick_free(&fpick);
		}
	}
	else {
		if(cterm.log & CTERM_LOG_PAUSED) {
			char *opts[3]={
							 "Unpause"
							,"Close"
						  };
			i=0;
			uifc.helpbuf="`Capture Control`\n\n"
						"~ Unpause ~ Continues logging\n"
						"~ Close ~   Closes the log\n\n";
			if(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,NULL,"Capture Control",opts)!=-1) {
				switch(i) {
					case 0:
						cterm.log=cterm.log & CTERM_LOG_MASK;
						break;
					case 1:
						cterm_closelog();
						break;
				}
			}
		}
		else {
			char *opts[3]={
							 "Pause"
							,"Close"
						  };
			i=0;
			uifc.helpbuf="`Capture Control`\n\n"
						"~ Pause ~ Suspends logging\n"
						"~ Close ~ Closes the log\n\n";
			if(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,NULL,"Capture Control",opts)!=-1) {
				switch(i) {
					case 0:
						cterm.log=cterm.log |= CTERM_LOG_PAUSED;
						break;
					case 1:
						cterm_closelog();
						break;
				}
			}
		}
	}
	uifcbail();
	puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf);
	window(txtinfo.winleft,txtinfo.wintop,txtinfo.winright,txtinfo.winbottom);
	textattr(txtinfo.attribute);
	gotoxy(txtinfo.curx,txtinfo.cury);
}

BOOL doterm(struct bbslist *bbs)
#ifdef GUTS_BUILTIN
	unsigned char prn[1024];
#else
deuce's avatar
deuce committed
	unsigned char prn[BUFSIZE];
	unsigned char *p;
	BYTE zrqinit[] = { ZDLE, ZHEX, '0', '0', 0 };	/* for Zmodem auto-downloads */
	BYTE zrinit[] = { ZDLE, ZHEX, '0', '1', 0 };	/* for Zmodem auto-uploads */
#ifdef GUTS_BUILTIN
	BYTE gutsinit[] = { ESC, '[', '{' };	/* For GUTS auto-transfers */
	BYTE gutsbuf[3];
#endif
deuce's avatar
deuce committed
	long double nextchar=0;
	long double lastchar=0;
	long double thischar=0;
deuce's avatar
deuce committed
	int	oldmc;
	int	updated=FALSE;
deuce's avatar
deuce committed
	BOOL	sleep;
deuce's avatar
deuce committed
	speed = bbs->bpsrate;
	log_level = bbs->xfer_loglevel;
	telnet_log_level = bbs->telnet_loglevel;
	ciomouse_setevents(0);
	ciomouse_addevent(CIOLIB_BUTTON_1_DRAG_START);
	ciomouse_addevent(CIOLIB_BUTTON_1_DRAG_MOVE);
	ciomouse_addevent(CIOLIB_BUTTON_1_DRAG_END);
	ciomouse_addevent(CIOLIB_BUTTON_3_CLICK);
	ciomouse_addevent(CIOLIB_BUTTON_2_CLICK);
deuce's avatar
deuce committed
	if(scrollback_buf != NULL)
		memset(scrollback_buf,0,term.width*2*settings.backlines);
	cterm_init(term.height,term.width,term.x-1,term.y-1,settings.backlines,scrollback_buf);
	cterm.music_enable=bbs->music;
	zrqbuf[0]=0;
#ifdef GUTS_BUILTIN
	gutsbuf[0]=0;
#endif
deuce's avatar
deuce committed
	oldmc=hold_update;
	showmouse();
deuce's avatar
deuce committed
		hold_update=TRUE;
deuce's avatar
deuce committed
		if(!speed && bbs->bpsrate)
			speed = bbs->bpsrate;
		while(data_waiting(NULL, 0)) {
			if(!speed || thischar < lastchar /* Wrapped */ || thischar >= nextchar) {
				/* Get remote input */
				inch=recv_byte(NULL, 0);

				if(!term.nostatus)
					update_status(bbs, speed);
				switch(inch) {
					case -1:
						if(!is_connected(NULL)) {
							uifcmsg("Disconnected","`Disconnected`\n\nRemote host dropped connection");
							cterm_write("\x0c",1,NULL,0,NULL);	/* Clear screen into scrollback */
							scrollback_lines=cterm.backpos;
							cterm_end();
							conn_close();
							hidemouse();
							return(FALSE);
						}
						break;
					default:
						if(speed) {
							lastchar = xp_timer();
							nextchar = lastchar + 1/(long double)(speed/10);
						}

#ifdef GUTS_BUILTIN
						if(!gutsbuf[0]) {
							if(inch == gutsinit[0]) {
								gutsbuf[0]=inch;
								gutsbuf[1]=0;
								continue;
							}
						else {		/* Already have the start of the sequence */
							j=strlen(gutsbuf);
							if(inch == gutsinit[j]) {
								gutsbuf[j]=inch;
								gutsbuf[++j]=0;
								if(j==sizeof(gutsinit)) /* Have full sequence */
									guts_transfer(bbs);
							}
							else {
								gutsbuf[j++]=inch;
								cterm_write(gutsbuf, j, prn, sizeof(prn), &speed);
								if(prn[0])
									conn_send(prn,strlen(prn),0);
								updated=TRUE;
								gutsbuf[0]=0;
							}
							continue;
						if(!zrqbuf[0]) {
							if(inch == zrqinit[0] || inch == zrinit[0]) {
								zrqbuf[0]=inch;
								zrqbuf[1]=0;
								continue;
							}
						else {	/* Already have the start of the sequence */
							j=strlen(zrqbuf);
							if(inch == zrqinit[j] || inch == zrinit[j]) {
								zrqbuf[j]=inch;
								zrqbuf[++j]=0;
								if(j==sizeof(zrqinit)-1) {	/* Have full sequence (Assumes zrinit and zrqinit are same length */
									if(!strcmp(zrqbuf, zrqinit))
										zmodem_download(bbs);
									else
										begin_upload(bbs, TRUE);
									zrqbuf[0]=0;
								}
							}
							else {	/* Not a real zrqinit */
								zrqbuf[j++]=inch;
								cterm_write(zrqbuf, j, prn, sizeof(prn), &speed);
								if(prn[0])
									conn_send(prn,strlen(prn),0);
								updated=TRUE;
						ch[0]=inch;
						cterm_write(ch, 1, prn, sizeof(prn), &speed);
						if(prn[0])
							conn_send(prn, strlen(prn), 0);
						updated=TRUE;
						continue;
				}
			}
			else if (speed) {
				sleep=FALSE;
				break;
deuce's avatar
deuce committed
		hold_update=oldmc;
deuce's avatar
deuce committed
		if(updated && sleep)
deuce's avatar
deuce committed
			gotoxy(wherex(), wherey());
		while(kbhit()) {
deuce's avatar
deuce committed
			struct mouse_event mevent;
deuce's avatar
deuce committed
			updated=TRUE;
			gotoxy(wherex(), wherey());
			if(key==0 || key==0xff)
				key|=getch()<<8;
				case CIO_KEY_MOUSE:
					getmouse(&mevent);
					switch(mevent.event) {
						case CIOLIB_BUTTON_1_DRAG_START:
deuce's avatar
deuce committed
							mousedrag(scrollback_buf);
						case CIOLIB_BUTTON_2_CLICK:
						case CIOLIB_BUTTON_3_CLICK:
							p=getcliptext();
							if(p!=NULL) {
								conn_send(p,strlen(p),0);
								free(p);
							}
					}

					break;
				case CIO_KEY_LEFT:
					conn_send("\033[D",3,0);
					break;
				case CIO_KEY_RIGHT:
					conn_send("\033[C",3,0);
					break;
				case CIO_KEY_UP:
					conn_send("\033[A",3,0);
					break;
				case CIO_KEY_DOWN:
					conn_send("\033[B",3,0);
					break;
				case CIO_KEY_HOME:
					conn_send("\033[H",3,0);
					break;
				case CIO_KEY_END:
				case CIO_KEY_SELECT:	/* Some terminfo/termcap entries use KEY_SELECT as the END key! */
				case CIO_KEY_DC:		/* "Delete" key, send ASCII 127 (DEL) */
					conn_send("\x7f",1,0);
					break;
				case CIO_KEY_NPAGE:		/* Page down */
					conn_send("\033[U",3,0);
					break;
				case CIO_KEY_PPAGE:	/* Page up */
					conn_send("\033[V",3,0);
					break;
				case CIO_KEY_F(1):
					conn_send("\033OP",3,0);
					break;
				case CIO_KEY_F(2):
					conn_send("\033OQ",3,0);
					break;
				case CIO_KEY_F(3):
					conn_send("\033OR",3,0);
					conn_send("\033OS",3,0);
					break;
				case CIO_KEY_F(5):
					conn_send("\033Ot",3,0);
					break;
				case CIO_KEY_F(6):
					conn_send("\033[17~",5,0);
					break;
				case CIO_KEY_F(7):
					conn_send("\033[18~",5,0);
					break;
				case CIO_KEY_F(8):
					conn_send("\033[19~",5,0);
					break;
				case CIO_KEY_F(9):
					conn_send("\033[20~",5,0);
					break;
				case CIO_KEY_F(10):
					conn_send("\033[21~",5,0);
					break;
				case CIO_KEY_F(11):
					conn_send("\033[23~",5,0);
					break;
				case CIO_KEY_F(12):
					conn_send("\033[24~",5,0);
					break;
				case CIO_KEY_IC:
					conn_send("\033[@",3,0);
				case 0x3000:	/* ALT-B - Scrollback */
					viewscroll();
					showmouse();
					break;
				case 0x2e00:	/* ALT-C - Capture */
					capture_control(bbs);
					showmouse();
					break;
				case 0x2000:	/* ALT-D - Download */
					showmouse();
				case 0x2100:	/* ALT-F */
					font_control(bbs);
					showmouse();
				case 0x2600:	/* ALT-L */
					conn_send(bbs->user,strlen(bbs->user),0);
					conn_send("\r",1,0);
					SLEEP(10);
					conn_send(bbs->password,strlen(bbs->password),0);
					conn_send("\r",1,0);
					if(bbs->syspass[0]) {
						SLEEP(10);
						conn_send(bbs->syspass,strlen(bbs->syspass),0);
						conn_send("\r",1,0);
					}
deuce's avatar
deuce committed
				case 0x3200:	/* ALT-M */
					music_control(bbs);
					showmouse();
deuce's avatar
deuce committed
					break;
				case 0x1600:	/* ALT-U - Upload */
					showmouse();
deuce's avatar
deuce committed
				case 17:		/* CTRL-Q */
					if(cio_api.mode!=CIOLIB_MODE_CURSES
							&& cio_api.mode!=CIOLIB_MODE_CURSES_IBM
							&& cio_api.mode!=CIOLIB_MODE_ANSI) {
						ch[0]=key;
						conn_send(ch,1,0);
						break;
					}
					/* FALLTHROUGH for curses/ansi modes */
				case 0x2d00:	/* Alt-X - Exit */
				case 0x2300:	/* Alt-H - Hangup */
deuce's avatar
deuce committed
					{
						char *opts[3]={
										 "Yes"
										,"No"
										,""
									  };
						char *buf;
						struct	text_info txtinfo;

    					gettextinfo(&txtinfo);
						buf=(char *)alloca(txtinfo.screenheight*txtinfo.screenwidth*2);
deuce's avatar
deuce committed
						gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf);
						i=0;
deuce's avatar
deuce committed
						if(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,NULL,"Disconnect... Are you sure?",opts)==0) {
							uifcbail();
							cterm_write("\x0c",1,NULL,0,NULL);	/* Clear screen into scrollback */
							scrollback_lines=cterm.backpos;
deuce's avatar
deuce committed
							cterm_end();
							conn_close();
							hidemouse();
							return(key==0x2d00 /* Alt-X? */);
deuce's avatar
deuce committed
						}
						uifcbail();
						puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,buf);
						window(txtinfo.winleft,txtinfo.wintop,txtinfo.winright,txtinfo.winbottom);
						textattr(txtinfo.attribute);
						gotoxy(txtinfo.curx,txtinfo.cury);
						showmouse();
deuce's avatar
deuce committed
					}
					break;
					if(cio_api.mode!=CIOLIB_MODE_CURSES
							&& cio_api.mode!=CIOLIB_MODE_CURSES_IBM
							&& cio_api.mode!=CIOLIB_MODE_ANSI) {
						ch[0]=key;
						conn_send(ch,1,0);
						break;
					}
					/* FALLTHROUGH for curses/ansi modes */
				case 0x2c00:		/* ALT-Z */
					switch(syncmenu(bbs, &speed)) {
							cterm_write("\x0c",1,NULL,0,NULL);	/* Clear screen into scrollback */
							scrollback_lines=cterm.backpos;
							conn_close();
							hidemouse();
							return(FALSE);
						case 3:
							capture_control(bbs);
							break;
						case 8:
deuce's avatar
deuce committed
							music_control(bbs);
							break;
						case 9:
							cterm_write("\x0c",1,NULL,0,NULL);	/* Clear screen into scrollback */
							scrollback_lines=cterm.backpos;
							cterm_end();
							conn_close();
							hidemouse();
					showmouse();
				case 0x9800:	/* ALT-Up */
					if(speed)
						speed=rates[get_rate_num(speed)+1];
					else
						speed=rates[0];
					break;
				case 0xa000:	/* ALT-Down */
					i=get_rate_num(speed);
					if(i==0)
						speed=0;
					else
						speed=rates[i-1];
					break;
				case '\b':
					key='\b';
					/* FALLTHROUGH to default */
				default:
					if(key<256) {
						ch[0]=key;
						conn_send(ch,1,0);
deuce's avatar
deuce committed
		if(sleep)
deuce's avatar
deuce committed
			SLEEP(1);
		else
			MAYBE_YIELD();
deuce's avatar
deuce committed
/*
	hidemouse();
	return(FALSE);
deuce's avatar
deuce committed
 */