mudwindow.cpp
来自「MudMaster 2000 的C++源码」· C++ 代码 · 共 838 行 · 第 1/2 页
CPP
838 行
case 32 : // Green
wAttr = F_GREEN;
break;
case 33 : // Brown
wAttr = F_BROWN;
break;
case 34 : // Blue
wAttr = F_BLUE;
break;
case 35 : // Magenta
wAttr = F_MAGENTA;
break;
case 36 : // Cyan
wAttr = F_CYAN;
break;
case 37 : // Light Grey
wAttr = F_LIGHTGREY;
break;
} // Switch
if (m_bBold)
wAttr |= FOREGROUND_INTENSITY;
_nForeColor = wAttr;
m_nCurrentColor = _nForeColor | _nBackColor;
} // if >= 30 && <= 37
else
if (nValue >= 40 && nValue <= 47)
{
switch(nValue)
{
case 40 : // Black
wAttr = B_BLACK;
break;
case 41 : // Red
wAttr = B_RED;
break;
case 42 : // Green
wAttr = B_GREEN;
break;
case 43 : // Brown
wAttr = B_BROWN;
break;
case 44 : // Blue
wAttr = B_BLUE;
break;
case 45 : // Magenta
wAttr = B_MAGENTA;
break;
case 46 : // Cyan
wAttr = B_CYAN;
break;
case 47 : // Light Grey
wAttr = B_LIGHTGREY;
break;
} // switch
_nBackColor = wAttr;
m_nCurrentColor = _nForeColor | _nBackColor;
} // if >= 40 && <= 47
}
ptrToken = strtok(NULL,";");
} // ptrToken != NULL
}
void CMudWindow::Scroll()
{
SMALL_RECT rScroll;
rScroll.Top = 1;
rScroll.Left = 0;
rScroll.Right = 79;
rScroll.Bottom = m_nWindowLines-1;
COORD dwOrigin;
dwOrigin.X = 0;
dwOrigin.Y = 0;
CHAR_INFO ci;
ci.Char.AsciiChar = ' ';
ci.Attributes = F_WHITE|B_BLACK;
ScrollConsoleScreenBuffer(m_hScreen,&rScroll,NULL,dwOrigin,&ci);
}
void CMudWindow::LineDone(int x)
{
m_szCharBuf[x] = '\x0';
// Log the line.
if (_bLogOpen)
_logFile.Write(m_szCharBuf);
// Create the line for the scrollback window.
int nScrollIndex = 0;
int nCharIndex = 0;
while(m_szCharBuf[nCharIndex])
{
*(m_scrollBuf+nScrollIndex) = HIBYTE(m_attrBuf[nCharIndex]);
nScrollIndex++;
*(m_scrollBuf+nScrollIndex) = LOBYTE(m_attrBuf[nCharIndex]);
nScrollIndex++;
*(m_scrollBuf+nScrollIndex) = m_szCharBuf[nCharIndex];
nScrollIndex++;
nCharIndex++;
}
// Need to pad the buffer with spaces for scroll back.
unsigned char hiAttr = HIBYTE(m_wAttr);
unsigned char loAttr = LOBYTE(m_wAttr);
while(nCharIndex < 80)
{
*(m_scrollBuf+nScrollIndex) = hiAttr;
nScrollIndex++;
*(m_scrollBuf+nScrollIndex) = loAttr;
nScrollIndex++;
*(m_scrollBuf+nScrollIndex) = ' ';
nScrollIndex++;
nCharIndex++;
}
_scrollBack.AddLine(m_scrollBuf);
}
void CMudWindow::CheckActions(const char *pszText)
{
if (m_bDoActions)
{
CString strTemp(pszText);
if (strTemp.Right(1) == "\n")
strTemp = strTemp.Left(strTemp.GetLength()-1);
_actions.CheckAction(strTemp);
}
}
void CMudWindow::PrintTextLine(CTextLine &tlText)
{
// Set so procs can see what the last line's attributes were.
_ptlLastText = &tlText;
if (_config.bPreSub && !_config.bCommandPrintOn)
_subs.CheckSub(tlText);
CheckActions(tlText.m_ptrText);
if (!_config.bCommandPrintOn)
{
if (_gags.CheckGag(tlText.m_ptrText))
{
tlText.m_nLen = 0;
_ptlLastText = NULL;
m_bEatEnter = TRUE;
return;
}
if (!_config.bPreSub)
_subs.CheckSub(tlText);
_highlights.CheckHighlight(tlText);
}
// Make sure the color is what we think it is.
SetColor(m_wAttr);
// Put the cursor back to last printed position.
Gotoxyns(m_dwCursor);
// If sitting at the bottom of the screen, scroll it up.
if (m_dwCursor.X == 0 && m_dwCursor.Y == m_nWindowLines)
{
Scroll();
m_dwCursor.Y--;
Gotoxyns(m_dwCursor);
}
int x = m_dwCursor.X;
int y = m_dwCursor.Y;
for (int i=0;i<tlText.m_nLen;i++)
{
// Check to see if the color has changed.
if (m_wAttr != tlText.m_ptrAttr[i])
SetColor(tlText.m_ptrAttr[i]);
if (tlText.m_ptrText[i] == 0x0a)
{
LineDone(x);
x = 0;
y++;
Gotoxyns(x,y);
}
else
{
// Print the character.
_putch(tlText.m_ptrText[i]);
// Keep track of the attribute and char being printed. These
// buffers are used by LineDone to put into scrollback and
// log the line to disk. These lines are actual screen lines
// which are at most 80 chars.
m_attrBuf[x] = m_wAttr;
m_szCharBuf[x] = tlText.m_ptrText[i];
// Increment screen position.
x++;
}
// Figure out the cursor position and scrolling.
if (x == 80)
{
// Screen line complete. Stuff it in backup buffer
// and log it to disk.
LineDone(x);
x = 0;
y++;
}
if (y == m_nWindowLines)
{
Scroll();
y--;
Gotoxyns(x,y);
}
}
// Save the current cursor position.
m_dwCursor.X = x;
m_dwCursor.Y = y;
_ptlLastText = NULL;
}
void CMudWindow::TelnetCommand(unsigned char chCommand)
{
m_chTelnetCommand = chCommand;
switch(chCommand)
{
case WILL : // requires an option.
m_bTelnetOption = TRUE;
break;
case WONT : // requires an option.
m_bTelnetOption = TRUE;
break;
case DO : // requires an option.
m_bTelnetOption = TRUE;
break;
case DONT : // requires and option.
m_bTelnetOption = TRUE;
break;
}
}
void CMudWindow::TelnetOption(unsigned char chOption)
{
m_chTelnetOption = chOption;
switch(chOption)
{
case ECHO : // Turns the echo of chars on/off.
switch(m_chTelnetCommand)
{
// Means that the other side of the connection has
// decided to echo characters, so I should stop echoing
// them myself.
case WILL :
m_bOldEcho = _config.bEcho;
_config.bEcho = FALSE;
// Send a confirmation.
SendText(_szDoEcho,FALSE);
break;
// The other side of the connection has decided to stop
// echoing characters -- I need to echo them myself.
case WONT :
_config.bEcho = m_bOldEcho;
break;
// The other side wants me to begin echoing commands
// received. Going to refuse this command. Refusing
// is done with IAC WONT ECHO.
case DO :
SendText(_szWontEcho,FALSE);
break;
// I'm not covering DONT because that is a request for
// to stop echoing the data from the remote side. Since
// I don't support that....
}
break;
case SGA :
switch(m_chTelnetCommand)
{
// Other side is requesting permission to suppress the
// go ahead signal. Send a DO back to confirm.
case WILL :
SendText(_szDoSGA,FALSE);
break;
// Requests that I suppress the sending of the go ahead
// signal. Send a WILL back to confirm.
case DO :
SendText(_szWillSGA,FALSE);
break;
}
break;
}
}
void CMudWindow::DoMSP()
{
CString strFilename;
char *ptr;
CString strType;
BOOL bSound; // True if sound, false if midi.
bSound = m_szMSPBuf[2] == 'S';
// The volume defaults to 100% if not specified.
int nLeftVol = 100;
int nRightVol = 100;
// Defaults to play just 1 time.
int nRepeat = 1;
// Defaults to 50.
int nPriority = 50;
// Filename is the first parameter.
ptr = strtok(m_szMSPBuf+8," ");
strFilename = ptr;
// No filename then just ignore it.
if (strFilename.IsEmpty())
return;
// Filename of "Off" is supposed to stop the playing of the sounds.
if (strFilename.GetLength() == 3 && strFilename == "Off")
{
if (bSound)
_sound.PlayWave(NULL);
else
_sound.PlayMidi(NULL);
return;
}
// If there isn't an extension, need to default to a wave file.
if (strFilename.Find('.') == -1)
if (bSound)
strFilename += ".wav";
else
strFilename += ".mid";
// Pull out any other parameters that may exist.
char *ptrVol;
ptr = strtok(NULL," ");
while(ptr)
{
switch(*ptr)
{
case 'V' :
ptrVol = strchr(ptr+2,',');
if (!ptrVol)
{
nLeftVol = atoi(ptr+2);
nRightVol = nLeftVol;
}
else
{
nLeftVol = atoi(ptr+2);
nRightVol = atoi(ptrVol+1);
}
break;
case 'L' :
nRepeat = atoi(ptr+2);
break;
case 'P' :
nPriority = atoi(ptr+2);
break;
case 'T' :
strType = ptr+2;
break;
}
ptr = strtok(NULL," ");
}
if (strchr(strFilename,'*') || strchr(strFilename,'?'))
strFilename = _msp.MatchWildcard(strFilename,(bSound ? MATCH_WAVE : MATCH_MIDI));
if (bSound)
if (_config.bUsePlaySound)
PlaySound(_msp.GetPath()+strFilename,NULL,SND_ASYNC|SND_FILENAME);
else
{
_sound.PlayWave(_msp.GetPath()+strFilename,nLeftVol,nRightVol,nPriority,nRepeat);
}
else
_sound.PlayMidi(_msp.GetPath()+strFilename);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?