From ba6a9e534cfab2ecab6e120af4ab6ae11aee26c4 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Fri, 9 Jan 2009 16:45:48 +0100 Subject: Made respawn location a config option --- src/game-server/character.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 780a142b..a17e3d89 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -26,6 +26,7 @@ #include "game-server/character.hpp" #include "defines.h" +#include "common/configuration.hpp" #include "game-server/accountconnection.hpp" #include "game-server/attackzone.hpp" #include "game-server/buysell.hpp" @@ -130,9 +131,9 @@ void Character::respawn() } //warp back to spawn point - static const int spawnMap = 1; - static const int spawnX = 1024; - static const int spawnY = 1024; + int spawnMap = Configuration::getValue("respawnMap", 1); + int spawnX = Configuration::getValue("respawnX", 1024); + int spawnY = Configuration::getValue("respawnY", 1024); GameState::enqueueWarp(this, MapManager::getMap(spawnMap), spawnX, spawnY); //make alive again -- cgit v1.2.3-70-g09d2 From 8b171e3a7e006aa492e2369969999a2336e2a731 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sat, 17 Jan 2009 16:21:58 +0100 Subject: Made script error reports more informative and readable --- src/scripting/lua.cpp | 11 ++++++++--- src/scripting/script.cpp | 6 +++++- src/scripting/script.hpp | 5 ++++- 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index e2be2d3f..aead80cb 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -93,6 +93,7 @@ class LuaScript: public Script lua_State *mState; int nbArgs; + std::string mCurFunction; }; static char const registryKey = 0; @@ -1213,6 +1214,7 @@ void LuaScript::prepare(std::string const &name) assert(nbArgs == -1); lua_getglobal(mState, name.c_str()); nbArgs = 0; + mCurFunction = name; } void LuaScript::push(int v) @@ -1244,15 +1246,18 @@ int LuaScript::execute() if (res || !(lua_isnil(mState, 1) || lua_isnumber(mState, 1))) { char const *s = lua_tostring(mState, 1); - LOG_WARN("Failure while calling Lua function: error=" << res - << ", type=" << lua_typename(mState, lua_type(mState, 1)) - << ", message=" << (s ? s : "")); + + LOG_WARN("Lua Script Error" << std::endl + << " Script : " << mScriptFile << std::endl + << " Function: " << mCurFunction << std::endl + << " Error : " << (s ? s : "") << std::endl); lua_pop(mState, 1); return 0; } res = lua_tointeger(mState, 1); lua_pop(mState, 1); return res; + mCurFunction = ""; } void LuaScript::load(char const *prog) diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp index ea1721f9..a20efb5c 100644 --- a/src/scripting/script.cpp +++ b/src/scripting/script.cpp @@ -69,14 +69,18 @@ void Script::update() execute(); } -void Script::loadFile(std::string const &name) +bool Script::loadFile(std::string const &name) { int size; char *buffer = ResourceManager::loadFile(name, size); if (buffer) { + mScriptFile = name; load(buffer); free(buffer); + return true; + } else { + return false; } } diff --git a/src/scripting/script.hpp b/src/scripting/script.hpp index fad6ad95..c87bf182 100644 --- a/src/scripting/script.hpp +++ b/src/scripting/script.hpp @@ -68,7 +68,7 @@ class Script * Loads a text file into script context and executes its global * statements. */ - virtual void loadFile(std::string const &); + virtual bool loadFile(std::string const &); /** * Loads a chunk of text and considers it as an NPC handler. This @@ -129,6 +129,9 @@ class Script virtual void processDeathEvent(Being* thing) = 0; + protected: + std::string mScriptFile; + private: MapComposite *mMap; EventListener mEventListener; /**< Tracking of being deaths. */ -- cgit v1.2.3-70-g09d2 From 85b659f70cbe7374eb511acf6a61abc443332752 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sat, 17 Jan 2009 16:57:59 +0100 Subject: Filenames of item use scripts are now taken from the items.xml --- src/game-server/item.cpp | 4 ++-- src/game-server/itemmanager.cpp | 29 ++++++++++++++++------------- src/game-server/spawnarea.cpp | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp index 892be2cf..817c81ec 100644 --- a/src/game-server/item.cpp +++ b/src/game-server/item.cpp @@ -147,9 +147,9 @@ bool ItemClass::use(Being *itemUser) if (mType != ITEM_USABLE) return false; if (mScript) { - mScript->prepare("item_use"); - mScript->push(mDatabaseID); + mScript->prepare("use"); mScript->push(itemUser); + mScript->push(mDatabaseID); // ID of the item mScript->execute(); } mModifiers.applyAttributes(itemUser); diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 3f67ae8b..e275d1a6 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -135,7 +135,7 @@ void ItemManager::reload() int value = XML::getProperty(node, "value", 0); int maxPerSlot = XML::getProperty(node, "max-per-slot", 0); int sprite = XML::getProperty(node, "sprite_id", 0); - std::string scriptName = XML::getProperty(node, "script_name", std::string()); + std::string scriptFile = XML::getProperty(node, "script", ""); std::string attackShape = XML::getProperty(node, "attack-shape", "cone"); std::string attackTarget = XML::getProperty(node, "attack-target", "multi"); int attackRange = XML::getProperty(node, "attack-range", 32); @@ -172,8 +172,8 @@ void ItemManager::reload() if (maxPerSlot == 0) { - LOG_WARN("Item Manager: Missing max-per-slot property for " - "item " << id << " in " << itemReferenceFile << '.'); + //LOG_WARN("Item Manager: Missing max-per-slot property for " + // "item " << id << " in " << itemReferenceFile << '.'); maxPerSlot = 1; } @@ -193,21 +193,24 @@ void ItemManager::reload() } // TODO: Clean this up some - Script *s = 0; - std::stringstream filename; - filename << "scripts/items/" << id << ".lua"; - - if (ResourceManager::exists(filename.str())) // file exists! + if (scriptFile != "") { - LOG_INFO("Loading item script: " + filename.str()); - s = Script::create("lua"); - s->loadFile(filename.str()); + std::stringstream filename; + filename << "scripts/items/" << scriptFile; + if (ResourceManager::exists(filename.str())) // file exists! + { + LOG_INFO("Loading item script: " << filename.str()); + Script *s = Script::create("lua"); + s->loadFile(filename.str()); + item->setScript(s); + } else { + LOG_WARN("Could not find script file \"" << filename.str() << "\" for item #"<setWeight(weight); item->setCost(value); item->setMaxPerSlot(maxPerSlot); - item->setScript(s); item->setModifiers(modifiers); item->setSpriteID(sprite ? sprite : id); ++nbItems; @@ -250,7 +253,7 @@ void ItemManager::reload() LOG_DEBUG("Item: ID: " << id << ", itemType: " << itemType << ", weight: " << weight << ", value: " << value << - ", scriptName: " << scriptName << ", maxPerSlot: " << maxPerSlot << "."); + ", script: " << scriptFile << ", maxPerSlot: " << maxPerSlot << "."); } LOG_INFO("Loaded " << nbItems << " items from " diff --git a/src/game-server/spawnarea.cpp b/src/game-server/spawnarea.cpp index db7a01d6..fc493848 100644 --- a/src/game-server/spawnarea.cpp +++ b/src/game-server/spawnarea.cpp @@ -85,7 +85,7 @@ void SpawnArea::update() if (being->getModifiedAttribute(BASE_ATTR_HP) <= 0) { - LOG_WARN("Refusing to spawn dead monster " << mSpecy->getType()); + //LOG_WARN("Refusing to spawn dead monster " << mSpecy->getType()); delete being; being = 0; } -- cgit v1.2.3-70-g09d2 From 947014cf3c9477b44bafe389653f28074e9b43b3 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 18 Jan 2009 13:57:39 +0100 Subject: Added @where and @rights chat commands for querying the own location and access level. Improved feedback for erroneous chat commands. --- src/game-server/commandhandler.cpp | 94 +++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 5268d131..26c097d8 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -19,6 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "defines.h" #include "commandhandler.hpp" #include "accountconnection.hpp" @@ -39,7 +41,7 @@ static void say(const std::string error, Character *player) GameState::sayTo(player, NULL, error); } -static bool handlePermissions(Character *player, unsigned int permissions) +static bool checkPermission(Character *player, unsigned int permissions) { if (player->getAccountLevel() & permissions) { @@ -93,25 +95,30 @@ static void handleHelp(Character *player, std::string &args) { if (player->getAccountLevel() & AL_PLAYER) { - say("Game Master Commands:", player); + say("=General Commands=", player); say("@help [command]", player); say("@report ", player); + say("@where", player); + say("@rights", player); } if (player->getAccountLevel() & AL_TESTER) { + say("=Tester Commands=", player); say("@warp ", player); say("@goto ", player); } if (player->getAccountLevel() & AL_GM) { + say("=Game Master Commands=", player); say("@recall ", player); say("@ban ", player); } if (player->getAccountLevel() & AL_DEV) { + say("=Developer Commands=", player); say("@item ", player); say("@drop ", player); say("@money ", player); @@ -121,7 +128,7 @@ static void handleHelp(Character *player, std::string &args) if (player->getAccountLevel() & AL_ADMIN) { - say("Administrator Commands", player); + say("=Administrator Commands=", player); say("@reload", player); say("@setgroup ", player); say("@announce ", player); @@ -149,6 +156,7 @@ static void handleWarp(Character *player, std::string &args) if (character == "" || mapstr == "" || xstr == "" || ystr == "") { say("Invalid number of arguments given.", player); + say("Usage: @warp ", player); return; } @@ -230,6 +238,7 @@ static void handleItem(Character *player, std::string &args) if (character == "" || itemclass == "" || valuestr == "") { say("Invalid number of arguments given.", player); + say("Usage: @item ", player); return; } @@ -299,6 +308,7 @@ static void handleDrop(Character *player, std::string &args) if (itemclass == "" || valuestr == "") { say("Invalid number of arguments given.", player); + say("Usage: @drop ", player); return; } @@ -349,6 +359,7 @@ static void handleMoney(Character *player, std::string &args) if (character == "" || valuestr == "") { say("Invalid number of arguments given", player); + say("Usage: @money ", player); return; } @@ -397,6 +408,7 @@ static void handleSpawn(Character *player, std::string &args) if (monsterclass == "" || valuestr == "") { say("Invalid amount of arguments given.", player); + say("Usage: @spawn ", player); return; } @@ -453,6 +465,7 @@ static void handleGoto(Character *player, std::string &args) if (character == "") { say("Invalid amount of arguments given.", player); + say("Usage: @goto ", player); return; } @@ -481,6 +494,7 @@ static void handleRecall(Character *player, std::string &args) if (character == "") { say("Invalid amount of arguments given.", player); + say("Usage: @recall ", player); return; } @@ -518,6 +532,7 @@ static void handleBan(Character *player, std::string &args) if (character == "" || valuestr == "") { say("Invalid number of arguments given.", player); + say("Usage: @ban ", player); return; } @@ -562,6 +577,7 @@ static void handleSetGroup(Character *player, std::string &args) if (character == "" || levelstr == "") { say("Invalid number of arguments given.", player); + say("Usage: @setgroup ", player); return; } @@ -628,6 +644,7 @@ static void handleAttribute(Character *player, std::string &args) if (character == "" || valuestr == "" || attrstr == "") { say("Invalid number of arguments given.", player); + say("Usage: @attribute ", player); return; } @@ -683,6 +700,7 @@ static void handleReport(Character *player, std::string &args) if (bugReport == "") { say("Invalid number of arguments given.", player); + say("Usage: @report ", player); return; } @@ -696,12 +714,44 @@ static void handleAnnounce(Character *player, std::string &args) if (msg == "") { say("Invalid number of arguments given.", player); + say("Usage: @announce ", player); return; } GameState::sayToAll(msg); } +static void handleWhere(Character *player) +{ + std::stringstream str; + str << "Your current location is map " + << player->getMapId() + << " [" + << player->getPosition().x + << ":" + << player->getPosition().y + << "]"; + say (str.str(), player); +} + +static void handleRights(Character *player) +{ + std::stringstream str; + str << "Your rights level is: " + << player->getAccountLevel() + << " (AL_PLAYER"; + if (checkPermission(player, AL_TESTER)) + str << ", AL_TESTER"; + if (checkPermission(player, AL_GM)) + str << ", AL_GM"; + if (checkPermission(player, AL_ADMIN)) + str << ", AL_ADMIN"; + str << ")"; + say(str.str(), player); +} + + + void CommandHandler::handleCommand(Character *player, const std::string &command) { @@ -714,72 +764,82 @@ void CommandHandler::handleCommand(Character *player, // handle the command if (type == "help") { - if (handlePermissions(player, AL_PLAYER)) + if (checkPermission(player, AL_PLAYER)) handleHelp(player, args); } + else if (type == "where" || type == "location") + { + if (checkPermission(player, AL_PLAYER)) + handleWhere(player); + } + else if (type == "rights" || type == "right" || type == "permission") + { + if (checkPermission(player, AL_PLAYER)) + handleRights(player); + } else if (type == "warp") { - if (handlePermissions(player, AL_TESTER)) + if (checkPermission(player, AL_TESTER)) handleWarp(player, args); } else if (type == "item") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleItem(player, args); } else if (type == "drop") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleDrop(player, args); } else if (type == "money") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleMoney(player, args); } else if (type == "spawn") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleSpawn(player, args); } else if (type == "goto") { - if (handlePermissions(player, AL_TESTER)) + if (checkPermission(player, AL_TESTER)) handleGoto(player, args); } else if (type == "recall") { - if (handlePermissions(player, AL_GM)) + if (checkPermission(player, AL_GM)) handleRecall(player, args); } else if (type == "reload") { - if (handlePermissions(player, AL_ADMIN)) + if (checkPermission(player, AL_ADMIN)) handleReload(player); } else if (type == "ban") { - if (handlePermissions(player, AL_GM)) + if (checkPermission(player, AL_GM)) handleBan(player, args); } else if (type == "setgroup") { - if (handlePermissions(player, AL_ADMIN)) + if (checkPermission(player, AL_ADMIN)) handleSetGroup(player, args); } else if (type == "attribute") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleAttribute(player, args); } else if (type == "report") { - if (handlePermissions(player, AL_PLAYER)) + if (checkPermission(player, AL_PLAYER)) handleReport(player, args); } else if (type == "announce") { - if (handlePermissions(player, AL_ADMIN)) + if (checkPermission(player, AL_ADMIN)) handleAnnounce(player, args); } else -- cgit v1.2.3-70-g09d2 From c59fe51b4c9c08ccb2e001baf9b2f347fc2fc0ee Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 18 Jan 2009 14:00:55 +0100 Subject: Fixed invalid permission spam for low level accounts --- src/game-server/commandhandler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 26c097d8..9aefbcab 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -740,11 +740,11 @@ static void handleRights(Character *player) str << "Your rights level is: " << player->getAccountLevel() << " (AL_PLAYER"; - if (checkPermission(player, AL_TESTER)) + if (player->getAccountLevel() & AL_TESTER) str << ", AL_TESTER"; - if (checkPermission(player, AL_GM)) + if (player->getAccountLevel() & AL_GM) str << ", AL_GM"; - if (checkPermission(player, AL_ADMIN)) + if (player->getAccountLevel() & AL_ADMIN) str << ", AL_ADMIN"; str << ")"; say(str.str(), player); -- cgit v1.2.3-70-g09d2 From 64877056e3b297707b02c93f89185cea6a5f39a3 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 18 Jan 2009 14:21:03 +0100 Subject: Made command handler even more helpful when entering an invalid command. --- src/game-server/commandhandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 9aefbcab..3c716da5 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -844,6 +844,6 @@ void CommandHandler::handleCommand(Character *player, } else { - say("command not found", player); + say("Command not found. Enter @help to view the list of available commands.", player); } } -- cgit v1.2.3-70-g09d2 From ece7a5e46a92a5cbf88bb72892dfc67dba059859 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Wed, 21 Jan 2009 22:27:35 +0100 Subject: Added script command to get the id of the current map (requested by Invertika). --- src/scripting/lua.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index aead80cb..e711623d 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1151,6 +1151,18 @@ static int LuaTest_Tableget(lua_State *s) return 4; } +/** + * Returns the ID of the current map + */ +static int LuaGet_MapId(lua_State *s) +{ + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + Script *t = static_cast