AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
AutobroadcastMgr Class Reference

#include "AutobroadcastMgr.h"

Public Member Functions

void LoadAutobroadcasts ()
 
void SendAutobroadcasts ()
 

Static Public Member Functions

static AutobroadcastMgrinstance ()
 

Private Types

typedef std::map< uint8, std::string > AutobroadcastsMap
 
typedef std::map< uint8, uint8AutobroadcastsWeightMap
 

Private Member Functions

void SendWorldAnnouncement (std::string msg)
 
void SendNotificationAnnouncement (std::string msg)
 

Private Attributes

AutobroadcastsMap _autobroadcasts
 
AutobroadcastsWeightMap _autobroadcastsWeights
 
AnnounceType _announceType
 

Detailed Description

Member Typedef Documentation

◆ AutobroadcastsMap

typedef std::map<uint8, std::string> AutobroadcastMgr::AutobroadcastsMap
private

◆ AutobroadcastsWeightMap

Member Function Documentation

◆ instance()

AutobroadcastMgr * AutobroadcastMgr::instance ( )
static
25{
27 return &instance;
28}
Definition: AutobroadcastMgr.h:32
static AutobroadcastMgr * instance()
Definition: AutobroadcastMgr.cpp:24

References instance().

Referenced by instance().

◆ LoadAutobroadcasts()

void AutobroadcastMgr::LoadAutobroadcasts ( )
31{
32 uint32 oldMSTime = getMSTime();
33
34 _autobroadcasts.clear();
36
37 uint32 realmId = sConfigMgr->GetOption<int32>("RealmID", 0);
39 stmt->SetData(0, realmId);
40 PreparedQueryResult result = LoginDatabase.Query(stmt);
41
42 if (!result)
43 {
44 LOG_WARN("autobroadcast", ">> Loaded 0 autobroadcasts definitions. DB table `autobroadcast` is empty for this realm!");
45 LOG_INFO("autobroadcast", " ");
46 return;
47 }
48
49 _announceType = static_cast<AnnounceType>(sWorld->getIntConfig(CONFIG_AUTOBROADCAST_CENTER));
50
51 if (_announceType < AnnounceType::World || _announceType > AnnounceType::Both)
52 {
53 LOG_ERROR("autobroadcast", "AutobroadcastMgr::LoadAutobroadcasts: Config option AutoBroadcast.Center set to not allowed value {}. Set to default value 0", (int8)_announceType);
54 _announceType = AnnounceType::World;
55 }
56
57 uint32 count = 0;
58
59 do
60 {
61 Field* fields = result->Fetch();
62 uint8 id = fields[0].Get<uint8>();
63
64 _autobroadcasts[id] = fields[2].Get<std::string>();
65 _autobroadcastsWeights[id] = fields[1].Get<uint8>();
66
67 ++count;
68 } while (result->NextRow());
69
70 LOG_INFO("autobroadcast", ">> Loaded {} Autobroadcast Definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
71 LOG_INFO("autobroadcast", " ");
72}
#define sConfigMgr
Definition: Config.h:92
std::int32_t int32
Definition: Define.h:104
std::uint8_t uint8
Definition: Define.h:110
std::uint32_t uint32
Definition: Define.h:108
std::int8_t int8
Definition: Define.h:106
#define LOG_INFO(filterType__,...)
Definition: Log.h:167
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
#define LOG_WARN(filterType__,...)
Definition: Log.h:163
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:46
@ LOGIN_SEL_AUTOBROADCAST
Definition: LoginDatabase.h:98
AnnounceType
Definition: AutobroadcastMgr.h:25
@ CONFIG_AUTOBROADCAST_CENTER
Definition: IWorld.h:351
#define sWorld
Definition: World.h:451
Definition: PreparedStatement.h:158
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
AutobroadcastsMap _autobroadcasts
Definition: AutobroadcastMgr.h:46
AnnounceType _announceType
Definition: AutobroadcastMgr.h:49
AutobroadcastsWeightMap _autobroadcastsWeights
Definition: AutobroadcastMgr.h:47

References _announceType, _autobroadcasts, _autobroadcastsWeights, CONFIG_AUTOBROADCAST_CENTER, Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LOG_ERROR, LOG_INFO, LOG_WARN, LOGIN_SEL_AUTOBROADCAST, LoginDatabase, sConfigMgr, and sWorld.

◆ SendAutobroadcasts()

void AutobroadcastMgr::SendAutobroadcasts ( )
75{
76 if (_autobroadcasts.empty())
77 {
78 return;
79 }
80
81 uint32 weight = 0;
82 AutobroadcastsWeightMap selectionWeights;
83
84 std::string msg;
85
86 for (AutobroadcastsWeightMap::const_iterator it = _autobroadcastsWeights.begin(); it != _autobroadcastsWeights.end(); ++it)
87 {
88 if (it->second)
89 {
90 weight += it->second;
91 selectionWeights[it->first] = it->second;
92 }
93 }
94
95 if (weight)
96 {
97 uint32 selectedWeight = urand(0, weight - 1);
98 weight = 0;
99 for (AutobroadcastsWeightMap::const_iterator it = selectionWeights.begin(); it != selectionWeights.end(); ++it)
100 {
101 weight += it->second;
102 if (selectedWeight < weight)
103 {
104 msg = _autobroadcasts[it->first];
105 break;
106 }
107 }
108 }
109 else
110 {
111 msg = _autobroadcasts[urand(0, _autobroadcasts.size())];
112 }
113
114 switch (_announceType)
115 {
116 case AnnounceType::World:
118 break;
119 case AnnounceType::Notification:
121 break;
122 case AnnounceType::Both:
125 default:
126 break;
127 }
128
129 LOG_DEBUG("autobroadcast", "AutobroadcastMgr::SendAutobroadcasts: '{}'", msg);
130}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44
void SendWorldAnnouncement(std::string msg)
Definition: AutobroadcastMgr.cpp:132
std::map< uint8, uint8 > AutobroadcastsWeightMap
Definition: AutobroadcastMgr.h:44
void SendNotificationAnnouncement(std::string msg)
Definition: AutobroadcastMgr.cpp:137

References _announceType, _autobroadcasts, _autobroadcastsWeights, LOG_DEBUG, SendNotificationAnnouncement(), SendWorldAnnouncement(), and urand().

◆ SendNotificationAnnouncement()

void AutobroadcastMgr::SendNotificationAnnouncement ( std::string  msg)
private
138{
139 WorldPacket data(SMSG_NOTIFICATION, (msg.size() + 1));
140 data << msg.data();
141 sWorld->SendGlobalMessage(&data);
142}
@ SMSG_NOTIFICATION
Definition: Opcodes.h:489
Definition: WorldPacket.h:27

References SMSG_NOTIFICATION, and sWorld.

Referenced by SendAutobroadcasts().

◆ SendWorldAnnouncement()

void AutobroadcastMgr::SendWorldAnnouncement ( std::string  msg)
private
133{
134 sWorld->SendWorldTextOptional(LANG_AUTO_BROADCAST, ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST, msg.data());
135}
@ ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST
Definition: PlayerSettings.h:35
@ LANG_AUTO_BROADCAST
Definition: Language.h:1285

References ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST, LANG_AUTO_BROADCAST, and sWorld.

Referenced by SendAutobroadcasts().

Member Data Documentation

◆ _announceType

AnnounceType AutobroadcastMgr::_announceType
private

◆ _autobroadcasts

AutobroadcastsMap AutobroadcastMgr::_autobroadcasts
private

◆ _autobroadcastsWeights

AutobroadcastsWeightMap AutobroadcastMgr::_autobroadcastsWeights
private