- Lua new event: handle_server_loop
- Fix timers check delay - "online" field for account object
This commit is contained in:
parent
acb87fa225
commit
6a43773b43
6 changed files with 52 additions and 8 deletions
|
@ -426,6 +426,10 @@ namespace pvpgn
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Get one channel table object */
|
||||
extern int __channel_get_by_id(lua_State* L)
|
||||
{
|
||||
|
@ -452,7 +456,6 @@ namespace pvpgn
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Get usernames online. If allusers = true then return all server users */
|
||||
extern int __server_get_users(lua_State* L)
|
||||
{
|
||||
|
|
|
@ -32,13 +32,17 @@ namespace pvpgn
|
|||
|
||||
extern int __message_send_text(lua_State* L);
|
||||
extern int __eventlog(lua_State* L);
|
||||
|
||||
extern int __account_get_by_name(lua_State* L);
|
||||
extern int __account_get_attr(lua_State* L);
|
||||
extern int __account_set_attr(lua_State* L);
|
||||
extern int __account_get_friends(lua_State* L);
|
||||
extern int __account_get_teams(lua_State* L);
|
||||
|
||||
extern int __clan_get_members(lua_State* L);
|
||||
|
||||
extern int __game_get_by_id(lua_State* L);
|
||||
|
||||
extern int __channel_get_by_id(lua_State* L);
|
||||
|
||||
extern int __server_get_users(lua_State* L);
|
||||
|
|
|
@ -126,6 +126,7 @@ namespace pvpgn
|
|||
{ "account_get_teams", __account_get_teams },
|
||||
{ "clan_get_members", __clan_get_members },
|
||||
{ "game_get_by_id", __game_get_by_id },
|
||||
|
||||
{ "channel_get_by_id", __channel_get_by_id },
|
||||
|
||||
{ "server_get_users", __server_get_users },
|
||||
|
@ -145,6 +146,7 @@ namespace pvpgn
|
|||
g.update("PVPGN_SOFTWARE", PVPGN_SOFTWARE);
|
||||
g.update("PVPGN_VERSION", PVPGN_VERSION);
|
||||
|
||||
|
||||
// config variables from bnetd.conf
|
||||
lua::transaction bind(vm);
|
||||
bind.lookup("config");
|
||||
|
@ -467,6 +469,31 @@ namespace pvpgn
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
extern void lua_handle_server(unsigned int time, t_luaevent_type luaevent)
|
||||
{
|
||||
const char * func_name;
|
||||
switch (luaevent)
|
||||
{
|
||||
case luaevent_server_mainloop:
|
||||
func_name = "handle_server_mainloop"; // one time per second
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
lua::transaction(vm) << lua::lookup(func_name) << time << lua::invoke << 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");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -50,7 +50,9 @@ namespace pvpgn
|
|||
|
||||
luaevent_user_whisper, // user-to-user
|
||||
luaevent_user_login,
|
||||
luaevent_user_disconnect
|
||||
luaevent_user_disconnect,
|
||||
|
||||
luaevent_server_mainloop
|
||||
|
||||
} t_luaevent_type;
|
||||
|
||||
|
@ -62,6 +64,7 @@ namespace pvpgn
|
|||
extern void lua_handle_game(t_game * game, t_connection * c, t_luaevent_type luaevent);
|
||||
extern void 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 void lua_handle_server(unsigned int time, t_luaevent_type luaevent);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -87,9 +87,13 @@ namespace pvpgn
|
|||
o_account["locked"] = account_get_auth_lock(account) ? "true" : "false";
|
||||
o_account["muted"] = account_get_auth_mute(account) ? "true" : "false";
|
||||
|
||||
o_account["online"] = "false";
|
||||
|
||||
// if user online
|
||||
if (t_connection * c = account_get_conn(account))
|
||||
{
|
||||
o_account["online"] = "true";
|
||||
|
||||
o_account["country"] = conn_get_country(c);
|
||||
o_account["clientver"] = conn_get_clientver(c);
|
||||
o_account["latency"] = std::to_string(conn_get_latency(c));
|
||||
|
@ -101,6 +105,7 @@ namespace pvpgn
|
|||
o_account["channel_id"] = std::to_string(channel_get_channelid(channel));
|
||||
}
|
||||
|
||||
|
||||
if (account->clanmember)
|
||||
o_account["clan_id"] = account->clanmember->clan->clanid;
|
||||
|
||||
|
|
|
@ -1238,7 +1238,7 @@ namespace pvpgn
|
|||
std::time_t next_savetime, track_time;
|
||||
std::time_t war3_ladder_updatetime;
|
||||
std::time_t output_updatetime;
|
||||
unsigned int count;
|
||||
unsigned int prev_time = 0;
|
||||
|
||||
starttime = std::time(NULL);
|
||||
track_time = starttime - prefs_get_track();
|
||||
|
@ -1246,8 +1246,6 @@ namespace pvpgn
|
|||
war3_ladder_updatetime = starttime - prefs_get_war3_ladder_update_secs();
|
||||
output_updatetime = starttime - prefs_get_output_update_secs();
|
||||
|
||||
count = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
@ -1489,11 +1487,14 @@ namespace pvpgn
|
|||
do_restart = 0;
|
||||
}
|
||||
|
||||
count += BNETD_POLL_INTERVAL;
|
||||
if (count >= 1000) /* only check timers once a second */
|
||||
/* only check timers once a second */
|
||||
if (now > prev_time)
|
||||
{
|
||||
prev_time = now;
|
||||
timerlist_check_timers(now);
|
||||
count = 0;
|
||||
#ifdef WITH_LUA
|
||||
lua_handle_server(now, luaevent_server_mainloop);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* no need to populate the fdwatch structures as they are populated on the fly
|
||||
|
@ -1518,6 +1519,7 @@ namespace pvpgn
|
|||
|
||||
/* reap dead connections */
|
||||
connlist_reap();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue