summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMnikolenko Productengine <mnikolenko@productengine.com>2024-05-22 21:03:45 +0300
committerMnikolenko Productengine <mnikolenko@productengine.com>2024-05-22 21:03:45 +0300
commit85664b011e37c6c9926924f6fb72ceeb10d07833 (patch)
treea0706f10a1a982f5dad823cd79e5c69f95facb46
parent0f00dc2f658869cc73a18b03b024a6cc88964e0b (diff)
add throttle for sending messages; add simple demo script
-rw-r--r--indra/newview/llfloaterimnearbychatlistener.cpp11
-rw-r--r--indra/newview/scripts/lua/test_LLChat.lua18
2 files changed, 29 insertions, 0 deletions
diff --git a/indra/newview/llfloaterimnearbychatlistener.cpp b/indra/newview/llfloaterimnearbychatlistener.cpp
index d6dfe42639..e8fb510111 100644
--- a/indra/newview/llfloaterimnearbychatlistener.cpp
+++ b/indra/newview/llfloaterimnearbychatlistener.cpp
@@ -35,6 +35,7 @@
#include "llchat.h"
#include "llviewercontrol.h"
+static const F32 CHAT_THROTTLE_PERIOD = 1.f;
LLFloaterIMNearbyChatListener::LLFloaterIMNearbyChatListener()
: LLEventAPI("LLChatBar",
@@ -52,6 +53,16 @@ LLFloaterIMNearbyChatListener::LLFloaterIMNearbyChatListener()
// "sendChat" command
void LLFloaterIMNearbyChatListener::sendChat(LLSD const & chat_data) const
{
+ static F64 last_throttle_time = 0.0;
+ F64 cur_time = LLTimer::getElapsedSeconds();
+
+ if (cur_time < last_throttle_time + CHAT_THROTTLE_PERIOD)
+ {
+ LL_DEBUGS("LLFloaterIMNearbyChatListener") << "'sendChat' was throttled" << LL_ENDL;
+ return;
+ }
+ last_throttle_time = cur_time;
+
// Extract the data
std::string chat_text = LUA_PREFIX + chat_data["message"].asString();
diff --git a/indra/newview/scripts/lua/test_LLChat.lua b/indra/newview/scripts/lua/test_LLChat.lua
new file mode 100644
index 0000000000..95bd218baa
--- /dev/null
+++ b/indra/newview/scripts/lua/test_LLChat.lua
@@ -0,0 +1,18 @@
+LLChat = require 'LLChat'
+
+function generateRandomWord(length)
+ local alphabet = "abcdefghijklmnopqrstuvwxyz"
+ local word = ""
+ for i = 1, length do
+ local randomIndex = math.random(1, #alphabet)
+ word = word .. alphabet:sub(randomIndex, randomIndex)
+ end
+ return word
+end
+
+local msg = ""
+math.randomseed(os.time())
+for i = 1, math.random(1, 10) do
+ msg = msg .. " ".. generateRandomWord(math.random(1, 8))
+end
+LLChat.sendNearby(msg)