// -------------------
void CreatureEventAIMgr::LoadCreatureEventAI_Texts(bool check_entry_use)
{
// Drop Existing Text Map, only done once and we are ready to add data from multiple sources.
m_CreatureEventAI_TextMap.clear();
// Load EventAI Text
sObjectMgr.LoadMangosStrings(WorldDatabase,"creature_ai_texts",MIN_CREATURE_AI_TEXT_STRING_ID,MAX_CREATURE_AI_TEXT_STRING_ID);
// Gather Additional data from EventAI Texts
QueryResult *result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM creature_ai_texts");
sLog.outString("Loading EventAI Texts additional data...");
if (result)
{
BarGoLink bar(result->GetRowCount());
uint32 count = 0;
do
{
bar.step();
Field* fields = result->Fetch();
StringTextData temp;
int32 i = fields[0].GetInt32();
temp.SoundId = fields[1].GetInt32();
temp.Type = fields[2].GetInt32();
temp.Language = fields[3].GetInt32();
temp.Emote = fields[4].GetInt32();
// range negative
if (i > MIN_CREATURE_AI_TEXT_STRING_ID || i <= MAX_CREATURE_AI_TEXT_STRING_ID)
{
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` is not in valid range(%d-%d)",i,MIN_CREATURE_AI_TEXT_STRING_ID,MAX_CREATURE_AI_TEXT_STRING_ID);
continue;
}
// range negative (don't must be happen, loaded from same table)
if (!sObjectMgr.GetMangosStringLocale(i))
{
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` not found",i);
continue;
}
if (temp.SoundId)
{
if (!sSoundEntriesStore.LookupEntry(temp.SoundId))
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` has Sound %u but sound does not exist.",i,temp.SoundId);
}
if (!GetLanguageDescByID(temp.Language))
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` using Language %u but Language does not exist.",i,temp.Language);
if (temp.Type > CHAT_TYPE_ZONE_YELL)
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` has Type %u but this Chat Type does not exist.",i,temp.Type);
if (temp.Emote)
{
if (!sEmotesStore.LookupEntry(temp.Emote))
sLog.outErrorDb("CreatureEventAI: Entry %i in table `creature_ai_texts` has Emote %u but emote does not exist.",i,temp.Emote);
}
m_CreatureEventAI_TextMap[i] = temp;
++count;
} while (result->NextRow());
delete result;
if(check_entry_use)
CheckUnusedAITexts();
sLog.outString();
sLog.outString(">> Loaded %u additional CreatureEventAI Texts data.", count);
}
else
{
BarGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString(">> Loaded 0 additional CreatureEventAI Texts data. DB table `creature_ai_texts` is empty.");
}
}
void CreatureTextMgr::LoadCreatureTexts()
{
uint32 oldMSTime = getMSTime();
mTextMap.clear(); // for reload case
mTextRepeatMap.clear(); //reset all currently used temp texts
PreparedStatement* stmt = WorldDB.GetPreparedStatement(WORLD_LOAD_CRETEXT);
PreparedQueryResult result = WorldDB.Query(stmt);
if (!result)
{
sLog->outString(">> Loaded 0 ceature texts. DB table `creature_texts` is empty.");
sLog->outString();
return;
}
uint32 textCount = 0;
uint32 creatureCount = 0;
do
{
Field* fields = result->Fetch();
CreatureTextEntry temp;
temp.entry = fields[0].GetUInt32();
temp.group = fields[1].GetUInt8();
temp.id = fields[2].GetUInt8();
temp.text = fields[3].GetString();
temp.type = ChatType(fields[4].GetUInt8());
temp.lang = Language(fields[5].GetUInt8());
temp.probability = fields[6].GetFloat();
temp.emote = Emote(fields[7].GetUInt32());
temp.duration = fields[8].GetUInt32();
temp.sound = fields[9].GetUInt32();
if (temp.sound)
{
if (!sSoundEntriesStore.LookupEntry(temp.sound)){
sLog->outErrorDb("CreatureTextMgr: Entry %u, Group %u in table `creature_texts` has Sound %u but sound does not exist.", temp.entry, temp.group, temp.sound);
temp.sound = 0;
}
}
if (!GetLanguageDescByID(temp.lang))
{
sLog->outErrorDb("CreatureTextMgr: Entry %u, Group %u in table `creature_texts` using Language %u but Language does not exist.", temp.entry, temp.group, uint32(temp.lang));
temp.lang = LANG_UNIVERSAL;
}
if (temp.type >= CHAT_TYPE_ZONE_YELL)//CHAT_TYPE_ZONE_YELL and more will be used later
{
sLog->outErrorDb("CreatureTextMgr: Entry %u, Group %u in table `creature_texts` has Type %u but this Chat Type does not exist.", temp.entry, temp.group, uint32(temp.type));
temp.type = CHAT_TYPE_SAY;
}
if (temp.emote)
{
if (!sEmotesStore.LookupEntry(temp.emote))
{
sLog->outErrorDb("CreatureTextMgr: Entry %u, Group %u in table `creature_texts` has Emote %u but emote does not exist.", temp.entry, temp.group, uint32(temp.emote));
temp.emote = EMOTE_ONESHOT_NONE;
}
}
//entry not yet added, add empty TextHolder (list of groups)
if (mTextMap.find(temp.entry) == mTextMap.end())
{
++creatureCount;
CreatureTextHolder TextHolder;
mTextMap[temp.entry] = TextHolder;
}
//group not yet added, add empty TextGroup (list of texts)
if (mTextMap[temp.entry].find(temp.group) == mTextMap[temp.entry].end())
{
CreatureTextGroup TextGroup;
mTextMap[temp.entry][temp.group] = TextGroup;
}
//add the text into our entry's group
mTextMap[temp.entry][temp.group].push_back(temp);
++textCount;
} while (result->NextRow());
sLog->outString(">> Loaded %u creature texts for %u creatures in %u ms", textCount, creatureCount, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
// -------------------
void CreatureEventAIMgr::LoadCreatureEventAI_Texts()
{
uint32 oldMSTime = getMSTime();
// Drop Existing Text Map, only done once and we are ready to add data from multiple sources.
m_CreatureEventAI_TextMap.clear();
// Load EventAI Text
sObjectMgr->LoadTrinityStrings("creature_ai_texts", MIN_CREATURE_AI_TEXT_STRING_ID, MAX_CREATURE_AI_TEXT_STRING_ID);
// Gather Additional data from EventAI Texts 0 1 2 3 4
QueryResult result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM creature_ai_texts");
if (!result)
{
TC_LOG_INFO(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 additional CreatureEventAI Texts data. DB table `creature_ai_texts` is empty.");
return;
}
uint32 count = 0;
do
{
Field* fields = result->Fetch();
StringTextData temp;
int32 i = fields[0].GetInt32();
temp.SoundId = fields[1].GetUInt32();
temp.Type = fields[2].GetUInt8();
temp.Language = fields[3].GetUInt8();
temp.Emote = fields[4].GetUInt16();
// range negative
if (i > MIN_CREATURE_AI_TEXT_STRING_ID || i <= MAX_CREATURE_AI_TEXT_STRING_ID)
{
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureEventAI: Entry %i in table `creature_ai_texts` is not in valid range(%d-%d)", i, MIN_CREATURE_AI_TEXT_STRING_ID, MAX_CREATURE_AI_TEXT_STRING_ID);
continue;
}
// range negative (must not happen, loaded from same table)
if (!sObjectMgr->GetTrinityStringLocale(i))
{
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureEventAI: Entry %i in table `creature_ai_texts` not found", i);
continue;
}
if (temp.SoundId)
{
if (!sSoundEntriesStore.LookupEntry(temp.SoundId))
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureEventAI: Entry %i in table `creature_ai_texts` has Sound %u but sound does not exist.", i, temp.SoundId);
}
if (!GetLanguageDescByID(temp.Language))
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureEventAI: Entry %i in table `creature_ai_texts` using Language %u but Language does not exist.", i, temp.Language);
if (temp.Type > CHAT_TYPE_ZONE_YELL)
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureEventAI: Entry %i in table `creature_ai_texts` has Type %u but this Chat Type does not exist.", i, temp.Type);
if (temp.Emote)
{
if (!sEmotesStore.LookupEntry(temp.Emote))
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureEventAI: Entry %i in table `creature_ai_texts` has Emote %u but emote does not exist.", i, temp.Emote);
}
m_CreatureEventAI_TextMap[i] = temp;
++count;
}
while (result->NextRow());
TC_LOG_INFO(LOG_FILTER_SERVER_LOADING, ">> Loaded %u additional CreatureEventAI Texts data in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
void ScriptMgr::LoadScripts(ScriptMapMap& scripts, const char* tablename)
{
if (IsScriptScheduled()) // function don't must be called in time scripts use.
return;
sLog.outString("%s :", tablename);
scripts.clear(); // need for reload support
QueryResult *result = WorldDatabase.PQuery("SELECT id, delay, command, datalong, datalong2, datalong3, datalong4, data_flags, dataint, dataint2, dataint3, dataint4, x, y, z, o FROM %s", tablename);
uint32 count = 0;
if (!result)
{
barGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString(">> Loaded %u script definitions", count);
return;
}
barGoLink bar((int)result->GetRowCount());
do
{
bar.step();
Field *fields = result->Fetch();
ScriptInfo tmp;
tmp.id = fields[0].GetUInt32();
tmp.delay = fields[1].GetUInt32();
tmp.command = fields[2].GetUInt32();
tmp.raw.data[0] = fields[3].GetUInt32();
tmp.raw.data[1] = fields[4].GetUInt32();
tmp.raw.data[2] = fields[5].GetUInt32();
tmp.raw.data[3] = fields[6].GetUInt32();
tmp.raw.data[4] = fields[7].GetUInt32();
tmp.raw.data[5] = fields[8].GetInt32();
tmp.raw.data[6] = fields[9].GetInt32();
tmp.raw.data[7] = fields[10].GetInt32();
tmp.raw.data[8] = fields[11].GetInt32();
tmp.x = fields[12].GetFloat();
tmp.y = fields[13].GetFloat();
tmp.z = fields[14].GetFloat();
tmp.o = fields[15].GetFloat();
// generic command args check
switch(tmp.command)
{
case SCRIPT_COMMAND_TALK:
{
if (tmp.talk.chatType > CHAT_TYPE_ZONE_YELL)
{
sLog.outErrorDb("Table `%s` has invalid CHAT_TYPE_ (datalong = %u) in SCRIPT_COMMAND_TALK for script id %u", tablename, tmp.talk.chatType, tmp.id);
continue;
}
if (tmp.talk.creatureEntry && !ObjectMgr::GetCreatureTemplate(tmp.talk.creatureEntry))
{
sLog.outErrorDb("Table `%s` has datalong2 = %u in SCRIPT_COMMAND_TALK for script id %u, but this creature_template does not exist.", tablename, tmp.talk.creatureEntry, tmp.id);
continue;
}
if (tmp.talk.creatureEntry && !tmp.talk.searchRadius)
{
sLog.outErrorDb("Table `%s` has datalong2 = %u in SCRIPT_COMMAND_TALK for script id %u, but search radius is too small (datalong3 = %u).", tablename, tmp.talk.creatureEntry, tmp.id, tmp.talk.searchRadius);
continue;
}
if (!GetLanguageDescByID(tmp.talk.language))
{
sLog.outErrorDb("Table `%s` has datalong4 = %u in SCRIPT_COMMAND_TALK for script id %u, but this language does not exist.", tablename, tmp.talk.language, tmp.id);
continue;
}
if (tmp.talk.textId[0] == 0)
{
sLog.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u", tablename, tmp.talk.textId[0], tmp.id);
continue;
}
for(int i = 0; i < MAX_TEXT_ID; ++i)
{
if (tmp.talk.textId[i] && (tmp.talk.textId[i] < MIN_DB_SCRIPT_STRING_ID || tmp.talk.textId[i] >= MAX_DB_SCRIPT_STRING_ID))
{
sLog.outErrorDb("Table `%s` has out of range text id (dataint = %i expected %u-%u) in SCRIPT_COMMAND_TALK for script id %u", tablename, tmp.talk.textId[i], MIN_DB_SCRIPT_STRING_ID, MAX_DB_SCRIPT_STRING_ID, tmp.id);
continue;
}
}
// if (!GetMangosStringLocale(tmp.dataint)) will be checked after db_script_string loading
break;
}
case SCRIPT_COMMAND_EMOTE:
{
if (!sEmotesStore.LookupEntry(tmp.emote.emoteId))
{
sLog.outErrorDb("Table `%s` has invalid emote id (datalong = %u) in SCRIPT_COMMAND_EMOTE for script id %u", tablename, tmp.emote.emoteId, tmp.id);
continue;
}
if (tmp.emote.creatureEntry && !ObjectMgr::GetCreatureTemplate(tmp.emote.creatureEntry))
{
//.........这里部分代码省略.........
void CreatureTextMgr::LoadCreatureTexts()
{
uint32 oldMSTime = getMSTime();
mTextMap.clear(); // for reload case
mTextRepeatMap.clear(); //reset all currently used temp texts
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_TEXT);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (!result)
{
TC_LOG_INFO(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 ceature texts. DB table `creature_texts` is empty.");
return;
}
uint32 textCount = 0;
uint32 creatureCount = 0;
do
{
Field* fields = result->Fetch();
CreatureTextEntry temp;
temp.entry = fields[0].GetUInt32();
temp.group = fields[1].GetUInt8();
temp.id = fields[2].GetUInt8();
temp.text = fields[3].GetString();
temp.type = ChatMsg(fields[4].GetUInt8());
temp.lang = Language(fields[5].GetUInt8());
temp.probability = fields[6].GetFloat();
temp.emote = Emote(fields[7].GetUInt32());
temp.duration = fields[8].GetUInt32();
temp.sound = fields[9].GetUInt32();
if (temp.sound)
{
if (!sSoundEntriesStore.LookupEntry(temp.sound)){
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureTextMgr: Entry %u, Group %u in table `creature_texts` has Sound %u but sound does not exist.", temp.entry, temp.group, temp.sound);
temp.sound = 0;
}
}
if (!GetLanguageDescByID(temp.lang))
{
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureTextMgr: Entry %u, Group %u in table `creature_texts` using Language %u but Language does not exist.", temp.entry, temp.group, uint32(temp.lang));
temp.lang = LANG_UNIVERSAL;
}
if (temp.type >= MAX_CHAT_MSG_TYPE)
{
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureTextMgr: Entry %u, Group %u in table `creature_texts` has Type %u but this Chat Type does not exist.", temp.entry, temp.group, uint32(temp.type));
temp.type = CHAT_MSG_SAY;
}
if (temp.emote)
{
if (!sEmotesStore.LookupEntry(temp.emote))
{
TC_LOG_ERROR(LOG_FILTER_SQL, "CreatureTextMgr: Entry %u, Group %u in table `creature_texts` has Emote %u but emote does not exist.", temp.entry, temp.group, uint32(temp.emote));
temp.emote = EMOTE_ONESHOT_NONE;
}
}
//entry not yet added, add empty TextHolder (list of groups)
if (mTextMap.find(temp.entry) == mTextMap.end())
++creatureCount;
//add the text into our entry's group
mTextMap[temp.entry][temp.group].push_back(temp);
++textCount;
} while (result->NextRow());
TC_LOG_INFO(LOG_FILTER_SERVER_LOADING, ">> Loaded %u creature texts for %u creatures in %u ms", textCount, creatureCount, GetMSTimeDiffToNow(oldMSTime));
}
void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data)
{
uint32 type;
uint32 lang;
switch (recv_data.GetOpcode())
{
case CMSG_MESSAGECHAT_SAY: type = CHAT_MSG_SAY; break;
case CMSG_MESSAGECHAT_YELL: type = CHAT_MSG_YELL; break;
case CMSG_MESSAGECHAT_CHANNEL: type = CHAT_MSG_CHANNEL; break;
case CMSG_MESSAGECHAT_WHISPER: type = CHAT_MSG_WHISPER; break;
case CMSG_MESSAGECHAT_GUILD: type = CHAT_MSG_GUILD; break;
case CMSG_MESSAGECHAT_OFFICER: type = CHAT_MSG_OFFICER; break;
case CMSG_MESSAGECHAT_AFK: type = CHAT_MSG_AFK; break;
case CMSG_MESSAGECHAT_DND: type = CHAT_MSG_DND; break;
case CMSG_MESSAGECHAT_EMOTE: type = CHAT_MSG_EMOTE; break;
case CMSG_MESSAGECHAT_PARTY: type = CHAT_MSG_PARTY; break;
case CMSG_MESSAGECHAT_RAID: type = CHAT_MSG_RAID; break;
case CMSG_MESSAGECHAT_BATTLEGROUND: type = CHAT_MSG_BATTLEGROUND; break;
case CMSG_MESSAGECHAT_RAID_WARNING: type = CHAT_MSG_RAID_WARNING; break;
default:
sLog.outError("HandleMessagechatOpcode : Unknown chat opcode (0x%X)", recv_data.GetOpcode());
recv_data.rfinish();
return;
}
// no language sent with emote packet.
if (type != CHAT_MSG_EMOTE && type != CHAT_MSG_AFK && type != CHAT_MSG_DND)
{
recv_data >> lang;
// prevent talking at unknown language (cheating)
LanguageDesc const* langDesc = GetLanguageDescByID(lang);
if (!langDesc)
{
SendNotification(LANG_UNKNOWN_LANGUAGE);
return;
}
if (langDesc->skill_id != 0 && !_player->HasSkill(langDesc->skill_id))
{
// also check SPELL_AURA_COMPREHEND_LANGUAGE (client offers option to speak in that language)
Unit::AuraList const& langAuras = _player->GetAurasByType(SPELL_AURA_COMPREHEND_LANGUAGE);
bool foundAura = false;
for (Unit::AuraList::const_iterator i = langAuras.begin(); i != langAuras.end(); ++i)
{
if ((*i)->GetModifier()->m_miscvalue == int32(lang))
{
foundAura = true;
break;
}
}
if (!foundAura)
{
SendNotification(LANG_NOT_LEARNED_LANGUAGE);
return;
}
}
if (lang == LANG_ADDON)
{
// Disabled addon channel?
if (!sWorld.getConfig(CONFIG_BOOL_ADDON_CHANNEL))
return;
}
// LANG_ADDON should not be changed nor be affected by flood control
else
{
// send in universal language if player in .gmon mode (ignore spell effects)
if (_player->isGameMaster())
lang = LANG_UNIVERSAL;
else
{
// send in universal language in two side iteration allowed mode
if (sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_CHAT))
lang = LANG_UNIVERSAL;
else
{
switch (type)
{
case CHAT_MSG_PARTY:
case CHAT_MSG_PARTY_LEADER:
case CHAT_MSG_RAID:
case CHAT_MSG_RAID_LEADER:
case CHAT_MSG_RAID_WARNING:
// allow two side chat at group channel if two side group allowed
if (sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_GROUP))
lang = LANG_UNIVERSAL;
break;
case CHAT_MSG_GUILD:
case CHAT_MSG_OFFICER:
// allow two side chat at guild channel if two side guild allowed
if (sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_GUILD))
lang = LANG_UNIVERSAL;
break;
}
}
// but overwrite it by SPELL_AURA_MOD_LANGUAGE auras (only single case used)
Unit::AuraList const& ModLangAuras = _player->GetAurasByType(SPELL_AURA_MOD_LANGUAGE);
if (!ModLangAuras.empty())
//.........这里部分代码省略.........
void CreatureTextMgr::LoadCreatureTexts()
{
uint32 oldMSTime = getMSTime();
mTextMap.clear(); // for reload case
//all currently used temp texts are NOT reset
QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, groupid, id, text, type, language, probability, emote, duration, sound, TextRange FROM creature_text");
if (!result)
{
sLog.outString(">> Loaded 0 ceature texts. DB table `creature_text` is empty.");
return;
}
uint32 textCount = 0;
do
{
Field* fields = result->Fetch();
CreatureTextEntry temp;
temp.entry = fields[0].GetUInt32();
temp.group = fields[1].GetUInt8();
temp.id = fields[2].GetUInt8();
temp.text = fields[3].GetString();
temp.type = ChatMsg(fields[4].GetUInt8());
temp.lang = Language(fields[5].GetUInt8());
temp.probability = fields[6].GetFloat();
temp.emote = Emote(fields[7].GetUInt32());
temp.duration = fields[8].GetUInt32();
temp.sound = fields[9].GetUInt32();
temp.TextRange = CreatureTextRange(fields[10].GetUInt8());
if (temp.sound)
{
if (!sSoundEntriesStore.LookupEntry(temp.sound))
{
sLog.outError("CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Sound %u but sound does not exist.", temp.entry, temp.group, temp.sound);
temp.sound = 0;
}
}
if (!GetLanguageDescByID(temp.lang))
{
sLog.outError("CreatureTextMgr: Entry %u, Group %u in table `creature_text` using Language %u but Language does not exist.", temp.entry, temp.group, uint32(temp.lang));
temp.lang = LANG_UNIVERSAL;
}
if (temp.type >= MAX_CHAT_MSG_TYPE)
{
sLog.outError("CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Type %u but this Chat Type does not exist.", temp.entry, temp.group, uint32(temp.type));
temp.type = CHAT_MSG_SAY;
}
if (temp.emote)
{
if (!sEmotesStore.LookupEntry(temp.emote))
{
sLog.outError("CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Emote %u but emote does not exist.", temp.entry, temp.group, uint32(temp.emote));
temp.emote = EMOTE_ONESHOT_NONE;
}
}
if (temp.TextRange > TEXT_RANGE_WORLD)
{
sLog.outError("CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has incorrect TextRange %u.", temp.entry, temp.group, temp.id, temp.TextRange);
temp.TextRange = TEXT_RANGE_NORMAL;
}
// add the text into our entry's group
mTextMap[temp.entry][temp.group].push_back(temp);
++textCount;
}
while (result->NextRow());
sLog.outString(">> Loaded %u creature texts for %lu creatures in %u ms", textCount, mTextMap.size(), GetMSTimeDiffToNow(oldMSTime));
}
void WorldSession::HandleMessagechatOpcode(WorldPacket & recvData)
{
uint32 type;
uint32 lang;
recvData >> type;
recvData >> lang;
if (type >= MAX_CHAT_MSG_TYPE)
{
sLog->outError("CHAT: Wrong message type received: %u", type);
recvData.rfinish();
return;
}
Player* sender = GetPlayer();
//sLog->outDebug("CHAT: packet received. type %u, lang %u", type, lang);
// pussywizard: chatting on most chat types requires 2 hours played to prevent spam/abuse
if (AccountMgr::IsPlayerAccount(GetSecurity()))
switch (type)
{
case CHAT_MSG_ADDON:
case CHAT_MSG_PARTY:
case CHAT_MSG_RAID:
case CHAT_MSG_GUILD:
case CHAT_MSG_OFFICER:
case CHAT_MSG_AFK:
case CHAT_MSG_DND:
case CHAT_MSG_RAID_LEADER:
case CHAT_MSG_RAID_WARNING:
case CHAT_MSG_BATTLEGROUND:
case CHAT_MSG_BATTLEGROUND_LEADER:
case CHAT_MSG_PARTY_LEADER:
break;
default:
if (sender->GetTotalPlayedTime() < 2*HOUR)
{
SendNotification("Speaking is allowed after playing for at least 2 hours. You may use party and guild chat.");
recvData.rfinish();
return;
}
}
// pussywizard:
switch (type)
{
case CHAT_MSG_SAY:
case CHAT_MSG_YELL:
case CHAT_MSG_EMOTE:
case CHAT_MSG_TEXT_EMOTE:
case CHAT_MSG_AFK:
case CHAT_MSG_DND:
if (sender->IsSpectator())
{
recvData.rfinish();
return;
}
}
// prevent talking at unknown language (cheating)
LanguageDesc const* langDesc = GetLanguageDescByID(lang);
if (!langDesc)
{
SendNotification(LANG_UNKNOWN_LANGUAGE);
recvData.rfinish();
return;
}
if (langDesc->skill_id != 0 && !sender->HasSkill(langDesc->skill_id))
{
// also check SPELL_AURA_COMPREHEND_LANGUAGE (client offers option to speak in that language)
Unit::AuraEffectList const& langAuras = sender->GetAuraEffectsByType(SPELL_AURA_COMPREHEND_LANGUAGE);
bool foundAura = false;
for (Unit::AuraEffectList::const_iterator i = langAuras.begin(); i != langAuras.end(); ++i)
{
if ((*i)->GetMiscValue() == int32(lang))
{
foundAura = true;
break;
}
}
if (!foundAura)
{
SendNotification(LANG_NOT_LEARNED_LANGUAGE);
recvData.rfinish();
return;
}
}
if (lang == LANG_ADDON)
{
// LANG_ADDON is only valid for the following message types
switch (type)
{
case CHAT_MSG_PARTY:
case CHAT_MSG_RAID:
case CHAT_MSG_GUILD:
case CHAT_MSG_BATTLEGROUND:
case CHAT_MSG_WHISPER:
//.........这里部分代码省略.........
void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
{
uint32 type;
uint32 lang;
recvData >> type;
recvData >> lang;
if (sWorld->getBoolConfig(BATTLEGROUND_CROSSFACTION_ENABLED) && lang != LANG_ADDON)
{
switch (type)
{
case CHAT_MSG_BATTLEGROUND:
case CHAT_MSG_BATTLEGROUND_LEADER:
lang = LANG_UNIVERSAL;
default:
break;
}
}
if (type >= MAX_CHAT_MSG_TYPE)
{
TC_LOG_ERROR("network", "CHAT: Wrong message type received: %u", type);
recvData.rfinish();
return;
}
if (lang == LANG_UNIVERSAL && type != CHAT_MSG_AFK && type != CHAT_MSG_DND)
{
TC_LOG_ERROR("network", "CMSG_MESSAGECHAT: Possible hacking-attempt: %s tried to send a message in universal language", GetPlayerInfo().c_str());
SendNotification(LANG_UNKNOWN_LANGUAGE);
recvData.rfinish();
return;
}
Player* sender = GetPlayer();
//TC_LOG_DEBUG("CHAT: packet received. type %u, lang %u", type, lang);
// prevent talking at unknown language (cheating)
LanguageDesc const* langDesc = GetLanguageDescByID(lang);
if (!langDesc)
{
SendNotification(LANG_UNKNOWN_LANGUAGE);
recvData.rfinish();
return;
}
if (langDesc->skill_id != 0 && !sender->HasSkill(langDesc->skill_id))
{
// also check SPELL_AURA_COMPREHEND_LANGUAGE (client offers option to speak in that language)
Unit::AuraEffectList const& langAuras = sender->GetAuraEffectsByType(SPELL_AURA_COMPREHEND_LANGUAGE);
bool foundAura = false;
for (Unit::AuraEffectList::const_iterator i = langAuras.begin(); i != langAuras.end(); ++i)
{
if ((*i)->GetMiscValue() == int32(lang))
{
foundAura = true;
break;
}
}
if (!foundAura)
{
SendNotification(LANG_NOT_LEARNED_LANGUAGE);
recvData.rfinish();
return;
}
}
if (lang == LANG_ADDON)
{
// LANG_ADDON is only valid for the following message types
switch (type)
{
case CHAT_MSG_PARTY:
case CHAT_MSG_RAID:
case CHAT_MSG_GUILD:
case CHAT_MSG_BATTLEGROUND:
case CHAT_MSG_WHISPER:
// check if addon messages are disabled
if (!sWorld->getBoolConfig(CONFIG_ADDON_CHANNEL))
{
recvData.rfinish();
return;
}
break;
default:
TC_LOG_ERROR("network", "Player %s (GUID: %u) sent a chatmessage with an invalid language/message type combination",
GetPlayer()->GetName().c_str(), GetPlayer()->GetGUIDLow());
recvData.rfinish();
return;
}
}
// LANG_ADDON should not be changed nor be affected by flood control
else
{
// send in universal language if player in .gmon mode (ignore spell effects)
if (sender->IsGameMaster())
lang = LANG_UNIVERSAL;
//.........这里部分代码省略.........
void WorldSession::HandleChatMessage(ChatMsg type, uint32 lang, std::string msg, std::string target /*= ""*/)
{
Player* sender = GetPlayer();
if (lang == LANG_UNIVERSAL && type != CHAT_MSG_EMOTE)
{
TC_LOG_ERROR("network", "CMSG_MESSAGECHAT: Possible hacking-attempt: %s tried to send a message in universal language", GetPlayerInfo().c_str());
SendNotification(LANG_UNKNOWN_LANGUAGE);
return;
}
// prevent talking at unknown language (cheating)
LanguageDesc const* langDesc = GetLanguageDescByID(lang);
if (!langDesc)
{
SendNotification(LANG_UNKNOWN_LANGUAGE);
return;
}
if (langDesc->skill_id != 0 && !sender->HasSkill(langDesc->skill_id))
{
// also check SPELL_AURA_COMPREHEND_LANGUAGE (client offers option to speak in that language)
Unit::AuraEffectList const& langAuras = sender->GetAuraEffectsByType(SPELL_AURA_COMPREHEND_LANGUAGE);
bool foundAura = false;
for (Unit::AuraEffectList::const_iterator i = langAuras.begin(); i != langAuras.end(); ++i)
{
if ((*i)->GetMiscValue() == int32(lang))
{
foundAura = true;
break;
}
}
if (!foundAura)
{
SendNotification(LANG_NOT_LEARNED_LANGUAGE);
return;
}
}
// send in universal language if player in .gm on mode (ignore spell effects)
if (sender->IsGameMaster())
lang = LANG_UNIVERSAL;
else
{
// send in universal language in two side iteration allowed mode
if (HasPermission(rbac::RBAC_PERM_TWO_SIDE_INTERACTION_CHAT))
lang = LANG_UNIVERSAL;
else
{
switch (type)
{
case CHAT_MSG_PARTY:
case CHAT_MSG_RAID:
case CHAT_MSG_RAID_WARNING:
// allow two side chat at group channel if two side group allowed
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
lang = LANG_UNIVERSAL;
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;
break;
default:
break;
}
}
// but overwrite it by SPELL_AURA_MOD_LANGUAGE auras (only single case used)
Unit::AuraEffectList const& ModLangAuras = sender->GetAuraEffectsByType(SPELL_AURA_MOD_LANGUAGE);
if (!ModLangAuras.empty())
lang = ModLangAuras.front()->GetMiscValue();
}
if (!sender->CanSpeak())
{
std::string timeStr = secsToTimeString(m_muteTime - time(NULL));
SendNotification(GetTrinityString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str());
return;
}
if (sender->HasAura(GM_SILENCE_AURA) && type != CHAT_MSG_WHISPER)
{
SendNotification(GetTrinityString(LANG_GM_SILENCE), sender->GetName().c_str());
return;
}
if (msg.empty())
return;
if (ChatHandler(this).ParseCommands(msg.c_str()))
return;
// Strip invisible characters for non-addon messages
if (sWorld->getBoolConfig(CONFIG_CHAT_FAKE_MESSAGE_PREVENTING))
stripLineInvisibleChars(msg);
if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY) && !ChatHandler(this).isValidChatMessage(msg.c_str()))
{
//.........这里部分代码省略.........
void CreatureTextMgr::LoadCreatureTexts()
{
uint32 oldMSTime = getMSTime();
mTextMap.clear(); // for reload case
//all currently used temp texts are NOT reset
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_TEXT);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (!result)
{
TC_LOG_INFO("server.loading", ">> Loaded 0 ceature texts. DB table `creature_text` is empty.");
return;
}
uint32 textCount = 0;
do
{
Field* fields = result->Fetch();
CreatureTextEntry temp;
temp.creatureId = fields[0].GetUInt32();
temp.groupId = fields[1].GetUInt8();
temp.id = fields[2].GetUInt8();
temp.text = fields[3].GetString();
temp.type = ChatMsg(fields[4].GetUInt8());
temp.lang = Language(fields[5].GetUInt8());
temp.probability = fields[6].GetFloat();
temp.emote = Emote(fields[7].GetUInt32());
temp.duration = fields[8].GetUInt32();
temp.sound = fields[9].GetUInt32();
temp.BroadcastTextId = fields[10].GetUInt32();
temp.TextRange = CreatureTextRange(fields[11].GetUInt8());
if (temp.sound)
{
if (!sSoundEntriesStore.LookupEntry(temp.sound))
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Sound %u but sound does not exist.", temp.creatureId, temp.groupId, temp.sound);
temp.sound = 0;
}
}
if (!GetLanguageDescByID(temp.lang))
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` using Language %u but Language does not exist.", temp.creatureId, temp.groupId, uint32(temp.lang));
temp.lang = LANG_UNIVERSAL;
}
if (temp.type >= MAX_CHAT_MSG_TYPE)
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Type %u but this Chat Type does not exist.", temp.creatureId, temp.groupId, uint32(temp.type));
temp.type = CHAT_MSG_SAY;
}
if (temp.emote)
{
if (!sEmotesStore.LookupEntry(temp.emote))
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u in table `creature_text` has Emote %u but emote does not exist.", temp.creatureId, temp.groupId, uint32(temp.emote));
temp.emote = EMOTE_ONESHOT_NONE;
}
}
if (temp.BroadcastTextId)
{
if (!sObjectMgr->GetBroadcastText(temp.BroadcastTextId))
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has non-existing or incompatible BroadcastTextId %u.", temp.creatureId, temp.groupId, temp.id, temp.BroadcastTextId);
temp.BroadcastTextId = 0;
}
}
if (temp.TextRange > TEXT_RANGE_WORLD)
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Entry %u, Group %u, Id %u in table `creature_text` has incorrect TextRange %u.", temp.creatureId, temp.groupId, temp.id, temp.TextRange);
temp.TextRange = TEXT_RANGE_NORMAL;
}
// add the text into our entry's group
mTextMap[temp.creatureId][temp.groupId].push_back(temp);
++textCount;
}
while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded %u creature texts for " SZFMTD " creatures in %u ms", textCount, mTextMap.size(), GetMSTimeDiffToNow(oldMSTime));
}
请发表评论