aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/BattleGroundMgr.cpp13
-rw-r--r--src/game/BattleGroundMgr.h1
-rw-r--r--src/game/World.cpp49
-rw-r--r--src/game/World.h25
4 files changed, 62 insertions, 26 deletions
diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp
index 93b6d0288f8..81ef8846075 100644
--- a/src/game/BattleGroundMgr.cpp
+++ b/src/game/BattleGroundMgr.cpp
@@ -1240,7 +1240,7 @@ void BattleGroundMgr::Update(uint32 diff)
{
DistributeArenaPoints();
m_NextAutoDistributionTime = time(NULL) + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS);
- CharacterDatabase.PExecute("UPDATE saved_variables SET NextArenaPointDistributionTime = '"UI64FMTD"'", m_NextAutoDistributionTime);
+ sWorld.setWorldState(WS_ARENA_DISTRIBUTION_TIME, uint64(m_NextAutoDistributionTime));
}
m_AutoDistributionTimeChecker = 600000; // check 10 minutes
}
@@ -1780,15 +1780,16 @@ void BattleGroundMgr::InitAutomaticArenaPointDistribution()
if (sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_POINTS))
{
sLog.outDebug("Initializing Automatic Arena Point Distribution");
- QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT NextArenaPointDistributionTime FROM saved_variables");
- if (!result)
+ uint64 wstime = sWorld.getWorldState(WS_ARENA_DISTRIBUTION_TIME);
+
+ if (!wstime)
{
- sLog.outDebug("Battleground: Next arena point distribution time not found in SavedVariables, reseting it now.");
+ sLog.outDebug("Battleground: Next arena point distribution time not found, reseting it now.");
m_NextAutoDistributionTime = time(NULL) + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS);
- CharacterDatabase.PExecute("INSERT INTO saved_variables (NextArenaPointDistributionTime) VALUES ('"UI64FMTD"')", m_NextAutoDistributionTime);
+ sWorld.setWorldState(WS_ARENA_DISTRIBUTION_TIME, uint64(m_NextAutoDistributionTime));
}
else
- m_NextAutoDistributionTime = time_t((*result)[0].GetUInt64());
+ m_NextAutoDistributionTime = time_t(wstime);
sLog.outDebug("Automatic Arena Point Distribution initialized.");
}
}
diff --git a/src/game/BattleGroundMgr.h b/src/game/BattleGroundMgr.h
index 0f5dc3c9255..548e4f34fc6 100644
--- a/src/game/BattleGroundMgr.h
+++ b/src/game/BattleGroundMgr.h
@@ -36,6 +36,7 @@ typedef UNORDERED_MAP<uint32, BattleGroundTypeId> BattleMastersMap;
#define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // seconds in a day
#define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME 10
+#define WS_ARENA_DISTRIBUTION_TIME 20001 // Custom worldstate
struct GroupQueueInfo; // type predefinition
struct PlayerQueueInfo // stores information for players in queue
diff --git a/src/game/World.cpp b/src/game/World.cpp
index f20b3d61dc3..6ab59cd9fb5 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -1650,6 +1650,9 @@ void World::SetInitialWorldSettings()
uint32 nextGameEvent = gameeventmgr.Initialize();
m_timers[WUPDATE_EVENTS].SetInterval(nextGameEvent); //depend on next event
+ sLog.outString("Loading World States..."); // must be loaded before battleground and outdoor PvP
+ LoadWorldStates();
+
///- Initialize Battlegrounds
sLog.outString("Starting BattleGround System");
sBattleGroundMgr.CreateInitialBattleGrounds();
@@ -2588,3 +2591,49 @@ void World::UpdateAreaDependentAuras()
itr->second->GetPlayer()->UpdateZoneDependentAuras(itr->second->GetPlayer()->GetZoneId());
}
}
+
+void World::LoadWorldStates()
+{
+ QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT entry, value FROM worldstates");
+
+ if (!result)
+ {
+ barGoLink bar(1);
+ bar.step();
+ sLog.outString();
+ sLog.outString(">> Loaded 0 world states.");
+ return;
+ }
+
+ barGoLink bar(result->GetRowCount());
+ uint32 counter = 0;
+
+ do
+ {
+ Field *fields = result->Fetch();
+ m_worldstates[fields[0].GetUInt32()] = fields[1].GetUInt64();
+ bar.step();
+ ++counter;
+ }
+ while (result->NextRow());
+
+ sLog.outString();
+ sLog.outString( ">> Loaded %u world states.", counter);
+}
+
+// Setting a worldstate will save it to DB
+void World::setWorldState(uint32 index, uint64 value)
+{
+ WorldStatesMap::const_iterator it = m_worldstates.find(index);
+ if (it != m_worldstates.end())
+ CharacterDatabase.PExecute("UPDATE worldstates SET value="UI64FMTD" where entry=%u", value, index);
+ else
+ CharacterDatabase.PExecute("INSERT INTO worldstates (entry, value) VALUES (%u,"UI64FMTD")", index, value);
+ m_worldstates[index] = value;
+}
+
+uint64 World::getWorldState(uint32 index) const
+{
+ WorldStatesMap::const_iterator it = m_worldstates.find(index);
+ return it != m_worldstates.end() ? it->second : 0;
+}
diff --git a/src/game/World.h b/src/game/World.h
index cc4e02f9642..5210dbf40cf 100644
--- a/src/game/World.h
+++ b/src/game/World.h
@@ -87,13 +87,6 @@ enum WorldTimers
WUPDATE_COUNT = 10
};
-// States than may change after server started
-enum WorldStates
-{
- WORLDSTATE_WINTERGRASP_CONTROLING_FACTION,
- WORLDSTATE_VALUE_COUNT
-};
-
/// Configuration elements
enum WorldConfigs
{
@@ -581,18 +574,9 @@ class World
return index < CONFIG_VALUE_COUNT ? m_configs[index] : 0;
}
- // Set a server state - Those general values that can change after server have been setup
- void setState(uint32 index, uint32 value)
- {
- if (index < WORLDSTATE_VALUE_COUNT)
- m_states[index] = value;
- }
-
- // Get a server state element
- uint32 getState(uint32 index) const
- {
- return index < WORLDSTATE_VALUE_COUNT ? m_states[index] : 0;
- }
+ void setWorldState(uint32 index, uint64 value);
+ uint64 getWorldState(uint32 index) const;
+ void LoadWorldStates();
/// Are we on a "Player versus Player" server?
bool IsPvPRealm() { return (getConfig(CONFIG_GAME_TYPE) == REALM_TYPE_PVP || getConfig(CONFIG_GAME_TYPE) == REALM_TYPE_RPPVP || getConfig(CONFIG_GAME_TYPE) == REALM_TYPE_FFA_PVP); }
@@ -696,7 +680,8 @@ class World
float rate_values[MAX_RATES];
uint32 m_configs[CONFIG_VALUE_COUNT];
- uint32 m_states[WORLDSTATE_VALUE_COUNT];
+ typedef std::map<uint32,uint64> WorldStatesMap;
+ WorldStatesMap m_worldstates;
int32 m_playerLimit;
AccountTypes m_allowedSecurityLevel;
LocaleConstant m_defaultDbcLocale; // from config for one from loaded DBC locales