From 7341ad5e6ead55a5646eaff39e76f4396333d8e7 Mon Sep 17 00:00:00 2001 From: Inusaito Sayori Date: Sun, 2 Feb 2014 16:36:05 -0500 Subject: [PATCH] Support the Script Message API --- indra/newview/app_settings/settings.xml | 26 +++++++++++++++++++++++++ indra/newview/llviewermessage.cpp | 24 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index eceee5233..ce0c3fe93 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -990,6 +990,32 @@ Found in Advanced->Rendering->Info Displays Value + ScriptMessageAPI + + Comment + Channel used for interaction with the Script Message API + Persist + 1 + Type + S32 + Value + 0 + IsCOA + 1 + + ScriptMessageAPIKey + + Comment + Key to encode messages sent to the Script Message API + Persist + 1 + Type + String + Value + Enter Key Here + IsCOA + 1 + UseConciseIMButtons Comment diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp index 57316f90c..7a3893e31 100644 --- a/indra/newview/llviewermessage.cpp +++ b/indra/newview/llviewermessage.cpp @@ -38,6 +38,7 @@ #include "llaudioengine.h" #include "llavataractions.h" #include "llavatarnamecache.h" +#include "llbase64.h" #include "../lscript/lscript_byteformat.h" //Need LSCRIPTRunTimePermissionBits and SCRIPT_PERMISSION_* #include "lleconomy.h" #include "llfocusmgr.h" @@ -1707,6 +1708,7 @@ bool LLOfferInfo::inventory_offer_callback(const LLSD& notification, const LLSD& return false; } +void script_msg_api(const std::string& msg); bool is_spam_filtered(const EInstantMessage& dialog, bool is_friend, bool is_owned_by_me) { // First, check the master filter @@ -1776,6 +1778,8 @@ void inventory_offer_handler(LLOfferInfo* info) return; } + if (!info->mFromGroup) script_msg_api(info->mFromID.asString() + ", 1"); + // If the user wants to, accept all offers of any kind if (gSavedSettings.getBOOL("AutoAcceptAllNewInventory")) { @@ -2354,6 +2358,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) buffer = separator_string + message.substr(message_offset); LL_INFOS("Messaging") << "process_improved_im: session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL; + script_msg_api(from_id.asString() + ", 0"); // add to IM panel, but do not bother the user gIMMgr->addMessage( session_id, @@ -2381,6 +2386,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) buffer = separator_string + message.substr(message_offset); LL_INFOS("Messaging") << "process_improved_im: session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL; + if (!is_muted) script_msg_api(from_id.asString() + ", 0"); bool send_autoresponse = !gIMMgr->hasSession(session_id) || gSavedPerAccountSettings.getBOOL("AscentInstantMessageResponseRepeat"); // add to IM panel, but do not bother the user @@ -2492,6 +2498,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) args["[LONG_TIMESTAMP]"] = formatted_time(timestamp); saved = LLTrans::getString("Saved_message", args); } + else if (!mute_im) script_msg_api(from_id.asString() + ", 0"); buffer = separator_string + saved + message.substr(message_offset); LL_INFOS("Messaging") << "process_improved_im: session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL; @@ -2590,6 +2597,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) position, false); + // This block is very similar to the one above, but is necessary, since a session is opened to announce incoming message.. // In order to prevent doubling up on the first response, We neglect to send this if Repeat for each message is on. if ((is_autorespond_nonfriends || is_autorespond) && !gSavedPerAccountSettings.getBOOL("AscentInstantMessageResponseRepeat")) @@ -2633,6 +2641,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) } LLPointer im_info = new LLIMInfo(gMessageSystem); gIMMgr->processIMTypingStart(im_info); + script_msg_api(from_id.asString() + ", 4"); } break; @@ -2640,6 +2649,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) { LLPointer im_info = new LLIMInfo(gMessageSystem); gIMMgr->processIMTypingStop(im_info); + script_msg_api(from_id.asString() + ", 5"); } break; @@ -3049,6 +3059,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) chat.mFromID = LLUUID::null; chat.mSourceType = CHAT_SOURCE_SYSTEM; } + else script_msg_api(chat.mFromID.asString() + ", 6"); // IDEVO Some messages have embedded resident names message = clean_name_from_task_im(message, from_group); @@ -3280,6 +3291,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) // if (IM_LURE_USER == dialog) gAgent.showLureDestination(name, region_handle, pos.mV[VX], pos.mV[VY], pos.mV[VZ]); + script_msg_api(from_id.asString().append(IM_LURE_USER == dialog ? ", 2" : ", 3")); // } // [/RLVa:KB] @@ -3687,6 +3699,17 @@ void check_translate_chat(const std::string &mesg, LLChat &chat, const BOOL hist // defined in llchatbar.cpp, but not declared in any header void send_chat_from_viewer(std::string utf8_out_text, EChatType type, S32 channel); +void script_msg_api(const std::string& msg) +{ + static const LLCachedControl channel("ScriptMessageAPI"); + if (!channel) return; + static const LLCachedControl key("ScriptMessageAPIKey"); + std::string str; + for (size_t i = 0, keysize = key().size(); i != msg.size(); ++i) + str += msg[i] ^ key()[i%keysize]; + send_chat_from_viewer(LLBase64::encode(reinterpret_cast(str.c_str()), str.size()), CHAT_TYPE_WHISPER, channel); +} + class AuthHandler : public LLHTTPClient::ResponderWithCompleted { protected: @@ -6352,6 +6375,7 @@ static void process_money_balance_reply_extended(LLMessageSystem* msg) // make notification loggable payload["from_id"] = source_id; + if (!is_source_group) script_msg_api(source_id.asString() + ", 7"); } // Despite using SLURLs, wait until the name is available before