summaryrefslogtreecommitdiff
path: root/src/account-server
diff options
context:
space:
mode:
authorFreeyorp <Freeyorp101@hotmail.com>2010-07-13 00:09:17 +1200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-08-03 17:57:29 +0200
commit6e1d5a811339a75f80ebb66a697c16ef0e9a7e67 (patch)
treeb2866e2ea7cb4307ea1650e82fca0be90d5aaa8f /src/account-server
parent5f4936e70b92a625f54d791debadf65d8fa3a02c (diff)
downloadmanaserv-6e1d5a811339a75f80ebb66a697c16ef0e9a7e67.tar.gz
manaserv-6e1d5a811339a75f80ebb66a697c16ef0e9a7e67.tar.bz2
manaserv-6e1d5a811339a75f80ebb66a697c16ef0e9a7e67.tar.xz
manaserv-6e1d5a811339a75f80ebb66a697c16ef0e9a7e67.zip
Allow default values for attributes at character creation time.
TODO: The game-server also needs to keep track of this for when new attributes or attributes not in the default scope need to be created. Also hopefully fix attribute calculation order for derived attributes. Still hardcoded for now. Reviewed-by: Bertram.
Diffstat (limited to 'src/account-server')
-rw-r--r--src/account-server/accounthandler.cpp24
-rw-r--r--src/account-server/serverhandler.cpp1
2 files changed, 24 insertions, 1 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp
index af04119a..99faad62 100644
--- a/src/account-server/accounthandler.cpp
+++ b/src/account-server/accounthandler.cpp
@@ -35,6 +35,7 @@
#include "net/messagein.hpp"
#include "net/messageout.hpp"
#include "net/netcomputer.hpp"
+#include "utils/functors.h"
#include "utils/logger.h"
#include "utils/stringfilter.h"
#include "utils/tokencollector.hpp"
@@ -54,6 +55,15 @@ static void addUpdateHost(MessageOut *msg)
static std::vector< unsigned int > initAttr;
+/*
+ * Map attribute ids to values that they need to be initialised to at account
+ * creation.
+ * The pair contains two elements of the same value (the default) so that the
+ * iterators can be used to copy a range.
+ */
+
+static std::map< unsigned int, std::pair< double, double> > defAttr;
+
class AccountHandler : public ConnectionHandler
{
public:
@@ -145,8 +155,19 @@ AccountHandler::AccountHandler(const std::string &attrFile):
}
for_each_xml_child_node(attributenode, node)
if (xmlStrEqual(attributenode->name, BAD_CAST "stat"))
+ {
+ unsigned int id = XML::getProperty(attributenode, "id", 0);
+ if (!id) continue;
if (utils::toupper(XML::getProperty(attributenode, "modifiable", "false")) == "TRUE")
- initAttr.push_back(XML::getProperty(attributenode, "id", 0)); // id
+ initAttr.push_back(id);
+ // Store as string initially to check that the property is defined.
+ std::string defStr = XML::getProperty(attributenode, "default", "");
+ if (!defStr.empty())
+ {
+ double val = string_to<double>()(defStr);
+ defAttr.insert(std::make_pair(id, std::make_pair(val, val)));
+ }
+ }
}
}
@@ -691,6 +712,7 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, Message
(unsigned int) (initAttr.at(i)),
std::make_pair((double) (attributes[i]),
(double) (attributes[i]))));
+ newCharacter->mAttributes.insert(defAttr.begin(), defAttr.end());
newCharacter->setAccount(acc);
newCharacter->setLevel(1);
newCharacter->setCharacterPoints(0);
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index 106f582e..c68cb623 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -116,6 +116,7 @@ NetComputer *ServerHandler::computerConnected(ENetPeer *peer)
void ServerHandler::computerDisconnected(NetComputer *comp)
{
+ LOG_INFO("Game-server disconnected.");
delete comp;
}