summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/account-server/serverhandler.cpp10
-rw-r--r--src/common/manaserv_protocol.h3
-rw-r--r--src/game-server/accountconnection.cpp22
-rw-r--r--src/game-server/accountconnection.h27
4 files changed, 27 insertions, 35 deletions
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index f228e043..1d2f9e0d 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -603,9 +603,9 @@ void GameServerHandler::syncDatabase(MessageIn &msg)
// It is safe to perform the following updates in a transaction
dal::PerformTransaction transaction(storage->database());
- int msgType = msg.readInt8();
- while (msgType != SYNC_END_OF_BUFFER && msg.getUnreadLength() > 0)
+ while (msg.getUnreadLength() > 0)
{
+ int msgType = msg.readInt8();
switch (msgType)
{
case SYNC_CHARACTER_POINTS:
@@ -640,14 +640,10 @@ void GameServerHandler::syncDatabase(MessageIn &msg)
{
LOG_DEBUG("received SYNC_ONLINE_STATUS");
int charId = msg.readInt32();
- bool online;
- msg.readInt8() == 0x00 ? online = false : online = true;
+ bool online = (msg.readInt8() == 1);
storage->setOnlineStatus(charId, online);
}
}
-
- // read next message type from buffer
- msgType = msg.readInt8();
}
transaction.commit();
diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h
index 337f2e27..8ff449e3 100644
--- a/src/common/manaserv_protocol.h
+++ b/src/common/manaserv_protocol.h
@@ -291,8 +291,7 @@ enum {
SYNC_CHARACTER_POINTS = 0x01, // D charId, D charPoints, D corrPoints
SYNC_CHARACTER_ATTRIBUTE = 0x02, // D charId, D attrId, DF base, DF mod
SYNC_CHARACTER_SKILL = 0x03, // D charId, B skillId, D skill value
- SYNC_ONLINE_STATUS = 0x04, // D charId, B 0x00 = offline, 0x01 = online
- SYNC_END_OF_BUFFER = 0xFF // shows, that the buffer ends here.
+ SYNC_ONLINE_STATUS = 0x04 // D charId, B 0 = offline, 1 = online
};
// Login specific return values
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)
*/