diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2011-03-27 19:44:53 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2011-04-02 20:19:37 +0200 |
commit | c013d7ba8cb97262d318fe30e1ef4da1aea19b82 (patch) | |
tree | 88e2577d32c8ce3777a6da302a931ccfcf07f25a /src/game-server | |
parent | b8c8c307b5de2881fb3a2fa4f0cb8848bc5df23c (diff) | |
download | manaserv-c013d7ba8cb97262d318fe30e1ef4da1aea19b82.tar.gz manaserv-c013d7ba8cb97262d318fe30e1ef4da1aea19b82.tar.bz2 manaserv-c013d7ba8cb97262d318fe30e1ef4da1aea19b82.tar.xz manaserv-c013d7ba8cb97262d318fe30e1ef4da1aea19b82.zip |
Some cleanups related to syncing from game to account server
* Remove SYNC_END_OF_BUFFER since the end of a message can already be
identified by no more data being available.
* Consistently prefix ++ rather than postfix ++ when incrementing
mSyncMessages.
* Made SYNC_BUFFER_SIZE into constants rather than defines, and moved
them into the .cpp file since they're not used anywhere else.
* Just use 1 and 0 to indicate online status. No point in writing it
like 0x01 and 0x00.
* Merged some duplicated documentation for
AccountConnection::syncChanges.
Reviewed-by: Jared Adams
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/accountconnection.cpp | 22 | ||||
-rw-r--r-- | src/game-server/accountconnection.h | 27 |
2 files changed, 23 insertions, 26 deletions
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index c404e421..5f0e55ae 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -36,8 +36,12 @@ #include "utils/tokendispenser.h" #include "utils/tokencollector.h" +const int SYNC_BUFFER_SIZE = 1024; /**< maximum size of sync buffer in bytes. */ +const int SYNC_BUFFER_LIMIT = 20; /**< maximum number of messages in sync buffer. */ + AccountConnection::AccountConnection(): - mSyncBuffer(0) + mSyncBuffer(0), + mSyncMessages(0) { } @@ -89,8 +93,8 @@ bool AccountConnection::start(int gameServerPort) send(msg); // initialize sync buffer - mSyncBuffer = new MessageOut(GAMSG_PLAYER_SYNC); - mSyncMessages = 0; + if (!mSyncBuffer) + mSyncBuffer = new MessageOut(GAMSG_PLAYER_SYNC); return true; } @@ -396,10 +400,8 @@ void AccountConnection::syncChanges(bool force) LOG_DEBUG("Sending GAMSG_PLAYER_SYNC with " << mSyncMessages << " messages." ); - // attach end-of-buffer flag - mSyncBuffer->writeInt8(SYNC_END_OF_BUFFER); send(*mSyncBuffer); - delete (mSyncBuffer); + delete mSyncBuffer; mSyncBuffer = new MessageOut(GAMSG_PLAYER_SYNC); mSyncMessages = 0; @@ -413,7 +415,7 @@ void AccountConnection::syncChanges(bool force) void AccountConnection::updateCharacterPoints(int charId, int charPoints, int corrPoints) { - mSyncMessages++; + ++mSyncMessages; mSyncBuffer->writeInt8(SYNC_CHARACTER_POINTS); mSyncBuffer->writeInt32(charId); mSyncBuffer->writeInt32(charPoints); @@ -436,7 +438,7 @@ void AccountConnection::updateAttributes(int charId, int attrId, double base, void AccountConnection::updateExperience(int charId, int skillId, int skillValue) { - mSyncMessages++; + ++mSyncMessages; mSyncBuffer->writeInt8(SYNC_CHARACTER_SKILL); mSyncBuffer->writeInt32(charId); mSyncBuffer->writeInt8(skillId); @@ -446,10 +448,10 @@ void AccountConnection::updateExperience(int charId, int skillId, void AccountConnection::updateOnlineStatus(int charId, bool online) { - mSyncMessages++; + ++mSyncMessages; mSyncBuffer->writeInt8(SYNC_ONLINE_STATUS); mSyncBuffer->writeInt32(charId); - mSyncBuffer->writeInt8(online ? 0x01 : 0x00); + mSyncBuffer->writeInt8(online ? 1 : 0); syncChanges(); } diff --git a/src/game-server/accountconnection.h b/src/game-server/accountconnection.h index 02903dc7..4e763158 100644 --- a/src/game-server/accountconnection.h +++ b/src/game-server/accountconnection.h @@ -27,22 +27,6 @@ class Character; class MapComposite; -/** \fn void AccountConnection::syncChanges(bool force = false) - * - * The gameserver holds a buffer with all changes made by a character. The - * changes are added at the time they occur. When the buffer reaches one of - * the following limits, the buffer is sent to the account server and applied - * to the database. - * - * The sync buffer is sent when: - * - forced by any process (param force = true) - * - every 10 seconds - * - buffer reaches size of 1kb (defined in #SYNC_BUFFER_SIZE) - * - buffer holds more then 20 messages (defined in #SYNC_BUFFER_LIMIT) - */ -#define SYNC_BUFFER_SIZE 1024 /**< maximum size of sync buffer in bytes. */ -#define SYNC_BUFFER_LIMIT 20 /**< maximum number of messages in sync buffer. */ - /** * A connection to the account server. */ @@ -120,6 +104,17 @@ class AccountConnection : public Connection * Sends all changed player data to the account server to minimize * dataloss due to failure of one server component. * + * The gameserver holds a buffer with all changes made by a character. + * The changes are added at the time they occur. When the buffer + * reaches one of the following limits, the buffer is sent to the + * account server and applied to the database. + * + * The sync buffer is sent when: + * - forced by any process (param force = true) + * - every 10 seconds + * - buffer reaches size of 1kb (SYNC_BUFFER_SIZE) + * - buffer holds more then 20 messages (SYNC_BUFFER_LIMIT) + * * @param force Send changes even if buffer hasn't reached its size * or message limit. (used to send in timed schedules) */ |