summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--example/scripts/maps/desert.lua4
-rw-r--r--example/scripts/npcs/banker.lua14
-rw-r--r--example/scripts/npcs/debugger.lua4
-rw-r--r--example/settings.xml1
-rw-r--r--scripts/lua/libmana.lua28
-rw-r--r--src/account-server/account.h3
-rw-r--r--src/account-server/accounthandler.cpp7
-rw-r--r--src/account-server/serverhandler.cpp23
-rw-r--r--src/account-server/storage.cpp6
-rw-r--r--src/chat-server/chatclient.h9
-rw-r--r--src/chat-server/guild.cpp5
-rw-r--r--src/chat-server/guildmanager.cpp5
-rw-r--r--src/chat-server/post.cpp2
-rw-r--r--src/common/permissionmanager.cpp16
-rw-r--r--src/dal/sqlitedataprovider.cpp1
-rw-r--r--src/game-server/attribute.cpp2
-rw-r--r--src/game-server/attribute.h2
-rw-r--r--src/game-server/being.cpp15
-rw-r--r--src/game-server/commandhandler.cpp23
-rw-r--r--src/game-server/main-game.cpp5
-rw-r--r--src/game-server/mapmanager.cpp121
-rw-r--r--src/game-server/mapmanager.h17
-rw-r--r--src/game-server/settingsmanager.cpp9
-rw-r--r--src/game-server/spawnareacomponent.cpp2
-rw-r--r--src/game-server/state.cpp2
-rw-r--r--src/net/netcomputer.cpp2
-rw-r--r--src/net/netcomputer.h2
-rw-r--r--src/scripting/luascript.cpp8
-rw-r--r--src/scripting/luautil.h11
-rw-r--r--src/utils/logger.cpp30
31 files changed, 192 insertions, 188 deletions
diff --git a/AUTHORS b/AUTHORS
index 4db57875..8ee2d8ba 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -8,5 +8,6 @@ Guillaume Melquiond <guillaume.melquiond@gmail.com>
Huynh Ngoc Chau Tran aka kindjal <nthuynh at users dot sourceforge dot net>
jurkan <jurkan@gmx.de>
Philipp Sehmisch <tmw@crushnet.org>
+Przemysław Grzywacz <nexather@gmail.com>
seeseekey <seeseekey@googlemail.com>
Yohann Ferreira <Bertram@cegetel.net>
diff --git a/example/scripts/maps/desert.lua b/example/scripts/maps/desert.lua
index 759dbb51..5f7f2d28 100644
--- a/example/scripts/maps/desert.lua
+++ b/example/scripts/maps/desert.lua
@@ -79,8 +79,8 @@ function Harmony(npc, ch, list)
--- Give the player 100 units of money the first time.
if harmony_have_talked_to_someone == false then
say("Here is some money for you to find some toys to play with.\nEh Eh!")
- chr_money_change(ch, 100)
- say(string.format("You now have %d shiny coins!", chr_money(ch)))
+ ch:change_money(100)
+ say(string.format("You now have %d shiny coins!", ch:money()))
harmony_have_talked_to_someone = true
say(string.format("Try to come back with a better level than %i.", ch:level()))
else
diff --git a/example/scripts/npcs/banker.lua b/example/scripts/npcs/banker.lua
index ce352a0c..a9375736 100644
--- a/example/scripts/npcs/banker.lua
+++ b/example/scripts/npcs/banker.lua
@@ -37,16 +37,16 @@ function Banker(npc, ch)
result = 1
while (result < 3) do --While they've choosen a valid option that isn't "Never mind"
account = tonumber(chr_get_quest(ch, "BankAccount")) --Why do I need to convert this?
- say("Your balance: " .. account .. ".\nYour money: " .. chr_money(ch) .. ".")
+ say("Your balance: " .. account .. ".\nYour money: " .. ch:money() .. ".")
result = ask("Deposit", "Withdraw", "Never mind")
if (result == 1) then --Deposit
- money = chr_money(ch);
+ money = ch:money();
if (money > 0) then --Make sure they have money to deposit
say("How much would you like to deposit? (0 will cancel)")
- input = ask_integer(0, money, 1)
- money = chr_money(ch)
+ input = ask_number(0, money, 1)
+ money = ch:money()
if (input > 0 and input <= money) then --Make sure something weird doesn't happen and they try to deposit more than they have
- chr_money_change(ch, -input)
+ ch:change_money(-input)
chr_set_quest(ch, "BankAccount", account + input)
say(input .. " GP deposited.")
elseif (input > money) then --Chosen more than they have
@@ -58,9 +58,9 @@ function Banker(npc, ch)
elseif (result == 2) then --Withdraw
if (account > 0) then --Make sure they have money to withdraw
say("How much would you like to withdraw? (0 will cancel)")
- input = ask_integer(0, account, 1)
+ input = ask_number(0, account, 1)
if (input > 0 and input <= account) then --Make sure something weird doesn't happen and they try to withdraw more than they have
- chr_money_change(ch, input)
+ ch:change_money(input)
chr_set_quest(ch, "BankAccount", account - input)
say(input .. " GP withdrawn.")
elseif (input > account) then --Chosen more than they have
diff --git a/example/scripts/npcs/debugger.lua b/example/scripts/npcs/debugger.lua
index 390f8f29..e65bf236 100644
--- a/example/scripts/npcs/debugger.lua
+++ b/example/scripts/npcs/debugger.lua
@@ -50,8 +50,8 @@ function npc1_talk(npc, ch)
end
elseif v == 3 then
- if chr_money_change(ch, -100) then
- say(string.format("Thank you for you patronage! You are left with %d GP.", chr_money(ch)))
+ if ch:change_money(-100) then
+ say(string.format("Thank you for you patronage! You are left with %d GP.", ch:money()))
local g = tonumber(chr_get_quest(ch, "001_donation"))
if not g then g = 0 end
g = g + 100
diff --git a/example/settings.xml b/example/settings.xml
index 5641d71f..ebe7a717 100644
--- a/example/settings.xml
+++ b/example/settings.xml
@@ -1,4 +1,5 @@
<settings>
+ <include file="maps.xml" />
<include file="attributes.xml" />
<include file="skills.xml" />
<include file="specials.xml" />
diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua
index 20a5e13f..7393ce60 100644
--- a/scripts/lua/libmana.lua
+++ b/scripts/lua/libmana.lua
@@ -367,27 +367,27 @@ end
-- Below are some convenience methods added to the engine API
---- LUA chr_money_change (inventory)
--- chr_money_change(handle character, int amount)
+--- LUA entity:change_money (inventory)
+-- entity:change_money(int amount)
---
--- Changes the money currently owned by ''character'' by ''amount''.
+-- Valid only for character entities.
+--
+-- Changes the money currently owned by this character by ''amount''.
--
-- **Warning:** Before reducing the money make sure to check if the character
--- owns enough money using chr_money.
-chr_money_change = function(ch, amount)
- ch:set_base_attribute(ATTR_GP,
- ch:base_attribute(ATTR_GP) + amount)
+-- owns enough money using entity:money.
+function Entity:change_money(amount)
+ self:set_base_attribute(ATTR_GP, self:base_attribute(ATTR_GP) + amount)
end
---- LUA chr_money (inventory)
--- chr_money(handle character)
+--- LUA entity:money (inventory)
+-- entity:money()
---
--- Changes the money currently owned by ''character'' by ''amount''.
+-- Valid only for character entities.
--
--- **Warning:** Before reducing the money make sure to check if the character
--- owns enough money using chr_money.
-chr_money = function(ch)
- return ch:base_attribute(ATTR_GP)
+-- Returns the money currently owned by this character.
+function Entity:money()
+ return self:base_attribute(ATTR_GP)
end
-- Register callbacks
diff --git a/src/account-server/account.h b/src/account-server/account.h
index 0ee84768..a359c11d 100644
--- a/src/account-server/account.h
+++ b/src/account-server/account.h
@@ -36,6 +36,9 @@ class Account
public:
Account(int id = -1)
: mID(id)
+ , mLevel(0)
+ , mRegistrationDate(0)
+ , mLastLogin(0)
{}
~Account();
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp
index 76a427ea..c1de5200 100644
--- a/src/account-server/accounthandler.cpp
+++ b/src/account-server/accounthandler.cpp
@@ -382,10 +382,9 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg)
// Check if the account exists
Account *acc = 0;
- std::list<Account*>::iterator ita;
- for ( ita = mPendingAccounts.begin() ; ita != mPendingAccounts.end(); ita++ )
- if ((*ita)->getName() == username)
- acc = *ita;
+ for (Account *account : mPendingAccounts)
+ if (account->getName() == username)
+ acc = account;
mPendingAccounts.remove(acc);
if (!acc || sha256(acc->getPassword() + acc->getRandomSalt()) != password)
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index dbf74d03..1ba3c03d 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -213,12 +213,11 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
// transmit global world state variables
std::map<std::string, std::string> variables;
variables = storage->getAllWorldStateVars(Storage::WorldMap);
- for (std::map<std::string, std::string>::iterator i = variables.begin();
- i != variables.end();
- i++)
+
+ for (auto &variableIt : variables)
{
- outMsg.writeString(i->first);
- outMsg.writeString(i->second);
+ outMsg.writeString(variableIt.first);
+ outMsg.writeString(variableIt.second);
}
comp->send(outMsg);
@@ -256,12 +255,10 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
// Map vars number
outMsg.writeInt16(variables.size());
- for (std::map<std::string, std::string>::iterator i = variables.begin();
- i != variables.end();
- i++)
+ for (auto &variableIt : variables)
{
- outMsg.writeString(i->first);
- outMsg.writeString(i->second);
+ outMsg.writeString(variableIt.first);
+ outMsg.writeString(variableIt.second);
}
// Persistent Floor Items
@@ -393,14 +390,12 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
// save the new value to the database
storage->setWorldStateVar(name, value, Storage::WorldMap);
// relay the new value to all gameservers
- for (ServerHandler::NetComputers::iterator i = clients.begin();
- i != clients.end();
- i++)
+ for (NetComputer *netComputer : clients)
{
MessageOut varUpdateMessage(AGMSG_SET_VAR_WORLD);
varUpdateMessage.writeString(name);
varUpdateMessage.writeString(value);
- (*i)->send(varUpdateMessage);
+ netComputer->send(varUpdateMessage);
}
} break;
diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp
index dd8cf9ac..72f4fc07 100644
--- a/src/account-server/storage.cpp
+++ b/src/account-server/storage.cpp
@@ -288,7 +288,7 @@ void Storage::fixCharactersSlot(int accountId)
}
}
- if (slotsToUpdate.size() > 0)
+ if (!slotsToUpdate.empty())
{
dal::PerformTransaction transaction(mDb);
@@ -776,7 +776,7 @@ bool Storage::updateCharacter(CharacterData *character)
{
std::map<int, int>::const_iterator kill_it;
for (kill_it = character->getKillCountBegin();
- kill_it != character->getKillCountEnd(); kill_it++)
+ kill_it != character->getKillCountEnd(); ++kill_it)
{
updateKillCount(character->getDatabaseID(),
kill_it->first, kill_it->second);
@@ -912,7 +912,7 @@ bool Storage::updateCharacter(CharacterData *character)
{
std::map<int, Status>::const_iterator status_it;
for (status_it = character->getStatusEffectBegin();
- status_it != character->getStatusEffectEnd(); status_it++)
+ status_it != character->getStatusEffectEnd(); ++status_it)
{
insertStatusEffect(character->getDatabaseID(),
status_it->first, status_it->second.time);
diff --git a/src/chat-server/chatclient.h b/src/chat-server/chatclient.h
index 7e8c4e2e..79de000a 100644
--- a/src/chat-server/chatclient.h
+++ b/src/chat-server/chatclient.h
@@ -38,10 +38,11 @@ class Party;
class ChatClient : public NetComputer
{
public:
- ChatClient(ENetPeer *peer):
- NetComputer(peer),
- party(0),
- accountLevel(0)
+ ChatClient(ENetPeer *peer)
+ : NetComputer(peer)
+ , characterId(0)
+ , party(0)
+ , accountLevel(0)
{
}
diff --git a/src/chat-server/guild.cpp b/src/chat-server/guild.cpp
index 47ace46e..e86130dc 100644
--- a/src/chat-server/guild.cpp
+++ b/src/chat-server/guild.cpp
@@ -26,8 +26,9 @@
#include <algorithm>
-Guild::Guild(const std::string &name) :
- mName(name)
+Guild::Guild(const std::string &name)
+ : mId(0)
+ , mName(name)
{
}
diff --git a/src/chat-server/guildmanager.cpp b/src/chat-server/guildmanager.cpp
index 39b0bdbb..b7f945de 100644
--- a/src/chat-server/guildmanager.cpp
+++ b/src/chat-server/guildmanager.cpp
@@ -29,10 +29,9 @@
using namespace ManaServ;
-GuildManager::GuildManager()
+GuildManager::GuildManager():
+ mGuilds(storage->getGuildList())
{
- // Load stored guilds from db
- mGuilds = storage->getGuildList();
}
GuildManager::~GuildManager()
diff --git a/src/chat-server/post.cpp b/src/chat-server/post.cpp
index 9da07535..e6248891 100644
--- a/src/chat-server/post.cpp
+++ b/src/chat-server/post.cpp
@@ -24,7 +24,7 @@
#include "../common/configuration.h"
Letter::Letter(unsigned type, CharacterData *sender, CharacterData *receiver)
- : mId(0), mType(type), mSender(sender), mReceiver(receiver)
+ : mId(0), mType(type), mExpiry(0), mSender(sender), mReceiver(receiver)
{
}
diff --git a/src/common/permissionmanager.cpp b/src/common/permissionmanager.cpp
index b1c93c10..bd1767a9 100644
--- a/src/common/permissionmanager.cpp
+++ b/src/common/permissionmanager.cpp
@@ -143,16 +143,15 @@ unsigned char PermissionManager::getMaskFromAlias(const std::string &alias)
std::list<std::string> PermissionManager::getPermissionList(const Entity* character)
{
std::list<std::string> result;
- std::map<std::string, unsigned char>::iterator i;
unsigned char mask = character->getComponent<CharacterComponent>()
->getAccountLevel();
- for (i = permissions.begin(); i != permissions.end(); i++)
+ for (auto &permissionIt : permissions)
{
- if (i->second & mask)
+ if (permissionIt.second & mask)
{
- result.push_back(i->first);
+ result.push_back(permissionIt.first);
}
}
@@ -162,17 +161,14 @@ std::list<std::string> PermissionManager::getPermissionList(const Entity* charac
std::list<std::string> PermissionManager::getClassList(const Entity* character)
{
std::list<std::string> result;
- std::map<std::string, unsigned char>::iterator i;
unsigned char mask = character->getComponent<CharacterComponent>()
->getAccountLevel();
- for (i = aliases.begin(); i != aliases.end(); i++)
+ for (auto &aliasIt : aliases)
{
- if (i->second & mask)
- {
- result.push_back(i->first);
- }
+ if (aliasIt.second & mask)
+ result.push_back(aliasIt.first);
}
return result;
diff --git a/src/dal/sqlitedataprovider.cpp b/src/dal/sqlitedataprovider.cpp
index e267e383..2a08e9be 100644
--- a/src/dal/sqlitedataprovider.cpp
+++ b/src/dal/sqlitedataprovider.cpp
@@ -43,6 +43,7 @@ const std::string SqLiteDataProvider::CFGPARAM_SQLITE_DB_DEF = "mana.db";
SqLiteDataProvider::SqLiteDataProvider()
throw()
: mDb(0)
+ , mStmt(0)
{
}
diff --git a/src/game-server/attribute.cpp b/src/game-server/attribute.cpp
index 71e5d944..f898b6e8 100644
--- a/src/game-server/attribute.cpp
+++ b/src/game-server/attribute.cpp
@@ -394,7 +394,7 @@ void AttributeModifiersEffect::clearMods(double baseValue)
mMod = mEffectType == Additive ? 0 : 1;
}
-double Attribute::checkBounds(double baseValue)
+double Attribute::checkBounds(double baseValue) const
{
LOG_DEBUG("Checking bounds for value: " << baseValue);
if (baseValue > mMaxValue)
diff --git a/src/game-server/attribute.h b/src/game-server/attribute.h
index 736e54a6..2ac1378c 100644
--- a/src/game-server/attribute.h
+++ b/src/game-server/attribute.h
@@ -195,7 +195,7 @@ class Attribute
* Checks the min and max permitted values for the given base value
* and return the adjusted value.
*/
- double checkBounds(double baseValue);
+ double checkBounds(double baseValue) const;
double mBase; // The attribute base value
double mMinValue; // The min authorized base and derived attribute value
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index 4ddec981..f3d45305 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -234,12 +234,11 @@ void BeingComponent::move(Entity &entity)
* class has been used, because that seems to be the most logical
* place extra functionality will be added.
*/
- for (Path::iterator pathIterator = mPath.begin();
- pathIterator != mPath.end(); pathIterator++)
+ for (Point &point : mPath)
{
const unsigned char walkmask =
entity.getComponent<ActorComponent>()->getWalkMask();
- if (!map->getWalk(pathIterator->x, pathIterator->y, walkmask))
+ if (!map->getWalk(point.x, point.y, walkmask))
{
mPath.clear();
break;
@@ -498,12 +497,10 @@ void BeingComponent::removeStatusEffect(int id)
bool BeingComponent::hasStatusEffect(int id) const
{
- StatusEffects::const_iterator it = mStatus.begin();
- while (it != mStatus.end())
+ for (auto &statusIt : mStatus)
{
- if (it->second.status->getId() == id)
+ if (statusIt.second.status->getId() == id)
return true;
- it++;
}
return false;
}
@@ -566,12 +563,12 @@ void BeingComponent::update(Entity &entity)
if (it->second.time <= 0 || mAction == DEAD)
{
StatusEffects::iterator removeIt = it;
- it++; // bring this iterator to the safety of the next element
+ ++it; // bring this iterator to the safety of the next element
mStatus.erase(removeIt);
}
else
{
- it++;
+ ++it;
}
}
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp
index dcdd8c6a..4c210bf0 100644
--- a/src/game-server/commandhandler.cpp
+++ b/src/game-server/commandhandler.cpp
@@ -198,13 +198,11 @@ static std::string playerRights(Entity *ch)
std::stringstream str;
str << (unsigned)ch->getComponent<CharacterComponent>()->getAccountLevel();
str << " ( ";
- std::list<std::string> classes =
- PermissionManager::getClassList(ch);
- for (std::list<std::string>::iterator i = classes.begin();
- i != classes.end();
- i++)
+ std::list<std::string> classes = PermissionManager::getClassList(ch);
+
+ for (std::string &permission : classes)
{
- str << (*i) << " ";
+ str << permission << " ";
}
str << ")";
return str.str();
@@ -257,7 +255,7 @@ static std::string getArgument(std::string &args)
}
else
{
- argument = args.substr(0);
+ argument = args;
args = std::string();
}
return argument;
@@ -269,12 +267,10 @@ static void handleHelp(Entity *player, std::string &args)
{
// short list of all commands
say("=Available Commands=", player);
- std::list<std::string> commands = PermissionManager::getPermissionList(player);
- for (std::list<std::string>::iterator i = commands.begin();
- i != commands.end();
- i++)
+ for (std::string &command :
+ PermissionManager::getPermissionList(player))
{
- say((*i), player);
+ say(command, player);
}
} else {
// don't show help for commands the player may not use
@@ -909,7 +905,7 @@ static void handleBan(Entity *player, std::string &args)
// feedback for command user
std::string otherName = other->getComponent<BeingComponent>()->getName();
std::string msg = "You've banned " + otherName + " for " + utils::toString(length) + " minutes";
- say(msg.c_str(), player);
+ say(msg, player);
// log transaction
msg = "User banned " + otherName + " for " + utils::toString(length) + " minutes";
accountHandler->sendTransaction(characterComponent->getDatabaseID(),
@@ -1423,7 +1419,6 @@ static void handleCraft(Entity *player, std::string &args)
std::stringstream errMsg;
std::list<InventoryItem> recipe;
Inventory playerInventory(player);
- std::map<int, int> totalAmountOfItem;
while (true)
{
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index e21b1ddf..894af5f9 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -128,11 +128,6 @@ static void initializeServer()
ResourceManager::initialize();
ScriptManager::initialize(); // Depends on ResourceManager
- if (MapManager::initialize(DEFAULT_MAPSDB_FILE) < 1)
- {
- LOG_FATAL("The Game Server can't find any valid/available maps.");
- exit(EXIT_MAP_FILE_NOT_FOUND);
- }
// load game settings files
settingsManager->initialize();
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index 50f79cd0..f3e9fcf2 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -22,10 +22,10 @@
#include "game-server/mapmanager.h"
#include "common/resourcemanager.h"
+#include "common/defines.h"
#include "game-server/map.h"
#include "game-server/mapcomposite.h"
#include "utils/logger.h"
-#include "utils/xml.h"
#include <cassert>
@@ -39,80 +39,87 @@ const MapManager::Maps &MapManager::getMaps()
return maps;
}
-int MapManager::initialize(const std::string &mapReferenceFile)
+void MapManager::initialize()
{
- // Indicates the number of maps loaded successfully
- int loadedMaps = 0;
- XML::Document doc(mapReferenceFile);
- xmlNodePtr rootNode = doc.rootNode();
+}
- if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "maps"))
+/**
+ * Destroys all maps.
+ */
+void MapManager::deinitialize()
+{
+ for (Maps::iterator i = maps.begin(), i_end = maps.end(); i != i_end; ++i)
{
- LOG_ERROR("Item Manager: Error while parsing map database ("
- << mapReferenceFile << ")!");
- return loadedMaps;
+ delete i->second;
}
+ maps.clear();
+}
- LOG_INFO("Loading map reference: " << mapReferenceFile);
- for_each_xml_child_node(node, rootNode)
- {
- if (!xmlStrEqual(node->name, BAD_CAST "map"))
- continue;
+/**
+ * Prepare map manager for a reload.
+ */
+void MapManager::reload()
+{
+ // TODO: this method needs proper map reloading
+ LOG_ERROR("MapManager::reload() not implemented yet");
+}
+
+/**
+ * Read a <map> node from settings
+ */
+void MapManager::readMapNode(xmlNodePtr node)
+{
+ int id = XML::getProperty(node, "id", 0);
+ std::string name = XML::getProperty(node, "name", std::string());
- int id = XML::getProperty(node, "id", 0);
- std::string name = XML::getProperty(node, "name", std::string());
- // Test id and map name
- if (id > 0 && !name.empty())
+ if (id <= 0)
+ {
+ LOG_WARN("Invalid map Id: " << id << " for map: "
+ << name << '.');
+ }
+ else if (name.empty())
+ {
+ LOG_WARN("Invalid unnamed map Id: " << id << '.');
+ }
+ else
+ {
+ // Testing if the file is actually in the maps folder
+ std::string file = std::string("maps/") + name + ".tmx";
+ bool mapFileExists = ResourceManager::exists(file);
+
+ // Try to fall back on fully compressed map
+ if (!mapFileExists)
{
- // Testing if the file is actually in the maps folder
- std::string file = std::string("maps/") + name + ".tmx";
- bool mapFileExists = ResourceManager::exists(file);
-
- // Try to fall back on fully compressed map
- if (!mapFileExists)
- {
- file += ".gz";
- mapFileExists = ResourceManager::exists(file);
- }
-
- if (mapFileExists)
- {
- maps[id] = new MapComposite(id, name);
- if (!maps[id]->readMap())
- LOG_FATAL("Failed to load map \"" << name << "\"!");
-
- ++loadedMaps;
- }
+ file += ".gz";
+ mapFileExists = ResourceManager::exists(file);
}
- else
+
+ if (mapFileExists)
{
- if (name.empty())
- {
- LOG_WARN("Invalid unnamed map Id: " << id << '.');
- }
- else
- {
- LOG_WARN("Invalid map Id: " << id << " for map: "
- << name << '.');
- }
+ maps[id] = new MapComposite(id, name);
+ if (!maps[id]->readMap())
+ LOG_FATAL("Failed to load map \"" << name << "\"!");
}
}
-
- if (loadedMaps > 0)
- LOG_INFO(loadedMaps << " valid map file references were loaded.");
-
- return loadedMaps;
}
-void MapManager::deinitialize()
+/**
+ * Check the status of recently loaded configuration.
+ */
+void MapManager::checkStatus()
{
- for (Maps::iterator i = maps.begin(), i_end = maps.end(); i != i_end; ++i)
+ int loadedMaps = maps.size();
+ if (loadedMaps > 0)
{
- delete i->second;
+ LOG_INFO(loadedMaps << " valid map file references were loaded.");
+ }
+ else
+ {
+ LOG_FATAL("The Game Server can't find any valid/available maps.");
+ exit(EXIT_MAP_FILE_NOT_FOUND);
}
- maps.clear();
}
MapComposite *MapManager::getMap(int mapId)
diff --git a/src/game-server/mapmanager.h b/src/game-server/mapmanager.h
index 12cbc342..b1b47591 100644
--- a/src/game-server/mapmanager.h
+++ b/src/game-server/mapmanager.h
@@ -25,23 +25,24 @@
#include <map>
#include <string>
+#include "utils/xml.h"
+
class MapComposite;
namespace MapManager
{
typedef std::map< int, MapComposite * > Maps;
- /**
- * Loads map reference file and prepares maps.
- * @return the number of maps loaded succesfully
- */
- int initialize(const std::string &mapReferenceFile);
+ void initialize();
- /**
- * Destroy loaded maps.
- */
void deinitialize();
+ void reload();
+
+ void readMapNode(xmlNodePtr node);
+
+ void checkStatus();
+
/**
* Returns the requested map.
*
diff --git a/src/game-server/settingsmanager.cpp b/src/game-server/settingsmanager.cpp
index 79aade1b..b45ef932 100644
--- a/src/game-server/settingsmanager.cpp
+++ b/src/game-server/settingsmanager.cpp
@@ -25,6 +25,7 @@
#include "common/resourcemanager.h"
+#include "game-server/mapmanager.h"
#include "game-server/attributemanager.h"
#include "game-server/skillmanager.h"
#include "game-server/specialmanager.h"
@@ -41,6 +42,7 @@
void SettingsManager::initialize()
{
// initialize all managers in correct order
+ MapManager::initialize();
attributeManager->initialize();
skillManager->initialize();
specialManager->initialize();
@@ -61,6 +63,7 @@ void SettingsManager::initialize()
*/
void SettingsManager::reload()
{
+ MapManager::reload();
attributeManager->reload();
skillManager->reload();
specialManager->reload();
@@ -125,6 +128,11 @@ void SettingsManager::loadFile(const std::string &filename)
}
}
}
+ else if (xmlStrEqual(childNode->name, BAD_CAST "map"))
+ {
+ // map config
+ MapManager::readMapNode(childNode);
+ }
else if (xmlStrEqual(childNode->name, BAD_CAST "attribute"))
{
// attribute config
@@ -181,6 +189,7 @@ void SettingsManager::loadFile(const std::string &filename)
*/
void SettingsManager::checkStatus()
{
+ MapManager::checkStatus();
attributeManager->checkStatus();
skillManager->checkStatus();
specialManager->checkStatus();
diff --git a/src/game-server/spawnareacomponent.cpp b/src/game-server/spawnareacomponent.cpp
index 54cb017f..33bd5acd 100644
--- a/src/game-server/spawnareacomponent.cpp
+++ b/src/game-server/spawnareacomponent.cpp
@@ -58,7 +58,6 @@ void SpawnAreaComponent::update(Entity &entity)
}
// Find a free spawn location. Give up after 10 tries
- int triesLeft = 10;
Point position;
const int x = mZone.x;
const int y = mZone.y;
@@ -81,6 +80,7 @@ void SpawnAreaComponent::update(Entity &entity)
if (being)
{
+ int triesLeft = 10;
do
{
position = Point(x + rand() % width, y + rand() % height);
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index db224b84..0b97ec07 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -110,7 +110,7 @@ static void serializeLooks(Entity *ch, MessageOut &msg)
}
}
- if (lookChanges.size() > 0)
+ if (!lookChanges.empty())
{
// Number of look changes to send
msg.writeInt8(lookChanges.size());
diff --git a/src/net/netcomputer.cpp b/src/net/netcomputer.cpp
index 8834f4a6..5d86f13a 100644
--- a/src/net/netcomputer.cpp
+++ b/src/net/netcomputer.cpp
@@ -34,7 +34,7 @@ NetComputer::NetComputer(ENetPeer *peer):
{
}
-bool NetComputer::isConnected()
+bool NetComputer::isConnected() const
{
return (mPeer->state == ENET_PEER_STATE_CONNECTED);
}
diff --git a/src/net/netcomputer.h b/src/net/netcomputer.h
index 09840348..228b30ea 100644
--- a/src/net/netcomputer.h
+++ b/src/net/netcomputer.h
@@ -40,7 +40,7 @@ class NetComputer
/**
* Returns <code>true</code> if this computer is connected.
*/
- bool isConnected();
+ bool isConnected() const;
/**
* Disconnects the computer from the server, after sending a message.
diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp
index 2b9644da..1617f74c 100644
--- a/src/scripting/luascript.cpp
+++ b/src/scripting/luascript.cpp
@@ -101,14 +101,12 @@ void LuaScript::push(const std::list<InventoryItem> &itemList)
lua_createtable(mCurrentState, itemList.size(), 0);
int itemTable = lua_gettop(mCurrentState);
- for (std::list<InventoryItem>::const_iterator i = itemList.begin();
- i != itemList.end();
- i++)
+ for (const InventoryItem &inventoryItem : itemList)
{
// create the item structure
std::map<std::string, int> item;
- item["id"] = i->itemId;
- item["amount"] = i->amount;
+ item["id"] = inventoryItem.itemId;
+ item["amount"] = inventoryItem.amount;
pushSTLContainer<std::string, int>(mCurrentState, item);
lua_rawseti(mCurrentState, itemTable, ++position);
}
diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h
index 8bcc2a30..f2b76896 100644
--- a/src/scripting/luautil.h
+++ b/src/scripting/luautil.h
@@ -106,6 +106,11 @@ public:
#else
luaL_setfuncs(s, members, 0);
#endif
+
+ // Make the functions table available as a global
+ lua_pushvalue(s, -1); // metatable, "__index", {}, {}
+ lua_setglobal(s, mTypeName); // metatable, "__index", {}
+
lua_rawset(s, -3); // metatable
lua_pop(s, 1); // -empty-
}
@@ -230,7 +235,7 @@ void pushSTLContainer(lua_State *s, const std::list<T> &container)
{
push(s, *i);
lua_rawseti(s, table, key);
- i++;
+ ++i;
}
}
@@ -264,7 +269,7 @@ void pushSTLContainer(lua_State *s, const std::map<Tkey, Tval> &container)
push(s, i->first);
push(s, i->second);
lua_settable(s, table);
- i++;
+ ++i;
}
}
@@ -282,7 +287,7 @@ void pushSTLContainer(lua_State *s, const std::set<T> &container)
{
push(s, *i);
lua_rawseti(s, table, key);
- i++;
+ ++i;
}
}
diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp
index 8a070570..50b0d4c2 100644
--- a/src/utils/logger.cpp
+++ b/src/utils/logger.cpp
@@ -138,23 +138,23 @@ void Logger::setLogFile(const std::string &logFile, bool append)
void Logger::output(const std::string &msg, Level atVerbosity)
{
- static const char *prefixes[] =
- {
-#ifdef T_COL_LOG
- "[\033[45mFTL\033[0m]",
- "[\033[41mERR\033[0m]",
- "[\033[43mWRN\033[0m]",
-#else
- "[FTL]",
- "[ERR]",
- "[WRN]",
-#endif
- "[INF]",
- "[DBG]"
- };
-
if (mVerbosity >= atVerbosity)
{
+ static const char *prefixes[] =
+ {
+ #ifdef T_COL_LOG
+ "[\033[45mFTL\033[0m]",
+ "[\033[41mERR\033[0m]",
+ "[\033[43mWRN\033[0m]",
+ #else
+ "[FTL]",
+ "[ERR]",
+ "[WRN]",
+ #endif
+ "[INF]",
+ "[DBG]"
+ };
+
bool open = mLogFile.is_open();
if (open)