📄 commandsstoz.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 "ScrollBack.h"
#include "Gags.h"
#include "Highlights.h"
#include "Chat.h"
#include "Undo.h"
#include "Dll.h"
#include "Msp.h"
#include "Sound.h"
#include "Notifications.h"
#include "Substitute.h"
void SaveScrollback(CString &strLine)
{
CString strFilename;
FindStatement(strLine,strFilename);
ReplaceVariables(strFilename);
if (strFilename.IsEmpty())
return;
if (_scrollBack.SaveFile(strFilename))
PrintMessage("Scrollback buffer saved.");
}
void ScriptPath(CString &strLine)
{
CString strPath;
FindStatement(strLine,strPath);
ReplaceVariables(strPath);
if (!strPath.IsEmpty())
if (strPath.Right(1) != "\\")
strPath += "\\";
_config.strScriptPath = strPath;
WriteIniString("Paths","Script",strPath);
PrintMessage(CString("Script path changed to: ")+strPath);
}
void SendAction(CString &strLine)
{
CString strPerson;
CString strAction;
FindStatement(strLine,strPerson);
FindStatement(strLine,strAction);
ReplaceVariables(strPerson);
ReplaceVariables(strAction);
if (strPerson.IsEmpty() || strAction.IsEmpty())
return;
ACTION *pAct;
int nIndex = atoi(strAction);
if (nIndex)
pAct = _actions.GetAt(nIndex-1);
else
pAct = _actions.FindExact(strAction);
if (pAct == NULL)
return;
CString strTemp;
_actions.ActionToTrigger(pAct,strTemp);
char *pBuf = strAction.GetBuffer(strTemp.GetLength()+pAct->strAction.GetLength()+pAct->strGroup.GetLength()+40);
int nResult = sprintf(pBuf,"%caction {%s} {%s} {%s}",
_config.chCommand,
(const char *)strTemp,
(const char *)pAct->strAction,
(const char *)pAct->strGroup);
strAction.ReleaseBuffer(nResult);
nIndex = atoi(strPerson);
if (nIndex)
_chat.SendCommand(CHAT_SEND_ACTION,nIndex-1,strAction);
else
_chat.SendCommand(CHAT_SEND_ACTION,strPerson,strAction);
}
void SendAlias(CString &strLine)
{
CString strPerson;
CString strAlias;
FindStatement(strLine,strPerson);
FindStatement(strLine,strAlias);
ReplaceVariables(strPerson);
ReplaceVariables(strAlias);
if (strPerson.IsEmpty() || strAlias.IsEmpty())
return;
ALIAS_MAP *pAlias;
int nIndex = atoi(strAlias);
if (nIndex)
pAlias = _aliases.GetAt(nIndex-1);
else
pAlias = _aliases.FindExact(strAlias);
if (pAlias == NULL)
return;
_aliases.MapToCommand(pAlias,strAlias);
nIndex = atoi(strPerson);
if (nIndex)
_chat.SendCommand(CHAT_SEND_ALIAS,nIndex-1,strAlias);
else
_chat.SendCommand(CHAT_SEND_ALIAS,strPerson,strAlias);
}
void SendArray(CString &strLine)
{
CString strPerson;
CString strArray;
FindStatement(strLine,strPerson);
FindStatement(strLine,strArray);
ReplaceVariables(strPerson);
ReplaceVariables(strArray);
if (strPerson.IsEmpty() || strArray.IsEmpty())
return;
ARRAY *pArray;
int nIndex = atoi(strArray);
if (nIndex)
pArray = _arrays.GetAt(nIndex-1);
else
pArray = _arrays.FindExact(strArray);
if (pArray == NULL)
return;
CString strText;
char *pBuf;
int nResult;
if (pArray->bSingleDim)
{
pBuf = strText.GetBuffer(pArray->strName.GetLength()+pArray->strGroup.GetLength()+40);
nResult = sprintf(pBuf,"%carray {%s} {%d} {%s}",
_config.chCommand,
(const char *)pArray->strName,
pArray->nDim[0],
(const char *)pArray->strGroup);
strText.ReleaseBuffer(nResult);
}
else
{
pBuf = strText.GetBuffer(pArray->strName.GetLength()+pArray->strGroup.GetLength()+30);
nResult = sprintf(pBuf,"%carray {%s} {%d,%d} {%s}",
_config.chCommand,
(const char *)pArray->strName,
pArray->nDim[0],
pArray->nDim[1],
(const char *)pArray->strGroup);
strText.ReleaseBuffer(nResult);
}
nIndex = atoi(strPerson);
if (nIndex)
_chat.SendCommand(CHAT_SEND_ARRAY,nIndex-1,strText);
else
_chat.SendCommand(CHAT_SEND_ARRAY,strPerson,strText);
CString strTemp;
CString strPrepare;
if (pArray->bSingleDim)
{
for (int i=1;i<=pArray->nDim[0];i++)
{
_arrays.GetItem(pArray,i,0,strTemp);
PrepareForWrite(strTemp,strPrepare);
if (!strPrepare.IsEmpty())
{
pBuf = strText.GetBuffer(pArray->strName.GetLength()+strPrepare.GetLength()+40);
nResult = sprintf(pBuf,"%cassign {%s} {%d} {%s}",
_config.chCommand,
(const char *)pArray->strName,
i,
(const char *)strPrepare);
strText.ReleaseBuffer(nResult);
if (nIndex)
_chat.SendCommand(CHAT_SEND_ARRAY,nIndex-1,strText);
else
_chat.SendCommand(CHAT_SEND_ARRAY,strPerson,strText);
}
}
}
else
{
int j;
for (int i=1;i<=pArray->nDim[0];i++)
for (j=1;j<=pArray->nDim[1];j++)
{
_arrays.GetItem(pArray,i,j,strTemp);
PrepareForWrite(strTemp,strPrepare);
if (!strPrepare.IsEmpty())
{
pBuf = strText.GetBuffer(pArray->strName.GetLength()+strPrepare.GetLength()+40);
nResult = sprintf(pBuf,"%cassign {%s} {%d,%d} {%s}",
_config.chCommand,
(const char *)pArray->strName,
i,j,
(const char *)strPrepare);
strText.ReleaseBuffer(nResult);
if (nIndex)
_chat.SendCommand(CHAT_SEND_ARRAY,nIndex-1,strText);
else
_chat.SendCommand(CHAT_SEND_ARRAY,strPerson,strText);
}
}
}
}
void SendBarItem(CString &strLine)
{
CString strPerson;
CString strItem;
FindStatement(strLine,strPerson);
FindStatement(strLine,strItem);
ReplaceVariables(strPerson);
ReplaceVariables(strItem);
if (strPerson.IsEmpty() || strItem.IsEmpty())
return;
BAR_ITEM *pItem;
int nIndex = atoi(strItem);
if (nIndex)
pItem = _statusBar.GetAt(nIndex-1);
else
pItem = _statusBar.FindItem(strItem);
if (pItem == NULL)
return;
CString strText;
char *pBuf;
int nResult;
if (pItem->bSeparator)
{
pBuf = strText.GetBuffer(pItem->strItem.GetLength()+pItem->strGroup.GetLength()+40);
nResult = sprintf(pBuf,"%cbarseparator {%s} {%d} {%s}",
_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()+40);
nResult = sprintf(pBuf,"%cbaritem {%s} {%s} {%d} {%d} {%d} {%d} {%s}",
_config.chCommand,
(const char *)pItem->strItem,
(const char *)pItem->strText,
pItem->nPos,
pItem->nLen,
pItem->nFore,
pItem->nBack,
pItem->strGroup);
strText.ReleaseBuffer(nResult);
}
nIndex = atoi(strPerson);
if (nIndex)
_chat.SendCommand(CHAT_SEND_BARITEM,nIndex-1,strText);
else
_chat.SendCommand(CHAT_SEND_BARITEM,strPerson,strText);
}
void SendEvent(CString &strLine)
{
CString strPerson;
CString strEvent;
FindStatement(strLine,strPerson);
FindStatement(strLine,strEvent);
ReplaceVariables(strPerson);
ReplaceVariables(strEvent);
if (strPerson.IsEmpty() || strEvent.IsEmpty())
return;
EVENT *pEvent;
int nIndex = atoi(strEvent);
if (nIndex)
pEvent = _events.GetAt(nIndex-1);
else
pEvent = _events.FindByName(strEvent);
if (pEvent == NULL)
return;
CString strText;
char *pBuf = strText.GetBuffer(pEvent->strName.GetLength()+pEvent->strEvent.GetLength()+pEvent->strGroup.GetLength()+40);
int nResult = sprintf(pBuf,"%cevent {%s} {%d} {%s} {%s}",_config.chCommand,
(const char *)pEvent->strName,
pEvent->nSeconds,
(const char *)pEvent->strEvent,
(const char *)pEvent->strGroup);
strText.ReleaseBuffer(nResult);
nIndex = atoi(strPerson);
if (nIndex)
_chat.SendCommand(CHAT_SEND_EVENT,nIndex-1,strText);
else
_chat.SendCommand(CHAT_SEND_EVENT,strPerson,strText);
}
void SendFile(CString &strLine)
{
CString strPerson;
CString strFilename;
FindStatement(strLine,strPerson);
FindStatement(strLine,strFilename);
ReplaceVariables(strPerson);
ReplaceVariables(strFilename);
if (strPerson.IsEmpty() || strFilename.IsEmpty())
return;
int nIndex = atoi(strPerson);
if (nIndex)
_chat.SendFile(nIndex-1,strFilename);
else
_chat.SendFile(strPerson,strFilename);
}
void SendGag(CString &strLine)
{
CString strPerson;
CString strGag;
FindStatement(strLine,strPerson);
FindStatement(strLine,strGag);
ReplaceVariables(strPerson);
ReplaceVariables(strGag);
if (strPerson.IsEmpty() || strGag.IsEmpty())
return;
GAG *pGag;
int nIndex = atoi(strGag);
if (nIndex)
pGag = _gags.GetAt(nIndex-1);
else
pGag = _gags.FindExact(strGag);
if (pGag == NULL)
return;
CString strTemp;
CString strText;
_gags.GagToMask(pGag,strTemp);
char *pBuf = strText.GetBuffer(strTemp.GetLength()+pGag->strGroup.GetLength()+30);
int nResult = sprintf(pBuf,"%cgag {%s} {%s}",
_config.chCommand,
(const char *)strTemp,
(const char *)pGag->strGroup);
strText.ReleaseBuffer(nResult);
nIndex = atoi(strPerson);
if (nIndex)
_chat.SendCommand(CHAT_SEND_GAG,nIndex-1,strText);
else
_chat.SendCommand(CHAT_SEND_GAG,strPerson,strText);
}
void SendGroup(CString &strLine)
{
CString strPerson, strGroup;
FindStatement(strLine,strPerson);
FindStatement(strLine,strGroup);
ReplaceVariables(strPerson);
ReplaceVariables(strGroup);
if (strPerson.IsEmpty() || strGroup.IsEmpty())
return;
CString strText;
CString strTemp;
CString strKey;
int nIndex = atoi(strPerson);
char *pBuf;
int nResult;
int nActions = 0;
ACTION *pAction = _actions.GetFirst();
while(pAction != NULL)
{
if (pAction->strGroup == strGroup)
{
_actions.ActionToTrigger(pAction,strTemp);
pBuf = strText.GetBuffer(strTemp.GetLength()+pAction->strAction.GetLength()+pAction->strGroup.GetLength()+40);
nResult = sprintf(pBuf,"%caction {%s} {%s} {%s}",
_config.chCommand,
(const char *)strTemp,
(const char *)pAction->strAction,
(const char *)pAction->strGroup);
strText.ReleaseBuffer(nResult);
if (nIndex)
_chat.SendCommand(CHAT_SEND_ACTION,nIndex-1,strText);
else
_chat.SendCommand(CHAT_SEND_ACTION,strPerson,strText);
nActions++;
}
pAction = _actions.GetNext();
}
int nAliases = 0;
ALIAS_MAP *pAlias = _aliases.GetFirst();
while(pAlias != NULL)
{
if (pAlias->strGroup == strGroup)
{
_aliases.MapToCommand(pAlias,strText);
if (nIndex)
_chat.SendCommand(CHAT_SEND_ALIAS,nIndex-1,strText);
else
_chat.SendCommand(CHAT_SEND_ALIAS,strPerson,strText);
nAliases++;
}
pAlias = _aliases.GetNext();
}
int nMacros = 0;
MACRO *pMac = _macros.GetFirst();
while(pMac != NULL)
{
if (pMac->strGroup == strGroup)
{
pBuf = strText.GetBuffer(pMac->strKeyName.GetLength()+pMac->strText.GetLength()+pMac->strGroup.GetLength()+40);
nResult = sprintf(pBuf,"%cmacro {%s} {%s} {%s}",_config.chCommand,
(const char *)pMac->strKeyName,
(const char *)pMac->strText,
(const char *)pMac->strGroup);
strText.ReleaseBuffer(nResult);
if (nIndex)
_chat.SendCommand(CHAT_SEND_MACRO,nIndex-1,strText);
else
_chat.SendCommand(CHAT_SEND_MACRO,strPerson,strText);
nMacros++;
}
pMac = _macros.GetNext();
}
int nVariables = 0;
STRING_MAP *pStringMap = _mapVars.GetFirst();
while(pStringMap != NULL)
{
if (pStringMap->strGroup == strGroup)
{
if (pStringMap->strText.IsEmpty())
{
pBuf = strTemp.GetBuffer(pStringMap->strKey.GetLength()+pStringMap->strGroup.GetLength()+40);
nResult = sprintf(pBuf,"%cempty {%s} {%s}",
_config.chCommand,
(const char *)pStringMap->strKey,
(const char *)pStringMap->strGroup);
strTemp.ReleaseBuffer(nResult);
}
else
{
pBuf = strTemp.GetBuffer(pStringMap->strKey.GetLength()+pStringMap->strText.GetLength()+pStringMap->strGroup.GetLength()+40);
nResult = sprintf(pBuf,"%cvariable {%s} {%s} {%s}",
_config.chCommand,
(const char *)pStringMap->strKey,
(const char *)pStringMap->strText,
(const char *)pStringMap->strGroup);
strTemp.ReleaseBuffer(nResult);
}
if (nIndex)
_chat.SendCommand(CHAT_SEND_VARIABLE,nIndex-1,strTemp);
else
_chat.SendCommand(CHAT_SEND_VARIABLE,strPerson,strTemp);
nVariables++;
}
pStringMap = _mapVars.GetNext();
}
int nEvents = 0;
EVENT *pEvent = _events.GetFirst();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -