From 4abae69f1180ffe6a4dbd2db60dfa76b6ef41ebb Mon Sep 17 00:00:00 2001 From: Andreas Habel Date: Sun, 30 Nov 2008 12:08:57 +0100 Subject: 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... --- src/account-server/serverhandler.cpp | 41 +++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/account-server/serverhandler.cpp') diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index bdbdb1f6..1c4a5219 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -31,7 +31,6 @@ #include "account-server/dalstorage.hpp" #include "chat-server/post.hpp" #include "net/connectionhandler.hpp" -#include "net/messagein.hpp" #include "net/messageout.hpp" #include "net/netcomputer.hpp" #include "serialize/characterdata.hpp" @@ -241,6 +240,12 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) } } break; + case GAMSG_PLAYER_SYNC: + { + LOG_DEBUG("GAMSG_PLAYER_SYNC"); + GameServerHandler::syncDatabase(msg); + } break; + case GAMSG_REDIRECT: { LOG_DEBUG("GAMSG_REDIRECT"); @@ -511,3 +516,37 @@ void GameServerHandler::sendPartyChange(Character *ptr, int partyId) s->send(msg); } } + +void GameServerHandler::syncDatabase(MessageIn &msg) +{ + int msgType = msg.readByte(); + while( msgType != SYNC_END_OF_BUFFER ) + { + switch (msgType) + { + case SYNC_CHARACTER_POINTS: + { + LOG_DEBUG("received SYNC_CHARACTER_POINTS"); + int CharId = msg.readLong(); + int CharPoints = msg.readLong(); + int CorrPoints = msg.readLong(); + int AttribId = msg.readByte(); + int AttribValue = msg.readLong(); + storage->updateCharacterPoints(CharId, CharPoints, CorrPoints, + AttribId, AttribValue); + } break; + + case SYNC_CHARACTER_SKILL: + { + LOG_DEBUG("received SYNC_CHARACTER_SKILL"); + int CharId = msg.readLong(); + int SkillId = msg.readByte(); + int SkillValue = msg.readLong(); + storage->updateExperience(CharId, SkillId, SkillValue); + } break; + } + + // read next message type from buffer + msgType = msg.readByte(); + } +} -- cgit v1.2.3-70-g09d2