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

View File

@@ -194,10 +194,8 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
return;
}
}
// LANG_ADDON should not be changed nor be affected by flood control
else
{
uint32 specialMessageLimit = 0;
// send in universal language if player in .gmon mode (ignore spell effects)
if (sender->IsGameMaster())
lang = LANG_UNIVERSAL;
@@ -218,20 +216,12 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
// allow two side chat at group channel if two side group allowed
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
lang = LANG_UNIVERSAL;
specialMessageLimit = 35;
break;
case CHAT_MSG_GUILD:
case CHAT_MSG_OFFICER:
// allow two side chat at guild channel if two side guild allowed
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD))
lang = LANG_UNIVERSAL;
specialMessageLimit = 15;
break;
case CHAT_MSG_WHISPER:
if (sender->getLevel() >= 80)
specialMessageLimit = 15;
break;
}
}
@@ -242,7 +232,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
}
if (type != CHAT_MSG_AFK && type != CHAT_MSG_DND)
sender->UpdateSpeakTime(specialMessageLimit);
sender->UpdateSpeakTime(lang == LANG_ADDON ? Player::ChatFloodThrottle::ADDON : Player::ChatFloodThrottle::REGULAR);
}
std::string to, channel, msg;
@@ -344,6 +334,11 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
}
}
else
{
++_addonMessageReceiveCount;
}
sScriptMgr->OnBeforeSendChatMessage(_player, type, lang, msg);
switch (type)
@@ -737,7 +732,7 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket& recvData)
if (!GetPlayer()->IsAlive())
return;
GetPlayer()->UpdateSpeakTime();
GetPlayer()->UpdateSpeakTime(Player::ChatFloodThrottle::REGULAR);
if (!GetPlayer()->CanSpeak())
{

View File

@@ -130,6 +130,7 @@ WorldSession::WorldSession(uint32 id, std::string&& name, std::shared_ptr<WorldS
isRecruiter(isARecruiter),
m_currentVendorEntry(0),
_calendarEventCreationCooldown(0),
_addonMessageReceiveCount(0),
_timeSyncClockDeltaQueue(6),
_timeSyncClockDelta(0),
_pendingTimeSyncRequests(),
@@ -459,6 +460,8 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
_recvQueue.readd(requeuePackets.begin(), requeuePackets.end());
METRIC_VALUE("processed_packets", processedPackets);
METRIC_VALUE("addon_messages", _addonMessageReceiveCount.load());
_addonMessageReceiveCount = 0;
if (!updater.ProcessUnsafe()) // <=> updater is of type MapSessionFilter
{

View File

@@ -1206,6 +1206,9 @@ private:
// Packets cooldown
time_t _calendarEventCreationCooldown;
// Addon Message count for Metric
std::atomic<uint32> _addonMessageReceiveCount;
CircularBuffer<std::pair<int64, uint32>> _timeSyncClockDeltaQueue; // first member: clockDelta. Second member: latency of the packet exchange that was used to compute that clockDelta.
int64 _timeSyncClockDelta;
void ComputeNewClockDelta();

View File

@@ -267,6 +267,8 @@ enum WorldIntConfigs
CONFIG_EXPANSION,
CONFIG_CHATFLOOD_MESSAGE_COUNT,
CONFIG_CHATFLOOD_MESSAGE_DELAY,
CONFIG_CHATFLOOD_ADDON_MESSAGE_COUNT,
CONFIG_CHATFLOOD_ADDON_MESSAGE_DELAY,
CONFIG_CHATFLOOD_MUTE_TIME,
CONFIG_EVENT_ANNOUNCE,
CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY,

View File

@@ -1023,6 +1023,8 @@ void World::LoadConfigSettings(bool reload)
m_int_configs[CONFIG_CHATFLOOD_MESSAGE_COUNT] = sConfigMgr->GetOption<int32>("ChatFlood.MessageCount", 10);
m_int_configs[CONFIG_CHATFLOOD_MESSAGE_DELAY] = sConfigMgr->GetOption<int32>("ChatFlood.MessageDelay", 1);
m_int_configs[CONFIG_CHATFLOOD_ADDON_MESSAGE_COUNT] = sConfigMgr->GetOption<int32>("ChatFlood.AddonMessageCount", 100);
m_int_configs[CONFIG_CHATFLOOD_ADDON_MESSAGE_DELAY] = sConfigMgr->GetOption<int32>("ChatFlood.AddonMessageDelay", 1);
m_int_configs[CONFIG_CHATFLOOD_MUTE_TIME] = sConfigMgr->GetOption<int32>("ChatFlood.MuteTime", 10);
m_bool_configs[CONFIG_CHAT_MUTE_FIRST_LOGIN] = sConfigMgr->GetOption<bool>("Chat.MuteFirstLogin", false);
m_int_configs[CONFIG_CHAT_TIME_MUTE_FIRST_LOGIN] = sConfigMgr->GetOption<int32>("Chat.MuteTimeFirstLogin", 120);