mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-29 00:02:50 +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, 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, 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_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_END()
|
||||||
|
|
||||||
RULE_CATEGORY(Merchant)
|
RULE_CATEGORY(Merchant)
|
||||||
|
|||||||
@ -340,3 +340,47 @@ std::string EQ::SayLinkEngine::GenerateQuestSaylink(std::string saylink_text, bo
|
|||||||
|
|
||||||
return linker.GenerateLink();
|
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();
|
void Reset();
|
||||||
|
|
||||||
|
static std::string InjectSaylinksIfNotExist(const char *message);
|
||||||
private:
|
private:
|
||||||
void generate_body();
|
void generate_body();
|
||||||
void generate_text();
|
void generate_text();
|
||||||
|
|||||||
@ -4185,8 +4185,10 @@ bool Entity::CheckCoordLosNoZLeaps(float cur_x, float cur_y, float cur_z,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityList::QuestJournalledSayClose(Mob *sender, float dist, const char *mobname, const char *message,
|
void EntityList::QuestJournalledSayClose(
|
||||||
Journal::Options &opts)
|
Mob *sender, float dist, const char *mobname, const char *message,
|
||||||
|
Journal::Options &opts
|
||||||
|
)
|
||||||
{
|
{
|
||||||
SerializeBuffer buf(sizeof(SpecialMesgHeader_Struct) + 12 + 64 + 64);
|
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); // location, client doesn't seem to do anything with this
|
||||||
buf.WriteInt32(0);
|
buf.WriteInt32(0);
|
||||||
buf.WriteInt32(0);
|
buf.WriteInt32(0);
|
||||||
buf.WriteString(message);
|
|
||||||
|
// 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);
|
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
|
||||||
|
|
||||||
|
|||||||
@ -755,7 +755,15 @@ double Lua_Mob::GetSize() {
|
|||||||
|
|
||||||
void Lua_Mob::Message(int type, const char *message) {
|
void Lua_Mob::Message(int type, const char *message) {
|
||||||
Lua_Safe_Call_Void();
|
Lua_Safe_Call_Void();
|
||||||
self->Message(type, message);
|
|
||||||
|
// 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) {
|
void Lua_Mob::MessageString(int type, int string_id, uint32 distance) {
|
||||||
|
|||||||
17
zone/mob.cpp
17
zone/mob.cpp
@ -2923,10 +2923,19 @@ void Mob::Say(const char *format, ...)
|
|||||||
talker = this;
|
talker = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_list.MessageCloseString(
|
if (RuleB(Chat, AutoInjectSaylinksToSay)) {
|
||||||
talker, false, 200, 10,
|
std::string new_message = EQ::SayLinkEngine::InjectSaylinksIfNotExist(buf);
|
||||||
GENERIC_SAY, GetCleanName(), 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
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@ -2620,7 +2620,15 @@ XS(XS_Mob_Message) {
|
|||||||
uint32 type = (uint32) SvUV(ST(1));
|
uint32 type = (uint32) SvUV(ST(1));
|
||||||
char *message = (char *) SvPV_nolen(ST(2));
|
char *message = (char *) SvPV_nolen(ST(2));
|
||||||
VALIDATE_THIS_IS_MOB;
|
VALIDATE_THIS_IS_MOB;
|
||||||
THIS->Message(type, message);
|
|
||||||
|
// 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;
|
XSRETURN_EMPTY;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user