From 4f7eb9b12e9c7eeb9f3ee0980bd4616df7d678b6 Mon Sep 17 00:00:00 2001 From: Kitty Barnett Date: Mon, 2 Sep 2024 01:57:34 +0200 Subject: Add the @getcommand command query reply command --- indra/newview/rlvcommon.cpp | 9 +++++++++ indra/newview/rlvcommon.h | 3 +++ indra/newview/rlvdefines.h | 2 ++ indra/newview/rlvhandler.cpp | 31 +++++++++++++++++++++++++++++++ indra/newview/rlvhelper.cpp | 1 + 5 files changed, 46 insertions(+) diff --git a/indra/newview/rlvcommon.cpp b/indra/newview/rlvcommon.cpp index 898df3af42..eda2cdedc8 100644 --- a/indra/newview/rlvcommon.cpp +++ b/indra/newview/rlvcommon.cpp @@ -9,6 +9,8 @@ #include "rlvdefines.h" #include "rlvcommon.h" +#include + using namespace Rlv; // ============================================================================ @@ -46,6 +48,13 @@ std::string Strings::getVersionImplNum() // RlvUtil // +bool Util::parseStringList(const std::string& strInput, std::vector& optionList, std::string_view strSeparator) +{ + if (!strInput.empty()) + boost::split(optionList, strInput, boost::is_any_of(strSeparator)); + return !optionList.empty(); +} + bool Util::sendChatReply(S32 nChannel, const std::string& strUTF8Text) { if (!isValidReplyChannel(nChannel)) diff --git a/indra/newview/rlvcommon.h b/indra/newview/rlvcommon.h index 79ac6e1704..bec3e23e11 100644 --- a/indra/newview/rlvcommon.h +++ b/indra/newview/rlvcommon.h @@ -1,5 +1,7 @@ #pragma once +#include "rlvdefines.h" + namespace Rlv { // ============================================================================ @@ -22,6 +24,7 @@ namespace Rlv namespace Util { bool isValidReplyChannel(S32 nChannel, bool isLoopback = false); + bool parseStringList(const std::string& strInput, std::vector& optionList, std::string_view strSeparator = Constants::OptionSeparator); bool sendChatReply(S32 nChannel, const std::string& strUTF8Text); bool sendChatReply(const std::string& strChannel, const std::string& strUTF8Text); }; diff --git a/indra/newview/rlvdefines.h b/indra/newview/rlvdefines.h index 0459b59483..c36512007b 100644 --- a/indra/newview/rlvdefines.h +++ b/indra/newview/rlvdefines.h @@ -52,6 +52,7 @@ namespace Rlv namespace Constants { constexpr char CmdPrefix = '@'; + constexpr std::string_view OptionSeparator = ";"; } } @@ -65,6 +66,7 @@ namespace Rlv Version = 0, VersionNew, VersionNum, + GetCommand, Count, Unknown, diff --git a/indra/newview/rlvhandler.cpp b/indra/newview/rlvhandler.cpp index 3d7f73937f..8b2620cf48 100644 --- a/indra/newview/rlvhandler.cpp +++ b/indra/newview/rlvhandler.cpp @@ -9,6 +9,8 @@ #include "rlvhandler.h" #include "rlvhelper.h" +#include + using namespace Rlv; // ============================================================================ @@ -143,6 +145,35 @@ ECmdRet CommandHandlerBaseImpl::processCommand(const RlvComma return eRet; } +// Handles: @getcommand[:[;[;]]]= +template<> template<> +ECmdRet ReplyHandler::onCommand(const RlvCommand& rlvCmd, std::string& strReply) +{ + std::vector optionList; + Util::parseStringList(rlvCmd.getOption(), optionList); + + // If a second parameter is present it'll specify the command type + EParamType eType = EParamType::Unknown; + if (optionList.size() >= 2) + { + if (optionList[1] == "any" || optionList[1].empty()) + eType = EParamType::Unknown; + else if (optionList[1] == "add") + eType = EParamType::AddRem; + else if (optionList[1] == "force") + eType = EParamType::Force; + else if (optionList[1] == "reply") + eType = EParamType::Reply; + else + return ECmdRet::FailedOption; + } + + std::list cmdList; + if (BehaviourDictionary::instance().getCommands(!optionList.empty() ? optionList[0] : LLStringUtil::null, eType, cmdList)) + strReply = boost::algorithm::join(cmdList, optionList.size() >= 3 ? optionList[2] : Constants::OptionSeparator); + return ECmdRet::Success; +} + // Handles: @version= and @versionnew= template<> template<> ECmdRet VersionReplyHandler::onCommand(const RlvCommand& rlvCmd, std::string& strReply) diff --git a/indra/newview/rlvhelper.cpp b/indra/newview/rlvhelper.cpp index c3f9e6f756..aad615d813 100644 --- a/indra/newview/rlvhelper.cpp +++ b/indra/newview/rlvhelper.cpp @@ -22,6 +22,7 @@ BehaviourDictionary::BehaviourDictionary() // // Reply-only // + addEntry(new ReplyProcessor("getcommand")); addEntry(new ReplyProcessor("version")); addEntry(new ReplyProcessor("versionnew")); addEntry(new ReplyProcessor("versionnum")); -- cgit v1.2.3