qboolean JPLua_Event_ClientUserinfoChanged( int clientNum, char *userinfo ) { qboolean ret = qfalse; #ifdef JPLUA jplua_plugin_t *plugin = NULL; while ( JPLua_IteratePlugins( &plugin ) ) { if ( plugin->eventListeners[JPLUA_EVENT_CLIENTUSERINFOCHANGED] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, plugin->eventListeners[JPLUA_EVENT_CLIENTUSERINFOCHANGED] ); lua_pushinteger( JPLua.state, clientNum ); JPLua_PushInfostring( JPLua.state, userinfo ); JPLua_Call( JPLua.state, 2, 1 ); // they wanted to modify it, parse it out and apply it if ( lua_type( JPLua.state, -1 ) == LUA_TTABLE ) { JPLua_PopInfostring( JPLua.state, userinfo ); ret = qtrue; } else if ( lua_type( JPLua.state, -1 ) != LUA_TNIL ) { Com_Printf( "Invalid return value in %s (JPLUA_EVENT_CLIENTUSERINFOCHANGED), expected table or nil but" "got %s\n", plugin->name, lua_typename( JPLua.state, -1 ) ); } } } #endif return ret; }
const char *JPLua_Event_ClientConnect( int clientNum, const char *userinfo, const char *IP, qboolean firstTime ) { #ifdef JPLUA jplua_plugin_t *plugin = NULL; while ( JPLua_IteratePlugins( &plugin ) ) { if ( plugin->eventListeners[JPLUA_EVENT_CLIENTCONNECT] ) { lua_rawgeti( JPLua.state, LUA_REGISTRYINDEX, plugin->eventListeners[JPLUA_EVENT_CLIENTCONNECT] ); lua_pushinteger( JPLua.state, clientNum ); JPLua_PushInfostring( JPLua.state, userinfo ); lua_pushstring( JPLua.state, IP ); lua_pushboolean( JPLua.state, !!firstTime ); JPLua_Call( JPLua.state, 4, 1 ); // connection allowed, pass to other plugins if ( lua_type( JPLua.state, -1 ) == LUA_TNIL ) continue; // denied, no use passing it to other plugins if ( lua_type( JPLua.state, -1 ) == LUA_TSTRING ) return lua_tostring( JPLua.state, -1 ); else { Com_Printf( "Invalid return value in %s (JPLUA_EVENT_CLIENTCONNECT), expected string or nil but got %s\n", plugin->name, lua_typename( JPLua.state, -1 ) ); return NULL; } } } #endif return NULL; }
static int JPLua_GetConfigString(lua_State *L){ int type = luaL_checkinteger(L, 1); #ifdef PROJECT_CGAME const char *info = CG_ConfigString(type); #elif defined (PROJECT_GAME) char info[MAX_INFO_STRING] = { '\0' }; trap->GetConfigstring(type, info, sizeof(info)); #endif if (!info[0]){ lua_pushnil(L); return 1; } JPLua_PushInfostring(L, info); return 1; }