summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorMnikolenko Productengine <mnikolenko@productengine.com>2024-06-14 15:39:35 +0300
committerMnikolenko Productengine <mnikolenko@productengine.com>2024-06-14 15:42:43 +0300
commit81a153da87f56e4db0a38ebb94a9c72471e0b002 (patch)
tree6004bb34dd1b8ef25ab0b63257749b038b86ea5d /indra
parente92689063bdbe34907348a12f1db39bc81132783 (diff)
Add nearby chat listener
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/llfloaterimnearbychatlistener.cpp40
-rw-r--r--indra/newview/llfloaterimnearbychatlistener.h7
-rw-r--r--indra/newview/llluamanager.cpp2
-rw-r--r--indra/newview/llviewermessage.cpp5
-rw-r--r--indra/newview/scripts/lua/LLChatListener.lua41
-rw-r--r--indra/newview/scripts/lua/test_LLChatListener.lua27
6 files changed, 121 insertions, 1 deletions
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<std::string, std::string> reply_pumps = mReplyPumps;
+ std::map<std::string, std::string> 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<std::string, std::string> 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()