Merge branch 'azerothcore:master' into Playerbot

This commit is contained in:
ZhengPeiRu21
2022-08-18 13:48:09 -06:00
committed by GitHub
13 changed files with 96 additions and 65 deletions

View File

@@ -153,9 +153,6 @@ Player::Player(WorldSession* session): Unit(true), m_mover(this)
#pragma warning(default:4355)
#endif
m_speakTime = 0;
m_speakCount = 0;
m_objectType |= TYPEMASK_PLAYER;
m_objectTypeId = TYPEID_PLAYER;

View File

@@ -2256,9 +2256,21 @@ public:
/*** FLOOD FILTER SYSTEM ***/
/*********************************************************/
void UpdateSpeakTime(uint32 specialMessageLimit = 0);
struct ChatFloodThrottle
{
enum Index
{
REGULAR = 0,
ADDON = 1,
MAX
};
time_t Time = 0;
uint32 Count = 0;
};
void UpdateSpeakTime(ChatFloodThrottle::Index index);
[[nodiscard]] bool CanSpeak() const;
void ChangeSpeakTime(int utime);
/*********************************************************/
/*** VARIOUS SYSTEMS ***/
@@ -2697,8 +2709,7 @@ public:
uint16 m_additionalSaveTimer; // pussywizard
uint8 m_additionalSaveMask; // pussywizard
uint16 m_hostileReferenceCheckTimer; // pussywizard
time_t m_speakTime;
uint32 m_speakCount;
std::array<ChatFloodThrottle, ChatFloodThrottle::MAX> m_chatFloodData;
Difficulty m_dungeonDifficulty;
Difficulty m_raidDifficulty;
Difficulty m_raidMapDifficulty;

View File

@@ -26,34 +26,44 @@
/*** FLOOD FILTER SYSTEM ***/
/*********************************************************/
void Player::UpdateSpeakTime(uint32 specialMessageLimit)
void Player::UpdateSpeakTime(ChatFloodThrottle::Index index)
{
// ignore chat spam protection for GMs in any mode
if (!AccountMgr::IsPlayerAccount(GetSession()->GetSecurity()))
return;
time_t current = GameTime::GetGameTime().count();
if (m_speakTime > current)
uint32 limit, delay;
switch (index)
{
uint32 max_count = specialMessageLimit ? specialMessageLimit : sWorld->getIntConfig(CONFIG_CHATFLOOD_MESSAGE_COUNT);
if (!max_count)
return;
++m_speakCount;
if (m_speakCount >= max_count)
case ChatFloodThrottle::ADDON:
limit = sWorld->getIntConfig(CONFIG_CHATFLOOD_ADDON_MESSAGE_COUNT);
delay = sWorld->getIntConfig(CONFIG_CHATFLOOD_ADDON_MESSAGE_DELAY);
break;
case ChatFloodThrottle::REGULAR:
limit = sWorld->getIntConfig(CONFIG_CHATFLOOD_MESSAGE_COUNT);
delay = sWorld->getIntConfig(CONFIG_CHATFLOOD_MESSAGE_DELAY);
[[fallthrough]];
default:
return;
}
time_t current = GameTime::GetGameTime().count();
if (m_chatFloodData[index].Time > current)
{
++m_chatFloodData[index].Count;
if (m_chatFloodData[index].Count >= limit)
{
// prevent overwrite mute time, if message send just before mutes set, for example.
time_t new_mute = current + sWorld->getIntConfig(CONFIG_CHATFLOOD_MUTE_TIME);
if (GetSession()->m_muteTime < new_mute)
GetSession()->m_muteTime = new_mute;
m_speakCount = 0;
m_chatFloodData[index].Count = 0;
}
}
else
m_speakCount = 1;
m_chatFloodData[index].Count = 1;
m_speakTime = current + sWorld->getIntConfig(CONFIG_CHATFLOOD_MESSAGE_DELAY);
m_chatFloodData[index].Time = current + delay;
}
bool Player::CanSpeak() const