From 434ec4758a2cdd2d880e51a6485e6ccb5db1e740 Mon Sep 17 00:00:00 2001 From: HarpyWar Date: Sat, 30 Aug 2014 16:32:38 +0400 Subject: [PATCH] * remove extra fields from Lua account objects to exclude additional sql query. * verious changes --- lua/handle_command.lua | 4 ++-- src/bnetd/command.cpp | 2 -- src/bnetd/i18n.cpp | 2 +- src/bnetd/luafunctions.cpp | 8 +++++--- src/bnetd/luainterface.cpp | 1 + src/bnetd/luaobjects.cpp | 7 ++----- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lua/handle_command.lua b/lua/handle_command.lua index 8ce2725..38faa31 100644 --- a/lua/handle_command.lua +++ b/lua/handle_command.lua @@ -45,8 +45,8 @@ function handle_command(account, text) for cmd,func in pairs(cmdlist) do if string.starts(text, cmd) then - -- check if command group is in account.commandgroups - if math_and(account.commandgroups, cg) == 0 then + -- check if command group is in account commandgroups + if math_and(account_get_auth_command_groups(account.name), cg) == 0 then api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "This command is reserved for admins.")) return -1 end diff --git a/src/bnetd/command.cpp b/src/bnetd/command.cpp index 16f7efd..164a3cd 100644 --- a/src/bnetd/command.cpp +++ b/src/bnetd/command.cpp @@ -607,8 +607,6 @@ namespace pvpgn // log command if (t_account * account = conn_get_account(c)) userlog_append(account, text); - - // TODO: modify all commands to return "0" only if success, and "-1" if not } return result; } diff --git a/src/bnetd/i18n.cpp b/src/bnetd/i18n.cpp index 16a548a..df3dfc9 100644 --- a/src/bnetd/i18n.cpp +++ b/src/bnetd/i18n.cpp @@ -285,7 +285,7 @@ namespace pvpgn } catch (const std::exception& e) { - ERROR2("Can't format translation string \"%s\" (%s)", fmt, e.what()); + WARN2("Can't format translation string \"%s\" (%s)", fmt, e.what()); } return output; diff --git a/src/bnetd/luafunctions.cpp b/src/bnetd/luafunctions.cpp index 4fa6763..0b17b7a 100644 --- a/src/bnetd/luafunctions.cpp +++ b/src/bnetd/luafunctions.cpp @@ -220,7 +220,8 @@ namespace pvpgn switch ((t_attr_type)attrtype) { case attr_type_str: - attrvalue = account_get_strattr(account, attrkey); + if (const char * val = account_get_strattr(account, attrkey)) + attrvalue = val; break; case attr_type_num: attrvalue = std_to_string(account_get_numattr(account, attrkey)); @@ -229,7 +230,8 @@ namespace pvpgn attrvalue = account_get_boolattr(account, attrkey) == 0 ? "false" : "true"; break; case attr_type_raw: - attrvalue = account_get_rawattr(account, attrkey); + if (const char * val = account_get_rawattr(account, attrkey)) + attrvalue = val; break; } } @@ -520,7 +522,7 @@ namespace pvpgn return 1; } - /* Get usernames online. If allaccounts = true then return all server users */ + /* Get usernames online. If allaccounts = true then return all accounts that were used by the server since start */ extern int __server_get_users(lua_State* L) { bool allaccounts = false; diff --git a/src/bnetd/luainterface.cpp b/src/bnetd/luainterface.cpp index 681af02..19c4f8b 100644 --- a/src/bnetd/luainterface.cpp +++ b/src/bnetd/luainterface.cpp @@ -220,6 +220,7 @@ namespace pvpgn config.update("version_exeinfo_maxdiff", prefs_get_version_exeinfo_maxdiff()); config.update("usersync", prefs_get_user_sync_timer()); config.update("userflush", prefs_get_user_flush_timer()); + config.update("userflush_connected", prefs_get_user_flush_connected()); config.update("userstep", prefs_get_user_step()); config.update("latency", prefs_get_latency()); config.update("nullmsg", prefs_get_nullmsg()); diff --git a/src/bnetd/luaobjects.cpp b/src/bnetd/luaobjects.cpp index 645b0e3..4d90f5b 100644 --- a/src/bnetd/luaobjects.cpp +++ b/src/bnetd/luaobjects.cpp @@ -95,13 +95,10 @@ namespace pvpgn if (!account) return o_account; + // DO NOT ADD FIELDS FROM A DATABASE HERE - IT WILL CAUSE WASTE SQL QUERIES WHEN ITERATE ALL CONNECTIONS + o_account["id"] = std_to_string(account_get_uid(account)); o_account["name"] = account_get_name(account); - if (const char * email = account_get_email(account)) // email can be empty - o_account["email"] = email; - o_account["commandgroups"] = std_to_string(account_get_command_groups(account)); - o_account["locked"] = account_get_auth_lock(account) ? "true" : "false"; - o_account["muted"] = account_get_auth_mute(account) ? "true" : "false"; o_account["online"] = "false"; // set init as offline