bool CResourceLink::ResourceLock( CResourceLock &s )
{
    ADDTOCALLSTACK("CResourceLink::ResourceLock");
    // Find the definition of this item in the scripts.
    // Open a locked copy of this script
    // NOTE: How can we tell the file has changed since last open ?
    // RETURN: true = found it.
    if ( !IsLinked() )	// has already failed previously.
        return false;

    ASSERT(m_pScript);

    //	Give several tryes to lock the script while multithreading
    int iRet = s.OpenLock( m_pScript, m_Context );
    if ( ! iRet )
        return true;

    s.AttachObj( this );

    // ret = -2 or -3
    lpctstr pszName = GetResourceName();
    DEBUG_ERR(("ResourceLock '%s':%d id=%s FAILED\n", s.GetFilePath(), m_Context.m_iOffset, pszName));

    return false;
}
bool CItemMessage::LoadSystemPages()
{
	DEBUG_CHECK( IsBookSystem());

	CResourceLock s;
	if ( ! g_Cfg.ResourceLock( s, m_itBook.m_ResID ))
		return false;

	int iPages = -1;
	while ( s.ReadKeyParse())
	{
		switch ( FindTableSorted( s.GetKey(), sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 ))
		{
		case CIC_AUTHOR:
			m_sAuthor = s.GetArgStr();
			break;
		case CIC_PAGES:
			iPages = s.GetArgVal();
			break;
		case CIC_TITLE:
			SetName( s.GetArgStr());	// Make sure the book is named.
			break;
		}
	}

	if ( iPages > 2*MAX_BOOK_PAGES || iPages < 0 )
		return( false );

	TCHAR szTemp[ 16*1024 ];
	for ( int iPage=1; iPage<=iPages; iPage++ )
	{
		if ( ! g_Cfg.ResourceLock( s, RESOURCE_ID( RES_BOOK, m_itBook.m_ResID.GetResIndex(), iPage )))
		{
			break;
		}

		int iLen = 0;
		while (s.ReadKey())
		{
			int iLenStr = strlen( s.GetKey());
			if ( iLen + iLenStr >= sizeof( szTemp ))
				break;
			iLen += strcpylen( szTemp+iLen, s.GetKey());
			szTemp[ iLen++ ] = '\t';
		}
		szTemp[ --iLen ] = '\0';

		AddPageText( szTemp );
	}

	return( true );
}
Exemple #3
0
TRIGRET_TYPE CClient::Menu_OnSelect( RESOURCE_ID_BASE rid, int iSelect, CObjBase * pObj ) // Menus for general purpose
{
	ADDTOCALLSTACK("CClient::Menu_OnSelect");
	// A select was made. so run the script.
	// iSelect = 0 = cancel.

	CResourceLock s;
	if ( ! g_Cfg.ResourceLock( s, rid ))
	{
		// Can't find the resource ?
		return( TRIGRET_ENDIF );
	}

	if ( pObj == NULL )
		pObj = m_pChar;

	// execute the menu script.
	if ( iSelect == 0 )	// Cancel button
	{

		while ( s.ReadKeyParse() )
		{
			if ( !s.IsKey( "ON" ) || ( *s.GetArgStr() != '@' ) )
				continue;

			if ( strcmpi( s.GetArgStr(), "@cancel" ) )
				continue;

			return pObj->OnTriggerRunVal( s, TRIGRUN_SECTION_TRUE, m_pChar, NULL );
		}
	}
	else
	{
		int i=0;	// 1 based selection.
		while ( s.ReadKeyParse())
		{
			if ( !s.IsKey( "ON" ) || ( *s.GetArgStr() == '@' ) )
				continue;

			i++;
			if ( i < iSelect )
				continue;
			if ( i > iSelect )
				break;

			return pObj->OnTriggerRunVal( s, TRIGRUN_SECTION_TRUE, m_pChar, NULL );
		}
	}

	// No selection ?
	return( TRIGRET_ENDIF );
}
Exemple #4
0
TRIGRET_TYPE CClient::Dialog_OnButton( RESOURCE_ID_BASE rid, DWORD dwButtonID, CObjBase * pObj, CDialogResponseArgs * pArgs )
{
	ADDTOCALLSTACK("CClient::Dialog_OnButton");
	// one of the gump dialog buttons was pressed.
	if ( !pObj )		// object is gone ?
		return TRIGRET_ENDIF;

	CResourceLock s;
	if ( !g_Cfg.ResourceLock(s, RESOURCE_ID(RES_DIALOG, rid.GetResIndex(), RES_DIALOG_BUTTON)) )
		return TRIGRET_ENDIF;

	INT64 piCmd[3];
	while ( s.ReadKeyParse())
	{
		if ( ! s.IsKeyHead( "ON", 2 ))
			continue;

		size_t iArgs = Str_ParseCmds( s.GetArgStr(), piCmd, COUNTOF(piCmd) );
		if ( iArgs == 0 )
			continue;

		if ( iArgs == 1 )
		{
			// single button value
			if ( (DWORD)piCmd[0] != dwButtonID )
				continue;
		}
		else
		{
			// range of button values
			if ( dwButtonID < (DWORD)piCmd[0] || dwButtonID > (DWORD)piCmd[1] )
				continue;
		}

		pArgs->m_iN1	 = dwButtonID;		
		return pObj->OnTriggerRunVal( s, TRIGRUN_SECTION_TRUE, m_pChar, pArgs );
	}

	return( TRIGRET_ENDIF );
}
Exemple #5
0
bool CDialogDef::GumpSetup( int iPage, CClient * pClient, CObjBase * pObjSrc, lpctstr Arguments )
{
    ADDTOCALLSTACK("CDialogDef::GumpSetup");
    CResourceLock	s;

    m_uiControls	= 0;
    m_uiTexts		= 0;
    m_pObj			= pObjSrc;
    m_iOriginX		= 0;
    m_iOriginY		= 0;
    m_wPage			= (word)(iPage);
    m_fNoDispose	= false;

    CScriptTriggerArgs	Args(iPage, 0, pObjSrc);
    //DEBUG_ERR(("Args.m_s1_raw %s  Args.m_s1 %s  Arguments 0x%x\n",Args.m_s1_raw, Args.m_s1, Arguments));
    Args.m_s1_raw = Args.m_s1 = Arguments;

    // read text first
    if ( g_Cfg.ResourceLock( s, CResourceID( RES_DIALOG, GetResourceID().GetResIndex(), RES_DIALOG_TEXT ) ) )
    {
        while ( s.ReadKey())
        {
            if ( m_uiTexts >= (CountOf(m_sText) - 1) )
                break;
            m_pObj->ParseText( s.GetKeyBuffer(), pClient->GetChar() );
            m_sText[m_uiTexts] = s.GetKey();
            m_uiTexts++;
        }
    }
    else
    {
        // no gump text?
    }

    // read the main dialog
    if ( !ResourceLock( s ) )
        return false;
    if ( !s.ReadKey() )		// read the size.
        return false;

    // starting x,y location.
    int64 iSizes[2];
    tchar * pszBuf = s.GetKeyBuffer();
    m_pObj->ParseText( pszBuf, pClient->GetChar() );

    Str_ParseCmds( pszBuf, iSizes, CountOf(iSizes) );
    m_x		= (int)(iSizes[0]);
    m_y		= (int)(iSizes[1]);

    if ( OnTriggerRunVal( s, TRIGRUN_SECTION_TRUE, pClient->GetChar(), &Args ) == TRIGRET_RET_TRUE )
        return false;
    return true;
}
Exemple #6
0
void CClient::Menu_Setup( RESOURCE_ID_BASE rid, CObjBase * pObj )
{
	ADDTOCALLSTACK("CClient::Menu_Setup");
	// Menus for general purpose
	// Expect PacketMenuChoice::onReceive() back.

	CResourceLock s;
	if ( ! g_Cfg.ResourceLock( s, rid ))
	{
		return;
	}

	if ( pObj == NULL )
	{
		pObj = m_pChar;
	}

	s.ReadKey();	// get title for the menu.
	pObj->ParseText( s.GetKeyBuffer(), m_pChar );

	CMenuItem item[MAX_MENU_ITEMS];
	item[0].m_sText = s.GetKey();
	// item[0].m_id = rid.m_internalrid;	// general context id

	size_t i = 0;
	while (s.ReadKeyParse())
	{
		if ( ! s.IsKey( "ON" ))
			continue;

		i++;
		if ( ! item[i].ParseLine( s.GetArgRaw(), pObj, m_pChar ))
			i--;

		if ( i >= (COUNTOF( item ) - 1))
			break;
	}

	m_tmMenu.m_ResourceID = rid;

	ASSERT(i < COUNTOF(item));
	addItemMenu( CLIMODE_MENU, item, i, pObj );
}
Exemple #7
0
size_t CClient::Cmd_Skill_Menu_Build( RESOURCE_ID_BASE rid, int iSelect, CMenuItem *item, size_t iMaxSize, bool &fShowMenu, bool &fLimitReached )
{
	ADDTOCALLSTACK("CClient::Cmd_Skill_Menu_Build");
	// Build the skill menu for the curent active skill.
	// Only list the things we have skill and ingrediants to make.
	//
	// ARGS:
	//	m_Targ_UID = the object used to get us here.
	//  rid = which menu ?
	//	iSelect = -2 = Just a test of the whole menu.,
	//	iSelect = -1 = 1st setup.
	//	iSelect = 0 = cancel
	//	iSelect = x = execute the selection.
	//  fShowMenu = whether or not menus can be shown
	//  item = pointer to entries list
	//  iMaxSize = maximum number of entries
	//
	// RETURN: number of entries in menu
	//   m_tmMenu.m_Item = the menu entries.

	ASSERT(m_pChar);
	if ( rid.GetResType() != RES_SKILLMENU )
		return 0;

	// Find section.
	CResourceLock s;
	if ( !g_Cfg.ResourceLock(s, rid) )
		return 0;

	// Get title line
	if ( !s.ReadKey() )
		return 0;

	if ( iSelect == 0 )		// cancelled
	{
		while ( s.ReadKeyParse() )
		{
			if ( !s.IsKey("ON") || (*s.GetArgStr() != '@') )
				continue;

			if ( strcmpi(s.GetArgStr(), "@Cancel") )
				continue;

			if ( m_pChar->OnTriggerRunVal(s, TRIGRUN_SECTION_TRUE, m_pChar, NULL) == TRIGRET_RET_TRUE )
				return 0;

			break;
		}
		return 1;
	}

	if ( iSelect < 0 )
	{
		item[0].m_sText = s.GetKey();
		if ( iSelect == -1 )
			m_tmMenu.m_ResourceID = rid;
	}

	bool fSkip = false;		// skip this if we lack resources or skill.
	int iOnCount = 0;
	size_t iShowCount = 0;
	CScriptTriggerArgs Args;

	while ( s.ReadKeyParse())
	{
		if ( s.IsKeyHead("ON", 2) )
		{
			if ( *s.GetArgStr() == '@' )
			{
				fSkip = true;
				continue;
			}

			// a new option to look at.
			fSkip = false;
			iOnCount++;

			if ( iSelect < 0 )	// building up the list.
			{
				if ( iSelect < -1 && iShowCount >= 1 )		// just a test. so we are done.
					return 1;

				iShowCount++;
				if ( !item[iSelect == -2 ? 0 : iShowCount].ParseLine(s.GetArgRaw(), NULL, m_pChar) )
				{
					// remove if the item is invalid.
					iShowCount--;
					fSkip = true;
					continue;
				}

				if ( iSelect == -1 )
					m_tmMenu.m_Item[iShowCount] = iOnCount;

				if ( iShowCount >= (iMaxSize - 1) )
					break;
			}
			else
			{
				if ( iOnCount > iSelect )	// we are done.
					break;
			}
			continue;
		}

		if ( fSkip )	// we have decided we cant do this option.
			continue;
		if ( iSelect > 0 && iOnCount != iSelect )	// only interested in the selected option
			continue;

		// Check for a skill / non-consumables required.
		if ( s.IsKey("TEST") )
		{
			m_pChar->ParseText(s.GetArgRaw(), m_pChar);
			CResourceQtyArray skills(s.GetArgStr());
			if ( !skills.IsResourceMatchAll(m_pChar) )
			{
				iShowCount--;
				fSkip = true;
			}
			continue;
		}

		if ( s.IsKey("TESTIF") )
		{
			m_pChar->ParseText(s.GetArgRaw(), m_pChar);
			if ( !s.GetArgVal() )
			{
				iShowCount--;
				fSkip = true;
			}
			continue;
		}

		// select to execute any entries here ?
		if ( iOnCount == iSelect )
		{
			// Execute command from script
			TRIGRET_TYPE tRet = m_pChar->OnTriggerRunVal(s, TRIGRUN_SINGLE_EXEC, m_pChar, &Args);
			if ( tRet != TRIGRET_RET_DEFAULT )
				return tRet == TRIGRET_RET_TRUE ? 0 : 1;

			iShowCount++;	// we are good. but continue til the end
		}
		else
		{
			ASSERT(iSelect < 0);
			if ( s.IsKey("SKILLMENU") )
			{
				static int sm_iReentrant = 0;
				if ( sm_iReentrant > 1024 )
				{
					if ( g_Cfg.m_wDebugFlags & DEBUGF_SCRIPTS )
						g_Log.EventDebug("SCRIPT: Too many skill menus (circular menus?) to continue searching in menu '%s'\n", g_Cfg.ResourceGetDef(rid)->GetResourceName());

					fLimitReached = true;
				}
				else
				{
					// Test if there is anything in this skillmenu we can do.
					++sm_iReentrant;
					if ( !Cmd_Skill_Menu_Build(g_Cfg.ResourceGetIDType(RES_SKILLMENU, s.GetArgStr()), -2, *&item, iMaxSize, fShowMenu, fLimitReached) )
					{
						iShowCount--;
						fSkip = true;
					}
					else
						fShowMenu = true;

					--sm_iReentrant;
				}
				continue;
			}

			if ( s.IsKey("MAKEITEM") )
			{
				// test if i can make this item using m_Targ_UID.
				// There should ALWAYS be a valid id here.
				if ( !m_pChar->Skill_MakeItem(static_cast<ITEMID_TYPE>(g_Cfg.ResourceGetIndexType(RES_ITEMDEF, s.GetArgStr())), m_Targ_UID, SKTRIG_SELECT) )
				{
					iShowCount--;
					fSkip = true;
				}
				continue;
			}
		}
	}
	return iShowCount;
}
Exemple #8
0
bool CWebPageDef::ServPagePost( CClient * pClient, LPCTSTR pszURLArgs, TCHAR * pContentData, int iContentLength )
{
	ADDTOCALLSTACK("CWebPageDef::ServPagePost");
	UNREFERENCED_PARAMETER(pszURLArgs);
	// RETURN: true = this was the page of interest.

	ASSERT(pClient);

	if ( pContentData == NULL || iContentLength <= 0 )
		return( false );
	if ( ! HasTrigger(XTRIG_UNKNOWN))	// this form has no triggers.
		return( false );

	// Parse the data.
	pContentData[iContentLength] = 0;
	TCHAR * ppArgs[64];
	size_t iArgs = Str_ParseCmds(pContentData, ppArgs, COUNTOF(ppArgs), "&");
	if (( iArgs <= 0 ) || ( iArgs >= 63 ))
		return false;

	// T or TXT or TEXT = the text fields.
	// B or BTN or BUTTON = the buttons
	// C or CHK or CHECK = the check boxes

	CDialogResponseArgs resp;
	DWORD dwButtonID = ULONG_MAX;
	for ( size_t i = 0; i < iArgs; i++ )
	{
		TCHAR * pszNum = ppArgs[i];
		while ( IsAlpha(*pszNum) )
			pszNum++;

		int iNum = ATOI(pszNum);
		while ( *pszNum )
		{
			if ( *pszNum == '=' )
			{
				pszNum++;
				break;
			}
			pszNum++;
		}
		switch ( toupper(ppArgs[i][0]) )
		{
			case 'B':
				dwButtonID = iNum;
				break;
			case 'C':
				if ( !iNum )
					continue;
				if ( ATOI(pszNum) )
				{
					resp.m_CheckArray.Add( iNum );
				}
				break;
			case 'T':
				if ( iNum > 0 )
				{
					TCHAR *pszData = Str_GetTemp();
					HtmlDeCode( pszData, pszNum );
					resp.AddText(static_cast<WORD>(iNum), pszData);
				}
				break;
		}
	}

	// Use the data in RES_WEBPAGE block.
	CResourceLock s;
	if ( !ResourceLock(s) )
		return false;

	// Find the correct entry point.
	while ( s.ReadKeyParse())
	{
		if ( !s.IsKeyHead("ON", 2) || ( (DWORD)s.GetArgVal() != dwButtonID ))
			continue;
		OnTriggerRunVal(s, TRIGRUN_SECTION_TRUE, pClient, &resp);
		return true;
	}

	// Put up some sort of failure page ?

	return( false );
}