|
|
1.1 ! root 1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */ ! 2: ! 3: /* $Id: SpyFormUnit.cpp,v 1.13 2003/05/10 03:19:03 rswindell Exp $ */ ! 4: ! 5: /**************************************************************************** ! 6: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 7: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 8: * * ! 9: * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html * ! 10: * * ! 11: * This program is free software; you can redistribute it and/or * ! 12: * modify it under the terms of the GNU General Public License * ! 13: * as published by the Free Software Foundation; either version 2 * ! 14: * of the License, or (at your option) any later version. * ! 15: * See the GNU General Public License for more details: gpl.txt or * ! 16: * http://www.fsf.org/copyleft/gpl.html * ! 17: * * ! 18: * Anonymous FTP access to the most recent released source is available at * ! 19: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 20: * * ! 21: * Anonymous CVS access to the development source and modification history * ! 22: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 23: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 24: * (just hit return, no password is necessary) * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 26: * * ! 27: * For Synchronet coding style and modification guidelines, see * ! 28: * http://www.synchro.net/source.html * ! 29: * * ! 30: * You are encouraged to submit any modifications (preferably in Unix diff * ! 31: * format) via e-mail to [email protected] * ! 32: * * ! 33: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 34: ****************************************************************************/ ! 35: ! 36: #include <vcl.h> ! 37: #pragma hdrstop ! 38: ! 39: #include "MainFormUnit.h" ! 40: #include "SpyFormUnit.h" ! 41: #include "telnet.h" ! 42: ! 43: #define SPYBUF_LEN 10000 ! 44: //--------------------------------------------------------------------------- ! 45: #pragma package(smart_init) ! 46: #pragma link "Emulvt" ! 47: #pragma resource "*.dfm" ! 48: TSpyForm *SpyForm; ! 49: //--------------------------------------------------------------------------- ! 50: __fastcall TSpyForm::TSpyForm(TComponent* Owner) ! 51: : TForm(Owner) ! 52: { ! 53: Width=MainForm->SpyTerminalWidth; ! 54: Height=MainForm->SpyTerminalHeight; ! 55: Terminal = new TEmulVT(this); ! 56: Terminal->Parent=this; ! 57: Terminal->Align=alClient; ! 58: Terminal->OnKeyPress=FormKeyPress; ! 59: Terminal->OnMouseUp=FormMouseUp; ! 60: Terminal->AutoWrap=true; ! 61: ActiveControl=Terminal; ! 62: } ! 63: //--------------------------------------------------------------------------- ! 64: __fastcall TSpyForm::~TSpyForm() ! 65: { ! 66: delete Terminal; ! 67: } ! 68: //--------------------------------------------------------------------------- ! 69: int __fastcall TSpyForm::strip_telnet(uchar *buf, int len) ! 70: { ! 71: int i; ! 72: int telnet_cmd=0; ! 73: int newlen=0; ! 74: ! 75: for(i=0;i<len;i++) { ! 76: if(buf[i]==FF) { ! 77: Terminal->Clear(); ! 78: continue; ! 79: } ! 80: if(buf[i]==TELNET_IAC || telnet_cmd) { ! 81: if(telnet_cmd==1 && buf[i]==TELNET_IAC) { ! 82: telnet_cmd=0; /* escape IAC */ ! 83: continue; ! 84: } ! 85: if(telnet_cmd==1 && buf[i]<TELNET_WILL) { ! 86: telnet_cmd=0; /* single byte command */ ! 87: continue; ! 88: } ! 89: if(telnet_cmd>=2) { ! 90: telnet_cmd=0; /* two byte command */ ! 91: continue; ! 92: } ! 93: telnet_cmd++; ! 94: continue; ! 95: } ! 96: buf[newlen++]=buf[i]; ! 97: } ! 98: return(newlen); ! 99: } ! 100: //--------------------------------------------------------------------------- ! 101: void __fastcall TSpyForm::SpyTimerTick(TObject *Sender) ! 102: { ! 103: uchar buf[1024]; ! 104: int rd; ! 105: ! 106: if(*outbuf==NULL) ! 107: return; ! 108: ! 109: rd=RingBufRead(*outbuf,buf,sizeof(buf)-1); ! 110: if(rd) { ! 111: rd=strip_telnet(buf,rd); ! 112: Terminal->WriteBuffer(buf,rd); ! 113: Timer->Interval=1; ! 114: } else ! 115: Timer->Interval=250; ! 116: } ! 117: //--------------------------------------------------------------------------- ! 118: void __fastcall TSpyForm::FormShow(TObject *Sender) ! 119: { ! 120: if((*outbuf=(RingBuf*)malloc(sizeof(RingBuf)))==NULL) { ! 121: Terminal->WriteStr("Malloc failure!"); ! 122: return; ! 123: } ! 124: RingBufInit(*outbuf,SPYBUF_LEN); ! 125: ! 126: Timer->Enabled=true; ! 127: ! 128: Terminal->Font=MainForm->SpyTerminalFont; ! 129: Terminal->Clear(); ! 130: Terminal->WriteStr("*** Synchronet Local Spy ***\r\n\r\n"); ! 131: Terminal->WriteStr("ANSI Terminal Emulation:"+CopyRight+"\r\n\r\n"); ! 132: ! 133: KeyboardActive->Checked=!MainForm->SpyTerminalKeyboardActive; ! 134: KeyboardActiveClick(Sender); ! 135: } ! 136: //--------------------------------------------------------------------------- ! 137: ! 138: void __fastcall TSpyForm::FormClose(TObject *Sender, TCloseAction &Action) ! 139: { ! 140: Timer->Enabled=false; ! 141: if(*outbuf!=NULL) { ! 142: RingBufDispose(*outbuf); ! 143: free(*outbuf); ! 144: *outbuf=NULL; ! 145: } ! 146: MainForm->SpyTerminalWidth=Width; ! 147: MainForm->SpyTerminalHeight=Height; ! 148: MainForm->SpyTerminalKeyboardActive=KeyboardActive->Checked; ! 149: } ! 150: //--------------------------------------------------------------------------- ! 151: ! 152: void __fastcall TSpyForm::ChangeFontClick(TObject *Sender) ! 153: { ! 154: TFontDialog *FontDialog=new TFontDialog(this); ! 155: ! 156: FontDialog->Font=MainForm->SpyTerminalFont; ! 157: FontDialog->Execute(); ! 158: MainForm->SpyTerminalFont->Assign(FontDialog->Font); ! 159: Terminal->Font=MainForm->SpyTerminalFont; ! 160: delete FontDialog; ! 161: Terminal->UpdateScreen(); ! 162: } ! 163: //--------------------------------------------------------------------------- ! 164: ! 165: void __fastcall TSpyForm::FormKeyPress(TObject *Sender, char &Key) ! 166: { ! 167: if(KeyboardActive->Checked && inbuf!=NULL && *inbuf!=NULL) ! 168: RingBufWrite(*inbuf,&Key,1); ! 169: ! 170: } ! 171: //--------------------------------------------------------------------------- ! 172: ! 173: void __fastcall TSpyForm::KeyboardActiveClick(TObject *Sender) ! 174: { ! 175: KeyboardActive->Checked=!KeyboardActive->Checked; ! 176: if(KeyboardActive->Checked) ! 177: Terminal->Cursor=crIBeam; ! 178: else ! 179: Terminal->Cursor=crDefault; ! 180: } ! 181: //--------------------------------------------------------------------------- ! 182: ! 183: void __fastcall TSpyForm::FormMouseUp(TObject *Sender, TMouseButton Button, ! 184: TShiftState Shift, int X, int Y) ! 185: { ! 186: if(Button==mbRight) ! 187: PopupMenu->Popup(ClientOrigin.x+X,ClientOrigin.y+Y); ! 188: } ! 189: //--------------------------------------------------------------------------- ! 190: ! 191:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.