📄 chwconn.cpp
字号:
if (!m_boolAnsiResetReceived)
{
/* The first time we get an ANSI
reset, switch all black objects
in the file to white */
GetTextOutput()->RemapColor( COLOR_BLACK,
COLOR_WHITE );
m_boolAnsiResetReceived = true;
}
m_ansiState.Reset( strCodeHTML );
break;
}
case 1: // High intensity
{
AnsiDisplay( "ANSI(bold)" );
m_ansiState.SetBold( true, strCodeHTML );
break;
}
case 2: // Low intensity
{
AnsiDisplay( "ANSI(nonbold)" );
m_ansiState.SetBold( false, strCodeHTML );
break;
}
case 3: // Italic
{
AnsiDisplay( "ANSI(italic)" );
m_ansiState.SetItalic( true, strCodeHTML );
break;
}
case 4: // Underline
{
AnsiDisplay( "ANSI(underline)" );
m_ansiState.SetUnderline( true, strCodeHTML );
break;
}
case 30: // Black foreground
{
AnsiDisplay( "ANSI(fg-black)" );
m_ansiState.SetForeColor( COLOR_BLACK, strCodeHTML );
break;
}
case 31: // Red foreground
{
AnsiDisplay( "ANSI(fg-red)" );
m_ansiState.SetForeColor( 0xff0000, strCodeHTML );
break;
}
case 32: // Green foreground
{
AnsiDisplay( "ANSI(fg-green)" );
m_ansiState.SetForeColor( 0x00ff00, strCodeHTML );
break;
}
case 33: // Yellow foreground
{
AnsiDisplay( "ANSI(fg-yellow)" );
m_ansiState.SetForeColor( 0xffff00, strCodeHTML );
break;
}
case 34: // Blue foreground
{
AnsiDisplay( "ANSI(fg-blue)" );
m_ansiState.SetForeColor( 0x0000ff, strCodeHTML );
break;
}
case 35: // Magenta foreground
{
AnsiDisplay( "ANSI(fg-magenta)" );
m_ansiState.SetForeColor( 0xff00ff, strCodeHTML );
break;
}
case 36: // Cyan foreground
{
AnsiDisplay( "ANSI(fg-cyan)" );
m_ansiState.SetForeColor( 0x00ffff, strCodeHTML );
break;
}
case 37: // White foreground
{
AnsiDisplay( "ANSI(fg-white)" );
m_ansiState.SetForeColor( COLOR_BRIGHT_WHITE,
strCodeHTML );
break;
}
case 40: // Black background
{
AnsiDisplay( "ANSI(bg-black)" );
m_ansiState.SetBackColor( COLOR_BLACK, strCodeHTML );
break;
}
case 41: // Red background
{
AnsiDisplay( "ANSI(bg-red)" );
m_ansiState.SetBackColor( 0xff0000, strCodeHTML );
break;
}
case 42: // Green background
{
AnsiDisplay( "ANSI(bg-green)" );
m_ansiState.SetBackColor( 0x00ff00, strCodeHTML );
break;
}
case 43: // Yellow background
{
AnsiDisplay( "ANSI(bg-yellow)" );
m_ansiState.SetBackColor( 0xffff00, strCodeHTML );
break;
}
case 44: // Blue background
{
AnsiDisplay( "ANSI(bg-blue)" );
m_ansiState.SetBackColor( 0x0000ff, strCodeHTML );
break;
}
case 45: // Magenta background
{
AnsiDisplay( "ANSI(bg-magenta)" );
m_ansiState.SetBackColor( 0xff00ff, strCodeHTML );
break;
}
case 46: // Cyan background
{
AnsiDisplay( "ANSI(bg-cyan)" );
m_ansiState.SetBackColor( 0x00ffff, strCodeHTML );
break;
}
case 47: // White background
{
AnsiDisplay( "ANSI(bg-white)" );
m_ansiState.SetBackColor( COLOR_BRIGHT_WHITE,
strCodeHTML );
break;
}
default:
{
break;
}
}
break;
}
case ANSI_ERASE:
{
switch( iCode )
{
case 2: // Clear display
{
AnsiDisplay( "ANSI(clear)" );
break;
}
default:
{
break;
}
}
break;
}
}
if (strCodeHTML.GetLength() > 0)
{
strOutput += strCodeHTML;
}
}
void ChWorldConn::TelnetSend( int iCommand, int iOption )
{
char cSequence[3];
cSequence[0] = (char)TN_IAC;
cSequence[1] = (char)iCommand;
cSequence[2] = (char)iOption;
SendBlock( cSequence, 3 );
#if defined( DUMP_TELNET_CODES )
{
string strSequence;
if (pstrTelnetLabel[iOption])
{
strSequence.Format( "sent IAC %s %s\n", pstrTelnetLabel[iCommand],
pstrTelnetLabel[iOption] );
}
else
{
strSequence.Format( "sent IAC %s %d\n", pstrTelnetLabel[iCommand],
iOption );
}
TelnetDisplay( strSequence );
}
#endif // defined( DUMP_TELNET_CODES )
}
void ChWorldConn::TelnetReceive( int iCommand, int iOption )
{
#if defined( DUMP_TELNET_CODES )
{
string strSequence;
if (pstrTelnetLabel[iOption])
{
strSequence.Format( "recv IAC %s %s\n", pstrTelnetLabel[iCommand],
pstrTelnetLabel[iOption] );
}
else
{
strSequence.Format( "recv IAC %s %d\n", pstrTelnetLabel[iCommand],
iOption );
}
TelnetDisplay( strSequence );
}
#endif // defined( DUMP_TELNET_CODES )
}
void ChWorldConn::DoTelnetCmd( int iCommand, int iOption )
{
/*
From RFC 854:
Telnet protocols always start with the IAC (255) character. Following
this character may be a number of bytes, but we only pay attention to
the following:
WILL 251
WON'T 252
DO 253
DON'T 254
These are commands, sent from one end to the other. They say that the
sender either WILL or WON'T do something, or that the receiver should
either DO or DON'T do something. The third byte indicates what should
be done. We currently pay attention to the following:
ECHO 1
TERMINAL_TYPE 24
Others are ignored.
*/
switch( iCommand )
{
case TN_WILL:
{
TelnetReceive( TN_WILL, iOption );
switch( iOption )
{
case TN_ECHO:
{
if (m_flTelnetState & telnetStateEcho)
{
// Stop local echo, and acknowledge
GetMainInfo()->SetEchoState( echoTelnetOff );
m_flTelnetState &= ~telnetStateEcho;
TelnetSend( TN_DO, TN_ECHO );
}
else
{
// We already said DO ECHO, so ignore WILL ECHO
}
break;
}
case TN_EOR_OPT:
{
if (!(m_flTelnetState & telnetStateEOR))
{
m_flTelnetState |= telnetStateEOR;
TelnetSend( TN_DO, TN_EOR_OPT );
}
else
{
// We already said DO EOR_OPT, so ignore WILL EOR_OPT
}
}
default:
{ // Don't accept other WILL offers
TelnetSend( TN_DONT, iOption );
break;
}
}
break;
}
case TN_WONT:
{
TelnetReceive( TN_WONT, iOption );
switch( iOption )
{
case TN_ECHO:
{
if (m_flTelnetState & telnetStateEcho)
{
// We're already echoing, so ignore WONT ECHO
}
else
{ // Resume local echo, and acknowledge
GetMainInfo()->SetEchoState( echoOn );
m_flTelnetState |= telnetStateEcho;
TelnetSend( TN_DONT, TN_ECHO );
}
break;
}
case TN_EOR_OPT:
{
if (!(m_flTelnetState & telnetStateEOR))
{
// We're in DONT EOR_OPT state, ignore WONT EOR_OPT
}
else
{ // Acknowledge
m_flTelnetState &= ~telnetStateEOR;
TelnetSend( TN_DONT, TN_EOR_OPT );
}
}
default:
{
break;
}
}
break;
}
case TN_DO:
{
TelnetReceive( TN_DO, iOption );
// Refuse all DO requests
TelnetSend( TN_WONT, iOption );
break;
}
case TN_DONT:
{
/* Ignore all DONT requests (we're
already in the DONT state) */
TelnetReceive( TN_DONT, iOption );
break;
}
default:
{
break;
}
}
}
void ChWorldConn::TranslateNewlinesToBreaks( string& strOut )
{
int iIndex;
iIndex = strOut.Find( '\n' );
if (-1 != iIndex)
{
string strReturn;
do
{
int iCopyChars = iIndex;
if ((iIndex > 0) && ('\r' == strOut[iIndex - 1]))
{
iCopyChars--;
}
strReturn += strOut.Left( iCopyChars ) + "<br>";
strOut = strOut.Mid( iIndex + 1 );
iIndex = strOut.Find( '\n' );
} while (-1 != iIndex);
// Append whatever's left
strReturn += strOut;
// Now return the processed string
strOut = strReturn;
}
}
void ChWorldConn::AddToTextBlock( const char* pstrData, int iDataLen,
bool boolEndOfLine )
{
int iOriginalLen = m_strCurrentLine.GetLength();
int iLen = iOriginalLen;
char* pstrCurrentLine;
iLen += iDataLen + 1;
pstrCurrentLine = m_strCurrentLine.GetBuffer( iLen );
pstrCurrentLine += iOriginalLen;
strncpy( pstrCurrentLine, pstrData, iDataLen );
pstrCurrentLine += iDataLen;
*pstrCurrentLine = 0;
m_strCurrentLine.ReleaseBuffer();
/* Process buffer on end-of-line or
on grossly large lines */
if (boolEndOfLine || (m_strCurrentLine.GetLength() > MAX_LINE_LEN))
{
OnTextLine( m_strCurrentLine );
m_strCurrentLine = "";
}
}
void ChWorldConn::OnTextLine( const string& strLine )
{
ChWorldMainInfo* pInfo = GetMainInfo();
string strWorking( strLine );
if (!IsPuebloEnhanced())
{ /* If we're not Pueblo Enhanced, we
keep hoping the world will tell
us that they are */
ChVersion ver;
if (pInfo->LookForPuebloEnhanced( strWorking, ver ))
{
// Yay! They are! Happy happy!
SetPuebloEnhanced( true, ver );
}
}
if (pInfo->WantTextLines())
{
if (IsPuebloEnhanced())
{
ChHtmlWnd::RemoveEntities( strWorking, strWorking );
}
// Process TinTin actions
pInfo->OnTextLine( strWorking );
}
}
void ChWorldConn::SetPuebloEnhanced( bool boolEnhanced,
const ChVersion& versEnhanced )
{
m_boolPuebloEnhanced = boolEnhanced;
if (m_boolPuebloEnhanced)
{
SetPuebloEnhancedVersion( versEnhanced );
}
}
// Local Variables: ***
// tab-width:4 ***
// End: ***
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -