Skip to content

Commit

Permalink
fix c++ command execution if Lua scripts has errors (earlier all c++ …
Browse files Browse the repository at this point in the history
…commands were ignored and it was not possible to run /lua rehash)
  • Loading branch information
HarpyWar committed Aug 9, 2014
1 parent cdd0129 commit 3613ad9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/bnetd/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -576,7 +576,7 @@ namespace pvpgn
{
// TODO: log command
}
if (result < 1)
if (result == 0 || result == -1)
return result;
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/bnetd/luainterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ namespace pvpgn
{
t_account * account;
const char * func_name;
int result = 0;
int result = -2;
switch (luaevent)
{
case luaevent_command:
Expand All @@ -328,7 +328,7 @@ namespace pvpgn
try
{
if (!(account = conn_get_account(c)))
return 0;
return -2;

std::map<std::string, std::string> o_account = get_account_object(account);
lua::transaction(vm) << lua::lookup(func_name) << o_account << text << lua::invoke >> result << lua::end; // invoke lua function
Expand Down
9 changes: 8 additions & 1 deletion src/bnetd/luawrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,14 @@ namespace lua
template<typename T> 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--;
Expand Down

0 comments on commit 3613ad9

Please sign in to comment.