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,9 +1,14 @@
function creation_message(mage, type, number) function creation_message(mage, type, number)
local msg = message.create("item_create_spell") local msg = message.create("item_create_spell")
msg:set_unit("mage", mage) local err = 0
msg:set_int("number", number) err = err + msg:set_unit("mage", mage)
msg:set_resource("item", type) err = err + msg:set_int("number", number)
return msg err = err + msg:set_resource("item", type)
if err ~= 0 then
return nil
else
return msg
end
end end
local function create_item(mage, level, name, number) local function create_item(mage, level, name, number)

View file

@ -72,6 +72,7 @@ int msg_set_resource(lua_message * msg, const char *param, const char *resname)
{ {
if (msg->mtype) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); int i = mtype_get_param(msg->mtype, param);
const resource_type * rtype;
if (i == msg->mtype->nparameters) { if (i == msg->mtype->nparameters) {
return E_INVALID_PARAMETER_NAME; 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; 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_OK;
} }
return E_INVALID_MESSAGE; return E_INVALID_MESSAGE;