⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mudwindow.h

📁 MudMaster 2000 的C++源码
💻 H
字号:
/************************************************************************************
	Copyright (c) 2000 Aaron O'Neil
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions
	are met:

		1) Redistributions of source code must retain the above copyright notice, 
				this list of conditions and the following disclaimer.
		2) Redistributions in binary form must reproduce the above copyright notice, 
				this list of conditions and the following disclaimer in the documentation
				and/or other materials provided with the distribution.
		3) Redistributions in binary form must reproduce the above copyright notice on
				program startup. Additional credits for program modification are acceptable
				but original copyright and credits must be visible at startup.
		4) You may charge a reasonable copying fee for any distribution of Mud Master. 
				You may charge any fee you choose for support of Mud Master. You may not 
				charge a fee for Mud Master itself.

  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
	IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
	OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
	IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
	INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
	DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
	THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
	THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

**************************************************************************************/
#define MAX_ANSI_LEN		50

// Telnet command codes.
#define AYT			(unsigned char)246	// Are you there.
#define GA			(unsigned char)249	// Go ahead.
#define WILL		(unsigned char)251
#define WONT		(unsigned char)252
#define DO			(unsigned char)253
#define DONT		(unsigned char)254
#define IAC			(unsigned char)255

// Telnet option codes.
#define ECHO		(unsigned char)1
#define SGA			(unsigned char)3		// Suppress go ahead.

// Telent command strings.
const char _szDoEcho[]			= {IAC, DO, ECHO, 0};
const char _szWontEcho[]		= {IAC, WONT, ECHO, 0};
const char _szGoAhead[]			= {IAC, GA, 0};
const char _szWillSGA[]			= {IAC, WILL, SGA, 0}; 
const char _szDoSGA[]			= {IAC, DO, SGA, 0};

// This is the length of the text of the prompt for a MSP string.
#define MSP_TAG_LEN				8

// The maximum number of characters to collect for an MSP string.
#define MAX_MSP_LEN				200

// This is the text that prmopt a MSP string.
const char _szMSPSound[MSP_TAG_LEN+1]	= "!!SOUND(";
const char _szMSPMusic[MSP_TAG_LEN+1]  = "!!MUSIC(";

class CTextLine;

class CMudWindow : public CScreen
{
public:
	CMudWindow();
	~CMudWindow();

	void Init();

	// Use this function to translate ansi codes and prepare the
	// text for printing. If nTextLen = 0 the function uses strlen to
	// determine the length. Some mud is sending NULL in the middle of their
	// text streams which is screwing up the print, this is the woorkaround.
	void Print(const char *pszText, int nTextLen = 0);

	// Scrolls the term window portion up by 1.
	void Scroll();

	// Used to turn the processing of actions on or off.
	void ActionsOff()			{ m_bDoActions = FALSE; }
	void ActionsOn()			{ m_bDoActions = TRUE; }
	BOOL ActionsState()		{ return(m_bDoActions); }

	// Switches the screen mode.
	void Mode25();
	void Mode50();

	int  GetWindowLines()	{ return(m_nWindowLines); }
	void SetWindowLines(int nLines) { m_nWindowLines = nLines; }

	// Statusbar calls this to make sure the cursor gets out of the
	// input/scrollbar range.
	void AdjustY()			{ m_dwCursor.Y = m_nWindowLines-1; }

private:
	char m_scrollBuf[240];	// Created in LineDone(x).
	WORD m_attrBuf[80];		// The attributes of the line to add to scrollback.
	char m_szCharBuf[81];	// The line to add to scrollback.

	// When this is set to TRUE, the next enter/newline encountered will be
	// eaten if it is the only thing on the line.  Used for gags to supress
	// the next blank line.
	BOOL m_bEatEnter;

	// Keep track of the current text color.  Foreground and Background.
	int m_nCurrentColor;

	int m_nWindowLines;		// Defaults to 24.

	// This is set to TRUE whenever a telnet IAC character (255)
	// is seen.
	BOOL m_bTelnetCommand;
	// True when we have received a telnet command the requires
	// an option.
	BOOL m_bTelnetOption;
	// This is the telnet code received.  This could be the end
	// of the command, or if the code has options associated with
	// it there will be 1 more char.
	unsigned char m_chTelnetCommand;
	// The option for a telnet code.
	unsigned char m_chTelnetOption;
	// When telnet requests that echo be turned off this value is set
	// with the client's echo value, when echo is requested to be
	// turned back on, this value is restored.  That way if the user
	// had echo turned off anyway, it would remain off.
	BOOL m_bOldEcho;

	// This is set to TRUE whenever an ESC character
	// is printed.  As long as this var is TRUE the
	// incoming characters are stored in a buffer 
	// rather than printed.  Until an alpha character
	// is encounted signaling the end of an ANSI
	// sequence.
	BOOL m_bPossibleAnsi;

	// Allocated in constructor.  Freed in destructor.
	char *m_pAnsiBuf;

	// Index into m_pAnsiBuf.
	int m_nAnsiIndex;

	// TRUE if High Intensity should be used.
	BOOL m_bBold;

	// Medievia uses two bolds in a row to mean white. I'm having some trouble
	// with muds that have the bold bit on, then send another bold command but
	// it doesn't immediately follow the first bold, it's chaning the color of
	// the text white. Need to keep track and only change it to white if they
	// are one after the other.
	BOOL m_bLastWasBold;

	// TRUE by default.  When true each time a line has been printed
	// on the terminal window, the line is passed to the action class
	// to see if it has a match.
	BOOL m_bDoActions;

	// TRUE while collecting the data from a MSP string.  The data
	// is ended by a line feed. 
	BOOL m_bMSP;

	// This buffer is used to collect the data from a MSP string.
	char m_szMSPBuf[MAX_MSP_LEN+1];

	// Index into m_szMSPBuf used while collecting MSP data.
	int  m_nMSPIndex;

	// Deals with the MSP string.
	void DoMSP();

	// Called to when the Print() routine thinks it has a complete
	// ansi sequence.  This just changes the _nForeColor variable.
	// It does not actually change the attribute of the screen.
	void TranslateAnsi();

	// Called by the print function whenever a line is complete.
	// This puts the line in the scroll back buffer and logs it
	// to the disk.
	void LineDone(int x);

	// Called whenever the maximum number of characters has been 
	// received for a line or a carriage return is found.
	void CheckActions(const char *pszText);

	// Prints the data in m_tlText.
	void PrintTextLine(CTextLine &tlText);

	// Pass a telnet command to deal with.
	void TelnetCommand(unsigned char chCommand);

	// Pass a telnet option to deal with.
	void TelnetOption(unsigned char chOption);
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -