summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-02-07 09:22:53 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-02-07 09:22:53 +0000
commite9e633a5b78799311ee765944a7aa52201bcef9d (patch)
tree13a78b9477dd1814ae68ab69e5ff4ec15cf1c413
parent05de4c0aa765fb1a448687c068ddae9ecd880542 (diff)
downloadmanaserv-e9e633a5b78799311ee765944a7aa52201bcef9d.tar.gz
manaserv-e9e633a5b78799311ee765944a7aa52201bcef9d.tar.bz2
manaserv-e9e633a5b78799311ee765944a7aa52201bcef9d.tar.xz
manaserv-e9e633a5b78799311ee765944a7aa52201bcef9d.zip
Fail gracefully on invalid monster IDs, don't leak monsters when called without
a map and handle insertion failures.
-rw-r--r--ChangeLog14
-rw-r--r--src/scripting/lua.cpp24
2 files changed, 27 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 530f4885..ee6e3284 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-07 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * src/scripting/lua.cpp: Fail gracefully on invalid monster IDs, don't
+ leak monsters when called without a map and handle insertion failures.
+
2008-02-06 Philipp Sehmisch <tmw@crushnet.org>
* src/scripting/lua.cpp: Implemented LUA callback function for
@@ -6,18 +11,19 @@
2008-02-05 Philipp Sehmisch <tmw@crushnet.org>
- * src/game-server/monster.cpp, src/game-server/monster.hpp,
+ * src/game-server/monster.cpp, src/game-server/monster.hpp,
src/game-server/monstermanager.cpp: Monster base attributes and
experience reward are now read from monsters.xml.
2008-01-28 Philipp Sehmisch <tmw@crushnet.org>
- * src/account-server/accounthandler.cpp, src/account-server/character.cpp,
- src/account-server/character.hpp, src/account-server/dalstorage.cpp,
+ * src/account-server/accounthandler.cpp,
+ src/account-server/character.cpp, src/account-server/character.hpp,
+ src/account-server/dalstorage.cpp,
src/account-server/dalstoragesql.hpp, src/dal/sqlitedataprovider.cpp,
src/defines.h, src/game-server/accountconnection.cpp,
src/game-server/being.hpp, src/game-server/character.cpp,
- src/game-server/character.hpp, src/game-server/gamehandler.cpp,
+ src/game-server/character.hpp, src/game-server/gamehandler.cpp,
src/game-server/item.cpp, src/game-server/itemmanager.cpp,
src/game-server/monster.cpp, src/game-server/monster.hpp,
src/serialize/characterdata.hpp: Implemented skill system, level gain
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index d0490547..a5de9917 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -380,24 +380,34 @@ static int LuaMonster_Create(lua_State *s)
LOG_WARN("LuaMonster_Create called with incorrect parameters.");
return 0;
}
+
lua_pushlightuserdata(s, (void *)&registryKey);
lua_gettable(s, LUA_REGISTRYINDEX);
Script *t = static_cast<Script *>(lua_touserdata(s, -1));
-
- MonsterClass *spec = MonsterManager::getMonster(lua_tointeger(s, 1));
- Monster *q = new Monster(spec);
MapComposite *m = t->getMap();
if (!m)
{
LOG_WARN("LuaMonster_Create called outside a map.");
return 0;
}
+
+ int monsterId = lua_tointeger(s, 1);
+ MonsterClass *spec = MonsterManager::getMonster(monsterId);
+ if (!spec)
+ {
+ LOG_WARN("LuaMonster_Create invalid monster ID: " << monsterId);
+ return 0;
+ }
+
+ Monster *q = new Monster(spec);
q->setMap(m);
q->setPosition(Point(lua_tointeger(s, 2), lua_tointeger(s, 3)));
- bool b = GameState::insert(q);
- /* Do not try to deal with a failure there. There are some serious issues
- if an insertion failed on an almost empty map. */
- assert(b); (void)b;
+ if (!GameState::insertSafe(q))
+ {
+ LOG_WARN("LuaMonster_Create failed to insert monster");
+ return 0;
+ }
+
lua_pushlightuserdata(s, q);
return 1;
};