AutoBroadcast system.

-This commit is paired with 1 database update
This commit is contained in:
H0zen 2017-01-12 16:47:40 +02:00 committed by Antz
parent a7f938e7e6
commit 2888858616
9 changed files with 618 additions and 461 deletions

View file

@ -237,6 +237,7 @@ bool ChatHandler::HandleReloadAllCommand(char* /*args*/)
HandleReloadAllAchievementCommand((char*)"");
HandleReloadAllAreaCommand((char*)"");
HandleReloadAutoBroadcastCommand((char*)"");
HandleReloadAllEventAICommand((char*)"");
HandleReloadAllLootCommand((char*)"");
HandleReloadAllNpcCommand((char*)"");
@ -423,6 +424,14 @@ bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(char* /*args*/)
return true;
}
bool ChatHandler::HandleReloadAutoBroadcastCommand(char* /*args*/)
{
sLog.outString("Re-Loading broadcast strings...");
sWorld.LoadBroadcastStrings();
SendGlobalSysMessage("Broadcast strings reloaded.");
return true;
}
bool ChatHandler::HandleReloadCommandCommand(char* /*args*/)
{
load_command_table = true;

View file

@ -1021,11 +1021,12 @@ enum MangosStrings
LANG_OPVP_SI_CAPTURE_H = 1635,
LANG_OPVP_SI_CAPTURE_A = 1636,
// Room for 4.x clients only 1700-1799
// Room for 4.x clients only 1702-1799
LANG_VENDOR_WRONG_ITEM_TYPE = 1700,
LANG_VENDOR_WRONG_CURRENCY_MAXCOUNT = 1701,
// FREE IDS 1800-9999
// FREE IDS 1801-9999
LANG_AUTOBROADCAST = 1800
// Use for not-in-official-sources patches
// 10000-10999

View file

@ -533,6 +533,7 @@ ChatCommand* ChatHandler::getCommandTable()
{ "areatrigger_involvedrelation", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadQuestAreaTriggersCommand, "", NULL },
{ "areatrigger_tavern", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadAreaTriggerTavernCommand, "", NULL },
{ "areatrigger_teleport", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadAreaTriggerTeleportCommand, "", NULL },
{ "autobroadcast", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadAutoBroadcastCommand, "", NULL },
{ "command", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadCommandCommand, "", NULL },
{ "conditions", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadConditionsCommand, "", NULL },
{ "creature_ai_scripts", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadEventAIScriptsCommand, "", NULL },

View file

@ -432,6 +432,7 @@ class ChatHandler
bool HandleReloadAchievementRewardCommand(char* args);
bool HandleReloadAreaTriggerTavernCommand(char* args);
bool HandleReloadAreaTriggerTeleportCommand(char* args);
bool HandleReloadAutoBroadcastCommand(char* args);
bool HandleReloadBattleEventCommand(char* args);
bool HandleReloadCreaturesStatsCommand(char* args);
bool HandleReloadCommandCommand(char* args);

View file

@ -77,6 +77,7 @@
#include "Weather.h"
#include "LFGMgr.h"
#include "revision.h"
#include "Language.h"
#ifdef ENABLE_ELUNA
#include "LuaEngine.h"
@ -124,6 +125,9 @@ World::World(): mail_timer(0), mail_timer_expires(0), m_NextMonthlyQuestReset(0)
m_NextCurrencyReset = 0;
m_NextDailyQuestReset = 0;
m_NextWeeklyQuestReset = 0;
m_broadcastEnable = false;
m_broadcastList.clear();
m_broadcastWeight = 0;
m_defaultDbcLocale = LOCALE_enUS;
m_availableDbcLocaleMask = 0;
@ -570,6 +574,21 @@ void World::LoadConfigSettings(bool reload)
VMAP::VMapFactory::chompAndTrim(forceLoadGridOnMaps);
while (VMAP::VMapFactory::getNextId(forceLoadGridOnMaps, pos, id))
m_configForceLoadMapIds.insert(id);
setConfig(CONFIG_UINT32_AUTOBROADCAST_INTERVAL, "AutoBroadcast", 600);
if (getConfig(CONFIG_UINT32_AUTOBROADCAST_INTERVAL) > 0)
{
m_broadcastEnable = true;
}
else
{
m_broadcastEnable = false;
}
if (reload && m_broadcastEnable)
{
m_broadcastTimer.SetInterval(getConfig(CONFIG_UINT32_AUTOBROADCAST_INTERVAL) * IN_MILLISECONDS);
}
setConfig(CONFIG_UINT32_INTERVAL_SAVE, "PlayerSave.Interval", 15 * MINUTE * IN_MILLISECONDS);
@ -995,6 +1014,7 @@ void World::LoadConfigSettings(bool reload)
#endif /* ENABLE_ELUNA */
sLog.outString();
}
}
/// Initialize the World
void World::SetInitialWorldSettings()
@ -1487,6 +1507,23 @@ void World::SetInitialWorldSettings()
// for Dungeon Finder
m_timers[WUPDATE_LFGMGR].SetInterval(30 * IN_MILLISECONDS); // every 30 sec
// for AutoBroadcast
sLog.outString("Starting AutoBroadcast System");
if (m_broadcastEnable)
{
LoadBroadcastStrings();
}
else
{
sLog.outString("AutoBroadcast is disabled");
}
sLog.outString();
if (m_broadcastEnable)
{
m_broadcastTimer.SetInterval(getConfig(CONFIG_UINT32_AUTOBROADCAST_INTERVAL) * IN_MILLISECONDS);
}
// to set mailtimer to return mails every day between 4 and 5 am
// mailtimer is increased when updating auctions
// one second is 1000 -(tested on win system)
@ -1743,6 +1780,24 @@ void World::Update(uint32 diff)
}
}
if (m_broadcastEnable)
{
if (m_broadcastTimer.GetCurrent() >= 0)
{
m_broadcastTimer.Update(diff);
}
else
{
m_broadcastTimer.SetCurrent(0);
}
if (m_broadcastTimer.Passed())
{
m_broadcastTimer.Reset();
AutoBroadcast();
}
}
///- Update the game time and check for shutdown time
_UpdateGameTime();
@ -2856,3 +2911,73 @@ void World::InvalidatePlayerDataToAllClient(ObjectGuid guid)
data << guid;
SendGlobalMessage(&data);
}
void World::LoadBroadcastStrings()
{
if (!m_broadcastEnable)
return;
std::string queryStr = "SELECT `autobroadcast`.`id`, `autobroadcast`.`content`,`autobroadcast`.`ratio` FROM `autobroadcast`";
QueryResult* result = WorldDatabase.Query(queryStr.c_str());
if (!result)
{
m_broadcastEnable = false;
sLog.outErrorDb("DB table `autobroadcast` is empty.");
sLog.outString();
return;
}
m_broadcastList.clear();
BarGoLink bar(result->GetRowCount());
m_broadcastWeight = 0;
do
{
Field* fields = result->Fetch();
bar.step();
uint32 ratio = fields[2].GetUInt32();
if (ratio == 0)
continue;
m_broadcastWeight += ratio;
BroadcastString bs;
bs.text = fields[1].GetString();
bs.freq = m_broadcastWeight;
m_broadcastList.push_back(bs);
} while (result->NextRow());
delete result;
if (m_broadcastWeight == 0)
{
sLog.outString(">> Loaded 0 broadcast strings.");
m_broadcastEnable = false;
}
else
{
sLog.outString(">> Loaded " SIZEFMTD " broadcast strings.", m_broadcastList.size());
}
}
void World::AutoBroadcast()
{
if (m_broadcastList.size() == 1)
{
SendWorldText(LANG_AUTOBROADCAST, m_broadcastList[0].text.c_str());
}
else
{
uint32 rn = urand(1, m_broadcastWeight);
std::vector<BroadcastString>::const_iterator it;
for (it = m_broadcastList.begin(); it != m_broadcastList.end(); ++it)
{
if (rn <= it->freq)
break;
}
SendWorldText(LANG_AUTOBROADCAST, it->text.c_str());
}
}

View file

@ -26,8 +26,8 @@
/// @{
/// \file
#ifndef __WORLD_H
#define __WORLD_H
#ifndef MANGOS_H_WORLD
#define MANGOS_H_WORLD
#include "Common.h"
#include "Timer.h"
@ -229,7 +229,8 @@ enum eConfigUInt32Values
CONFIG_UINT32_WARDEN_CLIENT_BAN_DURATION,
CONFIG_UINT32_WARDEN_NUM_MEM_CHECKS,
CONFIG_UINT32_WARDEN_NUM_OTHER_CHECKS,
CONFIG_UINT32_WARDEN_DB_LOGLEVEL
CONFIG_UINT32_WARDEN_DB_LOGLEVEL,
CONFIG_UINT32_AUTOBROADCAST_INTERVAL,
};
/// Configuration elements
@ -654,6 +655,7 @@ class World
char const* GetDBVersion() { return m_DBVersion.c_str(); }
void UpdatePhaseDefinitions();
void LoadBroadcastStrings();
/**
* \brief: force all client to request player data
@ -704,6 +706,18 @@ class World
bool configNoReload(bool reload, eConfigFloatValues index, char const* fieldname, float defvalue);
bool configNoReload(bool reload, eConfigBoolValues index, char const* fieldname, bool defvalue);
// AutoBroadcast system
void AutoBroadcast();
struct BroadcastString
{
uint32 freq;
std::string text;
};
std::vector<BroadcastString> m_broadcastList;
uint32 m_broadcastWeight;
bool m_broadcastEnable;
IntervalTimer m_broadcastTimer;
static volatile bool m_stopEvent;
static uint8 m_ExitCode;
uint32 m_ShutdownTimer;

View file

@ -3,7 +3,7 @@
################################################################################
[MangosdConf]
ConfVersion=2017021100
ConfVersion=2017021400
################################################################################
# CONNECTIONS AND DIRECTORIES
@ -796,6 +796,11 @@ SD3ErrorLogFile = "scriptdev3-errors.log"
# Motd
# Message of the Day. Displayed at worldlogin for every user ('@' for a newline).
#
# AutoBroadcast
# Timer interval (in seconds) for automatic server announcements (autobroadcasts). Zero value means AB is disabled
# 0 (AB is disabled)
# Default: 600 (AB every 10 minutes)
# N (>0, AB every N seconds)
################################################################################
GameType = 1
@ -867,6 +872,7 @@ WaitAtStartupError = 10
Raid.MinLevel = 10
PlayerCommands = 0
Motd = "Welcome to Mangos Three"
AutoBroadcast = 0
################################################################################
# PLAYER INTERACTION

View file

@ -42,7 +42,7 @@
// Format is YYYYMMDDRR where RR is the change in the conf file
// for that day.
#ifndef MANGOSD_CONFIG_VERSION
# define MANGOSD_CONFIG_VERSION 2016031901
# define MANGOSD_CONFIG_VERSION 2017021400
#endif
#ifndef REALMD_CONFIG_VERSION
# define REALMD_CONFIG_VERSION 2010062001

View file

@ -24,7 +24,7 @@
#ifndef MANGOS_H_REVISION
#define MANGOS_H_REVISION
#define REVISION_NR "21000"
#define REVISION_NR "21007"
#define REALMD_DB_VERSION_NR 21
#define REALMD_DB_STRUCTURE_NR 1
@ -37,7 +37,7 @@
#define CHAR_DB_UPDATE_DESCRIPTION "characters_pvpstats"
#define WORLD_DB_VERSION_NR 21
#define WORLD_DB_STRUCTURE_NR 5
#define WORLD_DB_STRUCTURE_NR 7
#define WORLD_DB_CONTENT_NR 1
#define WORLD_DB_UPDATE_DESCRIPTION "dbscripts_refactor"
#define WORLD_DB_UPDATE_DESCRIPTION "AutoBroadcast"
#endif // __REVISION_H__