New Lua functions:

- command_get_group
- icon_get_rank
This commit is contained in:
HarpyWar 2014-05-17 19:38:48 +04:00
parent 6883be9a11
commit 4d3e070617
5 changed files with 68 additions and 8 deletions

View file

@ -54,7 +54,6 @@ namespace pvpgn
static int skip_comments(char *buff);
static t_icon_var_info * _read_option(char *str, unsigned lineno);
static t_icon_info * _find_custom_icon(int rating, char * clienttag);
static char * _find_attr_key(char * clienttag);
@ -115,7 +114,7 @@ namespace pvpgn
text = str_replace((char*)text, tmp, (char*)value);
// also replace {var}->rank
if (icon = _find_custom_icon(atoi(value), clienttag_str))
if (icon = customicons_get_icon_by_rating(atoi(value), clienttag_str))
{
snprintf(tmp, sizeof(tmp), "{{%s->rank}}", var->key);
text = str_replace((char*)text, tmp, icon->rank);
@ -149,7 +148,7 @@ namespace pvpgn
rating = account_get_numattr(account, attr_key);
icon = _find_custom_icon(rating, clienttag_str);
icon = customicons_get_icon_by_rating(rating, clienttag_str);
return icon;
}
@ -444,7 +443,7 @@ namespace pvpgn
/* Get custom icon by rating for clienttag */
static t_icon_info * _find_custom_icon(int rating, char * clienttag)
extern t_icon_info * customicons_get_icon_by_rating(int rating, char * clienttag)
{
t_elem * curr;
t_elem * curr_icon;

View file

@ -68,6 +68,7 @@ namespace pvpgn
extern int prefs_get_custom_icons();
extern t_icon_info * get_custom_icon(t_account * account, t_clienttag clienttag);
extern const char * get_custom_stats_text(t_account * account, t_clienttag clienttag);
extern t_icon_info * customicons_get_icon_by_rating(int rating, char * clienttag);
extern int customicons_load(char const * filename);

View file

@ -44,6 +44,7 @@
#include "friends.h"
#include "clan.h"
#include "attrlayer.h"
#include "icons.h"
#include "luawrapper.h"
#include "luaobjects.h"
@ -456,10 +457,10 @@ namespace pvpgn
return 1;
}
/* Get usernames online. If allusers = true then return all server users */
/* Get usernames online. If allaccounts = true then return all server users */
extern int __server_get_users(lua_State* L)
{
bool all = false;
bool allaccounts = false;
const char *username;
std::map<unsigned int, std::string> users;
t_connection * conn;
@ -469,9 +470,9 @@ namespace pvpgn
{
lua::stack st(L);
// get args
st.at(1, all);
st.at(1, allaccounts);
if (all)
if (allaccounts)
{
t_entry * curr;
HASHTABLE_TRAVERSE(accountlist(), curr)
@ -560,5 +561,56 @@ namespace pvpgn
}
/* Get command groups for a command string */
extern int __command_get_group(lua_State* L)
{
char const * command;
try
{
lua::stack st(L);
// get args
st.at(1, command);
int group = command_get_group(command);
st.push(group);
}
catch (const std::exception& e)
{
eventlog(eventlog_level_error, __FUNCTION__, e.what());
}
catch (...)
{
eventlog(eventlog_level_error, __FUNCTION__, "lua exception\n");
}
return 1;
}
/* Get customicon rank by rating */
extern int __icon_get_rank(lua_State* L)
{
int rating;
char * clienttag;
try
{
lua::stack st(L);
// get args
st.at(1, rating);
st.at(2, clienttag);
if (t_icon_info * icon = customicons_get_icon_by_rating(rating, clienttag))
st.push(icon->rank);
}
catch (const std::exception& e)
{
eventlog(eventlog_level_error, __FUNCTION__, e.what());
}
catch (...)
{
eventlog(eventlog_level_error, __FUNCTION__, "lua exception\n");
}
return 1;
}
}
}

View file

@ -48,6 +48,10 @@ namespace pvpgn
extern int __server_get_users(lua_State* L);
extern int __server_get_games(lua_State* L);
extern int __server_get_channels(lua_State* L);
extern int __command_get_group(lua_State* L);
extern int __icon_get_rank(lua_State* L);
}
}

View file

@ -136,6 +136,10 @@ namespace pvpgn
{ "server_get_users", __server_get_users },
{ "server_get_games", __server_get_games },
{ "server_get_channels", __server_get_channels },
{ "command_get_group", __command_get_group },
{ "icon_get_rank", __icon_get_rank },
{ 0, 0 }
};
vm.reg("api", api);