📄 commandsmtor.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 "Notifications.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 "ScrollBack.h"
#include "Gags.h"
#include "Highlights.h"
#include "Chat.h"
#include "Undo.h"
#include "Dll.h"
#include "Sound.h"
#include "Msp.h"
void Macro(CString &strLine)
{
CString strParam1, strParam2, strGroup;
FindStatement(strLine,strParam1);
FindStatement(strLine,strParam2);
FindStatement(strLine,strGroup);
ReplaceVariables(strParam1);
ReplaceVariables(strGroup);
PretranslateString(strParam2);
// List them all if both params empty.
if (strParam1.IsEmpty() && strParam2.IsEmpty())
{
CString strText;
strText.Format("Defined Macros (%d):",_macros.GetCount());
PrintMessage(strText);
CommandPrintOn();
char *pBuf;
int nResult;
int nLineCount = 1;
int nNumLines = _terminal.GetWindowLines()-2;
int nInc;
MACRO *pMac = _macros.GetFirst();
while(pMac != NULL)
{
pBuf = strText.GetBuffer(pMac->strKeyName.GetLength()+pMac->strText.GetLength()+pMac->strGroup.GetLength()+30);
nResult = sprintf(pBuf,"%s%03d:%s%c{%s} {%s} {%s}\n",
ANSI_F_BOLDWHITE,
_macros.GetFindIndex()+1,
ANSI_RESET,
(pMac->bEnabled ? ' ' : '*'),
(const char *)pMac->strKeyName,
(const char *)pMac->strText,
(const char *)pMac->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;
}
pMac = _macros.GetNext();
}
CommandPrintOff();
return;
}
if (!strParam1.IsEmpty() && !strParam2.IsEmpty())
{
if (_macros.Assign(strParam1,strParam2,strGroup))
{
if (_config.bMacroMessages)
PrintMessage("Macro added.");
}
else
{
if (_config.bMacroMessages)
PrintMessage("Macro not added.");
}
return;
}
MACRO *pMac = _macros.FindKeyByName(strParam1);
if (pMac != NULL)
{
PrintMessage("Defined Macro:");
CString strText;
char *pBuf = strText.GetBuffer(pMac->strKeyName.GetLength()+pMac->strText.GetLength()+pMac->strGroup.GetLength()+30);
int nResult = sprintf(pBuf,"{%s} {%s} {%s}\n",
(const char *)pMac->strKeyName,
(const char *)pMac->strText,
(const char *)pMac->strGroup);
strText.ReleaseBuffer(nResult);
CommandPrintOn();
_terminal.Print(strText);
CommandPrintOff();
}
}
void Math(CString &strLine)
{
CString strVar, strMath;
FindStatement(strLine,strVar);
FindStatement(strLine,strMath);
if (strVar.IsEmpty() || strMath.IsEmpty())
return;
ReplaceVariables(strVar);
ReplaceVariables(strMath);
long lResult;
if (CalculateMath(strMath,lResult))
{
CString strValue;
strValue.Format("%ld",lResult);
_mapVars.Add(strVar,strValue,NULL);
}
}
void Message(CString &strLine)
{
CString strParam1;
FindStatement(strLine,strParam1);
if (strParam1.IsEmpty())
{
PrintMessage("You can toggle messages of the following types");
CommandPrintOn();
_terminal.Print(" Actions\n Aliases\n Arrays\n Bar\n EnableGroup\n Events\n "
"Gags\n Highlights\n Items\n Lists\n Macros\n Substitutes\n "
"TabList\n Variables\n");
CommandPrintOff();
return;
}
strParam1.MakeLower();
CString strText;
CString strSection = "Messages";
if (IsPartial(strParam1,"actions"))
{
if (_config.bActionMessages)
_config.bActionMessages = FALSE;
else
_config.bActionMessages = TRUE;
strText.Format("Messages concerning actions are now %s.",
(_config.bActionMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Actions",_config.bActionMessages);
return;
}
if (IsPartial(strParam1,"aliases"))
{
if (_config.bAliasMessages)
_config.bAliasMessages = FALSE;
else
_config.bAliasMessages = TRUE;
strText.Format("Messages concerning aliases are now %s.",
(_config.bAliasMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Aliases",_config.bAliasMessages);
return;
}
if (IsPartial(strParam1,"arrays"))
{
if (_config.bArrayMessages)
_config.bArrayMessages = FALSE;
else
_config.bArrayMessages = TRUE;
strText.Format("Messages concerning arrays are now %s.",
(_config.bArrayMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Arrays",_config.bArrayMessages);
return;
}
if (IsPartial(strParam1,"bar"))
{
if (_config.bBarMessages)
_config.bBarMessages = FALSE;
else
_config.bBarMessages = TRUE;
strText.Format("Messages concerning the status bar are now %s.",
(_config.bBarMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Bar Items",_config.bBarMessages);
return;
}
if (IsPartial(strParam1,"enablegroup"))
{
if (_config.bEnableMessages)
_config.bEnableMessages = FALSE;
else
_config.bEnableMessages = TRUE;
strText.Format("Messages concerning the enabling and disabling of groups are now %s.",
(_config.bEnableMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"EnableGroup",_config.bEnableMessages);
return;
}
if (IsPartial(strParam1,"events"))
{
if (_config.bEventMessages)
_config.bEventMessages = FALSE;
else
_config.bEventMessages = TRUE;
strText.Format("Messages concerning events are now %s.",
(_config.bEventMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Events",_config.bEventMessages);
return;
}
if (IsPartial(strParam1,"gags"))
{
if (_config.bGagMessages)
_config.bGagMessages = FALSE;
else
_config.bGagMessages = TRUE;
strText.Format("Messages concerning gags are now %s.",
(_config.bGagMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Gags",_config.bGagMessages);
return;
}
if (IsPartial(strParam1,"highlights"))
{
if (_config.bHighMessages)
_config.bHighMessages = FALSE;
else
_config.bHighMessages = TRUE;
strText.Format("Messages concerning highlights are now %s.",
(_config.bHighMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Highlights",_config.bHighMessages);
return;
}
if (IsPartial(strParam1,"items"))
{
if (_config.bItemMessages)
_config.bItemMessages = FALSE;
else
_config.bItemMessages = TRUE;
strText.Format("Messages concerning items are now %s",
(_config.bItemMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"List Items",_config.bItemMessages);
return;
}
if (IsPartial(strParam1,"lists"))
{
if (_config.bListMessages)
_config.bListMessages = FALSE;
else
_config.bListMessages = TRUE;
strText.Format("Messages concerning lists are now %s",
(_config.bListMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Lists",_config.bListMessages);
return;
}
if (IsPartial(strParam1,"macros"))
{
if (_config.bMacroMessages)
_config.bMacroMessages = FALSE;
else
_config.bMacroMessages = TRUE;
strText.Format("Messages concerning macros are now %s.",
(_config.bMacroMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Macros",_config.bMacroMessages);
return;
}
if (IsPartial(strParam1,"substitutes"))
{
if (_config.bSubMessages)
_config.bSubMessages = FALSE;
else
_config.bSubMessages = TRUE;
strText.Format("Messages concerning substitutes are now %s.",
(_config.bSubMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Subs",_config.bSubMessages);
return;
}
if (IsPartial(strParam1,"tablist"))
{
if (_config.bTabMessages)
_config.bTabMessages = FALSE;
else
_config.bTabMessages = TRUE;
strText.Format("Messages concerning the tab list are now %s.",
(_config.bTabMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Tabs",_config.bTabMessages);
return;
}
if (IsPartial(strParam1,"variables"))
{
if (_config.bVarMessages)
_config.bVarMessages = FALSE;
else
_config.bVarMessages = TRUE;
strText.Format("Messages concerning variables are now %s.",
(_config.bVarMessages ? "on" : "off"));
PrintMessage(strText);
WriteIniInt(strSection,"Variables",_config.bVarMessages);
return;
}
}
void MMLoadLibrary(CString &strLine)
{
CString strLib;
CString strTemp;
int nDllNum;
FindStatement(strLine,strLib);
ReplaceVariables(strLib);
if (strLib.IsEmpty())
return;
nDllNum = _dlls.Add(strLib);
if (nDllNum)
{
strTemp.Format("DLL loaded as #%d.",nDllNum);
PrintMessage(strTemp);
DLL *pDll = _dlls.FindExact(strLib);
if (!pDll)
return;
DLLCALLBACK proc = (DLLCALLBACK)GetProcAddress(pDll->hDLL,"CallbackAddress");
if (proc == NULL)
return;
(proc)(DllCallback);
}
else
PrintMessage("Failed to load the DLL.");
}
void Mode(CString &strLine)
{
CString strMode;
FindStatement(strLine,strMode);
if (strMode == "25")
{
BOOL bBar = _config.bStatusBar;
if (bBar)
_statusBar.HideBar();
_terminal.Mode25();
_tiUserInput.Move(0,24,80);
_tiUserInput.SetFocus();
if (bBar)
_statusBar.ShowBar(_config.nStatusBarPos);
}
else
if (strMode == "50")
{
BOOL bBar = _config.bStatusBar;
if (bBar)
_statusBar.HideBar();
_terminal.Mode50();
_tiUserInput.Move(0,49,80);
_tiUserInput.SetFocus();
if (bBar)
_statusBar.ShowBar(_config.nStatusBarPos);
}
}
void Msp(CString &strLine)
{
CString strPath;
FindStatement(strLine,strPath);
ReplaceVariables(strPath);
if (strPath.IsEmpty())
{
PrintMessage("MSP path cleared.");
_msp.Clear();
_config.bMspOn = FALSE;
return;
}
if (strPath[0] == '+')
{
CString strTemp;
strTemp = _msp.MatchWildcard(strPath.Right(strPath.GetLength()-1),MATCH_WAVE);
PrintMessage(strTemp);
return;
}
if (strPath == "?")
{
CommandPrintOn();
PrintMessage("MSP Files Found:");
CString strFile;
strFile = _msp.GetFirstWave();
while(!strFile.IsEmpty())
{
_terminal.Print(strFile+"\n");
strFile = _msp.GetNextWave();
}
strFile = _msp.GetFirstMidi();
while(!strFile.IsEmpty())
{
_terminal.Print(strFile+"\n");
strFile = _msp.GetNextMidi();
}
CommandPrintOff();
return;
}
strPath.MakeLower();
if (strPath == "on")
{
if (_msp.GetPath().IsEmpty())
{
PrintMessage("You need to give a MSP path before you can turn it on.");
return;
}
_config.bMspOn = TRUE;
PrintMessage("MSP processing on.");
return;
}
if (strPath == "off")
{
_config.bMspOn = FALSE;
PrintMessage("MSP processing off.");
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -