From 3613ad99f012d76a4189cf691c2996383857748f Mon Sep 17 00:00:00 2001 From: HarpyWar Date: Sun, 10 Aug 2014 02:23:34 +0400 Subject: [PATCH] fix c++ command execution if Lua scripts has errors (earlier all c++ commands were ignored and it was not possible to run /lua rehash) --- src/bnetd/command.cpp | 4 ++-- src/bnetd/luainterface.cpp | 4 ++-- src/bnetd/luawrapper.h | 9 ++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/bnetd/command.cpp b/src/bnetd/command.cpp index e98217a56..2af428581 100644 --- a/src/bnetd/command.cpp +++ b/src/bnetd/command.cpp @@ -558,7 +558,7 @@ namespace pvpgn // feature to ignore flood protection result = lua_handle_command(c, text, luaevent_command_before); #endif - if (result < 0) + if (result == -1) return result; if (result == 0) @@ -576,7 +576,7 @@ namespace pvpgn { // TODO: log command } - if (result < 1) + if (result == 0 || result == -1) return result; #endif diff --git a/src/bnetd/luainterface.cpp b/src/bnetd/luainterface.cpp index 608128e7b..31a7e3cb5 100644 --- a/src/bnetd/luainterface.cpp +++ b/src/bnetd/luainterface.cpp @@ -313,7 +313,7 @@ namespace pvpgn { t_account * account; const char * func_name; - int result = 0; + int result = -2; switch (luaevent) { case luaevent_command: @@ -328,7 +328,7 @@ namespace pvpgn try { if (!(account = conn_get_account(c))) - return 0; + return -2; std::map o_account = get_account_object(account); lua::transaction(vm) << lua::lookup(func_name) << o_account << text << lua::invoke >> result << lua::end; // invoke lua function diff --git a/src/bnetd/luawrapper.h b/src/bnetd/luawrapper.h index 837f25519..a4d424a0f 100644 --- a/src/bnetd/luawrapper.h +++ b/src/bnetd/luawrapper.h @@ -329,7 +329,14 @@ namespace lua template bind& operator>>(T& v) throw() { if (refuse || retvals_number < 1) - v = T(); + { + // INFO: (HarpyWar) -2 is default value if Lua code failed to run due to error + // it's needed for lua_handle_command() + if (typeid(T) == typeid(int)) + v = T(-2); + else + v = T(); + } else { get(v, -retvals_number); retvals_number--;