summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-01 19:41:59 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-01 19:41:59 +0000
commitd4edf76ec16c63ad126712ffbe86d8ed63ab70eb (patch)
tree7cf7d0d2354aa5468a5cb37699a61918e98a6ed5 /src
parentf07dbf97c27aef7630782052ba6021359294cd86 (diff)
downloadmanaserv-d4edf76ec16c63ad126712ffbe86d8ed63ab70eb.tar.gz
manaserv-d4edf76ec16c63ad126712ffbe86d8ed63ab70eb.tar.bz2
manaserv-d4edf76ec16c63ad126712ffbe86d8ed63ab70eb.tar.xz
manaserv-d4edf76ec16c63ad126712ffbe86d8ed63ab70eb.zip
Made character data persistent across logout/login.
Diffstat (limited to 'src')
-rw-r--r--src/account-server/characterdata.cpp13
-rw-r--r--src/account-server/characterdata.hpp5
-rw-r--r--src/account-server/serverhandler.cpp24
-rw-r--r--src/defines.h4
-rw-r--r--src/game-server/accountconnection.cpp1
-rw-r--r--src/game-server/character.cpp6
-rw-r--r--src/serialize/characterdata.hpp4
7 files changed, 23 insertions, 34 deletions
diff --git a/src/account-server/characterdata.cpp b/src/account-server/characterdata.cpp
index 5dab4c08..79fcce34 100644
--- a/src/account-server/characterdata.cpp
+++ b/src/account-server/characterdata.cpp
@@ -21,8 +21,6 @@
*/
#include "account-server/characterdata.hpp"
-#include "net/messagein.hpp"
-#include "serialize/characterdata.hpp"
CharacterData::CharacterData(std::string const &name, int id):
mDatabaseID(id), mAccountID(-1), mName(name), mGender(0), mHairStyle(0),
@@ -34,14 +32,3 @@ CharacterData::CharacterData(std::string const &name, int id):
}
}
-CharacterData::CharacterData(MessageIn & msg):
- mDatabaseID(-1), mAccountID(-1), mName(""), mGender(0), mHairStyle(0),
- mHairColor(0), mLevel(0), mMoney(0), mMapId(0), mPos(0,0)
-{
- for (int i = 0; i < NB_BASE_ATTRIBUTES; ++i)
- {
- mBaseAttributes[i] = 0;
- }
- deserializeCharacterData(*this, msg);
-}
-
diff --git a/src/account-server/characterdata.hpp b/src/account-server/characterdata.hpp
index 76b43da0..0dc53ba3 100644
--- a/src/account-server/characterdata.hpp
+++ b/src/account-server/characterdata.hpp
@@ -40,11 +40,6 @@ class CharacterData
CharacterData(std::string const &name, int id = -1);
/**
- * Constructor used for creating a character from a serialised message.
- */
- CharacterData(MessageIn & msg);
-
- /**
* Get and set methods
*/
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index 3adb7173..db7b903e 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -84,6 +84,8 @@ void ServerHandler::registerGameClient(std::string const &token, CharacterPtr pt
MessageOut msg(AGMSG_PLAYER_ENTER);
msg.writeString(token, MAGIC_TOKEN_LENGTH);
+ msg.writeLong(ptr->getDatabaseID());
+ msg.writeString(ptr->getName());
serializeCharacterData(*ptr, msg);
Servers::const_iterator i = servers.find(mapId);
@@ -128,15 +130,21 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
case GAMSG_PLAYER_DATA:
{
LOG_DEBUG("GAMSG_PLAYER_DATA");
- // TODO: Store it in memory, only update the database when needed.
- // That should get rid of the
- // no_update_on_switch_character_bug as well.
Storage &store = Storage::instance("tmw");
- CharacterPtr ptr(new CharacterData(msg));
-
- if (!store.updateCharacter(ptr))
- LOG_ERROR("Received character data for non-existing" <<
- " character " << ptr->getDatabaseID() << ".");
+ int id = msg.readLong();
+ CharacterPtr ptr = store.getCharacter(id);
+ if (ptr.get())
+ {
+ deserializeCharacterData(*ptr, msg);
+ if (!store.updateCharacter(ptr))
+ LOG_ERROR("Failed to update character " <<
+ ptr->getDatabaseID() << '.');
+ }
+ else
+ {
+ LOG_ERROR("Received data for non-existing character " <<
+ ptr->getDatabaseID() << '.');
+ }
} break;
diff --git a/src/defines.h b/src/defines.h
index de5d1025..c0f44daa 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -211,8 +211,8 @@ enum {
// Inter-server
GAMSG_REGISTER = 0x0500, // S address, W port, { W map id }*
AGMSG_ACTIVE_MAP = 0x0501, // W map id
- AGMSG_PLAYER_ENTER = 0x0510, // B*32 token, serialised character data
- GAMSG_PLAYER_DATA = 0x0520, // serialised character data
+ AGMSG_PLAYER_ENTER = 0x0510, // B*32 token, L id, S name, serialised character data
+ GAMSG_PLAYER_DATA = 0x0520, // L id, serialised character data
GAMSG_REDIRECT = 0x0530, // L id
AGMSG_REDIRECT_RESPONSE = 0x0531, // L id, B*32 token, S game address, W game port
GAMSG_PLAYER_RECONNECT = 0x0532, // L id, B*32 token
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index de1ec618..fa097921 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -60,6 +60,7 @@ bool AccountConnection::start()
void AccountConnection::sendCharacterData(Character *p)
{
MessageOut msg(GAMSG_PLAYER_DATA);
+ msg.writeLong(p->getDatabaseID());
serializeCharacterData(*p, msg);
send(msg);
}
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index b9613c1f..4d04c227 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -32,13 +32,15 @@ Character::Character(MessageIn & msg):
Being(OBJECT_CHARACTER, 65535),
mClient(NULL),
mAttributesChanged(true),
- mDatabaseID(-1), mName(""), mGender(0), mHairStyle(0), mHairColor(0),
+ mDatabaseID(-1), mName(), mGender(0), mHairStyle(0), mHairColor(0),
mLevel(0), mMoney(0)
{
// prepare attributes vector
mAttributes.resize(NB_ATTRIBUTES_CHAR, 1);
mOldAttributes.resize(NB_ATTRIBUTES_CHAR, 0);
- // get base attributes
+ // get character data
+ mDatabaseID = msg.readLong();
+ mName = msg.readString();
deserializeCharacterData(*this, msg);
// give the player 10 weapon skill for testing purpose
setAttribute(CHAR_SKILL_WEAPON_UNARMED, 10);
diff --git a/src/serialize/characterdata.hpp b/src/serialize/characterdata.hpp
index 2f24b579..a946a3aa 100644
--- a/src/serialize/characterdata.hpp
+++ b/src/serialize/characterdata.hpp
@@ -32,8 +32,6 @@
template< class T >
void serializeCharacterData(T const &data, MessageOut &msg)
{
- msg.writeLong(data.getDatabaseID());
- msg.writeString(data.getName());
msg.writeByte(data.getGender());
msg.writeByte(data.getHairStyle());
msg.writeByte(data.getHairColor());
@@ -66,8 +64,6 @@ void serializeCharacterData(T const &data, MessageOut &msg)
template< class T >
void deserializeCharacterData(T &data, MessageIn &msg)
{
- data.setDatabaseID(msg.readLong());
- data.setName(msg.readString());
data.setGender(msg.readByte());
data.setHairStyle(msg.readByte());
data.setHairColor(msg.readByte());