Skip to content

Instantly share code, notes, and snippets.

@irancore
Created November 19, 2013 09:27
Show Gist options
  • Save irancore/7542658 to your computer and use it in GitHub Desktop.
Save irancore/7542658 to your computer and use it in GitHub Desktop.
Save Per Sec For Player (TrinityCore)
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index b1ee724..91239b3 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -688,7 +688,7 @@ Player::Player(WorldSession* session): Unit(true)
m_areaUpdateId = 0;
- m_nextSave = sWorld->getIntConfig(CONFIG_INTERVAL_SAVE);
+ m_nextSave = sWorld->GetSaveInterval();
clearResurrectRequestData();
@@ -18907,7 +18907,7 @@ bool Player::_LoadHomeBind(PreparedQueryResult result)
void Player::SaveToDB(bool create /*=false*/)
{
// delay auto save at any saves (manual, in code, or autosave)
- m_nextSave = sWorld->getIntConfig(CONFIG_INTERVAL_SAVE);
+ m_nextSave = sWorld->GetSaveInterval();
//lets allow only players in world to be saved
if (IsBeingTeleportedFar())
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index cf6ad3f..08656e8 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -587,6 +587,7 @@ void World::LoadConfigSettings(bool reload)
m_int_configs[CONFIG_PRESERVE_CUSTOM_CHANNEL_DURATION] = sConfigMgr->GetIntDefault("PreserveCustomChannelDuration", 14);
m_bool_configs[CONFIG_GRID_UNLOAD] = sConfigMgr->GetBoolDefault("GridUnload", true);
m_int_configs[CONFIG_INTERVAL_SAVE] = sConfigMgr->GetIntDefault("PlayerSaveInterval", 15 * MINUTE * IN_MILLISECONDS);
+ m_int_configs[CONFIG_UINT32_INTERVAL_SAVEPERSEC] = sCOnfigMgr->GetIntDefault("PlayerSave.PerSecond", 2);
m_int_configs[CONFIG_INTERVAL_DISCONNECT_TOLERANCE] = sConfigMgr->GetIntDefault("DisconnectToleranceInterval", 0);
m_bool_configs[CONFIG_STATS_SAVE_ONLY_ON_LOGOUT] = sConfigMgr->GetBoolDefault("PlayerSave.Stats.SaveOnlyOnLogout", true);
@@ -3195,3 +3196,11 @@ void World::ReloadRBAC()
if (WorldSession* session = itr->second)
session->InvalidateRBACData();
}
+
+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/server/game/World/World.h b/src/server/game/World/World.h
index 9074914..e96fde6 100644
--- a/src/server/game/World/World.h
+++ b/src/server/game/World/World.h
@@ -187,6 +187,7 @@ enum WorldIntConfigs
{
CONFIG_COMPRESSION = 0,
CONFIG_INTERVAL_SAVE,
+ CONFIG_UINT32_INTERVAL_SAVEPERSEC,
CONFIG_INTERVAL_GRIDCLEAN,
CONFIG_INTERVAL_MAPUPDATE,
CONFIG_INTERVAL_CHANGEWEATHER,
@@ -561,6 +562,9 @@ class World
void SetPlayerAmountLimit(uint32 limit) { m_playerLimit = limit; }
uint32 GetPlayerAmountLimit() const { return m_playerLimit; }
+ //SAVE PER SEC
+ uint32 GetSaveInterval();
+
//player Queue
typedef std::list<WorldSession*> Queue;
void AddQueuedPlayer(WorldSession*);
diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp
index 9c29e31..caf5b22 100644
--- a/src/server/scripts/Commands/cs_misc.cpp
+++ b/src/server/scripts/Commands/cs_misc.cpp
@@ -893,7 +893,7 @@ public:
}
// save if the player has last been saved over 20 seconds ago
- uint32 saveInterval = sWorld->getIntConfig(CONFIG_INTERVAL_SAVE);
+ uint32 save_interval = sWorld->GetSaveInterval();
if (saveInterval == 0 || (saveInterval > 20 * IN_MILLISECONDS && player->GetSaveTimer() <= saveInterval - 20 * IN_MILLISECONDS))
player->SaveToDB();
diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist
index dbf2a80..2fe9d3d 100644
--- a/src/server/worldserver/worldserver.conf.dist
+++ b/src/server/worldserver/worldserver.conf.dist
@@ -265,6 +265,13 @@ PlayerSaveInterval = 900000
PlayerSave.Stats.MinLevel = 0
+# PlayerSave.PerSecond
+# Player saves per second (only applied if PlayerSave.Interval = 0)
+# Default: 2 (0.5s between saves)
+#
+
+PlayerSave.PerSecond = 2
+
#
# PlayerSave.Stats.SaveOnlyOnLogout
# Description: Save player stats only on logout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment