From 7c4a1f326716144b1d1bebfd152a41946212667b Mon Sep 17 00:00:00 2001 From: IconPippi Date: Thu, 27 Apr 2023 16:19:59 +0200 Subject: [PATCH] Add max topic length constraint --- plugin/init.server.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugin/init.server.lua b/plugin/init.server.lua index f5ea34b..64f6855 100644 --- a/plugin/init.server.lua +++ b/plugin/init.server.lua @@ -88,10 +88,16 @@ local Constraints = { max = (100 + 50 * _serverCount()) / 60, count = 0, lastTime = os.time() - } + }, + maxTopicLength = 80 } publishRequest.Event:Connect(function (topic: string, message) + -- check if topic length exceeds 80 chars + if string.len(topic) > Constraints.maxTopicLength then + error("Topic length exceeds 80 characters") + end + -- check if message size exceeds 1kB if string.len(tostring(message)) > 1024 then error("Message size exceeds 1kB") @@ -111,6 +117,11 @@ publishRequest.Event:Connect(function (topic: string, message) end) subscribeRequest.Event:Connect(function (topic: string) + -- check if topic length exceeds 80 chars + if string.len(topic) > Constraints.maxTopicLength then + error("Topic length exceeds 80 characters") + end + -- check if already subscribed to topic if subscribedTopics[topic] ~= nil then return end @@ -151,7 +162,7 @@ game:GetService("RunService").Heartbeat:Connect(function() end end) --- Unloading +-- ################## Unloading ################## plugin.Unloading:Connect(function() plugin:SetSetting("_serverCount", _serverCount() - 1)