Ejemplo n.º 1
0
// Call a function on a remote server
int CLuaFunctionDefs::FetchRemote ( lua_State* luaVM )
{
    //  bool fetchRemote ( string URL [, int connectionAttempts = 10, int connectTimeout = 10000 ], callback callbackFunction, [ string postData, bool bPostBinary, arguments... ] )
    CScriptArgReader argStream ( luaVM );
    SString strURL; CLuaFunctionRef iLuaFunction; SString strPostData; bool bPostBinary; CLuaArguments args; uint uiConnectionAttempts; uint uiConnectTimeoutMs;

    argStream.ReadString ( strURL );
    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, uiConnectionAttempts, uiConnectTimeoutMs );
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 2
0
int CLuaFunctionDefs::GetOriginalWeaponProperty ( lua_State* luaVM )
{
    eWeaponSkill eWepSkill = WEAPONSKILL_STD;
    eWeaponType eWep = WEAPONTYPE_UNARMED;
    eWeaponProperty eProp = WEAPON_INVALID_PROPERTY;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadEnumStringOrNumber ( eWep );
    argStream.ReadEnumStringOrNumber ( eWepSkill );
    argStream.ReadEnumString ( eProp );
    if ( !argStream.HasErrors () )
    {
        switch ( eProp )
        {
        case WEAPON_WEAPON_RANGE:
        case WEAPON_TARGET_RANGE:
        case WEAPON_ACCURACY:
        case WEAPON_FIRING_SPEED:
        case WEAPON_LIFE_SPAN:
        case WEAPON_SPREAD:
        case WEAPON_MOVE_SPEED:
        // Get only
        case WEAPON_REQ_SKILL_LEVEL:
        case WEAPON_ANIM_LOOP_START:
        case WEAPON_ANIM_LOOP_STOP:
        case WEAPON_ANIM_LOOP_RELEASE_BULLET_TIME:
        case WEAPON_ANIM2_LOOP_START:
        case WEAPON_ANIM2_LOOP_STOP:
        case WEAPON_ANIM2_LOOP_RELEASE_BULLET_TIME:
        case WEAPON_ANIM_BREAKOUT_TIME:
        case WEAPON_RADIUS:
        {
            float fWeaponInfo = 0.0f;

            if ( CStaticFunctionDefinitions::GetOriginalWeaponProperty ( eProp, eWep, eWepSkill, fWeaponInfo ) )
            {
                lua_pushnumber ( luaVM, fWeaponInfo );
                return 1;
            }
            break;
        }
        case WEAPON_DAMAGE:
        case WEAPON_MAX_CLIP_AMMO:
        case WEAPON_FLAGS:
        case WEAPON_ANIM_GROUP:
        case WEAPON_FIRETYPE:
        case WEAPON_MODEL:
        case WEAPON_MODEL2:
        case WEAPON_SLOT:
        case WEAPON_AIM_OFFSET:
        case WEAPON_SKILL_LEVEL:
        case WEAPON_DEFAULT_COMBO:
        case WEAPON_COMBOS_AVAILABLE:
        {
            int sWeaponInfo = 0;

            if ( CStaticFunctionDefinitions::GetOriginalWeaponProperty ( eProp, eWep, eWepSkill, sWeaponInfo ) )
            {
                lua_pushinteger ( luaVM, sWeaponInfo );
                return 1;
            }
            break;
        }
        case WEAPON_FIRE_OFFSET:
        {
            CVector vecWeaponInfo;

            if ( CStaticFunctionDefinitions::GetOriginalWeaponProperty ( eProp, eWep, eWepSkill, vecWeaponInfo ) )
            {
                lua_pushnumber ( luaVM, vecWeaponInfo.fX );
                lua_pushnumber ( luaVM, vecWeaponInfo.fY );
                lua_pushnumber ( luaVM, vecWeaponInfo.fZ );
                return 3;
            }
            break;
        }
        case WEAPON_FLAG_AIM_NO_AUTO:
        case WEAPON_FLAG_AIM_ARM:
        case WEAPON_FLAG_AIM_1ST_PERSON:
        case WEAPON_FLAG_AIM_FREE:
        case WEAPON_FLAG_MOVE_AND_AIM:
        case WEAPON_FLAG_MOVE_AND_SHOOT:
        case WEAPON_FLAG_TYPE_THROW:
        case WEAPON_FLAG_TYPE_HEAVY:
        case WEAPON_FLAG_TYPE_CONSTANT:
        case WEAPON_FLAG_TYPE_DUAL:
        case WEAPON_FLAG_ANIM_RELOAD:
        case WEAPON_FLAG_ANIM_CROUCH:
        case WEAPON_FLAG_ANIM_RELOAD_LOOP:
        case WEAPON_FLAG_ANIM_RELOAD_LONG:
        case WEAPON_FLAG_SHOT_SLOWS:
        case WEAPON_FLAG_SHOT_RAND_SPEED:
        case WEAPON_FLAG_SHOT_ANIM_ABRUPT:
        case WEAPON_FLAG_SHOT_EXPANDS:
        {
            MinServerReqCheck ( argStream, MIN_SERVER_REQ_WEAPON_PROPERTY_FLAG, "flag name is being used" );
            if ( !argStream.HasErrors () )
            {
                bool bEnable;
                if ( CStaticFunctionDefinitions::GetOriginalWeaponPropertyFlag ( eProp, eWep, eWepSkill, bEnable ) )
                {
                    lua_pushboolean ( luaVM, bEnable );
                    return 1;
                }
            }
            break;
        }
        default:
        {
            argStream.SetCustomError ( "unsupported weapon property at argument 3" );
            break;
        }
        }
    }
    if ( argStream.HasErrors () )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 3
0
// Call a function on a remote server
int CLuaFunctionDefs::CallRemote ( lua_State* luaVM )
{
    CScriptArgReader argStream ( luaVM );
    if ( !argStream.NextIsFunction ( 1 ) && !argStream.NextIsFunction ( 2 ) )
    {
        // Call type 1
        //  bool callRemote ( string host [, int connectionAttempts = 10, int connectTimeout = 10000 ], string resourceName, string functionName, callback callbackFunction, [ arguments... ] )
        SString strHost; uint uiConnectionAttempts; uint uiConnectTimeoutMs; SString strResourceName; SString strFunctionName; CLuaFunctionRef iLuaFunction; CLuaArguments args;

        argStream.ReadString ( strHost );
        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.ReadString ( strResourceName );
        argStream.ReadString ( strFunctionName );
        argStream.ReadFunction ( iLuaFunction );
        argStream.ReadLuaArguments ( args );
        argStream.ReadFunctionComplete ();

        if ( !argStream.HasErrors () )
        {
            CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
            if ( luaMain )
            {
                g_pGame->GetRemoteCalls ()->Call ( strHost, strResourceName, strFunctionName, &args, luaMain, iLuaFunction, uiConnectionAttempts, uiConnectTimeoutMs );
                lua_pushboolean ( luaVM, true );
                return 1;
            }
        }
    }
    else
    {
        // Call type 2
        //  bool callRemote ( string URL [, int connectionAttempts = 10, int connectTimeout = 10000 ], callback callbackFunction, [ arguments... ] )
        SString strURL; uint uiConnectionAttempts; uint uiConnectTimeoutMs; CLuaFunctionRef iLuaFunction; CLuaArguments args;

        argStream.ReadString ( strURL );
        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.ReadLuaArguments ( args );
        argStream.ReadFunctionComplete ();

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

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

    lua_pushboolean ( luaVM, false );
    return 1;
}
Ejemplo n.º 4
0
int CLuaFunctionDefs::SetWeaponProperty ( lua_State* luaVM )
{
    //  bool setWeaponProperty ( int weaponID/string weaponName, string weaponSkill, string property/int property, int/float theValue )

    eWeaponSkill eWepSkill = WEAPONSKILL_STD;
    eWeaponType eWep = WEAPONTYPE_BRASSKNUCKLE;
    eWeaponProperty eProp = WEAPON_ACCURACY;

    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsUserData () )
    {

        CCustomWeapon * pWeapon;
        eWeaponProperty weaponProperty;
        CScriptArgReader argStream ( luaVM );
        argStream.ReadUserData ( pWeapon );
        argStream.ReadEnumString ( weaponProperty );

        if ( !argStream.HasErrors () )
        {
            if ( weaponProperty == WEAPON_DAMAGE )
            {
                short sData = 0;
                argStream.ReadNumber ( sData );
                if ( !argStream.HasErrors () )
                {
                    if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, sData ) )
                    {
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                }
            }
            else
            {
                float fData = 0.0f;
                argStream.ReadNumber ( fData );
                if ( !argStream.HasErrors () )
                {
                    if ( CStaticFunctionDefinitions::SetWeaponProperty ( pWeapon, weaponProperty, fData ) )
                    {
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                }
            }
        }
        if ( argStream.HasErrors () )
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
    }
    else
    {
        argStream.ReadEnumStringOrNumber ( eWep );
        argStream.ReadEnumStringOrNumber ( eWepSkill );
        argStream.ReadEnumString ( eProp );
        if ( !argStream.HasErrors () )
        {
            switch ( eProp )
            {
            case WEAPON_WEAPON_RANGE:
            case WEAPON_TARGET_RANGE:
            case WEAPON_ACCURACY:
            case WEAPON_MOVE_SPEED:
            case WEAPON_ANIM_LOOP_START:
            case WEAPON_ANIM_LOOP_STOP:
            case WEAPON_ANIM_LOOP_RELEASE_BULLET_TIME:
            case WEAPON_ANIM2_LOOP_START:
            case WEAPON_ANIM2_LOOP_STOP:
            case WEAPON_ANIM2_LOOP_RELEASE_BULLET_TIME:
            case WEAPON_ANIM_BREAKOUT_TIME:
            {
                float fWeaponInfo = 0.0f;
                argStream.ReadNumber ( fWeaponInfo );
                if ( !argStream.HasErrors () )
                {
                    if ( CStaticFunctionDefinitions::SetWeaponProperty ( eProp, eWep, eWepSkill, fWeaponInfo ) )
                    {
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                }
                break;
            }
            case WEAPON_DAMAGE:
            case WEAPON_MAX_CLIP_AMMO:
            case WEAPON_FLAGS:
            {
                int sWeaponInfo = 0;
                argStream.ReadNumber ( sWeaponInfo );
                if ( !argStream.HasErrors () )
                {
                    if ( CStaticFunctionDefinitions::SetWeaponProperty ( eProp, eWep, eWepSkill, sWeaponInfo ) )
                    {
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                }
                break;
            }
            case WEAPON_FLAG_AIM_NO_AUTO:
            case WEAPON_FLAG_AIM_ARM:
            case WEAPON_FLAG_AIM_1ST_PERSON:
            case WEAPON_FLAG_AIM_FREE:
            case WEAPON_FLAG_MOVE_AND_AIM:
            case WEAPON_FLAG_MOVE_AND_SHOOT:
            case WEAPON_FLAG_TYPE_THROW:
            case WEAPON_FLAG_TYPE_HEAVY:
            case WEAPON_FLAG_TYPE_CONSTANT:
            case WEAPON_FLAG_TYPE_DUAL:
            case WEAPON_FLAG_ANIM_RELOAD:
            case WEAPON_FLAG_ANIM_CROUCH:
            case WEAPON_FLAG_ANIM_RELOAD_LOOP:
            case WEAPON_FLAG_ANIM_RELOAD_LONG:
            case WEAPON_FLAG_SHOT_SLOWS:
            case WEAPON_FLAG_SHOT_RAND_SPEED:
            case WEAPON_FLAG_SHOT_ANIM_ABRUPT:
            case WEAPON_FLAG_SHOT_EXPANDS:
            {
                MinServerReqCheck ( argStream, MIN_SERVER_REQ_WEAPON_PROPERTY_FLAG, "flag name is being used" );
                bool bEnable;
                argStream.ReadBool ( bEnable );
                if ( !argStream.HasErrors () )
                {
                    if ( CStaticFunctionDefinitions::SetWeaponPropertyFlag ( eProp, eWep, eWepSkill, bEnable ) )
                    {
                        lua_pushboolean ( luaVM, true );
                        return 1;
                    }
                }
                break;
            }

            default:
            {
                argStream.SetCustomError ( "unsupported weapon property at argument 3" );
                break;
            }

            }
        }
        if ( argStream.HasErrors () )
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
    }
    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}