mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-18 03:22:27 +00:00
[Saylinks] Implement Auto Saylink Injection (#1525)
* Implement auto saylink injection * Cover Lua say since it takes a different code path
This commit is contained in:
parent
94c1a50cc8
commit
6b93130c13
@ -598,6 +598,8 @@ RULE_INT(Chat, IntervalDurationMS, 60000, "Interval length in milliseconds")
|
||||
RULE_INT(Chat, KarmaUpdateIntervalMS, 1200000, "Karma update interval in milliseconds")
|
||||
RULE_INT(Chat, KarmaGlobalChatLimit, 72, "Amount of karma you need to be able to talk in ooc/auction/chat below the level limit")
|
||||
RULE_INT(Chat, GlobalChatLevelLimit, 8, "Level limit you need to of reached to talk in ooc/auction/chat if your karma is too low")
|
||||
RULE_BOOL(Chat, AutoInjectSaylinksToSay, true, "Automatically injects saylinks into dialogue that has [brackets in them]")
|
||||
RULE_BOOL(Chat, AutoInjectSaylinksToClientMessage, true, "Automatically injects saylinks into dialogue that has [brackets in them]")
|
||||
RULE_CATEGORY_END()
|
||||
|
||||
RULE_CATEGORY(Merchant)
|
||||
|
||||
@ -340,3 +340,47 @@ std::string EQ::SayLinkEngine::GenerateQuestSaylink(std::string saylink_text, bo
|
||||
|
||||
return linker.GenerateLink();
|
||||
}
|
||||
|
||||
std::string EQ::SayLinkEngine::InjectSaylinksIfNotExist(const char *message)
|
||||
{
|
||||
std::string new_message = message;
|
||||
|
||||
int link_index = 0;
|
||||
std::vector<std::string> links = {};
|
||||
|
||||
// loop through brackets until none exist
|
||||
while (new_message.find('[') != std::string::npos && new_message.find(']') != std::string::npos) {
|
||||
std::string bracket_message = get_between(new_message, "[", "]");
|
||||
|
||||
// already a saylink
|
||||
// todo: improve this later
|
||||
if (!bracket_message.empty() && bracket_message.length() > 50) {
|
||||
links.emplace_back(bracket_message);
|
||||
}
|
||||
else {
|
||||
links.emplace_back(EQ::SayLinkEngine::GenerateQuestSaylink(bracket_message, false, bracket_message));
|
||||
}
|
||||
|
||||
// replace with anchor
|
||||
find_replace(
|
||||
new_message,
|
||||
fmt::format("[{}]", bracket_message),
|
||||
fmt::format("<link:{}>", link_index)
|
||||
);
|
||||
|
||||
link_index++;
|
||||
}
|
||||
|
||||
// pop links onto anchors
|
||||
link_index = 0;
|
||||
for (auto &link: links) {
|
||||
find_replace(
|
||||
new_message,
|
||||
fmt::format("<link:{}>", link_index),
|
||||
fmt::format("[{}]", link)
|
||||
);
|
||||
link_index++;
|
||||
}
|
||||
|
||||
return new_message;
|
||||
}
|
||||
|
||||
@ -105,6 +105,7 @@ namespace EQ
|
||||
|
||||
void Reset();
|
||||
|
||||
static std::string InjectSaylinksIfNotExist(const char *message);
|
||||
private:
|
||||
void generate_body();
|
||||
void generate_text();
|
||||
|
||||
@ -4185,8 +4185,10 @@ bool Entity::CheckCoordLosNoZLeaps(float cur_x, float cur_y, float cur_z,
|
||||
return false;
|
||||
}
|
||||
|
||||
void EntityList::QuestJournalledSayClose(Mob *sender, float dist, const char *mobname, const char *message,
|
||||
Journal::Options &opts)
|
||||
void EntityList::QuestJournalledSayClose(
|
||||
Mob *sender, float dist, const char *mobname, const char *message,
|
||||
Journal::Options &opts
|
||||
)
|
||||
{
|
||||
SerializeBuffer buf(sizeof(SpecialMesgHeader_Struct) + 12 + 64 + 64);
|
||||
|
||||
@ -4199,7 +4201,15 @@ void EntityList::QuestJournalledSayClose(Mob *sender, float dist, const char *mo
|
||||
buf.WriteInt32(0); // location, client doesn't seem to do anything with this
|
||||
buf.WriteInt32(0);
|
||||
buf.WriteInt32(0);
|
||||
|
||||
// auto inject saylinks (say)
|
||||
if (RuleB(Chat, AutoInjectSaylinksToSay)) {
|
||||
std::string new_message = EQ::SayLinkEngine::InjectSaylinksIfNotExist(message);
|
||||
buf.WriteString(new_message);
|
||||
}
|
||||
else {
|
||||
buf.WriteString(message);
|
||||
}
|
||||
|
||||
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
|
||||
|
||||
|
||||
@ -755,8 +755,16 @@ double Lua_Mob::GetSize() {
|
||||
|
||||
void Lua_Mob::Message(int type, const char *message) {
|
||||
Lua_Safe_Call_Void();
|
||||
|
||||
// auto inject saylinks
|
||||
if (RuleB(Chat, AutoInjectSaylinksToClientMessage)) {
|
||||
std::string new_message = EQ::SayLinkEngine::InjectSaylinksIfNotExist(message);
|
||||
self->Message(type, new_message.c_str());
|
||||
}
|
||||
else {
|
||||
self->Message(type, message);
|
||||
}
|
||||
}
|
||||
|
||||
void Lua_Mob::MessageString(int type, int string_id, uint32 distance) {
|
||||
Lua_Safe_Call_Void();
|
||||
|
||||
@ -2923,11 +2923,20 @@ void Mob::Say(const char *format, ...)
|
||||
talker = this;
|
||||
}
|
||||
|
||||
if (RuleB(Chat, AutoInjectSaylinksToSay)) {
|
||||
std::string new_message = EQ::SayLinkEngine::InjectSaylinksIfNotExist(buf);
|
||||
entity_list.MessageCloseString(
|
||||
talker, false, 200, 10,
|
||||
GENERIC_SAY, GetCleanName(), new_message.c_str()
|
||||
);
|
||||
}
|
||||
else {
|
||||
entity_list.MessageCloseString(
|
||||
talker, false, 200, 10,
|
||||
GENERIC_SAY, GetCleanName(), buf
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// this is like the above, but the first parameter is a string id
|
||||
|
||||
@ -2620,8 +2620,16 @@ XS(XS_Mob_Message) {
|
||||
uint32 type = (uint32) SvUV(ST(1));
|
||||
char *message = (char *) SvPV_nolen(ST(2));
|
||||
VALIDATE_THIS_IS_MOB;
|
||||
|
||||
// auto inject saylinks
|
||||
if (RuleB(Chat, AutoInjectSaylinksToClientMessage)) {
|
||||
std::string new_message = EQ::SayLinkEngine::InjectSaylinksIfNotExist(message);
|
||||
THIS->Message(type, new_message.c_str());
|
||||
}
|
||||
else {
|
||||
THIS->Message(type, message);
|
||||
}
|
||||
}
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user