bool AssetContract::StringToAmountLocale(int64_t& amount,
                                         const std::string& str_input,
                                         const std::string& str_thousand,
                                         const std::string& str_decimal) const
{
    // Lookup separator and decimal point symbols based on locale.

    // Get a moneypunct facet from the global ("C") locale
    //

    // NOTE: from web searching, I've determined that locale / moneypunct has
    // internationalization problems. Therefore it looks like if you want to
    // build OT for various languages / regions, you're just going to have to
    // edit stdafx.hpp and change the OT_THOUSANDS_SEP and OT_DECIMAL_POINT
    // variables.
    //
    // The best improvement I can think on that is to check locale and then use
    // it to choose from our own list of hardcoded values. Todo.

    static String strSeparator(str_thousand.empty() ? OT_THOUSANDS_SEP
                                                    : str_thousand);
    static String strDecimalPoint(str_decimal.empty() ? OT_DECIMAL_POINT
                                                      : str_decimal);

    bool bSuccess = AssetContract::ParseFormatted(
        amount, str_input, GetCurrencyFactor(), GetCurrencyDecimalPower(),
        strSeparator.Get(), strDecimalPoint.Get());

    return bSuccess;
}
void CSettings::ParseCommandLine(char * szCommandLine)
{
	// Loop until we reach the end of the command line string
	while(*szCommandLine)
	{
		// Is the current char not a space?
		if(!isspace(*szCommandLine))
		{
			// Is the current char a '-'?
			if(*szCommandLine == '-')
			{
				// Skip the '-'
				szCommandLine++;

				// Collect the setting string
				String strSetting;

				while(*szCommandLine && !isspace(*szCommandLine))
				{
					strSetting += *szCommandLine;
					szCommandLine++;
				}

				// If we have run out of command line to process break out of the loop
				if(!(*szCommandLine))
					break;

				// Skip the spaces between the option and the value
				while(*szCommandLine && isspace(*szCommandLine))
					szCommandLine++;

				// If we have run out of command line to process break out of the loop
				if(!(*szCommandLine))
					break;

				// Collect the value string
				String strValue;

				while(*szCommandLine && !isspace(*szCommandLine))
				{
					strValue += *szCommandLine;
					szCommandLine++;
				}

				// Set the setting and value
				if(!SetEx(strSetting, strValue))
					CLogFile::Printf("WARNING: Command line setting %s does not exist.", strSetting.Get());

				CLogFile::Printf("argv/argc command line: setting %s value %s", strSetting.Get(), strValue.Get());

				// If we have run out of command line to process break out of the loop
				if(!(*szCommandLine))
					break;
			}
		}

		// Increment the command line string pointer
		szCommandLine++;
	}
}
bool Settings::LogChange_str(const String& strSection, const String& strKey,
                               const String& strValue)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }

    const char* const szValue = (strValue.Exists() && !strValue.Compare(""))
                                    ? strValue.Get()
                                    : "nullptr";

    String strCategory, strOption;
    if (!Log::StringFill(strCategory, strSection.Get(), 12)) return false;
    if (!Log::StringFill(strOption, strKey.Get(), 30, " to:")) return false;

    otWarn << "Setting " << strCategory << " " << strOption << " " << szValue
           << " \n";
    return true;
}
Beispiel #4
0
eNetworkResponse CNetworkModule::Connect( String strHost, unsigned short usPort, String strPass )
{
	// Are we already connected?
	if( IsConnected() )
	{
		// Disconnect
		Disconnect();
	}

	// Store the connection info
	SetLastConnection( strHost, usPort, strPass );

#ifdef DEBUG
	CLogFile::Printf( "Connection to %s:%d, password: %s", strHost.Get(), usPort, strPass.Get() );
#endif

	// Attempt to connect
	int iConnectionResult = m_pRakPeer->Connect( strHost.Get(), usPort, strPass.Get(), strPass.GetLength() );

	// Set the network state
	SetNetworkState( NETSTATE_CONNECTING );

	// Did we fail to connect?
	if( iConnectionResult != RakNet::INVALID_PARAMETER )
	{
		// Set the network state
		SetNetworkState( NETSTATE_NONE );

		// Set the last connection try
		m_uiLastConnectionTry = (unsigned int)SharedUtility::GetTime();
	}

	return (eNetworkResponse)iConnectionResult;
}
bool Settings::CheckSetSection(const String& strSection,
                                 const String& strComment,
                                 bool& out_bIsNewSection)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (!strComment.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strComment"
              << " is Empty!\n";
        OT_FAIL;
    }

    const char* const szComment =
        (strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
                                                         : nullptr;

    const int64_t lSectionSize =
        pvt->iniSimple.GetSectionSize(strSection.Get());

    if (1 > lSectionSize) {
        out_bIsNewSection = true;
        SI_Error rc = pvt->iniSimple.SetValue(strSection.Get(), nullptr,
                                              nullptr, szComment, false);
        if (0 > rc) return false;
    }
    else {
        out_bIsNewSection = false;
    }
    return true;
}
Beispiel #6
0
bool OTASCIIArmor::WriteArmoredFile(
    const String& foldername, const String& filename,
    const // for "-----BEGIN OT LEDGER-----", str_type would contain "LEDGER"
    std::string str_type, // There's no default, to force you to enter the right
                          // string.
    bool bEscaped) const
{
    OT_ASSERT(foldername.Exists());
    OT_ASSERT(filename.Exists());

    String strOutput;

    if (WriteArmoredString(strOutput, str_type, bEscaped) &&
        strOutput.Exists()) {
        // WRITE IT TO THE FILE
        // StorePlainString will attempt to create all the folders leading up to
        // the path
        // for the output file.
        //
        bool bSaved = OTDB::StorePlainString(strOutput.Get(), foldername.Get(),
                                             filename.Get());

        if (!bSaved) {
            otErr << "OTASCIIArmor::WriteArmoredFile"
                  << ": Failed saving to file: %s%s%s\n\n Contents:\n\n"
                  << strOutput << "\n\n",
                foldername.Get(), Log::PathSeparator(), filename.Get();
            return false;
        }

        return true;
    }

    return false;
}
bool AssetContract::FormatAmountLocale(int64_t amount, std::string& str_output,
                                       const std::string& str_thousand,
                                       const std::string& str_decimal) const
{
    // Lookup separator and decimal point symbols based on locale.

    // Get a moneypunct facet from the global ("C") locale
    //
    // NOTE: Turns out moneypunct kind of sucks.
    // As a result, for internationalization purposes,
    // these values have to be set here before compilation.
    //
    static String strSeparator(str_thousand.empty() ? OT_THOUSANDS_SEP
                                                    : str_thousand);
    static String strDecimalPoint(str_decimal.empty() ? OT_DECIMAL_POINT
                                                      : str_decimal);

    // NOTE: from web searching, I've determined that locale / moneypunct has
    // internationalization problems. Therefore it looks like if you want to
    // build OT for various languages / regions, you're just going to have to
    // edit stdafx.hpp and change the OT_THOUSANDS_SEP and OT_DECIMAL_POINT
    // variables.
    //
    // The best improvement I can think on that is to check locale and then use
    // it to choose from our own list of hardcoded values. Todo.

    str_output = AssetContract::formatLongAmount(
        amount, GetCurrencyFactor(), GetCurrencyDecimalPower(),
        m_strCurrencySymbol.Get(), strSeparator.Get(), strDecimalPoint.Get());
    return true; // Note: might want to return false if str_output is empty.
}
bool Settings::CheckSet_str(const String& strSection, const String& strKey,
                              const String& strDefault, std::string& out_strResult,
                              bool& out_bIsNew, const String& strComment)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }

    const char* const szDefault =
        (strDefault.Exists() && !strDefault.Compare("")) ? strDefault.Get()
                                                         : nullptr;

    String strTempResult;
    bool bKeyExist;
    if (!Check_str(strSection, strKey, strTempResult, bKeyExist)) return false;

    if (bKeyExist) {
        // Already have a key, lets use it's value.
        out_bIsNew = false;
        out_strResult = strTempResult.Get();
        return true;
    }
    else {
        bool bNewKeyCheck;
        if (!Set_str(strSection, strKey, strDefault, bNewKeyCheck, strComment))
            return false;

        if (nullptr == szDefault) // The Default is to have no key.
        {
            // Success
            out_bIsNew = false;
            out_strResult = "";
            return true;
        }

        if (bNewKeyCheck) {
            // Success
            out_bIsNew = true;
            out_strResult = strDefault.Get();
            return true;
        }
    }

    // If we get here, error!
    OT_FAIL;
}
Beispiel #9
0
// static
bool OTKeyring::FlatFile_DeleteSecret(const String& strUser,
                                      const std::string& str_display)
{
    OT_ASSERT(strUser.Exists());

    const std::string str_pw_folder(OTKeyring::FlatFile_GetPasswordFolder());
    if (!str_pw_folder.empty()) {
        String strExactPath;
        strExactPath.Format("%s%s%s", str_pw_folder.c_str(),
                            Log::PathSeparator(), strUser.Get());
        const std::string str_ExactPath(strExactPath.Get());

        std::ofstream ofs(str_ExactPath.c_str(),
                          std::ios::out | std::ios::binary);

        if (ofs.fail()) {
            otErr << __FUNCTION__ << ": Error opening file (to delete it): "
                  << str_ExactPath.c_str() << '\n';
            return false;
        }
        ofs.clear();
        ofs << "(This space intentionally left blank.)\n";

        bool bSuccess = ofs.good() ? true : false;
        ofs.close();
        // Note: I bet you think I should be overwriting the file 7 times here
        // with
        // random data, right? Wrong: YOU need to override OTKeyring and create
        // your
        // own subclass, where you can override DeleteSecret and do that stuff
        // yourself. It's outside of the scope of OT.

        //
        if (remove(str_ExactPath.c_str()) != 0) {
            bSuccess = false;
            otErr << "** (OTKeyring::FlatFile_DeleteSecret) Failed trying to "
                  << "delete file (containing secret):  "
                  << str_ExactPath.c_str() << '\n';
        }
        else {
            bSuccess = true;
            otInfo << "** (OTKeyring::FlatFile_DeleteSecret) Success "
                   << "deleting file: " << str_ExactPath.c_str() << '\n';
        }

        return bSuccess;
    }

    otErr << "OTKeyring::FlatFile_DeleteSecret: Unable to delete any derived "
             "key, since password_folder not provided in config file.\n";

    return false;
}
Beispiel #10
0
bool CHttpClient::Post(bool bHasResponse, String strPath, String strData, String strContentType)
{
	// Connect to the host
	if(!Connect())
	{
		// Connect failed
		return false;
	}

	// Reset the header and data
	m_headerMap.clear();
	m_strData.Clear();

	// Prepare the POST command
	String strGet("POST %s HTTP/1.0\r\n" \
				  "Host: %s\r\n" \
				  "User-Agent: %s\r\n\r\n" \
				  "Referer: %s\r\n" \
				  "Content-Type: %s\r\n" \
				  "Content-Length: %d\r\n" \
				  "Connection: close\r\n" \
				  "\r\n" \
				  "%s", 
				  strPath.Get(), m_strHost.Get(), m_strUserAgent.Get(), 
				  m_strReferer.Get(), strContentType.Get(), strData.GetLength(),
				  strData.Get());

	// Send the POST command
	if(!Write(strGet.C_String(), strGet.GetLength()))
	{
		// Send failed
		return false;
	}

	// Do we have a response
	if(bHasResponse)
	{
		// Set the status to get data
		m_status = HTTP_STATUS_GET_DATA;

		// Set the request start
		m_uiRequestStart = SharedUtility::GetTime();
	}
	else
	{
		// Disconnect from the host
		Disconnect();
	}

	return true;
	
}
Beispiel #11
0
bool Settings::Check_bool(const String& strSection, const String& strKey,
                            bool& out_bResult, bool& out_bKeyExist) const
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strSection.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Blank!\n";
        OT_FAIL;
    }

    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (strKey.Compare("")) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Blank!\n";
        OT_FAIL;
    }

    const char* szVar =
        pvt->iniSimple.GetValue(strSection.Get(), strKey.Get(), nullptr);
    String strVar(szVar);

    if (strVar.Exists() &&
        (strVar.Compare("false") || strVar.Compare("true"))) {
        out_bKeyExist = true;
        if (strVar.Compare("true"))
            out_bResult = true;
        else
            out_bResult = false;
    }
    else {
        out_bKeyExist = false;
        out_bResult = false;
    }

    return true;
}
Beispiel #12
0
HRESULT Variable9::SpecializedCasts( Value* pCached, const Value& value )
{
    HRESULT hr = S_OK;

    SASVARIABLE_TYPE type = Desc().Type;
    switch( type )
    {
        case SASVT_TEXTURE:
        case SASVT_TEXTURE1D:
        case SASVT_TEXTURE2D:
        case SASVT_TEXTURE3D:
        case SASVT_TEXTURECUBE:
        {
            if( value.Type() == SASVT_STRING )
            {
                IUnknown* pTexture = NULL;
                String* strValue = (String*) ((Object&)value).Get();
                const WCHAR* str = strValue->Get();

                if(str != NULL && str[0] != L'\0' )
                {
                    SourceInfo si;
                    if(! Sas::Host::GetIntegrator()->FindFile( str , m_Effect->GetCreation()->GetDirectoryPath(), si) )
                        return E_FAIL;

                    hr = m_Effect->LoadTexture(si.GetFilePath(), (IUnknown**)&pTexture);	
                    if( FAILED(hr) )
                    {
                        Sas::Host::Out( Sas::LEVEL_WARNING, L"Unable to cast string into texture: %s", si.GetFilePath() );
                        SAFE_RELEASE(pTexture);
                        return hr;
                    }
                }

                switch(Desc().Type)
                {
                    case SASVT_TEXTURE:
                        ((Object*)pCached)->Set( Texture(pTexture) );
                        break;
                    case SASVT_TEXTURE1D:
                        ((Object*)pCached)->Set( Texture1D(pTexture) );
                        break;
                    case SASVT_TEXTURE2D:
                        ((Object*)pCached)->Set( Texture2D(pTexture) );
                        break;
                    case SASVT_TEXTURE3D:
                        ((Object*)pCached)->Set( Texture3D(pTexture) );
                        break;
                    case SASVT_TEXTURECUBE:
                        ((Object*)pCached)->Set( TextureCube(pTexture) );
                        break;
                }
                SAFE_RELEASE(pTexture);
                return S_OK;
            }
        }
    }

    return E_NOTIMPL;//we don't support that cast;
}
Beispiel #13
0
// Let's say you don't know if the input string is raw base64, or if it has
// bookends
// on it like -----BEGIN BLAH BLAH ...
// And if it DOES have Bookends, you don't know if they are escaped:  -
// -----BEGIN ...
// Let's say you just want an easy function that will figure that crap out, and
// load the
// contents up properly into an OTASCIIArmor object. (That's what this function
// will do.)
//
// str_bookend is a default.
// So you could make it more specific like, -----BEGIN ENCRYPTED KEY (or
// whatever.)
//
// static
bool OTASCIIArmor::LoadFromString(OTASCIIArmor& ascArmor,
                                  const String& strInput,
                                  std::string str_bookend)
{

    if (strInput.Contains(str_bookend)) // YES there are bookends around this.
    {
        const std::string str_escaped("- " + str_bookend);

        const bool bEscaped = strInput.Contains(str_escaped);

        String strLoadFrom(strInput);

        if (!ascArmor.LoadFromString(strLoadFrom, bEscaped)) // removes the
                                                             // bookends so we
                                                             // have JUST the
                                                             // coded part.
        {
            //          otErr << "%s: Failure loading string into OTASCIIArmor
            // object:\n\n%s\n\n",
            //                        __FUNCTION__, strInput.Get());
            return false;
        }
    }
    else
        ascArmor.Set(strInput.Get());

    return true;
}
Beispiel #14
0
bool OTASCIIArmor::WriteArmoredString(
    String& strOutput,
    const // for "-----BEGIN OT LEDGER-----", str_type would contain "LEDGER"
    std::string str_type, // There's no default, to force you to enter the right
                          // string.
    bool bEscaped) const
{
    const char* szEscape = "- ";

    String strTemp;
    strTemp.Format(
        "%s%s %s-----\n" // "%s-----BEGIN OT ARMORED %s-----\n"
        "Version: Open Transactions %s\n"
        "Comment: "
        "http://opentransactions.org\n\n" // todo
        // hardcoding.
        "%s"                // Should already have a newline at the bottom.
        "%s%s %s-----\n\n", // "%s-----END OT ARMORED %s-----\n"
        bEscaped ? szEscape : "",
        OT_BEGIN_ARMORED, str_type.c_str(), // "%s%s %s-----\n"
        Log::Version(),                     // "Version: Open Transactions %s\n"
        /* No variable */                   // "Comment:
        // http://github.com/FellowTraveler/Open-Transactions/wiki\n\n",
        Get(), //  "%s"     <==== CONTENTS OF THIS OBJECT BEING
               // WRITTEN...
        bEscaped ? szEscape : "", OT_END_ARMORED,
        str_type.c_str()); // "%s%s %s-----\n"

    strOutput.Concatenate("%s", strTemp.Get());

    return true;
}
Beispiel #15
0
// Compress and Base64-encode
bool OTASCIIArmor::SetString(const String& strData, bool bLineBreaks) //=true
{
    Release();

    if (strData.GetLength() < 1) return true;

    std::string stdstring = std::string(strData.Get());
    std::string str_compressed = compress_string(stdstring);

    // "Success"
    if (str_compressed.size() == 0) {
        otErr << "OTASCIIArmor::" << __FUNCTION__ << ": compression fail 0.\n";
        return false;
    }

    char* pString = App::Me().Crypto().Util().Base64Encode(
        reinterpret_cast<const uint8_t*>((str_compressed.data())),
        static_cast<int32_t>(str_compressed.size()), bLineBreaks);

    if (!pString) {
        otErr << "OTASCIIArmor::" << __FUNCTION__ << ": Base64Encode fail.\n";
        return false;
    }

    Set(pString);
    delete[] pString;
    return true;
}
void CServerRPCHandler::Chat(CBitStream * pBitStream, CPlayerSocket * pSenderSocket)
{
	// Ensure we have a valid bit stream
	if(!pBitStream)
		return;

	EntityId playerId = pSenderSocket->playerId;
	CPlayer * pPlayer = g_pPlayerManager->GetAt(playerId);

	if(pPlayer)
	{
		String strChat;

		if(!pBitStream->Read(strChat))
			return;

		strChat.Truncate(128);

		CSquirrelArguments pArguments;
		pArguments.push(playerId);
		pArguments.push(strChat);

		if(g_pEvents->Call("playerText", &pArguments).GetInteger() == 1)
		{
			CLogFile::Printf("[Chat] %s: %s", pPlayer->GetName().C_String(), strChat.Get());

			CBitStream bsSend;
			bsSend.WriteCompressed(playerId);
			bsSend.Write(String(strChat));
			g_pNetworkManager->RPC(RPC_Chat, &bsSend, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, INVALID_ENTITY_ID, true);
		}
	}
}
Beispiel #17
0
CGUIScrollPane_Impl::CGUIScrollPane_Impl( CGUI_Impl * pGUI, CGUIElement_Impl * pParent )
{
	// Store the manager instance
	m_pManager = pGUI;

	// Get a unique name for cegui
	String strName = pGUI->GetUniqueName();

	// Create the window and set default settings
	m_pWindow = pGUI->GetWindowManager()->createWindow( "CGUI/ScrollablePane", strName.Get() );
	m_pWindow->setDestroyedByParent( false );
	m_pWindow->setRect( CEGUI::Relative, CEGUI::Rect( 0.9f, 0.9f, 0.9f, 0.9f ) );
	m_pWindow->setVisible( true );

	// Store the pointer to this element
	m_pWindow->setUserData( (void *)this );

	// Register our events
	AddEvents();

	// If a parent is set, add it to it's childs list, if not add it as a child to the gui manager
	if( pParent )
		SetParent( pParent );
	else
	{
		pGUI->AddChild( this );
		SetParent( NULL );
	}

	// Set defaults
	SetHorizontalScrollStepSize( 100.0f );
	SetVerticalScrollStepSize( 100.0f );
}
Beispiel #18
0
/// Looked up the voucher account (where cashier's cheques are issued for any
/// given instrument definition) return a pointer to the account.  Since it's
/// SUPPOSED to
/// exist, and since it's being requested, also will GENERATE it if it cannot
/// be found, add it to the list, and return the pointer. Should always succeed.
std::shared_ptr<Account> Transactor::getVoucherAccount(
    const Identifier& INSTRUMENT_DEFINITION_ID)
{
    std::shared_ptr<Account> pAccount;
    const Identifier NOTARY_NYM_ID(server_->m_nymServer),
        NOTARY_ID(server_->m_strNotaryID);
    bool bWasAcctCreated = false;
    pAccount = voucherAccounts_.GetOrRegisterAccount(
        server_->m_nymServer, NOTARY_NYM_ID, INSTRUMENT_DEFINITION_ID,
        NOTARY_ID, bWasAcctCreated);
    if (bWasAcctCreated) {
        String strAcctID;
        pAccount->GetIdentifier(strAcctID);
        const String strInstrumentDefinitionID(INSTRUMENT_DEFINITION_ID);

        Log::vOutput(0, "OTServer::GetVoucherAccount: Successfully created "
                        "voucher account ID: %s Instrument Definition ID: %s\n",
                     strAcctID.Get(), strInstrumentDefinitionID.Get());

        if (!server_->mainFile_.SaveMainFile()) {
            Log::Error("OTServer::GetVoucherAccount: Error saving main "
                       "server file containing new account ID!!\n");
        }
    }

    return pAccount;
}
Beispiel #19
0
CGUIButton_Impl::CGUIButton_Impl( CGUI_Impl * pGUI, String strCaption, CGUIElement_Impl * pParent )
{
	// Store the manager instance
	m_pManager = pGUI;

	// Get a unique name for cegui
	String strName = pGUI->GetUniqueName();

	// Create the window and set default settings
	m_pWindow = pGUI->GetWindowManager()->createWindow( "CGUI/Button", strName.Get() );
	m_pWindow->setDestroyedByParent( false );
	SetText( strCaption );
	m_pWindow->setSize( CEGUI::Absolute, CEGUI::Size( 128.0f, 24.0f ) );
	m_pWindow->setVisible( true );

	// Store the pointer to this element
	m_pWindow->setUserData( (void *)this );

	// Register our events
	AddEvents();

	// If a parent is set, add it to it's childs list, if not add it as a child to the gui manager
	if( pParent )
		SetParent( pParent );
	else
	{
		pGUI->AddChild( this );
		SetParent( NULL );
	}
}
Beispiel #20
0
void CBlipManager::SetName(EntityId blipId, String strName)
{
	if(blipId >= MAX_BLIPS)
		return;
	if(m_bActive[blipId])
		Scripting::ChangeBlipNameFromAscii(m_Blips[blipId].uiBlipIndex, strName.Get());
}
Beispiel #21
0
void CScript::Call(int functionRef, CScriptArguments * pArguments, CScriptArgument * pReturn, const String & comment)
{
	// Lock the squirrel call mutex
	m_squirrelCallMutex.TryLock(10);

	// Get the stack top
	//int iTop = lua_gettop(m_pVM);

	CLogFile::Printf("Script Call: %s", comment.Get());
/*
	if(comment == "M:\\Xenicgames\\IVMP\\Binary\\resources\\main\\c_scoreboard.lua:59: ")
	{
		CLogFile::Print("59!!!");
	}*/

	lua_rawgeti(m_pVM, LUA_REGISTRYINDEX, functionRef);
	if(lua_type(m_pVM, -1) == LUA_TFUNCTION)
	{
		// Process the parameters if needed
		int iParams = 0;

		if(pArguments)
		{
			pArguments->push_to_vm(m_pVM);
			iParams += pArguments->size();
		}

		if(lua_pcall(m_pVM, iParams, LUA_MULTRET, 0) == 0)
		{
			// Set the return value if needed
			if(pReturn)
				pReturn->pushFromStack(m_pVM, -1);
		}
		else
		{
			PrintLuaError("Function call", comment.Get());
		}
	}
	else
		PrintError(true, "Function ref is invalid, Ref: %d, %s", functionRef, comment.Get());

	// Restore the stack top
	lua_settop(m_pVM, 0);

	// Unlock the squirrel call mutex
	m_squirrelCallMutex.Unlock();
}
Beispiel #22
0
bool CGUITexture_Impl::LoadFromFile(String strFile)
{
	// Does the file not exist?
	if( !SharedUtility::Exists(strFile.Get()))
		return false;

	// Try and load the file
	try
	{
		m_pTexture->loadFromFile(strFile.Get(), "");
	}
	catch(CEGUI::Exception)
	{
		return false;
	}
	return true;
}
Beispiel #23
0
void String::Set(const String strString)
{
	// Set the string
	m_strString.assign(strString.Get());

	// Ensure we haven't passed the string limit
	LimitTruncate();
}
Beispiel #24
0
void String::Append(const String strString)
{
	// Copy the string to the end of our string
	m_strString.append(strString.Get());

	// Ensure we haven't passed the string limit
	LimitTruncate();
}
Beispiel #25
0
OTStash::OTStash(const String& strInstrumentDefinitionID, int64_t lAmount)
{
    OTStashItem* pItem = new OTStashItem(strInstrumentDefinitionID, lAmount);
    OT_ASSERT(nullptr != pItem);

    m_mapStashItems.insert(std::pair<std::string, OTStashItem*>(
        strInstrumentDefinitionID.Get(), pItem));
}
void CClientScriptManager::AddScript(String strName, String strPath)
{
	ClientScript * pClientScript = new ClientScript();
	pClientScript->strName = strName;
	pClientScript->strPath = strPath;
	m_clientScripts.push_back(pClientScript);
	CLogFile::Printf("ClientScript %s added.", strName.Get());
}
Beispiel #27
0
// static
bool OTPaths::Set(OTSettings& config, const String& strSection,
                  const String& strKey, const String& strValue,
                  const bool& bIsRelative, bool& out_bIsNewOrUpdated,
                  const String& strComment)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Null: "
              << "strSection"
              << " passed in!\n";
        OT_FAIL;
    }
    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Null: "
              << "strKey"
              << " passed in!\n";
        OT_FAIL;
    }

    out_bIsNewOrUpdated = false;

    const bool bPreLoaded(config.IsLoaded());

    if (!bPreLoaded) // we only need to load, if not already loaded.
    {
        config.Reset();
        if (!config.Load()) {
            OT_FAIL;
        }
    }

    bool bBoolIsNew(false);
    String strRelativeKey("");

    strRelativeKey.Format("%s%s", strKey.Get(), OT_CONFIG_ISRELATIVE);

    if (config.Set_bool(strSection, strRelativeKey, bIsRelative, bBoolIsNew,
                        strComment)) {
        bool bStringIsNew = false;
        if (config.Set_str(strSection, strKey, strValue, bStringIsNew)) {
            if (bBoolIsNew && bStringIsNew) // using existing key
            {
                out_bIsNewOrUpdated = true;
            }

            if (!bPreLoaded) {
                if (!config.Save()) {
                    OT_FAIL;
                }
                config.Reset();
            }

            return true;
        }
    }

    // if we get here, there has been a error!
    OT_FAIL;
}
Beispiel #28
0
bool CryptoHash::Digest(
    const HashType hashType,
    const String& data,
    OTData& digest)
{
    OTData plaintext(data.Get(), data.GetLength());

    return Digest(hashType, plaintext, digest);
}
Beispiel #29
0
void CClient::ExceptionHandlerCallback(String& strReportData)
{
	// Get our crash reporter path
	String strApplicationPath = SharedUtility::GetAbsolutePath("Client.CrashReporter" DEBUG_SUFFIX ".exe ");

	// Generate the command line
	String strCommandLine("%s %s", strApplicationPath.Get(), strReportData.Get());

	// Start our crash reporter
	STARTUPINFO siStartupInfo;
	PROCESS_INFORMATION piProcessInfo;
	memset(&siStartupInfo, 0, sizeof(siStartupInfo));
	memset(&piProcessInfo, 0, sizeof(piProcessInfo));
	siStartupInfo.cb = sizeof(siStartupInfo);

	if(!CreateProcess(strApplicationPath.Get(), (char *)strCommandLine.Get(), NULL, NULL, TRUE, NULL, NULL, SharedUtility::GetAppPath(), &siStartupInfo, &piProcessInfo))
		CLogFile::Printf("Failed to start crash reporter.");
}
Beispiel #30
0
// static
bool OTKeyring::FlatFile_RetrieveSecret(const String& strUser,
                                        OTPassword& thePassword,
                                        const std::string& str_display)
{
    OT_ASSERT(strUser.Exists());
    const std::string str_pw_folder(OTKeyring::FlatFile_GetPasswordFolder());
    if (!str_pw_folder.empty()) {
        String strExactPath;
        strExactPath.Format("%s%s%s", str_pw_folder.c_str(),
                            Log::PathSeparator(), strUser.Get());
        const std::string str_ExactPath(strExactPath.Get());

        // Get the password
        //
        OTASCIIArmor ascData;

        if (!ascData.LoadFromExactPath(str_ExactPath))
            otErr << "OTKeyring::FlatFile_RetrieveSecret: "
                  << "Failed trying to decode secret from flat file contents."
                  << "\n";
        else {
            OTData thePayload(ascData);
            ascData.zeroMemory();
            if (thePayload.IsEmpty())
                otErr << __FUNCTION__ << ": Failed trying to decode secret "
                                         "OTData from OTASCIIArmor from "
                                         "flat file contents.\n";
            else {
                thePassword.setMemory(thePayload.GetPointer(),
                                      thePayload.GetSize());
                thePayload.zeroMemory(); // for security.
                return true;
            }
        }
    }

    // Not an error: what if it just hasn't been set there yet?
    //
    otWarn << __FUNCTION__ << ": Unable to retrieve any derived key, since "
                              "password_folder not provided in config file.\n";

    return false;
}