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

📄 commandsgtol.cpp

📁 MudMaster 2000 的C++源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************************
	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.

**************************************************************************************/

#include "StdAfx.h"
#include "Commands.h"
#include "Extern.h"
#include "MudWindow.h"
#include "Keyboard.h"
#include "AliasMap.h"
#include "Actions.h"
#include "TextInput.h"
#include "TabList.h"
#include "Macros.h"
#include "UserLists.h"
#include "Modem.h"
#include "LogFile.h"
#include "Events.h"
#include "StatusBar.h"
#include "MudArray.h"
#include "Gags.h"
#include "Highlights.h"
#include "ScreenEdit.h"
#include "Chat.h"
#include "Sound.h"
#include "Msp.h"
#include "Procedures.h"
#include "Substitute.h"

void Gag(CString &strLine)
{
	CString strMask, strGroup;
	CString strTemp;
	int nGagNum;

	FindStatement(strLine,strMask);
	FindStatement(strLine,strGroup);
	ReplaceVariables(strMask);
	ReplaceVariables(strGroup);

	if (!strMask.IsEmpty())
	{
		nGagNum = _gags.Add(strMask,strGroup);
		if (_config.bGagMessages)
			if (nGagNum)
			{
				strTemp.Format("Gag added as #%d.",nGagNum);
				PrintMessage(strTemp);
			}
			else
				PrintMessage("Gag not added.");
		return;
	}

	PrintMessage("Defined Gags:");
	CommandPrintOn();

	CString strText;
	int nLineCount = 1;
	int nNumLines = _terminal.GetWindowLines()-2;
	int nInc;
	GAG *pGag = _gags.GetFirst();
	while(pGag != NULL)
	{
		_gags.GagToMask(pGag,strTemp);
		char *pBuf = strText.GetBuffer(strTemp.GetLength()+pGag->strGroup.GetLength()+40);
		int nResult = sprintf(pBuf,"%s%03d:%s%c{%s} {%s}\n",
			ANSI_F_BOLDWHITE,
			_gags.GetFindIndex()+1,
			ANSI_RESET,
			(pGag->bEnabled ? ' ' : '*'),
			(const char *)strTemp,
			(const char *)pGag->strGroup);
		strText.ReleaseBuffer(nResult);
		_terminal.Print(strText);
		
		if (_config.bPause)
		{
			nInc = strText.GetLength() / 80 + 1;
			nLineCount += nInc;
			if (nLineCount >= nNumLines)
				if (PausePrompt())
					nLineCount = 0;
				else
					break;
		}

		pGag = _gags.GetNext();
	}
	CommandPrintOff();
}

void GroupActions(CString &strLine)
{
	CString strGroup;
	FindStatement(strLine,strGroup);
	if (strGroup.IsEmpty())
		return;

	CString strText,strTemp;
	strText.Format("Defined Actions(%s):",(const char *)strGroup);
	PrintMessage(strText);
	CommandPrintOn();

	char *pBuf;
	int nResult;
	int nCount = 0;
	int nLineCount = 1;
	int nNumLines = _terminal.GetWindowLines()-2;
	int nInc;
	ACTION *pAct = _actions.GetFirst();
	while(pAct != NULL)
	{
		if (pAct->strGroup == strGroup)
		{
			nCount++;
			_actions.ActionToTrigger(pAct,strTemp);
			pBuf = strText.GetBuffer(strTemp.GetLength()+pAct->strAction.GetLength()+40);
			nResult = sprintf(pBuf,"%s%03d:%s%c{%s} {%s}\n",
				ANSI_F_BOLDWHITE,
				_actions.GetFindIndex()+1,
				ANSI_RESET,
				(pAct->bEnabled ? ' ' : '*'),
				(const char *)strTemp,
				(const char *)pAct->strAction); 
			strText.ReleaseBuffer(nResult);
			_terminal.Print(strText);
			
			if (_config.bPause)
			{
				nInc = strText.GetLength() / 80 + 1;
				nLineCount += nInc;
				if (nLineCount >= nNumLines)
					if (PausePrompt())
						nLineCount = 0;
					else
						break;
			}
		}
		pAct = _actions.GetNext();
	}
	strText.Format("[%d actions listed.]\n",nCount);
	_terminal.Print(strText);
	CommandPrintOff();
}

void GroupAliases(CString &strLine)
{
	CString strGroup;
	FindStatement(strLine,strGroup);
	if (strGroup.IsEmpty())
		return;

	CString strText,strTemp;
	strText.Format("Defined Aliases(%s):",(const char *)strGroup);
	PrintMessage(strText);
	CommandPrintOn();

	char *pBuf;
	int nResult;
	int nCount = 0;
	int nLineCount = 1;
	int nNumLines = _terminal.GetWindowLines()-2;
	int nInc;
	ALIAS_MAP *pMap = _aliases.GetFirst();
	while(pMap != NULL)
	{
		if (pMap->strGroup == strGroup)
		{
			nCount++;
			_aliases.MapToText(pMap,strText,FALSE);
			pBuf = strTemp.GetBuffer(strText.GetLength()+30);
			nResult = sprintf(pBuf,"%s%03d:%s%c%s\n",
				ANSI_F_BOLDWHITE,
				_aliases.GetFindIndex()+1,
				ANSI_RESET,
				(pMap->bEnabled ? ' ' : '*'),
				(const char *)strText);
			strTemp.ReleaseBuffer(nResult);
			_terminal.Print(strTemp);
			
			if (_config.bPause)
			{
				nInc = strTemp.GetLength() / 80 + 1;
				nLineCount += nInc;
				if (nLineCount >= nNumLines)
					if (PausePrompt())
						nLineCount = 0;
					else
						break;
			}
		}
		pMap = _aliases.GetNext();
	}
	strText.Format("[%d aliases listed.]\n",nCount);
	_terminal.Print(strText);
	CommandPrintOff();
}

void GroupBarItems(CString &strLine)
{
	CString strGroup;
	FindStatement(strLine,strGroup);
	if (strGroup.IsEmpty())
		return;

	CString strText;
	strText.Format("Defined Bar Items Words(%s):",(const char *)strGroup);
	PrintMessage(strText);
	CommandPrintOn();

	char *pBuf;
	int nResult;
	int nCount = 0;
	int nLineCount = 1;
	int nNumLines = _terminal.GetWindowLines()-2;
	int nInc;
	BAR_ITEM *pItem = _statusBar.GetFirst();
	while(pItem != NULL)
	{
		if (pItem->strGroup == strGroup)
		{
			nCount++;
			if (pItem->bSeparator)
			{
				pBuf = strText.GetBuffer(pItem->strItem.GetLength()+80);
				nResult = sprintf(pBuf,"%s%03d:%s%c{Pos:%2d} {Len: 1} {%s} {SEPARATOR}\n",
					ANSI_F_BOLDWHITE,
					_statusBar.GetFindIndex()+1,
					ANSI_RESET,
					(pItem->bEnabled ? ' ' : '*'),
					pItem->nPos,
					(const char *)pItem->strItem);
				strText.ReleaseBuffer(nResult);
			}
			else
			{
				pBuf = strText.GetBuffer(pItem->strItem.GetLength()+pItem->strText.GetLength()+80);
				nResult = sprintf(pBuf,"%s%03d:%s%c{Pos:%2d} {Len:%2d} {%s} {%s} {Fore:%d} {Back:%d}\n",
					ANSI_F_BOLDWHITE,
					_statusBar.GetFindIndex()+1,
					ANSI_RESET,
					(pItem->bEnabled ? ' ' : '*'),
					pItem->nPos,
					pItem->nLen,
					(const char *)pItem->strItem,
					(const char *)pItem->strText,
					pItem->nFore,
					pItem->nBack);
				strText.ReleaseBuffer(nResult);
			}
			_terminal.Print(strText);
			
			if (_config.bPause)
			{
				nInc = strText.GetLength() / 80 + 1;
				nLineCount += nInc;
				if (nLineCount >= nNumLines)
					if (PausePrompt())
						nLineCount = 0;
					else
						break;
			}
		}
		pItem = _statusBar.GetNext();
	}
	strText.Format("[%d bar items listed.]\n",nCount);
	_terminal.Print(strText);
	CommandPrintOff();
}

void GroupChat(CString &strLine)
{
	CString strGroup;
	FindStatement(strLine,strGroup);

	ReplaceVariables(strGroup);
	CString strSearchGroup(strGroup);
	strSearchGroup.MakeLower();

	// Make sure there are some grouped people.
	int nGroupCount = 0;
	CHAT *pChat = _chat.GetFirst();
	while(pChat != NULL)
	{
		if (pChat->strSearchGroup == strSearchGroup)
			nGroupCount++;
		pChat = _chat.GetNext();
	}

	if (!nGroupCount)
	{
		PrintMessage("You don't have anybody with that group.");
		return;
	}

	ReplaceVariables(strLine);

	if (strLine.IsEmpty())
		return;

	_chat.SendChatToGroup(strGroup,strLine);
}

void GroupEmote(CString &strLine)
{
	CString strGroup;
	FindStatement(strLine,strGroup);

	ReplaceVariables(strGroup);
	CString strSearchGroup(strGroup);
	strSearchGroup.MakeLower();

	// Make sure there are some grouped people.
	int nGroupCount = 0;
	CHAT *pChat = _chat.GetFirst();
	while(pChat != NULL)
	{
		if (pChat->strSearchGroup == strSearchGroup)
			nGroupCount++;
		pChat = _chat.GetNext();
	}

	if (!nGroupCount)
	{
		PrintMessage("You don't have anybody with that group.");
		return;
	}

	ReplaceVariables(strLine);

	if (strLine.IsEmpty())
		return;

	_chat.SendEmoteToGroup(strGroup,strLine);
}

void GroupEvents(CString &strLine)
{
	CString strGroup;
	FindStatement(strLine,strGroup);
	if (strGroup.IsEmpty())
		return;

	CString strText;
	strText.Format("Defined Events(%s):",(const char *)strGroup);
	PrintMessage(strText);
	CommandPrintOn();

	char *pBuf;
	int nResult;
	int nDif;
	int nCount = 0;
	int nLineCount = 1;
	int nNumLines = _terminal.GetWindowLines()-2;
	int nInc;
	EVENT *pEvent = _events.GetFirst();
	while(pEvent != NULL)
	{
		if (pEvent->strGroup == strGroup)
		{
			nCount++;
			nDif = pEvent->nSeconds - (_dwTime - pEvent->dwStarted);
			if (nDif < 0)
				nDif = 0;
			pBuf = strText.GetBuffer(pEvent->strName.GetLength()+pEvent->strEvent.GetLength()+80);
			nResult = sprintf(pBuf,"%s%03d:%s%c{%s} {F:%d} {T:%d} {%s}\n",
				ANSI_F_BOLDWHITE,
				_events.GetFindIndex()+1,
				ANSI_RESET,
				(pEvent->bEnabled ? ' ' : '*'),
				(const char *)pEvent->strName,
				pEvent->nSeconds,
				nDif,
				(const char *)pEvent->strEvent);
			strText.ReleaseBuffer(nResult);
			_terminal.Print(strText);
			
			if (_config.bPause)
			{
				nInc = strText.GetLength() / 80 + 1;
				nLineCount += nInc;
				if (nLineCount >= nNumLines)
					if (PausePrompt())
						nLineCount = 0;
					else
						break;
			}
		}
		pEvent = _events.GetNext();
	}
	strText.Format("[%d events listed.]\n",nCount);
	_terminal.Print(strText);
	CommandPrintOff();
}

void GroupLists(CString &strLine)
{
	CString strGroup;
	FindStatement(strLine,strGroup);
	if (strGroup.IsEmpty())
		return;

	CString strText;
	strText.Format("Defined Lists(%s):",(const char *)strGroup);
	PrintMessage(strText);
	CommandPrintOn();

	char *pBuf;
	int nResult;
	int nCount = 0;
	int nLineCount = 1;
	int nNumLines = _terminal.GetWindowLines()-2;
	int nInc;
	USER_LIST *pList = _lists.GetFirst();
	while(pList != NULL)
	{
		if (pList->strGroup == strGroup)
		{
			nCount++;
			pBuf = strText.GetBuffer(pList->strListName.GetLength()+30);
			nResult = sprintf(pBuf,"%s%03d:%s %s(%d)\n",
				ANSI_F_BOLDWHITE,
				_lists.GetFindIndex()+1,
				ANSI_RESET,
				(const char *)pList->strListName,
				pList->mapList.GetCount());
			strText.ReleaseBuffer(nResult);
			_terminal.Print(strText);
			
			if (_config.bPause)
			{
				nInc = strText.GetLength() / 80 + 1;
				nLineCount += nInc;
				if (nLineCount >= nNumLines)
					if (PausePrompt())
						nLineCount = 0;
					else
						break;
			}
		}
		pList = _lists.GetNext();
	}
	strText.Format("[%d lists listed.]\n",nCount);
	_terminal.Print(strText);
	CommandPrintOff();
}

void GroupMacros(CString &strLine)
{
	CString strGroup;
	FindStatement(strLine,strGroup);
	if (strGroup.IsEmpty())
		return;

	CString strText;
	strText.Format("Defined Macros(%s):",(const char *)strGroup);
	PrintMessage(strText);
	CommandPrintOn();

	char *pBuf;
	int nResult;
	int nCount = 0;
	int nLineCount = 1;
	int nNumLines = _terminal.GetWindowLines()-2;
	int nInc;
	MACRO *pMac = _macros.GetFirst();
	while(pMac != NULL)
	{
		if (pMac->strGroup == strGroup)
		{
			nCount++;
			pBuf = strText.GetBuffer(pMac->strKeyName.GetLength()+pMac->strText.GetLength()+30);
			nResult = sprintf(pBuf,"%c{%s%s%s} {%s}\n",
				(pMac->bEnabled ? ' ' : '*'),
				ANSI_F_BOLDWHITE,
				(const char *)pMac->strKeyName,
				ANSI_RESET,
				(const char *)pMac->strText);
			strText.ReleaseBuffer(nResult);
			_terminal.Print(strText);
			
			if (_config.bPause)
			{
				nInc = strText.GetLength() / 80 + 1;
				nLineCount += nInc;
				if (nLineCount >= nNumLines)
					if (PausePrompt())
						nLineCount = 0;
					else
						break;
			}
		}
		pMac = _macros.GetNext();
	}
	strText.Format("[%d macros listed.]\n",nCount);
	_terminal.Print(strText);
	CommandPrintOff();
}

void GroupSubs(CString &strLine)
{
	CString strGroup;
	FindStatement(strLine,strGroup);
	if (strGroup.IsEmpty())
		return;

	CString strText,strTemp;
	strText.Format("Defined Subs(%s):",(const char *)strGroup);
	PrintMessage(strText);
	CommandPrintOn();

	char *pBuf;
	int nResult;
	int nCount = 0;
	int nLineCount = 1;
	int nNumLines = _terminal.GetWindowLines()-2;

⌨️ 快捷键说明

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