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

📄 tintinmisc.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

------------------------------------------------------------------------------

	TinTin class miscellaneous methods.  Originally modified from TinTin++,
	(T)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t, originally coded by
	Peter Unold 1992.

----------------------------------------------------------------------------*/

// $Header: /home/cvs/chaco/modules/client/msw/ChWorld/TinTinMisc.cpp,v 2.26 1996/09/12 19:10:19 pritham Exp $

#include "headers.h"
#include <ChCore.h>
#include <ChDlg.h>

#include <mmsystem.h>

#include "headers.h"
#include "World.h"
#include "ChTextInput.h"
#include "ChTextOutput.h"

#include "TinTin.h"
#include "TinTinInfo.h"


/*----------------------------------------------------------------------------
	TinTin class protected methods
----------------------------------------------------------------------------*/

void TinTin::DoAlert()
{
	GetMainInfo()->DoAlert();
}


void TinTin::DoBell()
{
	MessageBeep( MB_OK );
}


/*----------------------------------------------------------------------------
	TinTin::DoChar
				Changes the TinTin escape character (start of commands.)
----------------------------------------------------------------------------*/

void TinTin::DoChar( const string& strArgs )
{
	string		strWorking;
	string		strMessage;

	GetArgInBraces( strArgs, strWorking, true );

	if ('\\' == strWorking[0])
	{
		LOADSTRING( IDS_TINTIN_CHAR_BACKSLASH_ERR, strMessage );
		ErrMessage( strMessage );
	}
	else if (ispunct( strWorking[0] ))
	{
		if (strWorking[0] != GetTinTinChar())
		{
			string		strFormat;

			SetTinTinChar( strWorking[0] );

			LOADSTRING( IDS_TINTIN_CHAR_OK, strFormat );
			strMessage.Format( strFormat, GetTinTinChar() );

			ErrMessage( strMessage );
		}
	}
	else
	{
		LOADSTRING( IDS_TINTIN_CHAR_ERR, strMessage );
		ErrMessage( strMessage );
	}
}


void TinTin::DoCR()
{
	Send( "\n" );
}


void TinTin::DoEnd( const string& strCommand )
{
	string		strMessage;

	if (0 != strCommand.Compare( "end" ))
	{
		LOADSTRING( IDS_TINTIN_END, strMessage );
		ErrMessage( strMessage );
	}
	else
	{
		ChPersistentFrame*	pFrame = GetMainInfo()->GetCore()->GetFrameWnd();
		string				strTitle;

		LOADSTRING( IDS_TINTIN_END_VERIFY, strMessage );
		LOADSTRING( IDS_TINTIN_END_VERIFY_TITLE, strTitle );
		if (IDYES == pFrame->MessageBox( strMessage, strTitle,
											MB_YESNO | MB_ICONEXCLAMATION ))
		{
			pFrame->PostMessage( WM_CLOSE );
		}
	}
}


void TinTin::DoHelp( const string& strArgs )
{
	string		strTopic;
	DWORD		dwKey = 0;

	GetArgStopAtSpaces( strArgs, strTopic );

	if (strTopic.IsEmpty())
	{
		strTopic = TINTIN_HELP_PREFIX ",overview";
		dwKey = (DWORD)(const char*)strTopic;
	}
	else
	{
		TTCommand	cmd;

		cmd = ParseTinTinCmd( strTopic );

		if (ttUnknown == cmd)
		{
			string		strFormat( "# Unknown command!  ('%s')" );
			string		strStatus;

			strStatus.Format( strFormat, (const char*)strTopic );
			ErrMessage( strStatus );
		}
		else
		{
			strTopic = m_pstrCommands[(int)cmd];

			strTopic = TINTIN_HELP_PREFIX ",#" + strTopic;
			dwKey = (DWORD)(const char*)strTopic;
		}
	}

	if (dwKey)
	{
		AfxGetApp()->WinHelp( dwKey, HELP_KEY );
	}
}


void TinTin::DoInfo()
{
	TinTinInfo		info;

	info.SetCounts( GetListActions()->GetCount(),
					GetListAliases()->GetCount(),
					GetListSubs()->GetCount(),
					GetListAntiSubs()->GetCount(),
					GetListVars()->GetCount(),
					GetListHighlights()->GetCount() );
	info.SetFlags( IsIgnore(), IsSpeedwalk(),
					IsUsingSubs(), IsUsingPresubs() );

	info.DoModal();
}


/*----------------------------------------------------------------------------
	TinTin::DoKillAll
				Empties the lists.
----------------------------------------------------------------------------*/

void TinTin::DoKillAll( bool boolQuiet )
{
	if (GetSettings())
	{
		GetSettings()->DoKillAll();
	}
	
	if (GetListPath())
	{
		GetListPath()->Empty();
	}

	if (!boolQuiet)
	{
		string		strMessage;

		LOADSTRING( IDS_TINTIN_KILLALL, strMessage );
		Message( strMessage );
	}
}


void TinTin::DoLog( const string& strArgs )
{
	string			strFilepath;
	ChTextOutput*	pTextOutput = GetMainInfo()->GetTextOutput();

											// Validate the path

	GetArgInBraces( strArgs, strFilepath, false );

	if (strFilepath.IsEmpty())
	{										// Turn off logging
		string		strMessage;

		if (pTextOutput->IsLogging())
		{
			pTextOutput->ToggleLogging();
		}

		LOADSTRING( IDS_TINTIN_LOG_OFF, strMessage );
		Message( strMessage );
	}
	else
	{
		string		strFormat;
		string		strMessage;
		bool		boolWasLogging = pTextOutput->IsLogging();

		if (pTextOutput->SetLogging( strFilepath ))
		{
			LOADSTRING( IDS_TINTIN_LOG_ON, strFormat );
			strMessage.Format( strFormat, (const char*)strFilepath );
			Message( strMessage );
		}
		else
		{
			LOADSTRING( IDS_TINTIN_LOG_ERROR, strFormat );
			strMessage.Format( strFormat, (const char*)strFilepath );
			ErrMessage( strMessage );

			if (boolWasLogging)
			{
				LOADSTRING( IDS_TINTIN_LOG_OFF, strMessage );
				ErrMessage( strMessage );
			}
		}
	}
}


void TinTin::DoLoop( const string& strArgs )
{
	const char*	pstrArgs = strArgs;
	string		strLeft;
	string		strRight;
	int			iBound1;
	int			iBound2;

	pstrArgs = GetArgInBraces( pstrArgs, strLeft, false );
	pstrArgs = GetArgInBraces( pstrArgs, strRight, true );

	if (sscanf( (const char*)strLeft, "%d,%d", &iBound1, &iBound2 ) != 2)
	{
		string		strMessage;

		LOADSTRING( IDS_TINTIN_LOOP_PARAM_ERR, strMessage );
		ErrMessage( strMessage );
	}
	else
	{
		bool	boolDone = false;
		int		iCounter = iBound1;

		while(!boolDone)
		{
			string		strResult;

			m_strVars[0].Format( "%d", iCounter );

			SubstituteVars( strRight, strResult );
			ParseInput( strResult );

			if (iBound1 < iBound2)
			{
				iCounter++;
				if (iCounter > iBound2)
				{
					boolDone = true;
				}
			}
			else
			{
				iCounter--;
				if (iCounter < iBound2)
				{
					boolDone = true;
				}
			}
		}
	}
}


void TinTin::DoMbox( const string& strArgs )
{
	string		strResult;
	string		strMessageTitle;

	GetArgInBraces( strArgs, strResult, true );

	PrepareActionAlias( strResult, strResult );

	LOADSTRING( IDS_TINTIN_MBOX_TITLE, strMessageTitle );
	GetMainInfo()->GetCore()->GetFrameWnd()->
				MessageBox( strResult, strMessageTitle );
}


void TinTin::DoMessage( const string& strArgs )
{
	static const char*	pstrNames[] = { "actions",
										"aliases",
										"antisubstitutes",
										"highlights",
										"pathdirs",
										"substitutes",
										"variables" };
	static const char*	pstrOff = "off";
	static const char*	pstrOn = "on";

	int					iOption;
	string				strOption;
	string				strFormat;
	string				strMessage;

	GetArgInBraces( strArgs, strOption, true );

	iOption = 0;
	while (!IsAbrev( strOption, pstrNames[iOption] ) &&
			(iOption < msgIndexLast))
	{
		iOption++;
	}

	if (iOption == msgIndexLast)
	{
		LOADSTRING( IDS_TINTIN_MESSAGE_ERR, strFormat );
		strMessage.Format( strFormat, (const char*)strOption );
		ErrMessage( strMessage );
	}
	else
	{
		SetDisplayingMsg( iOption, !IsDisplayingMsg( iOption ) );

		LOADSTRING( IDS_TINTIN_MESSAGE_OK, strFormat );
		strMessage.Format( strFormat, pstrNames[iOption],
							IsDisplayingMsg( iOption ) ? pstrOn :
																pstrOff );
		ErrMessage( strMessage );
	}
}


void TinTin::DoPlaySound( const string& strArgs )
{
	string			strFilepath;
											// Validate the path

	GetArgInBraces( strArgs, strFilepath, false );

	if (strFilepath.IsEmpty())
	{										// Turn off logging
		string		strMessage;

		LOADSTRING( IDS_TINTIN_PLAY_EMPTY, strMessage );
		ErrMessage( strMessage );
	}
	else
	{
		if (!PlaySound( strFilepath, 0, SND_FILENAME ))
		{
			string		strFormat;
			string		strMessage;

			LOADSTRING( IDS_TINTIN_PLAY_ERROR, strFormat );
			strMessage.Format( strFormat, (const char*)strFilepath );
			ErrMessage( strMessage );
		}
	}
}


void TinTin::DoRandom( const string& strArgs )
{
	const char*		pstrArgs = strArgs;
	string			strVar;
	string			strMax;
	string			strTemp;

	pstrArgs = GetArgInBraces( pstrArgs, strVar, false );
	pstrArgs = GetArgInBraces( pstrArgs, strMax, true );

	SubstituteVars( strMax, strTemp );
	SubstituteMyVars( strTemp, strMax );

	if (!strVar.IsEmpty() && !strMax.IsEmpty())
	{
		const char*		pstrMax = strMax;
		bool			boolSuccess = false;

		if (isdigit( *pstrMax ))
		{
			chint32		lMax = atol( pstrMax );

			if ((lMax > 0) && (lMax <= RAND_MAX))
			{
				chint32			lValue;
				TinTinListNode*	pNode;
											/* Generate a random number between
												0 and lMax */
				lValue = rand();
				lValue = (lValue * (lMax + 1)) / RAND_MAX;

				strTemp.Format( "%ld", lValue );

				if (pNode = GetListVars()->Search( strVar ))
				{
					GetListVars()->DeleteNode( pNode );
				}

				GetListVars()->InsertNode( strVar, strTemp, "0" );
				boolSuccess = true;
			}
		}

		if (!boolSuccess)
		{
			string	strMessage;
			string	strFormat;

			LOADSTRING( IDS_TINTIN_RANDOM_SIZE_ERR, strFormat );
			strMessage.Format( strFormat, (chint32)RAND_MAX );
			Message( strMessage );
		}
	}
	else
	{
		string	strMessage;

		LOADSTRING( IDS_TINTIN_RANDOM_USAGE, strMessage );
		Message( strMessage );
	}
}


void TinTin::DoShowMe( const string& strArgs )
{
	string	strResult;

	GetArgInBraces( strArgs, strResult, true );

	PrepareActionAlias( strResult, strResult );
	Message( strResult );
}


/*----------------------------------------------------------------------------
	TinTin::DoSplit
				Sets the size of the output or input windows, dependant on

⌨️ 快捷键说明

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