Lua function handle_user_icon (feature to override user icon from Lua)
This commit is contained in:
parent
5d05d6ce4a
commit
607d798609
4 changed files with 45 additions and 2 deletions
|
@ -19,7 +19,13 @@ function handle_user_login(account)
|
|||
--DEBUG(account.name.." logged in")
|
||||
--return 1;
|
||||
end
|
||||
|
||||
function handle_user_disconnect(account)
|
||||
--DEBUG(account.name.." disconnected")
|
||||
end
|
||||
|
||||
function handle_user_icon(account, iconinfo)
|
||||
--TRACE("iconinfo"..iconinfo)
|
||||
--return iconinfo
|
||||
end
|
||||
|
||||
|
|
|
@ -2639,6 +2639,12 @@ namespace pvpgn
|
|||
else
|
||||
std::strcpy(playerinfo, revtag); /* open char */
|
||||
|
||||
#ifdef WITH_LUA
|
||||
// change icon info from Lua
|
||||
if (const char * iconinfo = lua_handle_user_icon((t_connection*)c, playerinfo))
|
||||
return iconinfo;
|
||||
#endif
|
||||
|
||||
return playerinfo;
|
||||
}
|
||||
|
||||
|
@ -3764,9 +3770,15 @@ namespace pvpgn
|
|||
eventlog(eventlog_level_info, __FUNCTION__, "[%d] %s using user-selected icon [%s]", conn_get_socket(c), revtag, usericon);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_LUA
|
||||
// change icon info from Lua
|
||||
if (const char * iconinfo = lua_handle_user_icon(c, tempplayerinfo))
|
||||
{
|
||||
conn_set_w3_playerinfo(c, iconinfo);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
conn_set_w3_playerinfo(c, tempplayerinfo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -548,6 +548,30 @@ namespace pvpgn
|
|||
return result;
|
||||
}
|
||||
|
||||
extern const char * lua_handle_user_icon(t_connection * c, const char * iconinfo)
|
||||
{
|
||||
t_account * account;
|
||||
const char * result;
|
||||
try
|
||||
{
|
||||
if (!(account = conn_get_account(c)))
|
||||
return 0;
|
||||
std::map<std::string, std::string> o_account = get_account_object(account);
|
||||
|
||||
lua::transaction(vm) << lua::lookup("handle_user_icon") << o_account << iconinfo << lua::invoke >> result << lua::end; // invoke lua function
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "lua exception\n");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern void lua_handle_server(t_luaevent_type luaevent)
|
||||
{
|
||||
|
|
|
@ -73,6 +73,7 @@ namespace pvpgn
|
|||
|
||||
extern int lua_handle_channel(t_channel * channel, t_connection * c, char const * message_text, t_message_type message_type, t_luaevent_type luaevent);
|
||||
extern int lua_handle_user(t_connection * c, t_connection * c_dst, char const * message_text, t_luaevent_type luaevent);
|
||||
extern const char * lua_handle_user_icon(t_connection * c, const char * iconinfo);
|
||||
extern void lua_handle_server(t_luaevent_type luaevent);
|
||||
extern void lua_handle_client(t_connection * c, int request_id, std::vector<int> data, t_luaevent_type luaevent);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue