Esempio n. 1
0
VOID HideDoCommand(PSPAWNINFO pChar, PCHAR szLine, BOOL delayed)
{
    if (delayed)
    {
        PCHATBUF pChat = (PCHATBUF)malloc(sizeof(CHATBUF));
        if (pChat) {
            strcpy(pChat->szText,szLine);
            pChat->pNext = NULL;
            if (!gDelayedCommands) {
                gDelayedCommands = pChat;
            } else {
                PCHATBUF pCurrent;
                for (pCurrent = gDelayedCommands;pCurrent->pNext;pCurrent=pCurrent->pNext);
                pCurrent->pNext = pChat;
            }
        }
        return;
    }

    CAutoLock DoCommandLock(&gCommandCS);
    CHAR szCmd[MAX_STRING] = {0};
    CHAR szParam[MAX_STRING] = {0};
    CHAR szOriginalLine[MAX_STRING] = {0};

    strcpy(szOriginalLine,szLine);
    GetArg(szCmd,szLine,1);
    PALIAS pLoop = pAliases;
    while (pLoop) {
        if (!stricmp(szCmd,pLoop->szName)) {
            sprintf(szLine,"%s%s",pLoop->szCommand,szOriginalLine+strlen(pLoop->szName));
            break;
        }
        pLoop = pLoop->pNext;
    }


    GetArg(szCmd,szLine,1);
    if (szCmd[0]==0)
		return;
    strcpy(szParam, GetNextArg(szLine));

    if ((szCmd[0]==':') || (szCmd[0]=='{')) {
        bRunNextCommand = TRUE;
        return;
    }
	if(gMacroBlock && gMacroBlock->LoopLine!=0) {
		//this is a command thats inside a while loop
		//so its time to loop back
		gMacroBlock = GetWhileBlock(gMacroBlock->LoopLine);
		if (szCmd[0]=='}') {
			bRunNextCommand = TRUE;
			return;
		}
	} else if (szCmd[0]=='}') {
		if (strstr(szLine,"{")) {
			GetArg(szCmd,szLine,2);
			if (stricmp(szCmd,"else")) {
				FatalError("} and { seen on the same line without an else present");
			}
			//          DebugSpew("DoCommand - handing {} off to FailIf");
			FailIf(pChar,"{",gMacroBlock,TRUE);
		} else {
			// handle this: 
			//            /if () {
			//            } else /echo stuff
			GetArg(szCmd,szLine,2);
			if (!stricmp(szCmd,"else")) {
				// check here to fail this:
				//            /if () {
				//            } else 
				//                /echo stuff
				GetArg(szCmd,szLine,3);
				if (!stricmp(szCmd,"")) {
					FatalError("no command or { following else");
				}
				bRunNextCommand = TRUE;
			} else {
				bRunNextCommand = TRUE;
			}
		}
		return;
    }
    if (szCmd[0]==';' || szCmd[0]=='[')
    {
        pEverQuest->InterpretCmd((EQPlayer*)pChar,szOriginalLine);
        return;
    }



    PMQCOMMAND pCommand=pCommands;
    while(pCommand)
    {
        if (pCommand->InGameOnly && gGameState!=GAMESTATE_INGAME)
        {
            pCommand=pCommand->pNext;
            continue;
        }
        int Pos=strnicmp(szCmd,pCommand->Command,strlen(szCmd));
        if (Pos<0)
        {// command not found
            break;
        }
        if (Pos==0)
        {
            if (pCommand->Parse && bAllowCommandParse)
            {
                pCommand->Function(pChar,ParseMacroParameter(pChar,szParam)); 
            } else {
                pCommand->Function(pChar,szParam);
			}
            strcpy(szLastCommand,szOriginalLine);
            return;
        }
        pCommand=pCommand->pNext;
    }
    if (!strnicmp(szOriginalLine,"sub ",4)) {
        FatalError("Flow ran into another subroutine.");
        return;
    }

    strcpy(szLastCommand,szOriginalLine);
    MacroError("DoCommand - Couldn't parse '%s'",szOriginalLine);
}
Esempio n. 2
0
VOID HideDoCommand(PSPAWNINFO pChar, PCHAR szLine, BOOL delayed)
{
	
    if (delayed)
    {
		lockit lk(ghLockDelayCommand,"HideDoCommand");
		CHAR szTheCmd[MAX_STRING];
		strcpy_s(szTheCmd, szLine);
		PCHATBUF pChat = 0;
		try {
			pChat = new CHATBUF;
			strcpy_s(pChat->szText,szTheCmd);
            pChat->pNext = 0;
            if (!gDelayedCommands) {
                gDelayedCommands = pChat;
            } else {
                PCHATBUF pCurrent = 0;
                for (pCurrent = gDelayedCommands;pCurrent->pNext;pCurrent=pCurrent->pNext);
                pCurrent->pNext = pChat;
            }
		}
		catch(std::bad_alloc& exc)
		{
			UNREFERENCED_PARAMETER(exc);
			MessageBox(NULL,"HideDoCommand failed to allocate memory for gDelayedCommands","Did we just discover a memory leak?",MB_SYSTEMMODAL|MB_OK);
		};
        return;
    }
    CAutoLock DoCommandLock(&gCommandCS);
	CHAR szTheCmd[MAX_STRING];
	strcpy_s(szTheCmd, szLine);
	WeDidStuff();
    CHAR szOriginalLine[MAX_STRING];
    strcpy_s(szOriginalLine,szTheCmd);
	CHAR szArg1[MAX_STRING];
	GetArg(szArg1,szTheCmd,1);
	std::string sName = szArg1;
	std::transform(sName.begin(), sName.end(), sName.begin(), tolower);
	if (mAliases.find(sName) != mAliases.end()) {
		sprintf_s(szTheCmd, "%s%s", mAliases[sName].c_str(), szOriginalLine + sName.size());
	}

    GetArg(szArg1,szTheCmd,1);
    if (szArg1[0]==0)
		return;
	CHAR szParam[MAX_STRING];
	strcpy_s(szParam, GetNextArg(szTheCmd));

    if ((szArg1[0]==':') || (szArg1[0]=='{')) {
        bRunNextCommand = TRUE;
        return;
    }
	PMACROBLOCK pBlock = GetCurrentMacroBlock();
	if (szArg1[0]=='}') {
		if (pBlock && pBlock->Line[pBlock->CurrIndex].LoopStart != 0) {
			pBlock->CurrIndex = pBlock->Line[pBlock->CurrIndex].LoopStart;
			extern void pop_loop();
			pop_loop();
			return;
		}
		if (strstr(szTheCmd,"{")) {
			GetArg(szArg1,szTheCmd,2);
			if (_stricmp(szArg1,"else")) {
				FatalError("} and { seen on the same line without an else present");
			}
			//          DebugSpew("DoCommand - handing {} off to FailIf");
			if(pBlock)
				FailIf(pChar,"{",pBlock->CurrIndex,TRUE);
		} else {
			// handle this: 
			//            /if () {
			//            } else /echo stuff
			GetArg(szArg1,szTheCmd,2);
			if (!_stricmp(szArg1,"else")) {
				// check here to fail this:
				//            /if () {
				//            } else 
				//                /echo stuff
				GetArg(szArg1,szTheCmd,3);
				if (!_stricmp(szArg1,"")) {
					FatalError("no command or { following else");
				}
				bRunNextCommand = TRUE;
			} else {
				bRunNextCommand = TRUE;
			}
		}
		return;
    }
    if (szArg1[0]==';' || szArg1[0]=='[')
    {
        pEverQuest->InterpretCmd((EQPlayer*)pChar,szOriginalLine);
        return;
    }
    PMQCOMMAND pCommand=pCommands;
    while(pCommand)
    {
        if (pCommand->InGameOnly && gGameState!=GAMESTATE_INGAME)
        {
            pCommand=pCommand->pNext;
            continue;
        }
        int Pos=_strnicmp(szArg1,pCommand->Command,strlen(szArg1));
        if (Pos<0)
        {// command not found
            break;
        }
        if (Pos==0)
        {
            if (pCommand->Parse && bAllowCommandParse)
            {
                pCommand->Function(pChar,ParseMacroParameter(pChar,szParam)); 
            }
			else {
                pCommand->Function(pChar,szParam);
			}
            strcpy_s(szLastCommand,szOriginalLine);
            return;
        }
        pCommand=pCommand->pNext;
    }
    PBINDLIST pBind = pBindList;
    while( pBind )
    {
        if( gGameState != GAMESTATE_INGAME )
        {
            // Macro Binds only supported in-game
            pBind = pBind->pNext;
            continue;
        }

        int Pos = _strnicmp( szArg1, pBind->szName, strlen( szArg1 ) );

        if( Pos == 0 )
        {
            // found it!
            if( pBind->szFuncName )
            {
                if( PCHARINFO pCharInfo = GetCharInfo() )
                {
                    std::string sCallFunc( pBind->szFuncName );
                    sCallFunc += " ";
                    sCallFunc += szParam;
					CHAR szCallFunc[MAX_STRING] = { 0 };
					strcpy_s(szCallFunc, sCallFunc.c_str());
					ParseMacroData(szCallFunc, MAX_STRING);
					//Call(pCharInfo->pSpawn, (PCHAR)szCallFunc.c_str());
					if (pBlock && !pBlock->BindCmd.size()) {
						if (!gBindInProgress) {
							gBindInProgress = true;
							pBlock->BindCmd = szCallFunc;
						}
						else {
							Beep(1000, 100);
							WriteChatf("Can't execute bind while another bind is on progress");
						}
					}
                }
            }
            strcpy_s( szLastCommand, szOriginalLine );
            return;
        }

        pBind = pBind->pNext;
    }

    // skip this logic for Bind Commands.
    if( _strnicmp( szOriginalLine, "sub bind_", 9 ) != 0 ) {
        if( !_strnicmp( szOriginalLine, "sub ", 4 ) ) {
            FatalError( "Flow ran into another subroutine. (%s)", szOriginalLine );
            return;
        }

        strcpy_s( szLastCommand, szOriginalLine );
        MacroError( "DoCommand - Couldn't parse '%s'", szOriginalLine );
    }
}