Fixed a bug where a missing resource in E3 would crash the server

This commit is contained in:
Enno Rehling 2012-06-02 12:49:48 -07:00
parent 578334f2d0
commit 533c267b9a
2 changed files with 16 additions and 6 deletions

View File

@ -1,10 +1,15 @@
function creation_message(mage, type, number)
local msg = message.create("item_create_spell")
msg:set_unit("mage", mage)
msg:set_int("number", number)
msg:set_resource("item", type)
local err = 0
err = err + msg:set_unit("mage", mage)
err = err + msg:set_int("number", number)
err = err + msg:set_resource("item", type)
if err ~= 0 then
return nil
else
return msg
end
end
local function create_item(mage, level, name, number)
local count = number or 1

View File

@ -72,6 +72,7 @@ int msg_set_resource(lua_message * msg, const char *param, const char *resname)
{
if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param);
const resource_type * rtype;
if (i == msg->mtype->nparameters) {
return E_INVALID_PARAMETER_NAME;
}
@ -79,8 +80,12 @@ int msg_set_resource(lua_message * msg, const char *param, const char *resname)
return E_INVALID_PARAMETER_TYPE;
}
msg->args[i].v = (void *)rt_find(resname);
rtype = rt_find(resname);
if (rtype) {
msg->args[i].v = (void *)rtype;
} else {
return E_INVALID_PARAMETER_VALUE;
}
return E_OK;
}
return E_INVALID_MESSAGE;