Core/World: Improvements in Autobroadcast system (dropped from world database and moved to auth database, added realmid and weight columns)

This commit is contained in:
xjose93
2013-04-25 19:10:10 +02:00
parent 6dbd574a69
commit d7e9d1bafb
6 changed files with 52 additions and 6 deletions

View File

@@ -0,0 +1,8 @@
DROP TABLE IF EXISTS `autobroadcast`;
CREATE TABLE `autobroadcast` (
`realmid` int(10) NOT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`weight` tinyint(3) DEFAULT 1,
`text` longtext NOT NULL,
PRIMARY KEY (`id`, `realmid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS `autobroadcast`;

View File

@@ -1866,12 +1866,16 @@ void World::LoadAutobroadcasts()
uint32 oldMSTime = getMSTime();
m_Autobroadcasts.clear();
m_AutobroadcastsWeights.clear();
QueryResult result = WorldDatabase.Query("SELECT text FROM autobroadcast");
uint32 realmId = ConfigMgr::GetIntDefault("RealmID", 0);
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_AUTOBROADCAST);
stmt->setInt32(0, realmId);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
{
sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 autobroadcasts definitions. DB table `autobroadcast` is empty!");
sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 autobroadcasts definitions. DB table `autobroadcast` is empty for this realm!");
return;
}
@@ -1880,9 +1884,10 @@ void World::LoadAutobroadcasts()
do
{
Field* fields = result->Fetch();
std::string message = fields[0].GetString();
uint8 id = fields[0].GetUInt8();
m_Autobroadcasts.push_back(message);
m_Autobroadcasts[id] = fields[2].GetString();
m_AutobroadcastsWeights[id] = fields[1].GetUInt8();
++count;
} while (result->NextRow());
@@ -2635,9 +2640,35 @@ void World::SendAutoBroadcast()
if (m_Autobroadcasts.empty())
return;
uint32 weight = 0;
AutobroadcastsWeightMap selectionWeights;
std::string msg;
msg = Trinity::Containers::SelectRandomContainerElement(m_Autobroadcasts);
for (AutobroadcastsWeightMap::const_iterator it = m_AutobroadcastsWeights.begin(); it != m_AutobroadcastsWeights.end(); ++it)
{
if (it->second)
{
weight += it->second;
selectionWeights[it->first] = it->second;
}
}
if (weight)
{
uint32 selectedWeight = urand(0, weight - 1);
weight = 0;
for (AutobroadcastsWeightMap::const_iterator it = selectionWeights.begin(); it != selectionWeights.end(); ++it)
{
weight += it->second;
if (selectedWeight < weight)
{
msg = m_Autobroadcasts[it->first];
break;
}
}
}
else
msg = m_Autobroadcasts[urand(0, m_Autobroadcasts.size())];
uint32 abcenter = sWorld->getIntConfig(CONFIG_AUTOBROADCAST_CENTER);

View File

@@ -820,7 +820,11 @@ class World
// used versions
std::string m_DBVersion;
std::list<std::string> m_Autobroadcasts;
typedef std::map<uint8, std::string> AutobroadcastsMap;
AutobroadcastsMap m_Autobroadcasts;
typedef std::map<uint8, uint8> AutobroadcastsWeightMap;
AutobroadcastsWeightMap m_AutobroadcastsWeights;
std::map<uint32, CharacterNameData> _characterNameDataMap;
void LoadCharacterNameData();

View File

@@ -91,6 +91,7 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_SEL_REALMLIST_SECURITY_LEVEL, "SELECT allowedSecurityLevel from realmlist WHERE id = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_DEL_ACCOUNT, "DELETE FROM account WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_IP2NATION_COUNTRY, "SELECT c.country FROM ip2nationCountries c, ip2nation i WHERE i.ip < ? AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_AUTOBROADCAST, "SELECT id, weight, text FROM autobroadcast WHERE realmid = ? OR realmid = -1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_ACCESS_BY_ID, "SELECT gmlevel, RealmID FROM account_access WHERE id = ? and (RealmID = ? OR RealmID = -1) ORDER BY gmlevel desc", CONNECTION_SYNCH);

View File

@@ -111,6 +111,7 @@ enum LoginDatabaseStatements
LOGIN_SEL_REALMLIST_SECURITY_LEVEL,
LOGIN_DEL_ACCOUNT,
LOGIN_SEL_IP2NATION_COUNTRY,
LOGIN_SEL_AUTOBROADCAST,
LOGIN_SEL_ACCOUNT_ACCESS_BY_ID,
LOGIN_SEL_RBAC_ACCOUNT_GROUPS,