Big update.

This commit is contained in:
UltraNix
2022-03-12 22:28:00 +01:00
parent 6006eeeb01
commit 12d41d1314
2064 changed files with 427245 additions and 268481 deletions

View File

@@ -21,7 +21,6 @@
#include "Opcodes.h"
#include "Player.h"
#include "SpellAuraEffects.h"
#include "WorldSession.h"
uint32 AsyncAuctionListingMgr::auctionListingDiff = 0;
bool AsyncAuctionListingMgr::auctionListingAllowed = false;

View File

@@ -1,22 +0,0 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AvgDiffTracker.h"
AvgDiffTracker avgDiffTracker;
AvgDiffTracker lfgDiffTracker;
AvgDiffTracker devDiffTracker;

View File

@@ -1,91 +0,0 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __AVGDIFFTRACKER_H
#define __AVGDIFFTRACKER_H
#include "Common.h"
#include <cstring>
#define AVG_DIFF_COUNT 500
class AvgDiffTracker
{
public:
AvgDiffTracker() : total(0), index(0), average(0) { memset(&tab, 0, sizeof(tab)); max[0] = 0; max[1] = 0; }
uint32 getAverage()
{
return average;
}
uint32 getTimeWeightedAverage()
{
if (tab[AVG_DIFF_COUNT - 1] == 0)
return 0;
uint32 sum = 0, weightsum = 0;
for (uint32 i = 0; i < AVG_DIFF_COUNT; ++i)
{
sum += tab[i] * tab[i];
weightsum += tab[i];
}
return sum / weightsum;
}
uint32 getMax()
{
return max[0] > max[1] ? max[0] : max[1];
}
void Update(uint32 diff)
{
if (diff < 1)
diff = 1;
total -= tab[index];
total += diff;
tab[index] = diff;
if (diff > max[0])
max[0] = diff;
if (++index >= AVG_DIFF_COUNT)
{
index = 0;
max[1] = max[0];
max[0] = 0;
}
if (tab[AVG_DIFF_COUNT - 1])
average = total / AVG_DIFF_COUNT;
else if (index)
average = total / index;
else
average = 0;
}
private:
uint32 tab[AVG_DIFF_COUNT];
uint32 total;
uint32 index;
uint32 max[2];
uint32 average;
};
extern AvgDiffTracker avgDiffTracker;
extern AvgDiffTracker lfgDiffTracker;
extern AvgDiffTracker devDiffTracker;
#endif

View File

@@ -18,9 +18,9 @@
#include "BanMgr.h"
#include "AccountMgr.h"
#include "DatabaseEnv.h"
#include "GameTime.h"
#include "Language.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "World.h"
@@ -49,23 +49,23 @@ BanReturn BanMgr::BanAccount(std::string const& AccountName, std::string const&
// pussywizard: check existing ban to prevent overriding by a shorter one! >_>
LoginDatabasePreparedStatement* stmtAccountBanned = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED);
stmtAccountBanned->setUInt32(0, AccountID);
stmtAccountBanned->SetData(0, AccountID);
PreparedQueryResult banresult = LoginDatabase.Query(stmtAccountBanned);
if (banresult && ((*banresult)[0].GetUInt32() == (*banresult)[1].GetUInt32() || ((*banresult)[1].GetUInt32() > time(nullptr) + DurationSecs && DurationSecs)))
if (banresult && ((*banresult)[0].Get<uint32>() == (*banresult)[1].Get<uint32>() || ((*banresult)[1].Get<uint32>() > GameTime::GetGameTime().count() + DurationSecs && DurationSecs)))
return BAN_LONGER_EXISTS;
// make sure there is only one active ban
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_NOT_BANNED);
stmt->setUInt32(0, AccountID);
stmt->SetData(0, AccountID);
trans->Append(stmt);
// No SQL injection with prepared statements
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_BANNED);
stmt->setUInt32(0, AccountID);
stmt->setUInt32(1, DurationSecs);
stmt->setString(2, Author);
stmt->setString(3, Reason);
stmt->SetData(0, AccountID);
stmt->SetData(1, DurationSecs);
stmt->SetData(2, Author);
stmt->SetData(3, Reason);
trans->Append(stmt);
if (WorldSession* session = sWorld->FindSession(AccountID))
@@ -111,23 +111,23 @@ BanReturn BanMgr::BanAccountByPlayerName(std::string const& CharacterName, std::
// pussywizard: check existing ban to prevent overriding by a shorter one! >_>
LoginDatabasePreparedStatement* stmtAccountBanned = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED);
stmtAccountBanned->setUInt32(0, AccountID);
stmtAccountBanned->SetData(0, AccountID);
PreparedQueryResult banresult = LoginDatabase.Query(stmtAccountBanned);
if (banresult && ((*banresult)[0].GetUInt32() == (*banresult)[1].GetUInt32() || ((*banresult)[1].GetUInt32() > time(nullptr) + DurationSecs && DurationSecs)))
if (banresult && ((*banresult)[0].Get<uint32>() == (*banresult)[1].Get<uint32>() || ((*banresult)[1].Get<uint32>() > GameTime::GetGameTime().count() + DurationSecs && DurationSecs)))
return BAN_LONGER_EXISTS;
// make sure there is only one active ban
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_NOT_BANNED);
stmt->setUInt32(0, AccountID);
stmt->SetData(0, AccountID);
trans->Append(stmt);
// No SQL injection with prepared statements
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_BANNED);
stmt->setUInt32(0, AccountID);
stmt->setUInt32(1, DurationSecs);
stmt->setString(2, Author);
stmt->setString(3, Reason);
stmt->SetData(0, AccountID);
stmt->SetData(1, DurationSecs);
stmt->SetData(2, Author);
stmt->SetData(3, Reason);
trans->Append(stmt);
if (WorldSession* session = sWorld->FindSession(AccountID))
@@ -170,14 +170,14 @@ BanReturn BanMgr::BanIP(std::string const& IP, std::string const& Duration, std:
// No SQL injection with prepared statements
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BY_IP);
stmt->setString(0, IP);
stmt->SetData(0, IP);
PreparedQueryResult resultAccounts = LoginDatabase.Query(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_IP_BANNED);
stmt->setString(0, IP);
stmt->setUInt32(1, DurationSecs);
stmt->setString(2, Author);
stmt->setString(3, Reason);
stmt->SetData(0, IP);
stmt->SetData(1, DurationSecs);
stmt->SetData(2, Author);
stmt->SetData(3, Reason);
LoginDatabase.Execute(stmt);
if (sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
@@ -202,7 +202,7 @@ BanReturn BanMgr::BanIP(std::string const& IP, std::string const& Duration, std:
do
{
Field* fields = resultAccounts->Fetch();
uint32 AccountID = fields[0].GetUInt32();
uint32 AccountID = fields[0].Get<uint32>();
if (WorldSession* session = sWorld->FindSession(AccountID))
if (session->GetPlayerName() != Author)
@@ -237,14 +237,14 @@ BanReturn BanMgr::BanCharacter(std::string const& CharacterName, std::string con
// make sure there is only one active ban
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHARACTER_BAN);
stmt->setUInt32(0, TargetGUID.GetCounter());
stmt->SetData(0, TargetGUID.GetCounter());
CharacterDatabase.Execute(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHARACTER_BAN);
stmt->setUInt32(0, TargetGUID.GetCounter());
stmt->setUInt32(1, DurationSecs);
stmt->setString(2, Author);
stmt->setString(3, Reason);
stmt->SetData(0, TargetGUID.GetCounter());
stmt->SetData(1, DurationSecs);
stmt->SetData(2, Author);
stmt->SetData(3, Reason);
CharacterDatabase.Execute(stmt);
if (target)
@@ -275,7 +275,7 @@ bool BanMgr::RemoveBanAccount(std::string const& AccountName)
// NO SQL injection as account is uint32
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_NOT_BANNED);
stmt->setUInt32(0, AccountID);
stmt->SetData(0, AccountID);
LoginDatabase.Execute(stmt);
return true;
@@ -290,7 +290,7 @@ bool BanMgr::RemoveBanAccountByPlayerName(std::string const& CharacterName)
// NO SQL injection as account is uint32
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_NOT_BANNED);
stmt->setUInt32(0, AccountID);
stmt->SetData(0, AccountID);
LoginDatabase.Execute(stmt);
return true;
@@ -300,7 +300,7 @@ bool BanMgr::RemoveBanAccountByPlayerName(std::string const& CharacterName)
bool BanMgr::RemoveBanIP(std::string const& IP)
{
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_IP_NOT_BANNED);
stmt->setString(0, IP);
stmt->SetData(0, IP);
LoginDatabase.Execute(stmt);
return true;
@@ -322,7 +322,7 @@ bool BanMgr::RemoveBanCharacter(std::string const& CharacterName)
return false;
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHARACTER_BAN);
stmt->setUInt32(0, guid.GetCounter());
stmt->SetData(0, guid.GetCounter());
CharacterDatabase.Execute(stmt);
return true;
}

View File

@@ -46,19 +46,19 @@ void Graveyard::LoadGraveyardFromDB()
do
{
Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32();
uint32 ID = fields[0].Get<uint32>();
GraveyardStruct Graveyard;
Graveyard.Map = fields[1].GetUInt32();
Graveyard.x = fields[2].GetFloat();
Graveyard.y = fields[3].GetFloat();
Graveyard.z = fields[4].GetFloat();
Graveyard.name = fields[5].GetString();
Graveyard.Map = fields[1].Get<uint32>();
Graveyard.x = fields[2].Get<float>();
Graveyard.y = fields[3].Get<float>();
Graveyard.z = fields[4].Get<float>();
Graveyard.name = fields[5].Get<std::string>();
if (!Utf8toWStr(Graveyard.name, Graveyard.wnameLow))
{
LOG_ERROR("sql.sql", "Wrong UTF8 name for id %u in `game_graveyard` table, ignoring.", ID);
LOG_ERROR("sql.sql", "Wrong UTF8 name for id {} in `game_graveyard` table, ignoring.", ID);
continue;
}
@@ -69,7 +69,7 @@ void Graveyard::LoadGraveyardFromDB()
++Count;
} while (result->NextRow());
LOG_INFO("server.loading", ">> Loaded %i graveyard in %u ms", Count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", ">> Loaded {} graveyard in {} ms", Count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
@@ -111,11 +111,16 @@ GraveyardStruct const* Graveyard::GetClosestGraveyard(Player* player, TeamId tea
uint32 areaId = 0;
player->GetZoneAndAreaId(zoneId, areaId);
return GetClosestGraveyard(mapId, x, y, z, teamId, areaId, zoneId, player->getClass() == CLASS_DEATH_KNIGHT);
}
GraveyardStruct const* Graveyard::GetClosestGraveyard(uint32 mapId, float x, float y, float z, TeamId teamId, uint32 areaId, uint32 zoneId, bool isDeathKnight)
{
if (!zoneId && !areaId)
{
if (z > -500)
{
LOG_ERROR("sql.sql", "GetClosestGraveyard: unable to find zoneId and areaId for map %u coords (%f, %f, %f)", mapId, x, y, z);
LOG_ERROR("sql.sql", "GetClosestGraveyard: unable to find zoneId and areaId for map {} coords ({}, {}, {})", mapId, x, y, z);
return GetDefaultGraveyard(teamId);
}
}
@@ -152,7 +157,7 @@ GraveyardStruct const* Graveyard::GetClosestGraveyard(Player* player, TeamId tea
// not need to check validity of map object; MapId _MUST_ be valid here
if (range.first == range.second && !map->IsBattlegroundOrArena())
{
LOG_ERROR("sql.sql", "Table `graveyard_zone` incomplete: Zone %u Team %u does not have a linked graveyard.", zoneId, teamId);
LOG_ERROR("sql.sql", "Table `graveyard_zone` incomplete: Zone {} Team {} does not have a linked graveyard.", zoneId, teamId);
return GetDefaultGraveyard(teamId);
}
@@ -177,7 +182,7 @@ GraveyardStruct const* Graveyard::GetClosestGraveyard(Player* player, TeamId tea
GraveyardStruct const* entry = sGraveyard->GetGraveyard(graveyardLink.safeLocId);
if (!entry)
{
LOG_ERROR("sql.sql", "Table `graveyard_zone` has record for not existing `game_graveyard` table %u, skipped.", graveyardLink.safeLocId);
LOG_ERROR("sql.sql", "Table `graveyard_zone` has record for not existing `game_graveyard` table {}, skipped.", graveyardLink.safeLocId);
continue;
}
@@ -194,7 +199,7 @@ GraveyardStruct const* Graveyard::GetClosestGraveyard(Player* player, TeamId tea
GRAVEYARD_ARCHERUS = 1405
};
if (player->getClass() != CLASS_DEATH_KNIGHT && (graveyardLink.safeLocId == GRAVEYARD_EBON_HOLD || graveyardLink.safeLocId == GRAVEYARD_ARCHERUS))
if (!isDeathKnight && (graveyardLink.safeLocId == GRAVEYARD_EBON_HOLD || graveyardLink.safeLocId == GRAVEYARD_ARCHERUS))
{
continue;
}
@@ -291,10 +296,10 @@ bool Graveyard::AddGraveyardLink(uint32 id, uint32 zoneId, TeamId teamId, bool p
{
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_GRAVEYARD_ZONE);
stmt->setUInt32(0, id);
stmt->setUInt32(1, zoneId);
stmt->SetData(0, id);
stmt->SetData(1, zoneId);
// Xinef: DB Data compatibility...
stmt->setUInt16(2, uint16(teamId == TEAM_NEUTRAL ? 0 : (teamId == TEAM_ALLIANCE ? ALLIANCE : HORDE)));
stmt->SetData(2, uint16(teamId == TEAM_NEUTRAL ? 0 : (teamId == TEAM_ALLIANCE ? ALLIANCE : HORDE)));
WorldDatabase.Execute(stmt);
}
@@ -307,7 +312,7 @@ void Graveyard::RemoveGraveyardLink(uint32 id, uint32 zoneId, TeamId teamId, boo
GraveyardMapBoundsNonConst range = GraveyardStore.equal_range(zoneId);
if (range.first == range.second)
{
LOG_ERROR("sql.sql", "Table `graveyard_zone` incomplete: Zone %u Team %u does not have a linked graveyard.", zoneId, teamId);
LOG_ERROR("sql.sql", "Table `graveyard_zone` incomplete: Zone {} Team {} does not have a linked graveyard.", zoneId, teamId);
return;
}
@@ -342,10 +347,10 @@ void Graveyard::RemoveGraveyardLink(uint32 id, uint32 zoneId, TeamId teamId, boo
{
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_GRAVEYARD_ZONE);
stmt->setUInt32(0, id);
stmt->setUInt32(1, zoneId);
stmt->SetData(0, id);
stmt->SetData(1, zoneId);
// Xinef: DB Data compatibility...
stmt->setUInt16(2, uint16(teamId == TEAM_NEUTRAL ? 0 : (teamId == TEAM_ALLIANCE ? ALLIANCE : HORDE)));
stmt->SetData(2, uint16(teamId == TEAM_NEUTRAL ? 0 : (teamId == TEAM_ALLIANCE ? ALLIANCE : HORDE)));
WorldDatabase.Execute(stmt);
}
@@ -375,36 +380,36 @@ void Graveyard::LoadGraveyardZones()
Field* fields = result->Fetch();
uint32 safeLocId = fields[0].GetUInt32();
uint32 zoneId = fields[1].GetUInt32();
uint32 team = fields[2].GetUInt16();
uint32 safeLocId = fields[0].Get<uint32>();
uint32 zoneId = fields[1].Get<uint32>();
uint32 team = fields[2].Get<uint16>();
TeamId teamId = team == 0 ? TEAM_NEUTRAL : (team == ALLIANCE ? TEAM_ALLIANCE : TEAM_HORDE);
GraveyardStruct const* entry = sGraveyard->GetGraveyard(safeLocId);
if (!entry)
{
LOG_ERROR("sql.sql", "Table `graveyard_zone` has a record for not existing `game_graveyard` table %u, skipped.", safeLocId);
LOG_ERROR("sql.sql", "Table `graveyard_zone` has a record for not existing `game_graveyard` table {}, skipped.", safeLocId);
continue;
}
AreaTableEntry const* areaEntry = sAreaTableStore.LookupEntry(zoneId);
if (!areaEntry)
{
LOG_ERROR("sql.sql", "Table `graveyard_zone` has a record for not existing zone id (%u), skipped.", zoneId);
LOG_ERROR("sql.sql", "Table `graveyard_zone` has a record for not existing zone id ({}), skipped.", zoneId);
continue;
}
if (team != 0 && team != HORDE && team != ALLIANCE)
{
LOG_ERROR("sql.sql", "Table `graveyard_zone` has a record for non player faction (%u), skipped.", team);
LOG_ERROR("sql.sql", "Table `graveyard_zone` has a record for non player faction ({}), skipped.", team);
continue;
}
if (!AddGraveyardLink(safeLocId, zoneId, teamId, false))
LOG_ERROR("sql.sql", "Table `graveyard_zone` has a duplicate record for Graveyard (ID: %u) and Zone (ID: %u), skipped.", safeLocId, zoneId);
LOG_ERROR("sql.sql", "Table `graveyard_zone` has a duplicate record for Graveyard (ID: {}) and Zone (ID: {}), skipped.", safeLocId, zoneId);
} while (result->NextRow());
LOG_INFO("server.loading", ">> Loaded %u graveyard-zone links in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", ">> Loaded {} graveyard-zone links in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}

View File

@@ -58,6 +58,7 @@ public:
GraveyardStruct const* GetGraveyard(const std::string& name) const;
GraveyardStruct const* GetDefaultGraveyard(TeamId teamId);
GraveyardStruct const* GetClosestGraveyard(Player* player, TeamId teamId, bool nearCorpse = false);
GraveyardStruct const* GetClosestGraveyard(uint32 mapId, float x, float y, float z, TeamId teamId, uint32 areaId, uint32 zoneId, bool isDeathKnight);
GraveyardData const* FindGraveyardData(uint32 id, uint32 zone);
GraveyardContainer const& GetGraveyardData() const { return _graveyardStore; }
bool AddGraveyardLink(uint32 id, uint32 zoneId, TeamId teamId, bool persist = true);

View File

@@ -1,83 +0,0 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SavingSystem.h"
#include "World.h"
uint32 SavingSystemMgr::m_savingCurrentValue = 0;
uint32 SavingSystemMgr::m_savingMaxValueAssigned = 0;
uint32 SavingSystemMgr::m_savingDiffSum = 0;
std::list<uint32> SavingSystemMgr::m_savingSkipList;
std::mutex SavingSystemMgr::_savingLock;
void SavingSystemMgr::Update(uint32 diff)
{
if (GetSavingMaxValue() > GetSavingCurrentValue())
{
const uint32 step = 120;
float multiplicator;
uint32 playerCount = sWorld->GetPlayerCount();
if (!playerCount)
{
m_savingCurrentValue = 0;
m_savingMaxValueAssigned = 0;
m_savingDiffSum = 0;
m_savingSkipList.clear();
return;
}
if (GetSavingMaxValue() - GetSavingCurrentValue() > playerCount + m_savingSkipList.size()) // this should not happen, but just in case
m_savingMaxValueAssigned = m_savingCurrentValue + playerCount + m_savingSkipList.size();
if (playerCount <= 1500) // every 2min
multiplicator = 1000.0f / playerCount;
else if (playerCount <= 2500) // every 3min
multiplicator = 1500.0f / playerCount;
else if (playerCount <= 2750) // every 4min
multiplicator = 2000.0f / playerCount;
else if (playerCount <= 3000) // every 6min
multiplicator = 3000.0f / playerCount;
else if (playerCount <= 3250) // every 7min
multiplicator = 3500.0f / playerCount;
else // every 8min
multiplicator = 4000.0f / playerCount;
m_savingDiffSum += diff;
while (m_savingDiffSum >= (uint32)(step * multiplicator))
{
IncreaseSavingCurrentValue(1);
while (m_savingSkipList.size() && *(m_savingSkipList.begin()) <= GetSavingCurrentValue())
{
IncreaseSavingCurrentValue(1);
m_savingSkipList.pop_front();
}
m_savingDiffSum -= (uint32)(step * multiplicator);
if (GetSavingCurrentValue() > GetSavingMaxValue())
{
m_savingDiffSum = 0;
break;
}
if (m_savingDiffSum > 60000)
m_savingDiffSum = 60000;
}
}
}

View File

@@ -1,46 +0,0 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SAVINGSYSTEM_H
#define __SAVINGSYSTEM_H
#include "Common.h"
#include <list>
#include <mutex>
// to evenly distribute saving players to db
class SavingSystemMgr
{
public:
static void Update(uint32 diff);
static uint32 GetSavingCurrentValue() { return m_savingCurrentValue; } // modified only during single thread
static uint32 GetSavingMaxValue() { return m_savingMaxValueAssigned; } // modified only during single thread
static void IncreaseSavingCurrentValue(uint32 inc) { m_savingCurrentValue += inc; } // used and modified only during single thread
static uint32 IncreaseSavingMaxValue(uint32 inc) { std::lock_guard<std::mutex> guard(_savingLock); return (m_savingMaxValueAssigned += inc); }
static void InsertToSavingSkipListIfNeeded(uint32 id) { if (id > m_savingCurrentValue) { std::lock_guard<std::mutex> guard(_savingLock); m_savingSkipList.push_back(id); } }
protected:
static uint32 m_savingCurrentValue;
static uint32 m_savingMaxValueAssigned;
static uint32 m_savingDiffSum;
static std::list<uint32> m_savingSkipList;
static std::mutex _savingLock;
};
#endif