Example #1
0
char *JPLua_Event_ChatMessageSent( const char *msg )
{
	static char tmpMsg[MAX_TOKEN_CHARS] = {0}; //Although a chat message can only be MAX_SAY_TEXT long..-name?

	Q_strncpyz( tmpMsg, msg, sizeof( tmpMsg ) );

#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_CHATMSGSEND] )
		{
			lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_CHATMSGSEND] );

			lua_pushstring( JPLua.state, tmpMsg );
			JPLUACALL( JPLua.state, 1, 1 );

			if ( lua_type( JPLua.state, -1 ) == LUA_TNIL )
			{// returned nil, no use passing it to other plugins
				return NULL;
			}
			else if ( lua_type( JPLua.state, -1 ) == LUA_TSTRING )
				Q_strncpyz( tmpMsg, lua_tostring( JPLua.state, -1 ), MAX_SAY_TEXT );
			else
				Com_Printf( "Invalid return value in %s (JPLUA_EVENT_CHATMSGSEND), expected string or nil but got %s", JPLua.currentPlugin->name, lua_typename( JPLua.state, -1 ) );
		}
	}
#endif // JPLUA

	return tmpMsg;
}
Example #2
0
void JPLua_Event_RunFrame( void )
{
#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_RUNFRAME] )
		{
			lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_RUNFRAME] );
			JPLUACALL( JPLua.state, 0, 0 );
		}
	}
#endif // JPLUA
}
Example #3
0
qboolean JPLua_Event_ClientCommand( void )
{
	qboolean ret = qfalse;
#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		jplua_plugin_command_t *cmd = JPLua.currentPlugin->clientCmds;

		while ( cmd )
		{
			int top = 0, i = 0, numArgs = trap->Argc();
			char arg1[MAX_TOKEN_CHARS] = {0};

			trap->Argv( 0, arg1, sizeof( arg1 ) );

			if ( !Q_stricmp( arg1, cmd->command ) )
			{
				lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, cmd->handle );

				//Push table of arguments
				lua_newtable( JPLua.state );
				top = lua_gettop( JPLua.state );
				for ( i=1; i<numArgs; i++ )
				{
					char argN[MAX_TOKEN_CHARS] = {0};
					trap->Argv( i, argN, sizeof( argN ) );
					lua_pushnumber( JPLua.state, i );
					lua_pushstring( JPLua.state, argN );
					lua_settable( JPLua.state, top );
				}

				JPLUACALL( JPLua.state, 1, 0 );
				if ( !ret )
					ret = qtrue;
			}

			cmd = cmd->next;
		}
	}
#endif // JPLUA
	return ret;
}
Example #4
0
void JPLua_Event_Shutdown( void )
{
#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		jplua_plugin_command_t *consoleCmd = JPLua.currentPlugin->consoleCmds, *nextConsoleCmd = consoleCmd;
		jplua_plugin_command_t *serverCmd = JPLua.currentPlugin->serverCmds, *nextServerCmd = serverCmd;

		if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_UNLOAD] )
		{//Fire the unload event
			lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_UNLOAD] );
			JPLUACALL( JPLua.state, 0, 0 );
		}

		//RAZTODO: Refcount because multiple plugins can register the same command
		while ( nextConsoleCmd )
		{//Remove all console commands
			lua_unref( JPLua.state, consoleCmd->handle );
			#ifndef OPENJK
				ENG_Cmd_RemoveCommand( consoleCmd->command );
			#endif // !OPENJK
			nextConsoleCmd = consoleCmd->next;

			free( consoleCmd );
			consoleCmd = nextConsoleCmd;
		}

		while ( nextServerCmd )
		{//Remove all server commands
			lua_unref( JPLua.state, serverCmd->handle );
			nextServerCmd = serverCmd->next;

			free( serverCmd );
			serverCmd = nextServerCmd;
		}

		JPLua.currentPlugin->consoleCmds = NULL;
		JPLua.currentPlugin->serverCmds = NULL;
	}
#endif // JPLUA
}
Example #5
0
qboolean JPLua_Event_ConsoleCommand( void )
{
	qboolean ret = qfalse;

#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		jplua_plugin_command_t *cmd = JPLua.currentPlugin->consoleCmds;

		while ( cmd )
		{
			int top = 0;
			int i = 0;

			if ( !Q_stricmp( CG_Argv( 0 ), cmd->command ) && cmd->handle )
			{
				lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, cmd->handle );

				//Push table of arguments
				lua_newtable( JPLua.state );
				top = lua_gettop( JPLua.state );
				for ( i=1; i<trap_Argc(); i++ )
				{
					lua_pushnumber( JPLua.state, i );
					lua_pushstring( JPLua.state, CG_Argv( i ) );
					lua_settable( JPLua.state, top );
				}

				JPLUACALL( JPLua.state, 1, 0 );
				if ( !ret )
					ret = qtrue;
			}

			cmd = cmd->next;
		}
	}
#endif // JPLUA

	return ret;
}
Example #6
0
void JPLua_Event_SaberTouch( int victim, int attacker )
{
#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_SABERTOUCH] )
		{
			lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_SABERTOUCH] );

			JPLua_Player_CreateRef( JPLua.state, victim );
			JPLua_Player_CreateRef( JPLua.state, attacker );

			JPLUACALL( JPLua.state, 2, 0 );
		}
	}
#endif // JPLUA
}
Example #7
0
void JPLua_Event_ClientConnect( int clientNum )
{
#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_CLIENTCONNECT] )
		{
			lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_CLIENTCONNECT] );

			// Create a player instance for this client number and push on stack
			JPLua_Player_CreateRef( JPLua.state, clientNum );

			JPLUACALL( JPLua.state, 1, 0 );
		}
	}
#endif // JPLUA
}
Example #8
0
void JPLua_Event_Pain( int clientNum, int damage )
{
#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_PAIN] )
		{
			lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_PAIN] );

			// Create a player instance for this client number and push on stack
			JPLua_Player_CreateRef( JPLua.state, clientNum );
			lua_pushinteger( JPLua.state, damage );

			JPLUACALL( JPLua.state, 2, 0 );
		}
	}
#endif // JPLUA
}
Example #9
0
qboolean JPLua_Event_HUD( void )
{
	qboolean ret = qfalse;

#ifdef JPLUA
	for ( JPLua.currentPlugin = JPLua.plugins;
			JPLua.currentPlugin;
			JPLua.currentPlugin = JPLua.currentPlugin->next
		)
	{
		if ( JPLua.currentPlugin->eventListeners[JPLUA_EVENT_HUD] )
		{
			lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, JPLua.currentPlugin->eventListeners[JPLUA_EVENT_HUD] );
			JPLUACALL( JPLua.state, 0, 1 );
			if ( !ret )
				ret = !!lua_tointeger( JPLua.state, -1 );
		}
	}
#endif //JPLUA

	return ret;
}