Created
November 19, 2013 09:27
-
-
Save irancore/7542652 to your computer and use it in GitHub Desktop.
Save Per Sec For Player (OregonCore)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 8092be0f53223c5931530550f9deda5007b43737 Mon Sep 17 00:00:00 2001 | |
From: Vstar <[email protected]> | |
Date: Sun, 10 Nov 2013 14:32:49 +0800 | |
Subject: [PATCH] Real time save | |
--- | |
src/game/Level0.cpp | 2 +- | |
src/game/Player.cpp | 6 +++--- | |
src/game/World.cpp | 9 +++++++++ | |
src/game/World.h | 4 ++++ | |
src/worldserver/worldserver.conf.dist.in | 5 +++++ | |
5 files changed, 22 insertions(+), 4 deletions(-) | |
diff --git a/src/game/Level0.cpp b/src/game/Level0.cpp | |
index 7ba7a6b..3e2a4d9 100644 | |
--- a/src/game/Level0.cpp | |
+++ b/src/game/Level0.cpp | |
@@ -156,7 +156,7 @@ bool ChatHandler::HandleSaveCommand(char* /*args*/) | |
} | |
// save or plan save after 20 sec (logout delay) if current next save time more this value and _not_ output any messages to prevent cheat planning | |
- uint32 save_interval = sWorld.getConfig(CONFIG_UINT32_INTERVAL_SAVE); | |
+ uint32 save_interval = sWorld.GetSaveInterval(); | |
if (save_interval == 0 || (save_interval > 20 * IN_MILLISECONDS && player->GetSaveTimer() <= save_interval - 20 * IN_MILLISECONDS)) | |
player->SaveToDB(); | |
diff --git a/src/game/Player.cpp b/src/game/Player.cpp | |
index 98b3657..7219869 100644 | |
--- a/src/game/Player.cpp | |
+++ b/src/game/Player.cpp | |
@@ -415,9 +415,9 @@ Player::Player(WorldSession* session): Unit(), m_mover(this), m_camera(this), m_ | |
m_areaUpdateId = 0; | |
- m_nextSave = sWorld.getConfig(CONFIG_UINT32_INTERVAL_SAVE); | |
+ m_nextSave = sWorld.GetSaveInterval(); | |
- // randomize first save time in range [CONFIG_UINT32_INTERVAL_SAVE] around [CONFIG_UINT32_INTERVAL_SAVE] | |
+ // randomize first save time in range saveinterval around saveinterval (sWorld.GetSaveInterval()) | |
// this must help in case next save after mass player load after server startup | |
m_nextSave = urand(m_nextSave / 2, m_nextSave * 3 / 2); | |
@@ -16141,7 +16141,7 @@ void Player::SaveToDB() | |
{ | |
// we should assure this: ASSERT((m_nextSave != sWorld.getConfig(CONFIG_UINT32_INTERVAL_SAVE))); | |
// delay auto save at any saves (manual, in code, or autosave) | |
- m_nextSave = sWorld.getConfig(CONFIG_UINT32_INTERVAL_SAVE); | |
+ m_nextSave = sWorld.GetSaveInterval(); | |
// lets allow only players in world to be saved | |
if (IsBeingTeleportedFar()) | |
diff --git a/src/game/World.cpp b/src/game/World.cpp | |
index f3485bf..e647728 100644 | |
--- a/src/game/World.cpp | |
+++ b/src/game/World.cpp | |
@@ -517,6 +517,7 @@ void World::LoadConfigSettings(bool reload) | |
setConfig(CONFIG_BOOL_CLEAN_CHARACTER_DB, "CleanCharacterDB", true); | |
setConfig(CONFIG_BOOL_GRID_UNLOAD, "GridUnload", true); | |
setConfig(CONFIG_UINT32_INTERVAL_SAVE, "PlayerSave.Interval", 15 * MINUTE * IN_MILLISECONDS); | |
+ setConfig(CONFIG_UINT32_INTERVAL_SAVEPERSEC, "PlayerSave.PerSecond", 2); | |
setConfigMinMax(CONFIG_UINT32_MIN_LEVEL_STAT_SAVE, "PlayerSave.Stats.MinLevel", 0, 0, MAX_LEVEL); | |
setConfig(CONFIG_BOOL_STATS_SAVE_ONLY_ON_LOGOUT, "PlayerSave.Stats.SaveOnlyOnLogout", true); | |
@@ -2197,3 +2198,11 @@ bool World::configNoReload(bool reload, eConfigBoolValues index, char const* fie | |
return false; | |
} | |
+ | |
+uint32 World::GetSaveInterval() | |
+{ | |
+ if (sWorld.getConfig(CONFIG_UINT32_INTERVAL_SAVE)) | |
+ return sWorld.getConfig(CONFIG_UINT32_INTERVAL_SAVE); | |
+ | |
+ return ceil(float((1.f/sWorld.getConfig(CONFIG_UINT32_INTERVAL_SAVEPERSEC))*sWorld.GetActiveSessionCount()*IN_MILLISECONDS)+1*IN_MILLISECONDS); | |
+} | |
\ No newline at end of file | |
diff --git a/src/game/World.h b/src/game/World.h | |
index 3210e78..8e7540a 100644 | |
--- a/src/game/World.h | |
+++ b/src/game/World.h | |
@@ -82,6 +82,7 @@ enum eConfigUInt32Values | |
{ | |
CONFIG_UINT32_COMPRESSION = 0, | |
CONFIG_UINT32_INTERVAL_SAVE, | |
+ CONFIG_UINT32_INTERVAL_SAVEPERSEC, | |
CONFIG_UINT32_INTERVAL_GRIDCLEAN, | |
CONFIG_UINT32_INTERVAL_MAPUPDATE, | |
CONFIG_UINT32_INTERVAL_CHANGEWEATHER, | |
@@ -459,6 +460,9 @@ class World | |
/// Set the active session server limit (or security level limitation) | |
void SetPlayerLimit(int32 limit, bool needUpdate = false); | |
+ //SAVE PER SEC | |
+ uint32 GetSaveInterval(); | |
+ | |
// player Queue | |
typedef std::list<WorldSession*> Queue; | |
void AddQueuedSession(WorldSession*); | |
diff --git a/src/worldserver/worldserver.conf.dist.in b/src/worldserver/worldserver.conf.dist.in | |
index c0c1224..7a35f4d 100644 | |
--- a/src/worldserver/worldserver.conf.dist.in | |
+++ b/src/worldserver/worldserver.conf.dist.in | |
@@ -128,6 +128,10 @@ BindIP = "0.0.0.0" | |
# Player save interval (in milliseconds) | |
# Default: 900000 (15 min) | |
# | |
+# PlayerSave.PerSecond | |
+# Player saves per second (only applied if PlayerSave.Interval = 0) | |
+# Default: 2 (0.5s between saves) | |
+# | |
# PlayerSave.Stats.MinLevel | |
# Minimum level for saving character stats for external usage in database | |
# Default: 0 (do not save character stats) | |
@@ -210,6 +214,7 @@ GridCleanUpDelay = 300000 | |
MapUpdateInterval = 100 | |
ChangeWeatherInterval = 600000 | |
PlayerSave.Interval = 900000 | |
+PlayerSave.PerSecond = 2 | |
PlayerSave.Stats.MinLevel = 0 | |
PlayerSave.Stats.SaveOnlyOnLogout = 1 | |
vmap.enableLOS = 1 | |
-- | |
1.8.3.msysgit.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment