diff options
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llviewermessage.cpp | 5 | ||||
-rw-r--r-- | indra/newview/scripts/lua/LLChatListener.lua | 45 | ||||
-rw-r--r-- | indra/newview/scripts/lua/test_LLChatListener.lua | 28 |
3 files changed, 78 insertions, 0 deletions
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..b4e90d272c --- /dev/null +++ b/indra/newview/scripts/lua/LLChatListener.lua @@ -0,0 +1,45 @@ +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) + 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) + if pump == "LLNearbyChat" then + return data + end + end + + fiber.launch(self.name, function() + event = waitfor:wait() + while event and self:handleMessages(event) do + event = waitfor:wait() + end + end) + + listener_name = leap.request(leap.cmdpump(), {op='listen', source='LLNearbyChat', listener="ChatListener", tweak=true}).listener +end + +function LLChatListener:stop() + leap.send(leap.cmdpump(), {op='stoplistening', source='LLNearbyChat', listener=listener_name}) + 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..b9696e7cfc --- /dev/null +++ b/indra/newview/scripts/lua/test_LLChatListener.lua @@ -0,0 +1,28 @@ +local LLChatListener = require 'LLChatListener' +local LLChat = require 'LLChat' +local leap = require 'leap' + +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 true +end + +listener:start() |