From 5b71734499d3d9a4bee8f0edf03990a568c072e4 Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Wed, 22 Jan 2025 12:54:26 +0000 Subject: [PATCH] Core: Use charVars to gate yell messages --- src/map/entities/charentity.cpp | 1 - src/map/entities/charentity.h | 2 -- src/map/packet_system.cpp | 13 +++++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/map/entities/charentity.cpp b/src/map/entities/charentity.cpp index 10204d87274..6fc5782a8c1 100644 --- a/src/map/entities/charentity.cpp +++ b/src/map/entities/charentity.cpp @@ -237,7 +237,6 @@ CCharEntity::CCharEntity() m_SaveTime = 0; m_reloadParty = false; - m_LastYell = 0; m_moghouseID = 0; m_moghancementID = 0; diff --git a/src/map/entities/charentity.h b/src/map/entities/charentity.h index cf7eb4dfa45..0763bada951 100644 --- a/src/map/entities/charentity.h +++ b/src/map/entities/charentity.h @@ -497,8 +497,6 @@ class CCharEntity : public CBattleEntity uint32 m_PlayTime; uint32 m_SaveTime; - uint32 m_LastYell; - time_point m_LeaderCreatedPartyTime; // Time that a party member joined and this player was leader. uint8 m_GMlevel; // Level of the GM flag assigned to this character diff --git a/src/map/packet_system.cpp b/src/map/packet_system.cpp index 8fe62b36a04..55936be9e10 100644 --- a/src/map/packet_system.cpp +++ b/src/map/packet_system.cpp @@ -5711,16 +5711,21 @@ void SmallPacket0x0B5(map_session_data_t* const PSession, CCharEntity* const PCh break; case MESSAGE_YELL: { + const auto yellCooldownTime = settings::get("map.YELL_COOLDOWN"); + const auto isYellBanned = PChar->getCharVar("[YELL]Banned") == 1; + const auto isInYellCooldown = PChar->getCharVar("[YELL]Cooldown") == 1; + if (PChar->loc.zone->CanUseMisc(MISC_YELL)) { - int yellBanned = PChar->getCharVar("[YELL]Banned"); - if (yellBanned == 1) + if (isYellBanned) { PChar->pushPacket(PChar, PChar, 0, 0, MSGBASIC_CANNOT_USE_IN_AREA); } - else if (gettick() >= PChar->m_LastYell) + else if (!isInYellCooldown) { - PChar->m_LastYell = gettick() + settings::get("map.YELL_COOLDOWN") * 1000; + // CharVar will self-expire and set to zero after the cooldown period + PChar->setCharVar("[YELL]Cooldown", 1, CVanaTime::getInstance()->getSysTime() + yellCooldownTime); + int8 packetData[4]{}; ref(packetData, 0) = PChar->id;