Esempio n. 1
0
int CLuaFileDefs::fileWrite ( lua_State* luaVM )
{
//  int fileWrite ( file theFile, string string1 [, string string2, string string3 ...])
    CScriptFile* pFile;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pFile );
    
    // Ensure we have atleast one string
    if ( !argStream.NextIsString () )
        argStream.SetTypeError ( "string" );

    if ( !argStream.HasErrors () )
    {
        long lBytesWritten = 0; // Total bytes written
        
        // While we're not out of string arguments
        // (we will always have at least one string because we validated it above)
        while ( argStream.NextIsString () )
        {
            // Grab argument and length
            SString strData;
            argStream.ReadString ( strData );
            unsigned long ulDataLen = strData.length ();

            // Write the data
            long lArgBytesWritten = pFile->Write ( ulDataLen, strData );

            // Did the file mysteriously disappear?
            if ( lArgBytesWritten == -1 )
            {
                m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 );
                lua_pushnil ( luaVM );
                return 1;
            }

            // Add the number of bytes written to our counter
            lBytesWritten += lArgBytesWritten;
        }

#ifdef MTA_CLIENT
        // Inform file verifier
        if ( lBytesWritten != 0 )
            g_pClientGame->GetResourceManager ()->OnFileModifedByScript ( pFile->GetAbsPath (), "fileWrite" );
#endif
        
        // Return the number of bytes we wrote
        lua_pushnumber ( luaVM, lBytesWritten );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Error
    lua_pushnil ( luaVM );
    return 1;
}
Esempio n. 2
0
int CLuaTextDefs::textItemSetPriority ( lua_State* luaVM )
{
    CTextItem * pTextItem;
    int iPriority;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pTextItem );
    if ( argStream.NextIsString( ) )
    {
        SString strPriority;
        argStream.ReadString ( strPriority );

        if ( strPriority == "high" )        iPriority = PRIORITY_HIGH;
        else if ( strPriority == "medium" ) iPriority = PRIORITY_MEDIUM;
        else                                iPriority = PRIORITY_LOW;

    }
    else
    {
        argStream.ReadNumber(iPriority);
    }

    if ( !argStream.HasErrors ( ) )
    {
        pTextItem->SetPriority ( (eTextPriority)iPriority );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::SetDevelopmentMode ( lua_State* luaVM )
{
//  bool setDevelopmentMode ( bool enable )
//  bool setDevelopmentMode ( string command )
    bool bEnable; SString strCommand;

    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsString () )
    {
        argStream.ReadString ( strCommand );
        //g_pClientGame->SetDevSetting ( strCommand );
        lua_pushboolean ( luaVM, true );
        return 1;
    }
    argStream.ReadBool ( bEnable );

    if ( !argStream.HasErrors () )
    {
        g_pClientGame->SetDevelopmentMode ( bEnable );
        lua_pushboolean ( luaVM, true );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Esempio n. 4
0
int CLuaFileDefs::fileWrite ( lua_State* luaVM )
{
//  int fileWrite ( file theFile, string string1 [, string string2, string string3 ...])
    CScriptFile* pFile;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pFile );
    
    if ( !argStream.NextIsString () )
        argStream.SetTypeError ( "string" );

    if ( !argStream.HasErrors () )
    {
        // While we're not out of string arguments
        long lBytesWritten = 0;
        long lArgBytesWritten = 0;
        
        do
        {
            // Grab argument and length
            SString strData;
            argStream.ReadString ( strData );
            unsigned long ulDataLen = strData.length ();

            // Write it and add the bytes written to our total bytes written
            lArgBytesWritten = pFile->Write ( ulDataLen, strData );
            if ( lArgBytesWritten == -1 )
            {
                m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 );
                lua_pushnil ( luaVM );
                return 1;
            }
            lBytesWritten += lArgBytesWritten;
        }
        while ( argStream.NextIsString () );
        
        // Return the number of bytes we wrote
        lua_pushnumber ( luaVM, lBytesWritten );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Error
    lua_pushnil ( luaVM );
    return 1;
}
//
// GuiFont/string
//
void MixedReadGuiFontString ( CScriptArgReader& argStream, SString& strOutFontName, const char* szDefaultFontName, CClientGuiFont*& poutGuiFontElement )
{
    poutGuiFontElement = NULL;
    if ( argStream.NextIsString () || argStream.NextIsNone () )
        argStream.ReadString ( strOutFontName, szDefaultFontName );
    else
        argStream.ReadUserData ( poutGuiFontElement );
}
Esempio n. 6
0
int CLuaBanDefs::AddBan ( lua_State* luaVM )
{
    //  ban addBan ( [ string IP, string Username, string Serial, player responsibleElement, string reason, int seconds = 0 ] )
    SString strIP = "";
    SString strUsername = "";
    SString strSerial = "";
    SString strResponsible = "Console";
    CPlayer * pResponsible = NULL;
    SString strReason = "";
    time_t tUnban;


    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strIP, "" );
    argStream.ReadString ( strUsername, "" );
    argStream.ReadString ( strSerial, "" );
    if ( argStream.NextIsUserData () )
    {
        CElement* pResponsibleElement;
        argStream.ReadUserData ( pResponsibleElement );
        if ( ( pResponsible = dynamic_cast <CPlayer*> ( pResponsibleElement ) ) )
            strResponsible = pResponsible->GetNick ();
    }
    else
        argStream.ReadString ( strResponsible, "Console" );

    argStream.ReadString ( strReason, "" );

    if ( argStream.NextIsString () )
    {
        SString strTime;
        argStream.ReadString ( strTime );
        tUnban = atoi ( strTime );
    }
    else
        if ( argStream.NextIsNumber () )
            argStream.ReadNumber ( tUnban );
        else
            tUnban = 0;

    if ( tUnban > 0 )
        tUnban += time ( NULL );

    if ( !argStream.HasErrors () )
    {
        CBan* pBan = NULL;
        if ( ( pBan = CStaticFunctionDefinitions::AddBan ( strIP, strUsername, strSerial, pResponsible, strResponsible, strReason, tUnban ) ) )
        {
            lua_pushban ( luaVM, pBan );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
//
// Read next as resource or resource name.  Result output as string
//
void MixedReadResourceString ( CScriptArgReader& argStream, SString& strOutResourceName )
{
    if ( !argStream.NextIsString () )
    {
        CResource* pResource;
        argStream.ReadUserData ( pResource );
        if ( pResource )
            strOutResourceName = pResource->GetName ();
    }
    else
        argStream.ReadString ( strOutResourceName );
}
int CLuaFunctionDefs::UnbindKey ( lua_State* luaVM )
{
    SString strKey = "", strHitState = "";
    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strKey );

    if ( !argStream.HasErrors ( ) )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            if ( argStream.NextIsString ( 1 ) ) // Check if has command
            {
                // bool unbindKey ( string key, string keyState, string command )
                SString strResource = pLuaMain->GetResource()->GetName();
                SString strCommand = "";
                argStream.ReadString ( strHitState );
                argStream.ReadString ( strCommand );
                if ( !argStream.HasErrors ( ) )
                {
                    if ( CStaticFunctionDefinitions::UnbindKey ( strKey, strHitState, strCommand, strResource ) )
                    {
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                }
            }
            else
            {
                // bool unbindKey ( string key, [ string keyState, function handler ] )
                CLuaFunctionRef iLuaFunction;
                argStream.ReadString ( strHitState, "" );
                argStream.ReadFunction ( iLuaFunction, LUA_REFNIL );
                argStream.ReadFunctionComplete ();
                if ( !argStream.HasErrors ( ) )
                {
                    const char* szHitState = strHitState == "" ? NULL : strHitState.c_str();
                    if ( CStaticFunctionDefinitions::UnbindKey ( strKey, pLuaMain, szHitState, iLuaFunction ) )
                    {
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                }
            }
        }
    }

    if ( argStream.HasErrors ( ) )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Esempio n. 9
0
int CLuaFileDefs::fileWrite ( lua_State* luaVM )
{
    // string fileWrite ( file, string [, string2, string3, ...] )

    // Grab the file pointer
    CScriptFile* pFile = NULL;
    SString strMessage = "";
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pFile );
    argStream.ReadString ( strMessage );

    if ( !argStream.HasErrors ( ) )
    {
        if ( pFile )
        {
            // While we're not out of string arguments
            long lBytesWritten = 0;
            long lArgBytesWritten = 0;
            do
            {
                unsigned long ulDataLen = strMessage.length ( );

                // Write it and add the bytes written to our total bytes written
                lArgBytesWritten = pFile->Write ( ulDataLen, strMessage.c_str ( ) );
                if ( lArgBytesWritten == -1 )
                {
                    m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 );
                    lua_pushnil ( luaVM );
                    return 1;
                }
                lBytesWritten += lArgBytesWritten;

                if ( !argStream.NextIsString ( ) )
                    break;

                argStream.ReadString ( strMessage );
            }
            while ( true );

            // Return the number of bytes we wrote
            lua_pushnumber ( luaVM, lBytesWritten );
            return 1;
        }
        else
            m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 );
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Error
    lua_pushnil ( luaVM );
    return 1;
}
Esempio n. 10
0
int CLuaFunctionDefs::BindKey ( lua_State* luaVM )
{
    SString strKey = "", strHitState = "", strCommand = "", strArguments = "";
    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strKey );
    argStream.ReadString ( strHitState );

    if ( !argStream.HasErrors ( ) )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLuaMain )
        {
            if ( argStream.NextIsString ( ) )
            {
                // bindKey ( string key, string keyState, string commandName, [ string arguments ] )
                SString strResource = pLuaMain->GetResource()->GetName();
                argStream.ReadString ( strCommand );
                argStream.ReadString ( strArguments, "" );
                if ( !argStream.HasErrors ( ) )
                {
                    if ( CStaticFunctionDefinitions::BindKey ( strKey, strHitState, strCommand, strArguments, strResource ) )
                    {
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }  
                }
            }
            else
            {
                // bindKey ( string key, string keyState, function handlerFunction,  [ var arguments, ... ] )
                CLuaFunctionRef iLuaFunction;
                CLuaArguments Arguments;
                argStream.ReadFunction ( iLuaFunction );
                argStream.ReadLuaArguments ( Arguments );
                argStream.ReadFunctionComplete ();
                if ( !argStream.HasErrors ( ) )
                {
                    if ( CStaticFunctionDefinitions::BindKey ( strKey, strHitState, pLuaMain, iLuaFunction, Arguments ) )
                    {
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                }
            }
        }
    }

    if ( argStream.HasErrors ( ) )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Esempio n. 11
0
int CLuaFileDefs::fileWrite ( lua_State* luaVM )
{
    // string fileWrite ( file, string [, string2, string3, ...] )
    CScriptFile* pFile;
    SString strMessage;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pFile );
    argStream.ReadString ( strMessage );

    if ( !argStream.HasErrors ( ) )
    {
        // While we're not out of string arguments
        long lBytesWritten = 0;
        long lArgBytesWritten = 0;
        do
        {
            unsigned long ulDataLen = strMessage.length ( );

            // Write it and add the bytes written to our total bytes written
            lArgBytesWritten = pFile->Write ( ulDataLen, strMessage.c_str ( ) );
            if ( lArgBytesWritten == -1 )
            {
                m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 );
                lua_pushnil ( luaVM );
                return 1;
            }
            lBytesWritten += lArgBytesWritten;

            if ( !argStream.NextIsString ( ) )
                break;

            argStream.ReadString ( strMessage );
        }
        while ( true );

        // Inform file verifier
        if ( lBytesWritten > 0 )
            g_pClientGame->GetResourceManager()->OnFileModifedByScript( pFile->GetAbsPath(), "fileWrite" );

        // Return the number of bytes we wrote
        lua_pushnumber ( luaVM, lBytesWritten );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushnil ( luaVM );
    return 1;
}
//
// Read next as resource or resource name.  Result output as resource
//
void MixedReadResourceString ( CScriptArgReader& argStream, CResource*& pOutResource )
{
    if ( !argStream.NextIsString () )
    {
        argStream.ReadUserData ( pOutResource );
    }
    else
    {
        SString strResourceName;
        argStream.ReadString ( strResourceName );
        pOutResource = g_pGame->GetResourceManager ()->GetResource ( strResourceName );

        if ( !pOutResource )
            argStream.SetTypeError ( "resource", argStream.m_iIndex - 1 );
    }
}
//
// DxFont/string
//
void MixedReadDxFontString(CScriptArgReader& argStream, eFontType& outFontType, eFontType defaultFontType, CClientDxFont*& poutDxFontElement)
{
    outFontType = FONT_DEFAULT;
    poutDxFontElement = NULL;
    if (argStream.NextIsNone())
        return;
    else if (argStream.NextIsString())
    {
        SString strFontName;
        argStream.ReadString(strFontName);
        StringToEnum(strFontName, outFontType);
        return;
    }
    else
        argStream.ReadUserData(poutDxFontElement);
}
//
// Read next as preg option flags
//
void ReadPregFlags( CScriptArgReader& argStream, pcrecpp::RE_Options& pOptions )
{
    if ( argStream.NextIsNumber() )
    {
        uint uiFlags = 0;
        argStream.ReadNumber ( uiFlags );
        pOptions.set_caseless ( ( uiFlags & 1 ) != 0 );
        pOptions.set_multiline ( ( uiFlags & 2 ) != 0 );
        pOptions.set_dotall ( ( uiFlags & 4 ) != 0 );
        pOptions.set_extended ( ( uiFlags & 8 ) != 0 );
        pOptions.set_utf8 ( ( uiFlags & 16 ) != 0 );
    }
    else
    if ( argStream.NextIsString() )
    {
        SString strFlags;
        argStream.ReadString ( strFlags );
        for( uint i = 0 ; i < strFlags.length() ; i++ )
        {
            switch ( strFlags[i] )
            {
                case 'i':
                    pOptions.set_caseless ( true );
                    break;
                case 'm':
                    pOptions.set_multiline ( true );
                    break;
                case 'd':
                    pOptions.set_dotall ( true );
                    break;
                case 'e':
                    pOptions.set_extended ( true );
                    break;
                case 'u':
                    pOptions.set_utf8 ( true );
                    break;
                default:
                    argStream.SetCustomError( "Flags all wrong" );
                    return;       
            }
        }
    }
}
//
// Material/string
//
void MixedReadMaterialString(CScriptArgReader& argStream, CClientMaterial*& pMaterialElement)
{
    pMaterialElement = NULL;
    if (!argStream.NextIsString())
        argStream.ReadUserData(pMaterialElement);
    else
    {
        SString strFilePath;
        argStream.ReadString(strFilePath);

        // If no element, auto find/create one
        CLuaMain*  pLuaMain = g_pClientGame->GetLuaManager()->GetVirtualMachine(argStream.m_luaVM);
        CResource* pParentResource = pLuaMain ? pLuaMain->GetResource() : NULL;
        if (pParentResource)
        {
            CResource* pFileResource = pParentResource;
            SString    strPath, strMetaPath;
            if (CResourceManager::ParseResourcePathInput(strFilePath, pFileResource, &strPath, &strMetaPath))
            {
                SString strUniqueName = SString("%s*%s*%s", pParentResource->GetName(), pFileResource->GetName(), strMetaPath.c_str()).Replace("\\", "/");
                pMaterialElement = g_pClientGame->GetManager()->GetRenderElementManager()->FindAutoTexture(strPath, strUniqueName);

                if (pMaterialElement)
                {
                    // Check if brand new
                    if (!pMaterialElement->GetParent())
                        // Make it a child of the resource's file root ** CHECK  Should parent be pFileResource, and element added to pParentResource's
                        // ElementGroup? **
                        pMaterialElement->SetParent(pParentResource->GetResourceDynamicEntity());
                }
                else
                    argStream.SetCustomError(strFilePath, "Error loading image");
            }
            else
                argStream.SetCustomError(strFilePath, "Bad file path");
        }
    }
}
// Call a function on a remote server
int CLuaFunctionDefs::FetchRemote ( lua_State* luaVM )
{
    //  bool fetchRemote ( string URL [, string queueName ][, int connectionAttempts = 10, int connectTimeout = 10000 ], callback callbackFunction, [ string postData, bool bPostBinary, arguments... ] )
    CScriptArgReader argStream ( luaVM );
    SString strURL; SString strQueueName; CLuaFunctionRef iLuaFunction; SString strPostData; bool bPostBinary; CLuaArguments args; uint uiConnectionAttempts; uint uiConnectTimeoutMs;

    argStream.ReadString ( strURL );
    if ( argStream.NextIsString () )
        MinServerReqCheck ( argStream, MIN_SERVER_REQ_CALLREMOTE_QUEUE_NAME, "'queue name' is being used" );
    argStream.ReadIfNextIsString ( strQueueName, CALL_REMOTE_DEFAULT_QUEUE_NAME );
    if ( argStream.NextIsNumber () )
        MinServerReqCheck ( argStream, MIN_SERVER_REQ_CALLREMOTE_CONNECTION_ATTEMPTS, "'connection attempts' is being used" );
    argStream.ReadIfNextIsNumber ( uiConnectionAttempts, 10 );
    if ( argStream.NextIsNumber () )
        MinServerReqCheck ( argStream, MIN_SERVER_REQ_CALLREMOTE_CONNECT_TIMEOUT, "'connect timeout' is being used" );
    argStream.ReadIfNextIsNumber ( uiConnectTimeoutMs, 10000 );
    argStream.ReadFunction ( iLuaFunction );
    argStream.ReadString ( strPostData, "" );
    argStream.ReadBool ( bPostBinary, false );
    argStream.ReadLuaArguments ( args );
    argStream.ReadFunctionComplete ();

    if ( !argStream.HasErrors () )
    {
        CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( luaMain )
        {
            g_pGame->GetRemoteCalls ()->Call ( strURL, &args, strPostData, bPostBinary, luaMain, iLuaFunction, strQueueName, uiConnectionAttempts, uiConnectTimeoutMs );
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Esempio n. 17
0
int CLuaACLDefs::aclListRights ( lua_State* luaVM )
{
//  table aclListRights ( acl theACL )
    CAccessControlList* pACL; SString strType; bool bAll = true; CAccessControlListRight::ERightType eAllowed = (CAccessControlListRight::ERightType)-1;
    
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pACL );
    if ( argStream.NextIsString () )
    {
        argStream.ReadString ( strType );

        bAll = false;
        if ( strType == "command" )
            eAllowed = CAccessControlListRight::RIGHT_TYPE_COMMAND;
        else if ( strType == "function" )
            eAllowed = CAccessControlListRight::RIGHT_TYPE_FUNCTION;
        else if ( strType == "resource" )
            eAllowed = CAccessControlListRight::RIGHT_TYPE_RESOURCE;
        else if ( strType == "general" )
            eAllowed = CAccessControlListRight::RIGHT_TYPE_GENERAL;
        else
            bAll = true;
    }
    
    if ( !argStream.HasErrors () )
    {
        // Create a table to return into
        lua_newtable ( luaVM );

        // Loop through ACL
        char szRightName [128];
        CAccessControlListRight::ERightType eType;
        unsigned int uiIndex = 0;
        list <CAccessControlListRight* > ::const_iterator iter = pACL->IterBegin ();
        for ( ; iter != pACL->IterEnd (); ++iter )
        {
            // Type
            eType = (*iter)->GetRightType ();
            if ( !bAll && eType != eAllowed )
                continue;

            switch ( eType )
            {
                case CAccessControlListRight::RIGHT_TYPE_COMMAND:
                strcpy ( szRightName, "command." );
                break;

                case CAccessControlListRight::RIGHT_TYPE_FUNCTION:
                strcpy ( szRightName, "function." );
                break;

                case CAccessControlListRight::RIGHT_TYPE_RESOURCE:
                strcpy ( szRightName, "resource." );
                break;

                case CAccessControlListRight::RIGHT_TYPE_GENERAL:
                strcpy ( szRightName, "general." );
                break;

                default:
                strcpy ( szRightName, "unknown." );
                break;
            }

            // Append right name
            strncat ( szRightName, (*iter)->GetRightName (), NUMELMS( szRightName ) - 1 );

            // Push its name onto the table
            lua_pushnumber ( luaVM, ++uiIndex );
            lua_pushstring ( luaVM, szRightName );
            lua_settable ( luaVM, -3 );
        }

        // Return the table
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Esempio n. 18
0
int CLuaWorldDefs::setTrafficLightState ( lua_State* luaVM )
{
//  bool setTrafficLightState ( int state )
//  bool setTrafficLightState ( string state )
//  bool setTrafficLightState ( string colorNS, string colorEW )

    CScriptArgReader argStream ( luaVM );

    // Determine which version to parse
    if ( argStream.NextIsNumber () )
    {
    //  bool setTrafficLightState ( int state )
        int iState;
        argStream.ReadNumber ( iState );

        if ( !argStream.HasErrors () )
        {
            if ( CStaticFunctionDefinitions::SetTrafficLightState ( iState ) )
            {
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
    if ( !argStream.NextIsString ( 1 ) )
    {
    //  bool setTrafficLightState ( string state )
        TrafficLight::EState eState;
        argStream.ReadEnumString ( eState );

        if ( !argStream.HasErrors () )
        {
            if ( eState == TrafficLight::AUTO )
            {
                bool bOk = CStaticFunctionDefinitions::SetTrafficLightsLocked ( false ) &&
                           CStaticFunctionDefinitions::SetTrafficLightState ( 0 );
                lua_pushboolean ( luaVM, bOk );
                return 1;
            }
            else
            {
                bool bOk = CStaticFunctionDefinitions::SetTrafficLightsLocked ( true ) &&
                           CStaticFunctionDefinitions::SetTrafficLightState ( 9 );
                lua_pushboolean ( luaVM, bOk );
                return 1;
            }
        }
    }
    else
    {
    //  bool setTrafficLightState ( string colorNS, string colorEW )
        TrafficLight::EColor eColorNS;
        TrafficLight::EColor eColorEW;
        argStream.ReadEnumString ( eColorNS );
        argStream.ReadEnumString ( eColorEW );

        if ( !argStream.HasErrors () )
        {
            unsigned char ucState = SharedUtil::GetTrafficLightStateFromColors ( eColorNS, eColorEW );

            // Change it.
            bool bOk = CStaticFunctionDefinitions::SetTrafficLightsLocked ( true ) &&
                       CStaticFunctionDefinitions::SetTrafficLightState ( ucState );
            lua_pushboolean ( luaVM, bOk );
            return 1;
        }
    }

    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Esempio n. 19
0
int CLuaTextDefs::textCreateTextItem ( lua_State* luaVM )
{
    
    SString strText, strHorzAlign, strVertAlign;
    float fX, fY, fScale;
    int iPriority;
    SColorRGBA color ( 255, 255, 255, 255 );
    unsigned char ucShadowAlpha;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strText, "" );
    argStream.ReadNumber ( fX, 0.5f );
    argStream.ReadNumber ( fY, 0.5f );

    if ( argStream.NextIsString( ) )
    {
        SString strPriority;
        argStream.ReadString ( strPriority );

        if ( strPriority == "high" )        iPriority = PRIORITY_HIGH;
        else if ( strPriority == "medium" ) iPriority = PRIORITY_MEDIUM;
        else                                iPriority = PRIORITY_LOW;

    }
    else
    {
        argStream.ReadNumber(iPriority, PRIORITY_LOW);
    }
    
    argStream.ReadNumber( color.R, 255 );
    argStream.ReadNumber( color.G, 255 );
    argStream.ReadNumber( color.B, 255 );
    argStream.ReadNumber( color.A, 255 );
    argStream.ReadNumber( fScale, 1 );
    argStream.ReadString( strHorzAlign, "left" );
    argStream.ReadString( strVertAlign, "top" );
    argStream.ReadNumber( ucShadowAlpha, 0);

    if ( !argStream.HasErrors ( ) )
    {
        unsigned char ucFormat = 0; 
        if ( strHorzAlign == "center" ) 
            ucFormat |= 0x00000001; // DT_CENTER
        else if ( strHorzAlign == "right" )
            ucFormat |= 0x00000002; // DT_RIGHT

        if ( strVertAlign == "center" )
            ucFormat |= 0x00000004; // DT_VCENTER
        else if ( strVertAlign == "bottom" )
            ucFormat |= 0x00000008; // DT_BOTTOM
        
        // Grab our virtual machine
        CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( luaMain )
        {
            CTextItem* pTextItem = luaMain->CreateTextItem ( strText, fX, fY, (eTextPriority) iPriority, color, fScale, ucFormat, ucShadowAlpha );
            lua_pushtextitem ( luaVM, pTextItem );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );


    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::GetSoundMetaTags ( lua_State* luaVM )
{
    CClientSound* pSound = NULL;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pSound );

    if ( !argStream.HasErrors() )
    {
        if ( pSound )
        {
            SString strMetaTags = "";
            if ( argStream.NextIsString ( ) )
            {
                SString strFormat = "";
                argStream.ReadString ( strFormat );
                if ( CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, strFormat, strMetaTags ) )
                {
                    if ( !strMetaTags.empty() )
                    {
                        lua_pushstring ( luaVM, strMetaTags );
                        return 1;
                    }
                }
            }
            else
            {
                lua_newtable ( luaVM );
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%TITL", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "title" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%ARTI", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "artist" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%ALBM", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "album" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%GNRE", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "genre" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%YEAR", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "year" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%CMNT", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "comment" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%TRCK", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "track" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%COMP", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "composer" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%COPY", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "copyright" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%SUBT", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "subtitle" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "%AART", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "album_artist" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "streamName", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "stream_name" );
                }
                CStaticFunctionDefinitions::GetSoundMetaTags ( *pSound, "streamTitle", strMetaTags );
                if ( !strMetaTags.empty() )
                {
                    lua_pushstring ( luaVM, strMetaTags );
                    lua_setfield ( luaVM, -2, "stream_title" );
                }
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}