diff options
author | Andreas Habel <mail@exceptionfault.de> | 2008-11-30 12:08:57 +0100 |
---|---|---|
committer | Andreas Habel <mail@exceptionfault.de> | 2008-11-30 12:08:57 +0100 |
commit | 4abae69f1180ffe6a4dbd2db60dfa76b6ef41ebb (patch) | |
tree | 4b2e3eb8e5c35e65ec18996060a5daac9bff1938 /src/game-server/accountconnection.cpp | |
parent | 6d263b7550468306018934ad1dc9928b57b8f129 (diff) | |
download | manaserv-4abae69f1180ffe6a4dbd2db60dfa76b6ef41ebb.tar.gz manaserv-4abae69f1180ffe6a4dbd2db60dfa76b6ef41ebb.tar.bz2 manaserv-4abae69f1180ffe6a4dbd2db60dfa76b6ef41ebb.tar.xz manaserv-4abae69f1180ffe6a4dbd2db60dfa76b6ef41ebb.zip |
Add sync Buffer according to mantis #550
The game server buffers all changes made to a character in a sync buffer.
The buffer is sent to the account server if the buffer contains more then
20 message, reaches size of 1kb or at least every 10 seconds.
ATM Character attributes, corr points and attribute points and skills are
synchronized. TODO: items, location, money...
Diffstat (limited to 'src/game-server/accountconnection.cpp')
-rw-r--r-- | src/game-server/accountconnection.cpp | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index 43c4f20d..bbdcdd13 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -33,12 +33,19 @@ #include "game-server/quest.hpp" #include "game-server/state.hpp" #include "net/messagein.hpp" -#include "net/messageout.hpp" #include "serialize/characterdata.hpp" #include "utils/logger.h" #include "utils/tokendispenser.hpp" #include "utils/tokencollector.hpp" +AccountConnection::~AccountConnection() +{ + if (mSyncBuffer) + { + delete (mSyncBuffer); + } +} + bool AccountConnection::start() { const std::string accountServerAddress = @@ -72,6 +79,10 @@ bool AccountConnection::start() } send(msg); + // initialize sync buffer + mSyncBuffer = new MessageOut(GAMSG_PLAYER_SYNC); + mSyncMessages = 0; + return true; } @@ -297,3 +308,57 @@ void AccountConnection::changeAccountLevel(Character *c, int level) msg.writeShort(level); send(msg); } + +void AccountConnection::syncChanges(bool force) +{ + if (mSyncMessages == 0) + return; + + // send buffer if: + // a.) forced by any process + // b.) every 10 seconds + // c.) buffer reaches size of 1kb + // d.) buffer holds more then 20 messages + if (force || + mSyncMessages > SYNC_BUFFER_LIMIT || + mSyncBuffer->getLength() > SYNC_BUFFER_SIZE ) + { + LOG_DEBUG("Sending GAMSG_PLAYER_SYNC with " << mSyncMessages << " messages." ); + + // attach end-of-buffer flag + mSyncBuffer->writeByte(SYNC_END_OF_BUFFER); + send(*mSyncBuffer); + delete (mSyncBuffer); + + mSyncBuffer = new MessageOut(GAMSG_PLAYER_SYNC); + mSyncMessages = 0; + } + else + { + LOG_DEBUG("No changes to sync with account server."); + } +} + +void AccountConnection::updateCharacterPoints(const int CharId, const int CharPoints, + const int CorrPoints, const int AttribId, const int AttribValue ) +{ + mSyncMessages++; + mSyncBuffer->writeByte(SYNC_CHARACTER_POINTS); + mSyncBuffer->writeLong(CharId); + mSyncBuffer->writeLong(CharPoints); + mSyncBuffer->writeLong(CorrPoints); + mSyncBuffer->writeByte(AttribId); + mSyncBuffer->writeLong(AttribValue); + syncChanges(); +} + +void AccountConnection::updateExperience(const int CharId, const int SkillId, + const int SkillValue) +{ + mSyncMessages++; + mSyncBuffer->writeByte(SYNC_CHARACTER_SKILL); + mSyncBuffer->writeLong(CharId); + mSyncBuffer->writeByte(SkillId); + mSyncBuffer->writeLong(SkillValue); + syncChanges(); +} |