Esempio n. 1
0
void RunJobWatchApp( char *pCmdLine )
{
	STARTUPINFO si;
	memset( &si, 0, sizeof( si ) );
	si.cb = sizeof( si );

	PROCESS_INFORMATION pi;
	memset( &pi, 0, sizeof( pi ) );

	// Working directory should be the same as our exe's directory.
	char dirName[512];
	if ( GetModuleFileName( NULL, dirName, sizeof( dirName ) ) != 0 )
	{
		char *s1 = V_strrchr( dirName, '\\' );
		char *s2 = V_strrchr( dirName, '/' );
		if ( s1 || s2 )
		{
			// Get rid of the last slash.
			s1 = max( s1, s2 );
			s1[0] = 0;
		
			if ( !CreateProcess( 
				NULL, 
				pCmdLine, 
				NULL,							// security
				NULL,
				TRUE,
				0,			// flags
				NULL,							// environment
				dirName,							// current directory
				&si,
				&pi ) )
			{
				Warning( "%s - error launching '%s'\n", VMPI_GetParamString( mpi_Job_Watch ), pCmdLine );
			}
		}
	}
}
// Message handler for PyNetworkCls
void __MsgFunc_PyNetworkCls( bf_read &msg )
{
	int iClassID;
	char networkName[PYNETCLS_BUFSIZE];

	iClassID = msg.ReadWord();
	msg.ReadString( networkName, PYNETCLS_BUFSIZE );

	DbgStrPyMsg( "__MsgFunc_PyNetworkCls: Registering Python network class message %d %s\n", iClassID, networkName );

	// Get module path
	const char *pch = V_strrchr( networkName, '.' );
	if( !pch )
	{
		Warning( "Invalid python class name %s\n", networkName );
		return;
	}
	int n = pch - networkName + 1;

	char modulePath[PYNETCLS_BUFSIZE];
	V_strncpy( modulePath, networkName, n );

	// Make sure the client class is imported
	SrcPySystem()->Import( modulePath );

	// Read which client class we are modifying
	PyClientClassBase *p = FindPyClientClassByID( iClassID );
	if( !p )
	{
		Warning( "__MsgFunc_PyNetworkCls: Invalid networked class %d\n", iClassID );
		return;
	}

	// Read network class name
	V_strncpy( p->m_strPyNetworkedClassName, networkName, sizeof( p->m_strPyNetworkedClassName ) );

	// Attach if a network class exists
	unsigned short lookup = m_NetworkClassDatabase.Find( networkName );
	if ( lookup != m_NetworkClassDatabase.InvalidIndex() )
	{
		m_NetworkClassDatabase.Element(lookup)->AttachClientClass( p );
	}
	else
	{
		Warning( "__MsgFunc_PyNetworkCls: Invalid networked class %s\n", networkName );
	}
}
// register message handler once
void HookPyNetworkCls() 
{
	usermessages->HookMessage( "PyNetworkCls", __MsgFunc_PyNetworkCls );
}

CON_COMMAND_F( rpc, "", FCVAR_HIDDEN )
{
	int iClassID = atoi(args[1]);
	const char *networkName = args[2];

	DbgStrPyMsg( "rpc: Registering Python network class message %d %s\n", iClassID, networkName );

	// Get module path
	const char *pch = V_strrchr( networkName, '.' );
	if( !pch )
	{
		Warning("Invalid python class name %s\n", networkName );
		return;
	}
	int n = pch - networkName + 1;

	char modulePath[PYNETCLS_BUFSIZE];
	V_strncpy( modulePath, networkName, n );

	// Make sure the client module is is imported so the entity class is registered
	SrcPySystem()->Import( modulePath );

	// Read which client class we are modifying
	PyClientClassBase *p = FindPyClientClassByID( iClassID );
Esempio n. 4
0
HSCRIPT VScriptCompileScript( const char *pszScriptName, bool bWarnMissing )
{
    if ( !g_pScriptVM )
    {
        return NULL;
    }

    static const char *pszExtensions[] =
    {
        "",		// SL_NONE
        ".gm",	// SL_GAMEMONKEY
        ".nut",	// SL_SQUIRREL
        ".lua", // SL_LUA
        ".py",  // SL_PYTHON
    };

    const char *pszVMExtension = pszExtensions[g_pScriptVM->GetLanguage()];
    const char *pszIncomingExtension = V_strrchr( pszScriptName , '.' );
    if ( pszIncomingExtension && V_strcmp( pszIncomingExtension, pszVMExtension ) != 0 )
    {
        Log_Warning( LOG_VScript, "Script file type does not match VM type\n" );
        return NULL;
    }

    CFmtStr scriptPath;
    if ( pszIncomingExtension )
    {
        scriptPath.sprintf( "scripts/vscripts/%s", pszScriptName );
    }
    else
    {
        scriptPath.sprintf( "scripts/vscripts/%s%s", pszScriptName,  pszVMExtension );
    }

    const char *pBase;
    CUtlBuffer bufferScript;

    if ( g_pScriptVM->GetLanguage() == SL_PYTHON )
    {
        // python auto-loads raw or precompiled modules - don't load data here
        pBase = NULL;
    }
    else
    {
        bool bResult = filesystem->ReadFile( scriptPath, "GAME", bufferScript );

        if( !bResult )
        {
            Log_Warning( LOG_VScript, "Script not found (%s) \n", scriptPath.operator const char *() );
            Assert( "Error running script" );
        }

        pBase = (const char *) bufferScript.Base();

        if ( !pBase || !*pBase )
        {
            return NULL;
        }
    }


    const char *pszFilename = V_strrchr( scriptPath, '/' );
    pszFilename++;
    HSCRIPT hScript = g_pScriptVM->CompileScript( pBase, pszFilename );
    if ( !hScript )
    {
        Log_Warning( LOG_VScript, "FAILED to compile and execute script file named %s\n", scriptPath.operator const char *() );
        Assert( "Error running script" );
    }
    return hScript;
}