From 81a153da87f56e4db0a38ebb94a9c72471e0b002 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Fri, 14 Jun 2024 15:39:35 +0300 Subject: Add nearby chat listener --- indra/newview/llfloaterimnearbychatlistener.cpp | 40 ++++++++++++++++++++++ indra/newview/llfloaterimnearbychatlistener.h | 7 ++++ indra/newview/llluamanager.cpp | 2 +- indra/newview/llviewermessage.cpp | 5 +++ indra/newview/scripts/lua/LLChatListener.lua | 41 +++++++++++++++++++++++ indra/newview/scripts/lua/test_LLChatListener.lua | 27 +++++++++++++++ 6 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 indra/newview/scripts/lua/LLChatListener.lua create mode 100644 indra/newview/scripts/lua/test_LLChatListener.lua diff --git a/indra/newview/llfloaterimnearbychatlistener.cpp b/indra/newview/llfloaterimnearbychatlistener.cpp index 0618741cc4..78642bce21 100644 --- a/indra/newview/llfloaterimnearbychatlistener.cpp +++ b/indra/newview/llfloaterimnearbychatlistener.cpp @@ -33,6 +33,7 @@ #include "llagent.h" #include "llchat.h" +#include "llluamanager.h" #include "llviewercontrol.h" #include "stringize.h" @@ -49,6 +50,35 @@ LLFloaterIMNearbyChatListener::LLFloaterIMNearbyChatListener() "[\"channel\"] chat channel number [default = 0]\n" "[\"type\"] chat type \"whisper\", \"normal\", \"shout\" [default = \"normal\"]", &LLFloaterIMNearbyChatListener::sendChat); + + add("listen", + "Start listening to the Nearby chat, chat messages will be resent to the script event pump", + &LLFloaterIMNearbyChatListener::listenChat, + llsd::map("coro_name", LLSD(), "reply", LLSD())); + + add("stopListening", + "Stop listening to the Nearby chat", + &LLFloaterIMNearbyChatListener::stopListeningChat, + llsd::map("coro_name", LLSD())); + + mOutConnection = LLEventPumps::instance().obtain("LLNearbyChat").listen("LLFloaterIMNearbyChatListener", [this](const LLSD &data) + { + std::map reply_pumps = mReplyPumps; + std::map scripts = LLLUAmanager::getScriptNames(); + for (auto &it : reply_pumps) + { + //check if listener script is still running + if (scripts.find(it.first) != scripts.end()) + { + LLEventPumps::instance().obtain(it.second).post(data); + } + else + { + mReplyPumps.erase(it.first); + } + } + return false; + }); } @@ -103,3 +133,13 @@ void LLFloaterIMNearbyChatListener::sendChat(LLSD const & chat_data) gSavedSettings.getBOOL("PlayChatAnim")); } + +void LLFloaterIMNearbyChatListener::listenChat(LLSD const &chat_data) +{ + mReplyPumps[chat_data["coro_name"].asString()] = chat_data["reply"].asString(); +} + +void LLFloaterIMNearbyChatListener::stopListeningChat(LLSD const &chat_data) +{ + mReplyPumps.erase(chat_data["coro_name"].asString()); +} diff --git a/indra/newview/llfloaterimnearbychatlistener.h b/indra/newview/llfloaterimnearbychatlistener.h index 18a8bacfaa..a466db8e5f 100644 --- a/indra/newview/llfloaterimnearbychatlistener.h +++ b/indra/newview/llfloaterimnearbychatlistener.h @@ -43,7 +43,14 @@ public: private: void sendChat(LLSD const & chat_data); + void listenChat(LLSD const &chat_data); + void stopListeningChat(LLSD const &chat_data); + F64 mLastThrottleTime{ 0.0 }; + + LLTempBoundListener mOutConnection; + std::map mReplyPumps; + }; #endif // LL_LLFLOATERIMNEARBYCHATLISTENER_H diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index 97779a12ad..d8e53f3e69 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -128,7 +128,7 @@ lua_function(post_on, "post_on(pumpname, data): post specified data to specified LLSD data{ lua_tollsd(L, 2) }; lua_pop(L, 2); LL_DEBUGS("Lua") << "post_on('" << pumpname << "', " << data << ")" << LL_ENDL; - LLEventPumps::instance().obtain(pumpname).post(data); + LLEventPumps::instance().obtain(pumpname).post(data.with("coro_name", LLCoros::getName())); return 0; } diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp index 01d4695eda..26b088e390 100644 --- a/indra/newview/llviewermessage.cpp +++ b/indra/newview/llviewermessage.cpp @@ -2749,6 +2749,11 @@ void process_chat_from_simulator(LLMessageSystem *msg, void **user_data) msg_notify["from_id"] = chat.mFromID; msg_notify["source_type"] = chat.mSourceType; on_new_message(msg_notify); + + + msg_notify["chat_type"] = chat.mChatType; + msg_notify["message"] = mesg; + LLEventPumps::instance().obtain("LLNearbyChat").post(msg_notify); } } diff --git a/indra/newview/scripts/lua/LLChatListener.lua b/indra/newview/scripts/lua/LLChatListener.lua new file mode 100644 index 0000000000..d615ae5dbc --- /dev/null +++ b/indra/newview/scripts/lua/LLChatListener.lua @@ -0,0 +1,41 @@ +local fiber = require 'fiber' +local inspect = require 'inspect' + +local LLChatListener = {} +local waitfor = {} + +function LLChatListener:new() + local obj = setmetatable({}, self) + self.__index = self + obj.name = 'Chat_listener' + + return obj +end + +function LLChatListener:handleMessages(event_data) + --print(inspect(event_data)) + return true +end + +function LLChatListener:start() + waitfor = leap.WaitFor:new(-1, self.name) + function waitfor:filter(pump, data) + return data + end + + fiber.launch(self.name, function() + event = waitfor:wait() + while event and self:handleMessages(event) do + event = waitfor:wait() + end + end) + + leap.send('LLChatBar', {op='listen'}) +end + +function LLChatListener:stop() + leap.send('LLChatBar', {op='stopListening'}) + waitfor:close() +end + +return LLChatListener diff --git a/indra/newview/scripts/lua/test_LLChatListener.lua b/indra/newview/scripts/lua/test_LLChatListener.lua new file mode 100644 index 0000000000..2c7b1dc3e5 --- /dev/null +++ b/indra/newview/scripts/lua/test_LLChatListener.lua @@ -0,0 +1,27 @@ +local LLChatListener = require 'LLChatListener' +local LLChat = require 'LLChat' + +function openOrEcho(message) + local floater_name = string.match(message, "^open%s+(%w+)") + if floater_name then + leap.send("LLFloaterReg", {name = floater_name, op = "showInstance"}) + else + LLChat.sendNearby('Echo: ' .. message) + end +end + +local listener = LLChatListener:new() + +function listener:handleMessages(event_data) + if string.find(event_data.message, '[LUA]') then + return true + elseif event_data.message == 'stop' then + LLChat.sendNearby('Closing echo script.') + return false + else + openOrEcho(event_data.message) + end + return LLChatListener.handleMessages(self, event_data) +end + +listener:start() -- cgit v1.2.3 From b2d484d7258508f0f82098ff113fa636554d67b8 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Mon, 17 Jun 2024 20:05:56 +0300 Subject: Remove useless 'coro_name' info --- indra/newview/llfloaterimnearbychatlistener.cpp | 9 ++++----- indra/newview/llluamanager.cpp | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/indra/newview/llfloaterimnearbychatlistener.cpp b/indra/newview/llfloaterimnearbychatlistener.cpp index 78642bce21..e61bf5ffc2 100644 --- a/indra/newview/llfloaterimnearbychatlistener.cpp +++ b/indra/newview/llfloaterimnearbychatlistener.cpp @@ -54,12 +54,11 @@ LLFloaterIMNearbyChatListener::LLFloaterIMNearbyChatListener() add("listen", "Start listening to the Nearby chat, chat messages will be resent to the script event pump", &LLFloaterIMNearbyChatListener::listenChat, - llsd::map("coro_name", LLSD(), "reply", LLSD())); + llsd::map("reply", LLSD())); add("stopListening", "Stop listening to the Nearby chat", - &LLFloaterIMNearbyChatListener::stopListeningChat, - llsd::map("coro_name", LLSD())); + &LLFloaterIMNearbyChatListener::stopListeningChat); mOutConnection = LLEventPumps::instance().obtain("LLNearbyChat").listen("LLFloaterIMNearbyChatListener", [this](const LLSD &data) { @@ -136,10 +135,10 @@ void LLFloaterIMNearbyChatListener::sendChat(LLSD const & chat_data) void LLFloaterIMNearbyChatListener::listenChat(LLSD const &chat_data) { - mReplyPumps[chat_data["coro_name"].asString()] = chat_data["reply"].asString(); + mReplyPumps[LLCoros::getName()] = chat_data["reply"].asString(); } void LLFloaterIMNearbyChatListener::stopListeningChat(LLSD const &chat_data) { - mReplyPumps.erase(chat_data["coro_name"].asString()); + mReplyPumps.erase(LLCoros::getName()); } diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index d8e53f3e69..97779a12ad 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -128,7 +128,7 @@ lua_function(post_on, "post_on(pumpname, data): post specified data to specified LLSD data{ lua_tollsd(L, 2) }; lua_pop(L, 2); LL_DEBUGS("Lua") << "post_on('" << pumpname << "', " << data << ")" << LL_ENDL; - LLEventPumps::instance().obtain(pumpname).post(data.with("coro_name", LLCoros::getName())); + LLEventPumps::instance().obtain(pumpname).post(data); return 0; } -- cgit v1.2.3 From 09b814a2dc6d3a647d75bcf0a310eba2678a0228 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Thu, 20 Jun 2024 00:42:25 +0300 Subject: Use LLLeapListener to listen to LLNearbyChat pump --- indra/newview/llfloaterimnearbychatlistener.cpp | 39 ----------------------- indra/newview/llfloaterimnearbychatlistener.h | 7 ---- indra/newview/scripts/lua/LLChatListener.lua | 12 ++++--- indra/newview/scripts/lua/test_LLChatListener.lua | 3 +- 4 files changed, 10 insertions(+), 51 deletions(-) diff --git a/indra/newview/llfloaterimnearbychatlistener.cpp b/indra/newview/llfloaterimnearbychatlistener.cpp index e61bf5ffc2..0618741cc4 100644 --- a/indra/newview/llfloaterimnearbychatlistener.cpp +++ b/indra/newview/llfloaterimnearbychatlistener.cpp @@ -33,7 +33,6 @@ #include "llagent.h" #include "llchat.h" -#include "llluamanager.h" #include "llviewercontrol.h" #include "stringize.h" @@ -50,34 +49,6 @@ LLFloaterIMNearbyChatListener::LLFloaterIMNearbyChatListener() "[\"channel\"] chat channel number [default = 0]\n" "[\"type\"] chat type \"whisper\", \"normal\", \"shout\" [default = \"normal\"]", &LLFloaterIMNearbyChatListener::sendChat); - - add("listen", - "Start listening to the Nearby chat, chat messages will be resent to the script event pump", - &LLFloaterIMNearbyChatListener::listenChat, - llsd::map("reply", LLSD())); - - add("stopListening", - "Stop listening to the Nearby chat", - &LLFloaterIMNearbyChatListener::stopListeningChat); - - mOutConnection = LLEventPumps::instance().obtain("LLNearbyChat").listen("LLFloaterIMNearbyChatListener", [this](const LLSD &data) - { - std::map reply_pumps = mReplyPumps; - std::map scripts = LLLUAmanager::getScriptNames(); - for (auto &it : reply_pumps) - { - //check if listener script is still running - if (scripts.find(it.first) != scripts.end()) - { - LLEventPumps::instance().obtain(it.second).post(data); - } - else - { - mReplyPumps.erase(it.first); - } - } - return false; - }); } @@ -132,13 +103,3 @@ void LLFloaterIMNearbyChatListener::sendChat(LLSD const & chat_data) gSavedSettings.getBOOL("PlayChatAnim")); } - -void LLFloaterIMNearbyChatListener::listenChat(LLSD const &chat_data) -{ - mReplyPumps[LLCoros::getName()] = chat_data["reply"].asString(); -} - -void LLFloaterIMNearbyChatListener::stopListeningChat(LLSD const &chat_data) -{ - mReplyPumps.erase(LLCoros::getName()); -} diff --git a/indra/newview/llfloaterimnearbychatlistener.h b/indra/newview/llfloaterimnearbychatlistener.h index a466db8e5f..18a8bacfaa 100644 --- a/indra/newview/llfloaterimnearbychatlistener.h +++ b/indra/newview/llfloaterimnearbychatlistener.h @@ -43,14 +43,7 @@ public: private: void sendChat(LLSD const & chat_data); - void listenChat(LLSD const &chat_data); - void stopListeningChat(LLSD const &chat_data); - F64 mLastThrottleTime{ 0.0 }; - - LLTempBoundListener mOutConnection; - std::map mReplyPumps; - }; #endif // LL_LLFLOATERIMNEARBYCHATLISTENER_H diff --git a/indra/newview/scripts/lua/LLChatListener.lua b/indra/newview/scripts/lua/LLChatListener.lua index d615ae5dbc..b4e90d272c 100644 --- a/indra/newview/scripts/lua/LLChatListener.lua +++ b/indra/newview/scripts/lua/LLChatListener.lua @@ -1,8 +1,10 @@ local fiber = require 'fiber' local inspect = require 'inspect' +local leap = require 'leap' local LLChatListener = {} local waitfor = {} +local listener_name = {} function LLChatListener:new() local obj = setmetatable({}, self) @@ -13,14 +15,16 @@ function LLChatListener:new() end function LLChatListener:handleMessages(event_data) - --print(inspect(event_data)) + print(inspect(event_data)) return true end function LLChatListener:start() waitfor = leap.WaitFor:new(-1, self.name) function waitfor:filter(pump, data) - return data + if pump == "LLNearbyChat" then + return data + end end fiber.launch(self.name, function() @@ -30,11 +34,11 @@ function LLChatListener:start() end end) - leap.send('LLChatBar', {op='listen'}) + listener_name = leap.request(leap.cmdpump(), {op='listen', source='LLNearbyChat', listener="ChatListener", tweak=true}).listener end function LLChatListener:stop() - leap.send('LLChatBar', {op='stopListening'}) + leap.send(leap.cmdpump(), {op='stoplistening', source='LLNearbyChat', listener=listener_name}) waitfor:close() end diff --git a/indra/newview/scripts/lua/test_LLChatListener.lua b/indra/newview/scripts/lua/test_LLChatListener.lua index 2c7b1dc3e5..b9696e7cfc 100644 --- a/indra/newview/scripts/lua/test_LLChatListener.lua +++ b/indra/newview/scripts/lua/test_LLChatListener.lua @@ -1,5 +1,6 @@ local LLChatListener = require 'LLChatListener' local LLChat = require 'LLChat' +local leap = require 'leap' function openOrEcho(message) local floater_name = string.match(message, "^open%s+(%w+)") @@ -21,7 +22,7 @@ function listener:handleMessages(event_data) else openOrEcho(event_data.message) end - return LLChatListener.handleMessages(self, event_data) + return true end listener:start() -- cgit v1.2.3