Skip to content
Snippets Groups Projects
Commit 4b5633bd authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Support UTF-8 translation to CP437 and non 80x25 terminals

Reads the new(ish) node*/terminal.ini file when it's changed to determine
the connected-client's terminal type/dimensions. Now reports the terminal
details in the spy form title/caption and if it's UTF-8, does a real-time
translation to CP437 (since F. Piette's terminal lib only supports CP437).
There is a bug here where if the data read from the RingBuffer is a
partial UTF-8 sequence, it isn't decoded correctly. Fix that later (?) if it
actually bugs anyone.

There's no PETSCII conversion/support added here. I expect to someday replace
this entirely (likely with something that uses cterm), so didn't want to
invest too much time into this.

But at least now spying on non-traditional ANSI-BBS clients isn't so terrible
to look at.
parent e59a247c
No related branches found
No related tags found
No related merge requests found
Pipeline #5927 passed
/* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
/* $Id: NodeFormUnit.cpp,v 1.32 2020/04/30 18:28:50 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -15,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -334,6 +320,8 @@ void __fastcall TNodeForm::SpyButtonClick(TObject *Sender)
SpyForms[i]->inbuf=&MainForm->bbs_startup.node_inbuf[i];
SpyForms[i]->outbuf=&MainForm->bbs_startup.node_spybuf[i];
SpyForms[i]->Caption="Node "+AnsiString(i+1);
SpyForms[i]->NodeNum = i + 1;
SpyForms[i]->TerminalIniFile = AnsiString(MainForm->cfg.node_path[i]) + "/terminal.ini";
}
SpyForms[i]->Show();
}
......
/* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
/* $Id: SpyFormUnit.cpp,v 1.15 2020/04/15 05:37:36 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -15,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -39,6 +25,7 @@
#include "MainFormUnit.h"
#include "SpyFormUnit.h"
#include "telnet.h"
#include "str_util.h"
#define SPYBUF_LEN 10000
//---------------------------------------------------------------------------
......@@ -50,6 +37,7 @@ TSpyForm *SpyForm;
__fastcall TSpyForm::TSpyForm(TComponent* Owner)
: TForm(Owner)
{
IdleCount = 0;
Width=MainForm->SpyTerminalWidth;
Height=MainForm->SpyTerminalHeight;
Terminal = new TEmulVT(this);
......@@ -106,13 +94,42 @@ void __fastcall TSpyForm::SpyTimerTick(TObject *Sender)
if(*outbuf==NULL)
return;
rd=RingBufRead(*outbuf,buf,sizeof(buf));
if(rd) {
rd=RingBufRead(*outbuf,buf,sizeof(buf) - 1);
if(rd > 0) {
if(IdleCount >= 2) {
if(fdate(TerminalIniFile.c_str()) > terminal_fdate)
ReadTerminalIniFile();
}
rd=strip_telnet(buf,rd);
Terminal->WriteBuffer(buf,rd);
buf[rd] = 0;
if(utf8)
utf8_to_cp437_inplace(buf);
Terminal->WriteBuffer(buf, strlen(buf));
IdleCount = 0;
Timer->Interval=1;
} else
} else {
++IdleCount;
Timer->Interval=250;
}
}
//---------------------------------------------------------------------------
void __fastcall TSpyForm::ReadTerminalIniFile()
{
FILE* fp = iniOpenFile(TerminalIniFile.c_str(), /* for_modify: */FALSE);
if(fp != NULL) {
char type[128] = {0};
char chars[128] = {0};
iniReadString(fp, ROOT_SECTION, "type", /* default: */NULL, type);
iniReadString(fp, ROOT_SECTION, "chars", /* default: */NULL, chars);
Terminal->Cols = iniReadInteger(fp, ROOT_SECTION, "cols", 80);
Terminal->Rows = iniReadInteger(fp, ROOT_SECTION, "rows", 25);
fclose(fp);
utf8 = stricmp(chars, "UTF-8") == 0;
Caption = "Node " + AnsiString(NodeNum) + " ("
+ AnsiString(Terminal->Cols) + "x" + AnsiString(Terminal->Rows) + " "
+ chars + " / " + type + ")";
}
terminal_fdate = fdate(TerminalIniFile.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TSpyForm::FormShow(TObject *Sender)
......@@ -128,7 +145,8 @@ void __fastcall TSpyForm::FormShow(TObject *Sender)
Terminal->Font=MainForm->SpyTerminalFont;
Terminal->Clear();
Terminal->WriteStr("*** Synchronet Local Spy ***\r\n\r\n");
Terminal->WriteStr("ANSI Terminal Emulation:"+CopyRight+"\r\n\r\n");
ReadTerminalIniFile();
Terminal->WriteStr("ANSI Terminal Emulation:"+CopyRight+"\r\n\r\n");
KeyboardActive->Checked=!MainForm->SpyTerminalKeyboardActive;
KeyboardActiveClick(Sender);
......
/* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
/* $Id: SpyFormUnit.h,v 1.10 2018/07/24 01:11:29 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -15,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -75,10 +61,16 @@ __published: // IDE-managed Components
TShiftState Shift, int X, int Y);
private: // User declarations
int __fastcall strip_telnet(uchar *buf, int len);
time_t terminal_fdate;
void __fastcall ReadTerminalIniFile();
bool utf8;
public: // User declarations
TEmulVT* Terminal;
RingBuf** inbuf;
RingBuf** outbuf;
AnsiString TerminalIniFile;
int NodeNum;
unsigned long IdleCount;
__fastcall TSpyForm(TComponent* Owner);
__fastcall ~TSpyForm();
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment