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

📄 commandsstoz.cpp

📁 MudMaster 2000 的C++源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			if (_config.bPause)
			{
				nInc = strTemp.GetLength() / 80 + 1;
				nLineCount += nInc;
				if (nLineCount >= nNumLines)
					if (PausePrompt())
						nLineCount = 0;
					else
						break;
			}
			
			pMap = _mapVars.GetNext();
		}
		CommandPrintOff();
		return;
	}

	if (strParam2.IsEmpty())
	{
		PrintMessage("Defined Variable:");
		STRING_MAP *pMap = _mapVars.FindExactByKey(strParam1);
		if (pMap != NULL)
		{
			CString strText;
			char *pBuf = strText.GetBuffer(pMap->strKey.GetLength()+pMap->strText.GetLength()+pMap->strGroup.GetLength()+40);
			int nResult = sprintf(pBuf,"{%s} {%s} {%s}\n",(const char *)pMap->strKey,
				(const char *)pMap->strText,
				(const char *)pMap->strGroup);
			strText.ReleaseBuffer(nResult);
			CommandPrintOn();
			_terminal.Print(strText);
			CommandPrintOff();
		}
		return;
	}
	ReplaceVariables(strParam1);
	ReplaceVariables(strParam2);

	nVarNum = _mapVars.Add(strParam1,strParam2,strGroup);
	if (_config.bVarMessages)
		if (nVarNum)
		{
			strTemp.Format("Variable added as #%d.",nVarNum);
			PrintMessage(strTemp);
		}
		else
			PrintMessage("Variable not added.");
}

void Version(CString &strLine)
{
	CString strText;
	strText = "Version: ";
	strText += _config.strVersion;
	PrintMessage(strText);
}

void VolumeBits(CString &strLine)
{
	_sound.SetVolumeBits(atoi(strLine));
	WriteIniInt("Sounds","Volume Bits",_sound.GetVolumeBits());
}

void VolumeDefault(CString &strLine)
{
	int nDefault = atoi(strLine);
	if (nDefault < 1 || nDefault > 100)
		nDefault = 100;
	_config.nDefaultVolume = nDefault;
	WriteIniInt("Sounds","Default Volume",nDefault);
}

void VolumeMax(CString &strLine)
{
	CString strVol;
	FindStatement(strLine,strVol);

	ReplaceVariables(strVol);
	if (strVol.IsEmpty())
		return;

	_sound.SetMaxVolume(atoi(strVol));
	WriteIniInt("Sounds","Max Volume",_sound.GetMaxVolume());
}

void While(CString &strLine)
{
	CString strCondition, strParam;
	FindStatement(strLine,strCondition);
	FindStatement(strLine,strParam);
	if (strCondition.IsEmpty() || strParam.IsEmpty())
		return;

	CString strTemp, strStuffToDo;
	strTemp = strCondition;
	ReplaceVariables(strTemp,TRUE);
	while(EvaluateLine(strTemp))
	{
		strStuffToDo = strParam;
		HandleInput(strStuffToDo);
		strTemp = strCondition;
		ReplaceVariables(strTemp,TRUE);
	}
}

void WinMessages(CString &strLine)
{
	CString strArg;
	FindStatement(strLine,strArg);
	ReplaceVariables(strArg);

	if (strArg.IsEmpty())
	{
		CommandPrintOn();
		if (_config.bWinMessages)
			PrintMessage("Window messages are being processed.");
		else
			PrintMessage("Window messages are not being processed.");
		_terminal.Print("Usage: /winmessages on, /winmessages off\n");
		CommandPrintOff();
		return;
	}

	strArg.MakeLower();
	if (strArg == "on")
	{
		_config.bWinMessages = TRUE;
		PrintMessage("Window messages are being processed.");
		WriteIniInt("Run","Win Messages",TRUE);
	}
	else
		if (strArg == "off")
		{
			_config.bWinMessages = FALSE;
			PrintMessage("Window message are not being processed.");
			WriteIniInt("Run","Win Messages",FALSE);
		}
		else
			PrintMessage("Invalid argument.");
}

void Write(CString &strLine)
{
	CStdioFileFixed file;

	CString strFilename;
	FindStatement(strLine,strFilename);
	ReplaceVariables(strFilename);

	CString strPath(_config.strScriptPath+strFilename);
	if (_config.bPromptOverwrite)
	{
		CFileStatus fs;
		char ch;
		if (CFile::GetStatus(strPath,fs))
		{
			PrintMessage(CString("File (")+strPath+") exists, overwrite it (y/N)?");
			ch = tolower(getch());
			if (ch != 'y')
				return;
		}
	}
	BackupFile(strPath);
	if (!file.Open(strPath,CFile::modeWrite|CFile::modeCreate|CFile::typeText))
	{
		PrintMessage("Unable to open that file.");
		return;
	}

	PrintMessage(CString("Writing command file: ")+strPath);

	CString strText;
	CString strTemp;
	CString strKey;
	CString strPrepare;
	char *pBuf;
	int nResult;

	ACTION *pAction = _actions.GetFirst();
	while(pAction != NULL)
	{
		_actions.ActionToTrigger(pAction,strTemp);
		pBuf = strText.GetBuffer(strTemp.GetLength()+pAction->strAction.GetLength()+pAction->strGroup.GetLength()+40);
		nResult = sprintf(pBuf,"%caction {%s} {%s} {%s}\n",
			_config.chCommand,
			(const char *)strTemp,
			(const char *)pAction->strAction,
			(const char *)pAction->strGroup);
		strText.ReleaseBuffer(nResult);
		file.WriteString(strText);
		pAction = _actions.GetNext();
	}
	
	ALIAS_MAP *pAlias = _aliases.GetFirst();
	while(pAlias != NULL)
	{
		_aliases.MapToCommand(pAlias,strText);
		file.WriteString(strText+"\n");
		pAlias = _aliases.GetNext();
	}

	MACRO *pMac = _macros.GetFirst();
	while(pMac != NULL)
	{
		pBuf = strText.GetBuffer(pMac->strKeyName.GetLength()+pMac->strText.GetLength()+pMac->strGroup.GetLength()+40);
		nResult = sprintf(pBuf,"%cmacro {%s} {%s} {%s}\n",_config.chCommand,
			(const char *)pMac->strKeyName,
			(const char *)pMac->strText,
			(const char *)pMac->strGroup);
		strText.ReleaseBuffer(nResult);
		file.WriteString(strText);
		pMac = _macros.GetNext();
	}

	TAB *pTab = _tabList.GetFirst();
	while(pTab != NULL)
	{
		pBuf = strText.GetBuffer(pTab->strText.GetLength()+pTab->strGroup.GetLength()+40);
		nResult = sprintf(pBuf,"%ctabadd {%s} {%s}\n",_config.chCommand,
			(const char *)pTab->strText,
			(const char *)pTab->strGroup);
		strText.ReleaseBuffer(nResult);
		file.WriteString(strText);
		pTab = _tabList.GetNext();
	}

	STRING_MAP *pStringMap = _mapVars.GetFirst();
	while(pStringMap != NULL)
	{
		if (pStringMap->strText.IsEmpty())
		{
			pBuf = strTemp.GetBuffer(pStringMap->strKey.GetLength()+pStringMap->strGroup.GetLength()+40);
			nResult = sprintf(pBuf,"%cempty {%s} {%s}\n",
				_config.chCommand,
				(const char *)pStringMap->strKey,
				(const char *)pStringMap->strGroup);
			strTemp.ReleaseBuffer(nResult);
		}
		else
		{
			PrepareForWrite(pStringMap->strText,strPrepare);
			pBuf = strTemp.GetBuffer(pStringMap->strKey.GetLength()+strPrepare.GetLength()+pStringMap->strGroup.GetLength()+40);
			nResult = sprintf(pBuf,"%cvariable {%s} {%s} {%s}\n",_config.chCommand,
				(const char *)pStringMap->strKey,
				(const char *)strPrepare,
				(const char *)pStringMap->strGroup);
			strTemp.ReleaseBuffer(nResult);
		}
		file.WriteString(strTemp);
		pStringMap = _mapVars.GetNext();
	}

	EVENT *pEvent = _events.GetFirst();
	while(pEvent != NULL)
	{
		pBuf = strText.GetBuffer(pEvent->strName.GetLength()+pEvent->strEvent.GetLength()+pEvent->strGroup.GetLength()+40);
		nResult = sprintf(pBuf,"%cevent {%s} {%d} {%s} {%s}\n",_config.chCommand,
			(const char *)pEvent->strName,
			pEvent->nSeconds,
			(const char *)pEvent->strEvent,
			(const char *)pEvent->strGroup);
		strText.ReleaseBuffer(nResult);
		file.WriteString(strText);
		pEvent = _events.GetNext();
	}

	GAG *pGag = _gags.GetFirst();
	while(pGag != NULL)
	{
		_gags.GagToMask(pGag,strTemp);
		pBuf = strText.GetBuffer(strTemp.GetLength()+pGag->strGroup.GetLength()+30);
		nResult = sprintf(pBuf,"%cgag {%s} {%s}\n",
			_config.chCommand,
			(const char *)strTemp,
			(const char *)pGag->strGroup);
		strText.ReleaseBuffer(nResult);
		file.WriteString(strText);
		pGag = _gags.GetNext();
	}

	SUB *pSub = _subs.GetFirst();
	while(pSub != NULL)
	{
		_subs.SubToTrigger(pSub,strTemp);
		pBuf = strText.GetBuffer(strTemp.GetLength()+pSub->strSub.GetLength()+pSub->strGroup.GetLength()+40);
		nResult = sprintf(pBuf,"%csubstitute {%s} {%s} {%s}\n",
			_config.chCommand,
			(const char *)strTemp,
			(const char *)pSub->strSub,
			(const char *)pSub->strGroup);
		strText.ReleaseBuffer(nResult);
		file.WriteString(strText);
		pSub = _subs.GetNext();
	}

	CString strColor;
	HIGHLIGHT *pHigh = _highlights.GetFirst();
	while(pHigh != NULL)
	{
		_highlights.HighlightToMask(pHigh,strTemp);
		_highlights.AttrToText(pHigh->wAttr,strColor);
		pBuf = strText.GetBuffer(strTemp.GetLength()+strColor.GetLength()+pHigh->strGroup.GetLength()+40);
		nResult = sprintf(pBuf,"%chighlight {%s} {%s} {%s}\n",
			_config.chCommand,
			(const char *)strTemp,
			(const char *)strColor,
			(const char *)pHigh->strGroup);
		strText.ReleaseBuffer(nResult);
		file.WriteString(strText);
		pHigh = _highlights.GetNext();
	}

	USER_LIST *pList = _lists.GetFirst();
	while(pList != NULL)
	{
		pBuf = strText.GetBuffer(pList->strListName.GetLength()+pList->strGroup.GetLength()+40);
		nResult = sprintf(pBuf,"%clistadd {%s} {%s}\n",_config.chCommand,
			(const char *)pList->strListName,
			(const char *)pList->strGroup);
		strText.ReleaseBuffer(nResult);
		file.WriteString(strText);

		// Write the items in the list out.
		pStringMap = pList->mapList.GetFirst();
		while(pStringMap != NULL)
		{
			PrepareForWrite(pStringMap->strKey,strPrepare);
			pBuf = strText.GetBuffer(pList->strListName.GetLength()+strPrepare.GetLength()+40);
			nResult = sprintf(pBuf,"%citemadd {%s} {%s}\n",_config.chCommand,
				(const char *)pList->strListName,
				(const char *)strPrepare);
			strText.ReleaseBuffer(nResult);
			file.WriteString(strText);
			pStringMap = pList->mapList.GetNext();
		}

		pList = _lists.GetNext();
	}

	DLL *pDll = _dlls.GetFirst();
	while(pDll != NULL)
	{
		pBuf = strText.GetBuffer(pDll->strName.GetLength()+30);
		nResult = sprintf(pBuf,"%cloadlibrary {%s}\n",
			_config.chCommand,
			(const char *)pDll->strName);
		strText.ReleaseBuffer(nResult);
		file.WriteString(strText);
		pDll = _dlls.GetNext();
	}

	ARRAY *ptr = _arrays.GetFirst();
	while(ptr != NULL)
	{
		if (ptr->bSingleDim)
		{
			pBuf = strText.GetBuffer(ptr->strName.GetLength()+ptr->strGroup.GetLength()+40);
			nResult = sprintf(pBuf,"%carray {%s} {%d} {%s}\n",
				_config.chCommand,
				(const char *)ptr->strName,
				ptr->nDim[0],
				(const char *)ptr->strGroup);
			strText.ReleaseBuffer(nResult);
		}
		else
		{
			pBuf = strText.GetBuffer(ptr->strName.GetLength()+ptr->strGroup.GetLength()+50);
			nResult = sprintf(pBuf,"%carray {%s} {%d,%d} {%s}\n",
				_config.chCommand,
				(const char *)ptr->strName,
				ptr->nDim[0],
				ptr->nDim[1],
				(const char *)ptr->strGroup);
			strText.ReleaseBuffer(nResult);
		}
		file.WriteString(strText);

		// Write out the items.
		if (ptr->bSingleDim)
		{
			for (int i=1;i<=ptr->nDim[0];i++)
			{
				_arrays.GetItem(ptr,i,0,strTemp);
				PrepareForWrite(strTemp,strPrepare);
				if (!strPrepare.IsEmpty())
				{
					pBuf = strText.GetBuffer(ptr->strName.GetLength()+strPrepare.GetLength()+40);
					nResult = sprintf(pBuf,"%cassign {%s} {%d} {%s}\n",
						_config.chCommand,
						(const char *)ptr->strName,
						i,
						(const char *)strPrepare);
					strText.ReleaseBuffer(nResult);
					file.WriteString(strText);
				}
			}
		}
		else
		{
			int j;
			for (int i=1;i<=ptr->nDim[0];i++)
				for (j=1;j<=ptr->nDim[1];j++)
				{
					_arrays.GetItem(ptr,i,j,strTemp);
					PrepareForWrite(strTemp,strPrepare);
					if (!strPrepare.IsEmpty())
					{
						pBuf = strText.GetBuffer(ptr->strName.GetLength()+strPrepare.GetLength()+40);
						nResult = sprintf(pBuf,"%cassign {%s} {%d,%d} {%s}\n",
							_config.chCommand,
							(const char *)ptr->strName,
							i,j,
							(const char *)strPrepare);
						strText.ReleaseBuffer(nResult);
						file.WriteString(strText);
					}
				}
		}

		ptr = _arrays.GetNext();
	}

	BAR_ITEM *pItem = _statusBar.GetFirst();
	while(pItem != NULL)
	{
		if (pItem->bSeparator)
		{
			pBuf = strText.GetBuffer(pItem->strItem.GetLength()+pItem->strGroup.GetLength()+40);
			nResult = sprintf(pBuf,"%cbarseparator {%s} {%d} {%s}\n",
				_config.chCommand,
				(const char *)pItem->strItem,
				pItem->nPos,
				(const char *)pItem->strGroup);
			strText.ReleaseBuffer(nResult);
		}
		else
		{
			pBuf = strText.GetBuffer(pItem->strItem.GetLength()+pItem->strText.GetLength()+pItem->strGroup.GetLength()+80);
			nResult = sprintf(pBuf,"%cbaritem {%s} {%s} {%d} {%d} {%d} {%d} {%s}\n",
				_config.chCommand,
				(const char *)pItem->strItem,
				(const char *)pItem->strText,
				pItem->nPos,
				pItem->nLen,
				pItem->nFore,
				pItem->nBack,
				pItem->strGroup);
			strText.ReleaseBuffer(nResult);
		}

		file.WriteString(strText);
		pItem = _statusBar.GetNext();
	}

	if (!_chat.GetChatName().IsEmpty())
	{
		strTemp.Format("%cchatname {%s}\n",_config.chCommand,
			(const char *)_chat.GetChatName());
		file.WriteString(strTemp);
	}

	if (!_msp.GetPath().IsEmpty())
	{
		strTemp.Format("%cmsp {%s}\n",_config.chCommand,
			(const char *)_msp.GetPath());
		file.WriteString(strTemp);
	}

	file.Close();
	PrintMessage("Command file written."); 
}

void WriteGroup(CString &strLine)
{
	CStdioFileFixed file;

	CString strFilename, strGroup;
	FindStatement(strLine,strFilename);
	FindStatement(strLine,strGroup);

	ReplaceVariables(strFilename);
	ReplaceVariables(strGroup);

	CString strPath(_config.strScriptPath+strFilename);
	if (_config.bPromptOverwrite)
	{
		CFileStatus fs;
		char ch;
		if (CFile::GetStatus(strPath,fs))
		{
			PrintMessage(CString("File (")+strPath+") exists, overwrite it (y/N)?");
			ch = tolower(getch());
			if (ch != 'y')
				return;
		}
	}
	BackupFile(strPath);
	if (!file.Open(strPath,CFile::modeWrite|CFile::modeCreate|CFile::typeText))
	{
		PrintMessage("Unable to open that file.");
		return;
	}

	PrintMessage(CString("Writing command file:")+strPath);

	CString strText;
	CString strTemp;
	CString strKey;
	CString strPrepare;
	char *pBuf;
	int nResult;

	int nActions = 0;
	ACTION *pAction = _actions.GetFirst();
	while(pAction != NULL)
	{
		if (pAction->strGroup == strGroup)
		{
		

⌨️ 快捷键说明

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