📄 procedures.cpp
字号:
}
void CommandToList(CString &strParams)
{
CString strListName, strCommand;
FindParam(strParams,strListName);
FindParam(strParams,strCommand);
if (strListName.IsEmpty() || strCommand.IsEmpty())
return;
ReplaceVariables(strListName);
USER_LIST *pList;
int nListIndex = atoi(strListName);
if (!nListIndex)
pList = _lists.FindByName(strListName);
else
pList = _lists.GetAt(nListIndex-1);
if (pList == NULL)
return;
CString strText;
STRING_MAP *pMap;
int nCount = pList->mapList.GetCount();
for (int i=0;i<nCount;i++)
{
pMap = pList->mapList.GetAt(i);
_strListItem = pMap->strKey;
strText = strCommand;
ReplaceVariables(strText);
HandleInput(strText);
}
}
BOOL ConCat(CString &strParams, CString &strResult)
{
CString strText;
FindParam(strParams,strResult);
FindParam(strParams,strText);
ReplaceVariables(strResult);
ReplaceVariables(strText);
strResult += strText;
return(TRUE);
}
BOOL Connected(CString &strParams, CString &strResult)
{
if (_bConnected)
strResult = '1';
else
strResult = '0';
return(TRUE);
}
BOOL Day(CString &strParams, CString &strResult)
{
CTime tNow = CTime::GetCurrentTime();
strResult.Format("%d",tNow.GetDay());
return(TRUE);
}
BOOL EventTime(CString &strParams, CString &strResult)
{
CString strName;
FindParam(strParams,strName);
ReplaceVariables(strName);
EVENT *pEvent = _events.FindByName(strName);
if (pEvent == NULL)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@EventTime(%s): Event not found.",(const char *)strName);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
time_t tNow = time(NULL);
int nDif = pEvent->nSeconds - (_dwTime - pEvent->dwStarted);
if (nDif < 0)
nDif = 0;
strResult.Format("%d",nDif);
return(TRUE);
}
BOOL Exists(CString &strParams, CString &strResult)
{
CString strVarName;
FindParam(strParams,strVarName);
ReplaceVariables(strVarName);
if (strVarName.IsEmpty())
{
if (_config.bDebugMessages)
{
PrintMessage("@Exists(): Variable name is missing.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
if (_mapVars.FindExactByKey(strVarName) == NULL)
strResult = '0';
else
strResult = '1';
return(TRUE);
}
BOOL FileExists(CString &strParams, CString &strResult)
{
CString strName;
FindParam(strParams,strName);
ReplaceVariables(strName);
CFileStatus fs;
strResult.Format("%d",CFile::GetStatus(strName,fs));
return(TRUE);
}
BOOL ForeBlack(CString &strParams, CString &strResult)
{
strResult = ANSI_F_BLACK;
return(TRUE);
}
BOOL ForeBlue(CString &strParams, CString &strResult)
{
strResult = ANSI_F_BLUE;
return(TRUE);
}
BOOL ForeCyan(CString &strParams, CString &strResult)
{
strResult = ANSI_F_CYAN;
return(TRUE);
}
BOOL ForeGreen(CString &strParams, CString &strResult)
{
strResult = ANSI_F_GREEN;
return(TRUE);
}
BOOL ForeMagenta(CString &strParams, CString &strResult)
{
strResult = ANSI_F_MAGENTA;
return(TRUE);
}
BOOL ForeRed(CString &strParams, CString &strResult)
{
strResult = ANSI_F_RED;
return(TRUE);
}
BOOL ForeYellow(CString &strParams, CString &strResult)
{
strResult = ANSI_F_YELLOW;
return(TRUE);
}
BOOL ForeWhite(CString &strParams, CString &strResult)
{
strResult = ANSI_F_WHITE;
return(TRUE);
}
BOOL GetArray(CString &strParams, CString &strResult)
{
CString strName, strRow, strCol;
FindParam(strParams,strName);
FindParam(strParams,strRow);
FindParam(strParams,strCol);
ReplaceVariables(strName);
ReplaceVariables(strRow);
ReplaceVariables(strCol);
ARRAY *ptr;
int nIndex = atoi(strName);
if (nIndex)
ptr = _arrays.GetAt(nIndex-1);
else
ptr = _arrays.FindExact(strName);
if (ptr == NULL)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@GetArray(%s,%s,%s): Array not found.",
(const char *)strName,
(const char *)strRow,
(const char *)strCol);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
if (!_arrays.GetItem(ptr,atoi(strRow),atoi(strCol),strResult))
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@GetArray(%s,%s,%s): Index out of bounds.",
(const char *)strName,
(const char *)strRow,
(const char *)strCol);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
return(TRUE);
}
BOOL GetCount(CString &strParams, CString &strResult)
{
CString strListName;
FindParam(strParams,strListName);
ReplaceVariables(strListName);
if (strListName.IsEmpty())
{
if (_config.bDebugMessages)
{
PrintMessage("@GetCount(): Missing list name.",TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
USER_LIST *pList;
int nListIndex = atoi(strListName);
if (!nListIndex)
pList = _lists.FindByName(strListName);
else
pList = _lists.GetAt(nListIndex-1);
if (pList == NULL)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@GetCount(%s): Cannot find list.",(const char *)strListName);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult.Format("%u",pList->mapList.GetCount());
return(TRUE);
}
BOOL GetItem(CString &strParams, CString &strResult)
{
CString strListName, strIndex;
FindParam(strParams,strListName);
FindParam(strParams,strIndex);
ReplaceVariables(strListName);
ReplaceVariables(strIndex);
if (strListName.IsEmpty())
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@GetItem(,%s): List name is empty.",
(const char *)strIndex);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
if (strIndex.IsEmpty())
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("GetItem(%s,): The item index is missing.",
(const char *)strListName);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
USER_LIST *pList;
int nListIndex = atoi(strListName);
if (!nListIndex)
pList = _lists.FindByName(strListName);
else
pList = _lists.GetAt(nListIndex-1);
if (pList == NULL)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@GetItem(%s,%s): Cannot find list.",
(const char *)strListName,
(const char *)strIndex);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
int nItemIndex = atoi(strIndex);
nItemIndex--;
if (nItemIndex < 0 || nItemIndex >= pList->mapList.GetCount())
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@GetItem(%s,%s): Index out of bounds.",
(const char *)strListName,
(const char *)strIndex);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
STRING_MAP *pMap = pList->mapList.GetAt(nItemIndex);
if (pMap == NULL)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@GetItem(%s,%s): Item not found.",
(const char *)strListName,
(const char *)strIndex);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
strResult = pMap->strKey;
return(TRUE);
}
BOOL GetKey(CString &strParams, CString &strResult)
{
strResult = getch();
return(TRUE);
}
BOOL Hour(CString &strParams, CString &strResult)
{
CTime tNow = CTime::GetCurrentTime();
strResult.Format("%d",tNow.GetHour());
return(TRUE);
}
BOOL InList(CString &strParams, CString &strResult)
{
CString strListName, strItem;
FindParam(strParams,strListName);
FindParam(strParams,strItem);
ReplaceVariables(strListName);
ReplaceVariables(strItem);
if (strListName.IsEmpty())
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@InList(,%s): List name is empty.",
(const char *)strItem);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
if (strItem.IsEmpty())
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@InList(%s,): List name is empty.",
(const char *)strListName);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
USER_LIST *pList;
int nListIndex = atoi(strListName);
if (!nListIndex)
pList = _lists.FindByName(strListName);
else
pList = _lists.GetAt(nListIndex-1);
if (pList == NULL)
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@InList(%s,%s): Cannot find list.",
(const char *)strListName,
(const char *)strItem);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
if (pList->mapList.InList(strItem))
{
strResult = "1";
return(TRUE);
}
strResult = "0";
return(TRUE);
}
BOOL IP(CString &strParams, CString &strResult)
{
GetIPAddress();
strResult = _config.strIPAddress;
return(TRUE);
}
BOOL IPP(CString &strParams, CString &strResult)
{
GetIPAddress();
strResult.Format("%s %d",(const char *)_config.strIPAddress,_nListenPort);
return(TRUE);
}
BOOL IsEmpty(CString &strParams, CString &strResult)
{
CString strText;
FindParam(strParams,strText);
ReplaceVariables(strText);
strResult.Format("%d",strText.IsEmpty());
return(TRUE);
}
BOOL IsNumber(CString &strParams, CString &strResult)
{
CString strText;
FindParam(strParams,strText);
ReplaceVariables(strText);
if (strText.IsEmpty())
{
strResult = "0";
return(TRUE);
}
int nLen;
int i;
nLen = strText.GetLength();
i = 0;
while(i < nLen)
{
if (!isdigit(strText[i]) && strText[i] != '-')
{
strResult = "0";
return(TRUE);
}
i++;
}
strResult = "1";
return(TRUE);
}
BOOL KeyWaiting(CString &strParams, CString &strResult)
{
if (kbhit())
strResult = '1';
else
strResult = '0';
return(TRUE);
}
BOOL Left(CString &strParams, CString &strResult)
{
CString strText;
CString strNum;
FindParam(strParams,strText);
FindParam(strParams,strNum);
ReplaceVariables(strText);
ReplaceVariables(strNum);
if (strText.IsEmpty())
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@Left(,%s): Text string is empty.",
(const char *)strNum);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
}
return(FALSE);
}
if (strNum.IsEmpty())
{
if (_config.bDebugMessages)
{
CString strTemp;
strTemp.Format("@Left(%s,): Number of characters is empty.",
(const char *)strText);
PrintMessage(strTemp,TRUE,TRUE);
_debugStack.DumpStack(_config.nDebugDepth);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -