📄 commandsatof.cpp
字号:
/************************************************************************************
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 "Dll.h"
#include "Sound.h"
#include "Substitute.h"
#include "DebugStack.h"
#include "ChangesThread.h"
void Action(CString &strLine)
{
CString strParam1, strParam2, strGroup;
CString strTemp;
int nActionNum;
FindStatement(strLine,strParam1);
FindStatement(strLine,strParam2);
FindStatement(strLine,strGroup);
ReplaceVariables(strParam1);
ReplaceVariables(strGroup);
PretranslateString(strParam2);
if (!strParam1.IsEmpty() && !strParam2.IsEmpty())
{
nActionNum = _actions.Add(strParam1,strParam2,strGroup);
if (_config.bActionMessages)
if (nActionNum)
{
strTemp.Format("Action added as #%d.",nActionNum);
PrintMessage(strTemp);
}
else
PrintMessage("Action not added.");
return;
}
if (strParam1.IsEmpty() && strParam2.IsEmpty())
{
PrintMessage("Defined Actions:");
CommandPrintOn();
CString strTemp, strText;
char *ptr;
int nResult;
int nLineCount = 1;
int nNumLines = _terminal.GetWindowLines()-2;
int nInc;
ACTION *pAct = _actions.GetFirst();
while(pAct != NULL)
{
_actions.ActionToTrigger(pAct,strTemp);
ptr = strText.GetBuffer(strTemp.GetLength()+pAct->strAction.GetLength()+pAct->strGroup.GetLength()+80);
nResult = sprintf(ptr,"%s%03d:%s%c{%s} {%s} {%s}\n",
ANSI_F_BOLDWHITE,
_actions.GetFindIndex()+1,
ANSI_RESET,
(pAct->bEnabled ? ' ' : '*'),
(const char *)strTemp,
(const char *)pAct->strAction,
(const char *)pAct->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;
}
pAct = _actions.GetNext();
}
CommandPrintOff();
return;
}
if (strParam2.IsEmpty())
{
PrintMessage("Defined Action:");
CString strTemp, strText;
ACTION *pAct = _actions.FindExact(strParam1);
if (pAct != NULL)
{
_actions.ActionToTrigger(pAct,strTemp);
char *ptr = strText.GetBuffer(strTemp.GetLength()+pAct->strAction.GetLength()+pAct->strGroup.GetLength()+80);
int nResult = sprintf(ptr,"%c{%s} {%s} {%s}\n",
(pAct->bEnabled ? ' ' : '*'),
(const char *)strTemp,
(const char *)pAct->strAction,
(const char *)pAct->strGroup);
strText.ReleaseBuffer(nResult);
CommandPrintOn();
_terminal.Print(strText);
CommandPrintOff();
}
}
}
void Alias(CString &strLine)
{
CString strParam1, strParam2, strGroup;
CString strTemp;
int nAliasNum;
FindStatement(strLine,strParam1);
FindStatement(strLine,strParam2);
FindStatement(strLine,strGroup);
ReplaceVariables(strParam1);
ReplaceVariables(strGroup);
PretranslateString(strParam2);
// If have 2 params then add the alias.
if (!strParam1.IsEmpty() && !strParam2.IsEmpty())
{
nAliasNum = _aliases.Add(strParam1,strParam2,strGroup);
if (_config.bAliasMessages)
if (nAliasNum)
{
strTemp.Format("Alias added as #%d.",nAliasNum);
PrintMessage(strTemp);
}
else
PrintMessage("Alias not added.");
return;
}
// If don't have any params list them all.
if (strParam1.IsEmpty() && strParam2.IsEmpty())
{
PrintMessage("Defined Aliases:");
CommandPrintOn();
CString strTemp,strText;
char *ptr;
int nResult;
int nLineCount = 1;
int nNumLines = _terminal.GetWindowLines()-2;
int nInc;
ALIAS_MAP *pMap = _aliases.GetFirst();
while(pMap != NULL)
{
_aliases.MapToText(pMap,strText);
ptr = strTemp.GetBuffer(strText.GetLength()+30);
nResult = sprintf(ptr,"%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();
}
CommandPrintOff();
return;
}
if (strParam2.IsEmpty())
{
CString strText;
ALIAS_MAP *pMap = _aliases.FindExact(strParam1);
if (pMap != NULL)
{
PrintMessage("Defined Alias:");
_aliases.MapToText(pMap,strText);
CommandPrintOn();
if (pMap->bEnabled)
_terminal.Print(strText+"\n");
else
_terminal.Print(CString("*")+strText+"\n");
CommandPrintOff();
}
return;
}
}
void AltGr(CString &strLine)
{
if (_config.bAltGr)
{
_config.bAltGr = FALSE;
PrintMessage("AltGr disabled. The right Alt key will function the same as the left Alt Key.");
}
else
{
_config.bAltGr = TRUE;
PrintMessage("AltGr enabled. The right Alt key will function as the AltGr key.");
}
WriteIniInt("Miscellaneous","AltGr",_config.bAltGr);
}
void Array(CString &strLine)
{
CString strName, strDim, strGroup;
CString strTemp;
int nArrayNum;
FindStatement(strLine,strName);
FindStatement(strLine,strDim);
FindStatement(strLine,strGroup);
ReplaceVariables(strName);
ReplaceVariables(strDim);
ReplaceVariables(strGroup);
if (strName.IsEmpty())
{
// List the arrays.
PrintMessage("Arrays:");
CommandPrintOn();
CString strText;
char *pBuf;
int nResult;
int nLineCount = 1;
int nNumLines = _terminal.GetWindowLines()-2;
int nInc;
ARRAY *ptr = _arrays.GetFirst();
while(ptr != NULL)
{
if (ptr->bSingleDim)
{
pBuf = strText.GetBuffer(ptr->strName.GetLength()+ptr->strGroup.GetLength()+40);
nResult = sprintf(pBuf,"%s%03d:%s {%s} {Rows:%d} {%s}\n",
ANSI_F_BOLDWHITE,
_arrays.GetFindIndex()+1,
ANSI_RESET,
(const char *)ptr->strName,
ptr->nDim[0],
(const char *)ptr->strGroup);
strText.ReleaseBuffer(nResult);
}
else
{
pBuf = strText.GetBuffer(ptr->strName.GetLength()+ptr->strGroup.GetLength()+40);
nResult = sprintf(pBuf,"%s%03d:%s {%s} {Rows:%d} {Cols:%d} {%s}\n",
ANSI_F_BOLDWHITE,
_arrays.GetFindIndex()+1,
ANSI_RESET,
(const char *)ptr->strName,
ptr->nDim[0],
ptr->nDim[1],
(const char *)ptr->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;
}
ptr = _arrays.GetNext();
}
CommandPrintOff();
return;
}
if (strDim.IsEmpty())
return;
int nRows = atoi(strDim);
if (nRows < 1)
return;
int nIndex = strDim.Find(',');
BOOL bSingleDim;
int nCols = 0;
if (nIndex == -1)
bSingleDim = TRUE;
else
{
bSingleDim = FALSE;
nCols = atoi(strDim.Right(strDim.GetLength()-nIndex-1));
if (nCols < 1)
return;
}
nArrayNum = _arrays.Add(strName,bSingleDim,nRows,nCols,strGroup);
if (_config.bArrayMessages)
if (nArrayNum)
{
strTemp.Format("Array added as #%d.",nArrayNum);
PrintMessage(strTemp);
}
else
PrintMessage("Array not added.");
}
void Assign(CString &strLine)
{
CString strName, strIndex, strValue;
FindStatement(strLine,strName);
FindStatement(strLine,strIndex);
FindStatement(strLine,strValue);
if (strName.IsEmpty() || strIndex.IsEmpty())
return;
ReplaceVariables(strName);
ReplaceVariables(strIndex);
ReplaceVariables(strValue);
int nRow = atoi(strIndex);
int nCol;
int nIndex = strIndex.Find(',');
if (nIndex == -1)
nCol = 0;
else
nCol = atoi(strIndex.Right(strIndex.GetLength()-nIndex-1));
ARRAY *ptr;
nIndex = atoi(strName);
if (nIndex)
ptr = _arrays.GetAt(nIndex-1);
else
ptr = _arrays.FindExact(strName);
if (ptr == NULL)
return;
BOOL bResult = _arrays.Assign(ptr,nRow,nCol,strValue);
if (_config.bArrayMessages)
{
if (bResult)
PrintMessage("Item assigned.");
else
PrintMessage("Item not assigned.");
}
}
void AutoAccept(CString &strLine)
{
CString strAccept;
FindStatement(strLine,strAccept);
ReplaceVariables(strAccept);
if (strAccept.IsEmpty())
{
if (_config.bAutoAccept)
_config.bAutoAccept = FALSE;
else
_config.bAutoAccept = TRUE;
}
else
{
strAccept.MakeLower();
if (strAccept.Left(2) == "on")
_config.bAutoAccept = TRUE;
else
_config.bAutoAccept = FALSE;
}
strAccept.Format("Auto-Accept is now %s.",
(_config.bAutoAccept ? "On" : "Off"));
PrintMessage(strAccept);
WriteIniInt("Chat","Auto Accept",_config.bAutoAccept);
}
void BarBack(CString &strLine)
{
CString strBack;
FindStatement(strLine,strBack);
if (strBack.IsEmpty())
return;
ReplaceVariables(strBack);
int nBack = atoi(strBack);
_statusBar.SetBarBack(nBack);
WriteIniInt("Status Bar","Back Color",nBack);
}
void BarFore(CString &strLine)
{
CString strFore;
FindStatement(strLine,strFore);
if (strFore.IsEmpty())
return;
ReplaceVariables(strFore);
int nFore = atoi(strFore);
_statusBar.SetBarFore(nFore);
WriteIniInt("Status Bar","Fore Color",nFore);
}
void BarItem(CString &strLine)
{
CString strItem, strText, strPos, strLen, strFore, strBack, strGroup;
CString strTemp;
int nItemNum;
FindStatement(strLine,strItem);
FindStatement(strLine,strText);
FindStatement(strLine,strPos);
FindStatement(strLine,strLen);
FindStatement(strLine,strFore);
FindStatement(strLine,strBack);
FindStatement(strLine,strGroup);
if (strItem.IsEmpty())
{
PrintMessage("Bar Items:");
CommandPrintOn();
CString strText;
char *pBuf;
int nResult;
int nLineCount = 1;
int nNumLines = _terminal.GetWindowLines()-2;
int nInc;
BAR_ITEM *pItem = _statusBar.GetFirst();
while(pItem != NULL)
{
if (pItem->bSeparator)
{
pBuf = strText.GetBuffer(pItem->strItem.GetLength()+pItem->strGroup.GetLength()+80);
nResult = sprintf(pBuf,"%s%03d:%s%c{Pos:%2d} {Len: 1} {%s} {SEPARATOR} {%s}\n",
ANSI_F_BOLDWHITE,
_statusBar.GetFindIndex()+1,
ANSI_RESET,
(pItem->bEnabled ? ' ' : '*'),
pItem->nPos,
(const char *)pItem->strItem,
(const char *)pItem->strGroup);
strText.ReleaseBuffer(nResult);
}
else
{
pBuf = strText.GetBuffer(pItem->strItem.GetLength()+pItem->strText.GetLength()+pItem->strGroup.GetLength()+80);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -