Advertisement
Guest User

Roblox Server-Sided Script Execution Vulnerability

a guest
Jan 4th, 2018
16,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.45 KB | None | 0 0
  1. -- // FileName: ChatMain.lua
  2. -- // Written by: Xsitsu
  3. -- // Edited by: NystProxy / TeamCitex, bitch.
  4. -- // Description: Main module to handle initializing chat window UI and hooking up events to individual UI pieces.
  5. -- // Vulnerability edit by TeamCitex / NystProxy.
  6. -- // This is how you fuck with Roblox.
  7.  
  8. local moduleApiTable = {}
  9. local scriptExecution = {}
  10.  
  11. --// This section of code waits until all of the necessary RemoteEvents are found in EventFolder.
  12. --// I have to do some weird stuff since people could potentially already have pre-existing
  13. --// things in a folder with the same name, and they may have different class types.
  14. --// I do the useEvents thing and set EventFolder to useEvents so I can have a pseudo folder that
  15. --// the rest of the code can interface with and have the guarantee that the RemoteEvents they want
  16. --// exist with their desired names.
  17.  
  18. local FILTER_MESSAGE_TIMEOUT = 60
  19.  
  20. local RunService = game:GetService("RunService")
  21. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  22. local Chat = game:GetService("Chat")
  23. local StarterGui = game:GetService("StarterGui")
  24.  
  25. local DefaultChatSystemChatEvents = ReplicatedStorage:WaitForChild("DefaultChatSystemChatEvents")
  26. local EventFolder = ReplicatedStorage:WaitForChild("DefaultChatSystemChatEvents")
  27. local clientChatModules = Chat:WaitForChild("ClientChatModules")
  28. local ChatConstants = require(clientChatModules:WaitForChild("ChatConstants"))
  29. local ChatSettings = require(clientChatModules:WaitForChild("ChatSettings"))
  30. local messageCreatorModules = clientChatModules:WaitForChild("MessageCreatorModules")
  31. local MessageCreatorUtil = require(messageCreatorModules:WaitForChild("Util"))
  32.  
  33. local ChatLocalization = nil
  34. pcall(function() ChatLocalization = require(game:GetService("Chat").ClientChatModules.ChatLocalization) end)
  35. if ChatLocalization == nil then ChatLocalization = {} function ChatLocalization:Get(key,default) return default end end
  36.  
  37. local numChildrenRemaining = 10 -- #waitChildren returns 0 because it's a dictionary
  38. local waitChildren =
  39. {
  40. OnNewMessage = "RemoteEvent",
  41. OnMessageDoneFiltering = "RemoteEvent",
  42. OnNewSystemMessage = "RemoteEvent",
  43. OnChannelJoined = "RemoteEvent",
  44. OnChannelLeft = "RemoteEvent",
  45. OnMuted = "RemoteEvent",
  46. OnUnmuted = "RemoteEvent",
  47. OnMainChannelSet = "RemoteEvent",
  48.  
  49. SayMessageRequest = "RemoteEvent",
  50. GetInitDataRequest = "RemoteFunction",
  51. }
  52. -- waitChildren/EventFolder does not contain all the remote events, because the server version could be older than the client version.
  53. -- In that case it would not create the new events.
  54. -- These events are accessed directly from DefaultChatSystemChatEvents
  55.  
  56. local useEvents = {}
  57.  
  58. local FoundAllEventsEvent = Instance.new("BindableEvent")
  59.  
  60. function TryRemoveChildWithVerifyingIsCorrectType(child)
  61. if (waitChildren[child.Name] and child:IsA(waitChildren[child.Name])) then
  62. waitChildren[child.Name] = nil
  63. useEvents[child.Name] = child
  64. numChildrenRemaining = numChildrenRemaining - 1
  65. end
  66. end
  67.  
  68. for i, child in pairs(EventFolder:GetChildren()) do
  69. TryRemoveChildWithVerifyingIsCorrectType(child)
  70. end
  71.  
  72. if (numChildrenRemaining > 0) then
  73. local con = EventFolder.ChildAdded:connect(function(child)
  74. TryRemoveChildWithVerifyingIsCorrectType(child)
  75. if (numChildrenRemaining < 1) then
  76. FoundAllEventsEvent:Fire()
  77. end
  78. end)
  79.  
  80. FoundAllEventsEvent.Event:wait()
  81. con:disconnect()
  82.  
  83. FoundAllEventsEvent:Destroy()
  84. end
  85.  
  86. EventFolder = useEvents
  87.  
  88.  
  89.  
  90. --// Rest of code after waiting for correct events.
  91.  
  92. local UserInputService = game:GetService("UserInputService")
  93. local RunService = game:GetService("RunService")
  94.  
  95. local Players = game:GetService("Players")
  96. local LocalPlayer = Players.LocalPlayer
  97.  
  98. while not LocalPlayer do
  99. Players.ChildAdded:wait()
  100. LocalPlayer = Players.LocalPlayer
  101. end
  102.  
  103. local canChat = true
  104.  
  105. local ChatDisplayOrder = 6
  106. if ChatSettings.ScreenGuiDisplayOrder ~= nil then
  107. ChatDisplayOrder = ChatSettings.ScreenGuiDisplayOrder
  108. end
  109.  
  110. local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
  111. local GuiParent = Instance.new("ScreenGui")
  112. GuiParent.Name = "Chat"
  113. GuiParent.ResetOnSpawn = false
  114. GuiParent.DisplayOrder = ChatDisplayOrder
  115. GuiParent.Parent = PlayerGui
  116.  
  117. local DidFirstChannelsLoads = false
  118.  
  119. local modulesFolder = script
  120.  
  121. local moduleChatWindow = require(modulesFolder:WaitForChild("ChatWindow"))
  122. local moduleChatBar = require(modulesFolder:WaitForChild("ChatBar"))
  123. local moduleChannelsBar = require(modulesFolder:WaitForChild("ChannelsBar"))
  124. local moduleMessageLabelCreator = require(modulesFolder:WaitForChild("MessageLabelCreator"))
  125. local moduleMessageLogDisplay = require(modulesFolder:WaitForChild("MessageLogDisplay"))
  126. local moduleChatChannel = require(modulesFolder:WaitForChild("ChatChannel"))
  127. local moduleCommandProcessor = require(modulesFolder:WaitForChild("CommandProcessor"))
  128.  
  129. local ChatWindow = moduleChatWindow.new()
  130. local ChannelsBar = moduleChannelsBar.new()
  131. local MessageLogDisplay = moduleMessageLogDisplay.new()
  132. local CommandProcessor = moduleCommandProcessor.new()
  133. local ChatBar = moduleChatBar.new(CommandProcessor, ChatWindow)
  134.  
  135. ChatWindow:CreateGuiObjects(GuiParent)
  136.  
  137. ChatWindow:RegisterChatBar(ChatBar)
  138. ChatWindow:RegisterChannelsBar(ChannelsBar)
  139. ChatWindow:RegisterMessageLogDisplay(MessageLogDisplay)
  140.  
  141. MessageCreatorUtil:RegisterChatWindow(ChatWindow)
  142.  
  143. local MessageSender = require(modulesFolder:WaitForChild("MessageSender"))
  144. MessageSender:RegisterSayMessageFunction(EventFolder.SayMessageRequest)
  145.  
  146.  
  147.  
  148. if (UserInputService.TouchEnabled) then
  149. ChatBar:SetTextLabelText(ChatLocalization:Get("GameChat_ChatMain_ChatBarText",'Tap here to chat'))
  150. else
  151. ChatBar:SetTextLabelText(ChatLocalization:Get("GameChat_ChatMain_ChatBarTextTouch",'To chat click here or press "/" key'))
  152. end
  153.  
  154. spawn(function()
  155. local CurveUtil = require(modulesFolder:WaitForChild("CurveUtil"))
  156. local animationFps = ChatSettings.ChatAnimationFPS or 20.0
  157.  
  158. local updateWaitTime = 1.0 / animationFps
  159. local lastTick = tick()
  160. while true do
  161. local currentTick = tick()
  162. local tickDelta = currentTick - lastTick
  163. local dtScale = CurveUtil:DeltaTimeToTimescale(tickDelta)
  164.  
  165. if dtScale ~= 0 then
  166. ChatWindow:Update(dtScale)
  167. end
  168.  
  169. lastTick = currentTick
  170. wait(updateWaitTime)
  171. end
  172. end)
  173.  
  174.  
  175.  
  176.  
  177. --////////////////////////////////////////////////////////////////////////////////////////////
  178. --////////////////////////////////////////////////////////////// Code to do chat window fading
  179. --////////////////////////////////////////////////////////////////////////////////////////////
  180. function CheckIfPointIsInSquare(checkPos, topLeft, bottomRight)
  181. return (topLeft.X <= checkPos.X and checkPos.X <= bottomRight.X and
  182. topLeft.Y <= checkPos.Y and checkPos.Y <= bottomRight.Y)
  183. end
  184.  
  185. local backgroundIsFaded = false
  186. local textIsFaded = false
  187. local lastTextFadeTime = 0
  188. local lastBackgroundFadeTime = 0
  189.  
  190. local fadedChanged = Instance.new("BindableEvent")
  191. local mouseStateChanged = Instance.new("BindableEvent")
  192. local chatBarFocusChanged = Instance.new("BindableEvent")
  193.  
  194. function DoBackgroundFadeIn(setFadingTime)
  195. lastBackgroundFadeTime = tick()
  196. backgroundIsFaded = false
  197. fadedChanged:Fire()
  198. ChatWindow:FadeInBackground((setFadingTime or ChatSettings.ChatDefaultFadeDuration))
  199.  
  200. local currentChannelObject = ChatWindow:GetCurrentChannel()
  201. if (currentChannelObject) then
  202.  
  203. local Scroller = MessageLogDisplay.Scroller
  204. Scroller.ScrollingEnabled = true
  205. Scroller.ScrollBarThickness = moduleMessageLogDisplay.ScrollBarThickness
  206. end
  207. end
  208.  
  209. function DoBackgroundFadeOut(setFadingTime)
  210. lastBackgroundFadeTime = tick()
  211. backgroundIsFaded = true
  212. fadedChanged:Fire()
  213. ChatWindow:FadeOutBackground((setFadingTime or ChatSettings.ChatDefaultFadeDuration))
  214.  
  215. local currentChannelObject = ChatWindow:GetCurrentChannel()
  216. if (currentChannelObject) then
  217.  
  218. local Scroller = MessageLogDisplay.Scroller
  219. Scroller.ScrollingEnabled = false
  220. Scroller.ScrollBarThickness = 0
  221. end
  222. end
  223.  
  224. function DoTextFadeIn(setFadingTime)
  225. lastTextFadeTime = tick()
  226. textIsFaded = false
  227. fadedChanged:Fire()
  228. ChatWindow:FadeInText((setFadingTime or ChatSettings.ChatDefaultFadeDuration) * 0)
  229. end
  230.  
  231. function DoTextFadeOut(setFadingTime)
  232. lastTextFadeTime = tick()
  233. textIsFaded = true
  234. fadedChanged:Fire()
  235. ChatWindow:FadeOutText((setFadingTime or ChatSettings.ChatDefaultFadeDuration))
  236. end
  237.  
  238. function DoFadeInFromNewInformation()
  239. DoTextFadeIn()
  240. if ChatSettings.ChatShouldFadeInFromNewInformation then
  241. DoBackgroundFadeIn()
  242. end
  243. end
  244.  
  245. function InstantFadeIn()
  246. DoBackgroundFadeIn(0)
  247. DoTextFadeIn(0)
  248. end
  249.  
  250. function InstantFadeOut()
  251. DoBackgroundFadeOut(0)
  252. DoTextFadeOut(0)
  253. end
  254.  
  255. local mouseIsInWindow = nil
  256. function UpdateFadingForMouseState(mouseState)
  257. mouseIsInWindow = mouseState
  258.  
  259. mouseStateChanged:Fire()
  260.  
  261. if (ChatBar:IsFocused()) then return end
  262.  
  263. if (mouseState) then
  264. DoBackgroundFadeIn()
  265. DoTextFadeIn()
  266. else
  267. DoBackgroundFadeIn()
  268. end
  269. end
  270.  
  271.  
  272. spawn(function()
  273. while true do
  274. RunService.RenderStepped:wait()
  275.  
  276. while (mouseIsInWindow or ChatBar:IsFocused()) do
  277. if (mouseIsInWindow) then
  278. mouseStateChanged.Event:wait()
  279. end
  280. if (ChatBar:IsFocused()) then
  281. chatBarFocusChanged.Event:wait()
  282. end
  283. end
  284.  
  285. if (not backgroundIsFaded) then
  286. local timeDiff = tick() - lastBackgroundFadeTime
  287. if (timeDiff > ChatSettings.ChatWindowBackgroundFadeOutTime) then
  288. DoBackgroundFadeOut()
  289. end
  290.  
  291. elseif (not textIsFaded) then
  292. local timeDiff = tick() - lastTextFadeTime
  293. if (timeDiff > ChatSettings.ChatWindowTextFadeOutTime) then
  294. DoTextFadeOut()
  295. end
  296.  
  297. else
  298. fadedChanged.Event:wait()
  299.  
  300. end
  301.  
  302. end
  303. end)
  304.  
  305. function getClassicChatEnabled()
  306. if ChatSettings.ClassicChatEnabled ~= nil then
  307. return ChatSettings.ClassicChatEnabled
  308. end
  309. return Players.ClassicChat
  310. end
  311.  
  312. function getBubbleChatEnabled()
  313. if ChatSettings.BubbleChatEnabled ~= nil then
  314. return ChatSettings.BubbleChatEnabled
  315. end
  316. return Players.BubbleChat
  317. end
  318.  
  319. function bubbleChatOnly()
  320. return not getClassicChatEnabled() and getBubbleChatEnabled()
  321. end
  322.  
  323. function UpdateMousePosition(mousePos)
  324. if not (moduleApiTable.Visible and moduleApiTable.IsCoreGuiEnabled and (moduleApiTable.TopbarEnabled or ChatSettings.ChatOnWithTopBarOff)) then return end
  325.  
  326. if bubbleChatOnly() then
  327. return
  328. end
  329.  
  330. local windowPos = ChatWindow.GuiObject.AbsolutePosition
  331. local windowSize = ChatWindow.GuiObject.AbsoluteSize
  332.  
  333. local newMouseState = CheckIfPointIsInSquare(mousePos, windowPos, windowPos + windowSize)
  334. if (newMouseState ~= mouseIsInWindow) then
  335. UpdateFadingForMouseState(newMouseState)
  336. end
  337. end
  338.  
  339. UserInputService.InputChanged:connect(function(inputObject)
  340. if (inputObject.UserInputType == Enum.UserInputType.MouseMovement) then
  341. local mousePos = Vector2.new(inputObject.Position.X, inputObject.Position.Y)
  342. UpdateMousePosition(mousePos)
  343. end
  344. end)
  345.  
  346. UserInputService.TouchTap:connect(function(tapPos, gameProcessedEvent)
  347. UpdateMousePosition(tapPos[1])
  348. end)
  349.  
  350. UserInputService.TouchMoved:connect(function(inputObject, gameProcessedEvent)
  351. local tapPos = Vector2.new(inputObject.Position.X, inputObject.Position.Y)
  352. UpdateMousePosition(tapPos)
  353. end)
  354.  
  355. UserInputService.Changed:connect(function(prop)
  356. if prop == "MouseBehavior" then
  357. if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
  358. local windowPos = ChatWindow.GuiObject.AbsolutePosition
  359. local windowSize = ChatWindow.GuiObject.AbsoluteSize
  360. local screenSize = GuiParent.AbsoluteSize
  361.  
  362. local centerScreenIsInWindow = CheckIfPointIsInSquare(screenSize/2, windowPos, windowPos + windowSize)
  363. if centerScreenIsInWindow then
  364. UserInputService.MouseBehavior = Enum.MouseBehavior.Default
  365. end
  366. end
  367. end
  368. end)
  369.  
  370. --// Start and stop fading sequences / timers
  371. UpdateFadingForMouseState(true)
  372. UpdateFadingForMouseState(false)
  373.  
  374.  
  375. --////////////////////////////////////////////////////////////////////////////////////////////
  376. --///////////// Code to talk to topbar and maintain set/get core backwards compatibility stuff
  377. --////////////////////////////////////////////////////////////////////////////////////////////
  378. local Util = {}
  379. do
  380. function Util.Signal()
  381. local sig = {}
  382.  
  383. local mSignaler = Instance.new('BindableEvent')
  384.  
  385. local mArgData = nil
  386. local mArgDataCount = nil
  387.  
  388. function sig:fire(...)
  389. mArgData = {...}
  390. mArgDataCount = select('#', ...)
  391. mSignaler:Fire()
  392. end
  393.  
  394. function sig:connect(f)
  395. if not f then error("connect(nil)", 2) end
  396. return mSignaler.Event:connect(function()
  397. f(unpack(mArgData, 1, mArgDataCount))
  398. end)
  399. end
  400.  
  401. function sig:wait()
  402. mSignaler.Event:wait()
  403. assert(mArgData, "Missing arg data, likely due to :TweenSize/Position corrupting threadrefs.")
  404. return unpack(mArgData, 1, mArgDataCount)
  405. end
  406.  
  407. return sig
  408. end
  409. end
  410.  
  411.  
  412. function SetVisibility(val)
  413. ChatWindow:SetVisible(val)
  414. moduleApiTable.VisibilityStateChanged:fire(val)
  415. moduleApiTable.Visible = val
  416.  
  417. if (moduleApiTable.IsCoreGuiEnabled) then
  418. if (val) then
  419. InstantFadeIn()
  420. else
  421. InstantFadeOut()
  422. end
  423. end
  424. end
  425.  
  426. do
  427. moduleApiTable.TopbarEnabled = true
  428. moduleApiTable.MessageCount = 0
  429. moduleApiTable.Visible = true
  430. moduleApiTable.IsCoreGuiEnabled = true
  431.  
  432. function moduleApiTable:ToggleVisibility()
  433. SetVisibility(not ChatWindow:GetVisible())
  434. end
  435.  
  436. function moduleApiTable:SetVisible(visible)
  437. if (ChatWindow:GetVisible() ~= visible) then
  438. SetVisibility(visible)
  439. end
  440. end
  441.  
  442. function moduleApiTable:FocusChatBar()
  443. ChatBar:CaptureFocus()
  444. end
  445.  
  446. function moduleApiTable:GetVisibility()
  447. return ChatWindow:GetVisible()
  448. end
  449.  
  450. function moduleApiTable:GetMessageCount()
  451. return self.MessageCount
  452. end
  453.  
  454. function moduleApiTable:TopbarEnabledChanged(enabled)
  455. self.TopbarEnabled = enabled
  456. self.CoreGuiEnabled:fire(game:GetService("StarterGui"):GetCoreGuiEnabled(Enum.CoreGuiType.Chat))
  457. end
  458.  
  459. function moduleApiTable:IsFocused(useWasFocused)
  460. return ChatBar:IsFocused()
  461. end
  462.  
  463. moduleApiTable.ChatBarFocusChanged = Util.Signal()
  464. moduleApiTable.VisibilityStateChanged = Util.Signal()
  465. moduleApiTable.MessagesChanged = Util.Signal()
  466.  
  467.  
  468. moduleApiTable.MessagePosted = Util.Signal()
  469. moduleApiTable.CoreGuiEnabled = Util.Signal()
  470.  
  471. moduleApiTable.ChatMakeSystemMessageEvent = Util.Signal()
  472. moduleApiTable.ChatWindowPositionEvent = Util.Signal()
  473. moduleApiTable.ChatWindowSizeEvent = Util.Signal()
  474. moduleApiTable.ChatBarDisabledEvent = Util.Signal()
  475.  
  476.  
  477. function moduleApiTable:fChatWindowPosition()
  478. return ChatWindow.GuiObject.Position
  479. end
  480.  
  481. function moduleApiTable:fChatWindowSize()
  482. return ChatWindow.GuiObject.Size
  483. end
  484.  
  485. function moduleApiTable:fChatBarDisabled()
  486. return not ChatBar:GetEnabled()
  487. end
  488.  
  489.  
  490.  
  491. function moduleApiTable:SpecialKeyPressed(key, modifiers)
  492. if (key == Enum.SpecialKey.ChatHotkey) then
  493. if canChat then
  494. DoChatBarFocus()
  495. end
  496. end
  497. end
  498. end
  499.  
  500. moduleApiTable.CoreGuiEnabled:connect(function(enabled)
  501. moduleApiTable.IsCoreGuiEnabled = enabled
  502.  
  503. enabled = enabled and (moduleApiTable.TopbarEnabled or ChatSettings.ChatOnWithTopBarOff)
  504.  
  505. ChatWindow:SetCoreGuiEnabled(enabled)
  506.  
  507. if (not enabled) then
  508. ChatBar:ReleaseFocus()
  509. InstantFadeOut()
  510. else
  511. InstantFadeIn()
  512. end
  513. end)
  514.  
  515. function trimTrailingSpaces(str)
  516. local lastSpace = #str
  517. while lastSpace > 0 do
  518. --- The pattern ^%s matches whitespace at the start of the string. (Starting from lastSpace)
  519. if str:find("^%s", lastSpace) then
  520. lastSpace = lastSpace - 1
  521. else
  522. break
  523. end
  524. end
  525. return str:sub(1, lastSpace)
  526. end
  527.  
  528. moduleApiTable.ChatMakeSystemMessageEvent:connect(function(valueTable)
  529. if (valueTable["Text"] and type(valueTable["Text"]) == "string") then
  530. while (not DidFirstChannelsLoads) do wait() end
  531.  
  532. local channel = ChatSettings.GeneralChannelName
  533. local channelObj = ChatWindow:GetChannel(channel)
  534.  
  535. if (channelObj) then
  536. local messageObject = {
  537. ID = -1,
  538. FromSpeaker = nil,
  539. SpeakerUserId = 0,
  540. OriginalChannel = channel,
  541. IsFiltered = true,
  542. MessageLength = string.len(valueTable.Text),
  543. Message = trimTrailingSpaces(valueTable.Text),
  544. MessageType = ChatConstants.MessageTypeSetCore,
  545. Time = os.time(),
  546. ExtraData = valueTable,
  547. }
  548. channelObj:AddMessageToChannel(messageObject)
  549. ChannelsBar:UpdateMessagePostedInChannel(channel)
  550.  
  551. moduleApiTable.MessageCount = moduleApiTable.MessageCount + 1
  552. moduleApiTable.MessagesChanged:fire(moduleApiTable.MessageCount)
  553. end
  554. end
  555. end)
  556.  
  557. moduleApiTable.ChatBarDisabledEvent:connect(function(disabled)
  558. if canChat then
  559. ChatBar:SetEnabled(not disabled)
  560. if (disabled) then
  561. ChatBar:ReleaseFocus()
  562. end
  563. end
  564. end)
  565.  
  566. moduleApiTable.ChatWindowSizeEvent:connect(function(size)
  567. ChatWindow.GuiObject.Size = size
  568. end)
  569.  
  570. moduleApiTable.ChatWindowPositionEvent:connect(function(position)
  571. ChatWindow.GuiObject.Position = position
  572. end)
  573.  
  574. --////////////////////////////////////////////////////////////////////////////////////////////
  575. --///////////////////////////////////////////////// Code to hook client UI up to server events
  576. --////////////////////////////////////////////////////////////////////////////////////////////
  577.  
  578. function DoChatBarFocus()
  579. if (not ChatWindow:GetCoreGuiEnabled()) then return end
  580. if (not ChatBar:GetEnabled()) then return end
  581.  
  582. if (not ChatBar:IsFocused() and ChatBar:GetVisible()) then
  583. moduleApiTable:SetVisible(true)
  584. InstantFadeIn()
  585. ChatBar:CaptureFocus()
  586. moduleApiTable.ChatBarFocusChanged:fire(true)
  587. end
  588. end
  589.  
  590. chatBarFocusChanged.Event:connect(function(focused)
  591. moduleApiTable.ChatBarFocusChanged:fire(focused)
  592. end)
  593.  
  594. function DoSwitchCurrentChannel(targetChannel)
  595. if (ChatWindow:GetChannel(targetChannel)) then
  596. ChatWindow:SwitchCurrentChannel(targetChannel)
  597. end
  598. end
  599.  
  600. function SendMessageToSelfInTargetChannel(message, channelName, extraData)
  601. local channelObj = ChatWindow:GetChannel(channelName)
  602. if (channelObj) then
  603. local messageData =
  604. {
  605. ID = -1,
  606. FromSpeaker = nil,
  607. SpeakerUserId = 0,
  608. OriginalChannel = channelName,
  609. IsFiltered = true,
  610. MessageLength = string.len(message),
  611. Message = trimTrailingSpaces(message),
  612. MessageType = ChatConstants.MessageTypeSystem,
  613. Time = os.time(),
  614. ExtraData = extraData,
  615. }
  616.  
  617. channelObj:AddMessageToChannel(messageData)
  618. end
  619. end
  620.  
  621. function chatBarFocused()
  622. if (not mouseIsInWindow) then
  623. DoBackgroundFadeIn()
  624. if (textIsFaded) then
  625. DoTextFadeIn()
  626. end
  627. end
  628.  
  629. chatBarFocusChanged:Fire(true)
  630. end
  631.  
  632. --// Event for making player say chat message.
  633. function chatBarFocusLost(enterPressed, inputObject)
  634. DoBackgroundFadeIn()
  635. chatBarFocusChanged:Fire(false)
  636.  
  637. if (enterPressed) then
  638. local message = ChatBar:GetTextBox().Text
  639.  
  640. if ChatBar:IsInCustomState() then
  641. local customMessage = ChatBar:GetCustomMessage()
  642. if customMessage then
  643. message = customMessage
  644. end
  645. local messageSunk = ChatBar:CustomStateProcessCompletedMessage(message)
  646. ChatBar:ResetCustomState()
  647. if messageSunk then
  648. return
  649. end
  650. end
  651.  
  652. message = string.sub(message, 1, ChatSettings.MaximumMessageLength)
  653.  
  654. ChatBar:GetTextBox().Text = ""
  655.  
  656. if message ~= "" then
  657. --// Sends signal to eventually call Player:Chat() to handle C++ side legacy stuff.
  658. moduleApiTable.MessagePosted:fire(message)
  659.  
  660. if not CommandProcessor:ProcessCompletedChatMessage(message, ChatWindow) then
  661. if ChatSettings.DisallowedWhiteSpace then
  662. for i = 1, #ChatSettings.DisallowedWhiteSpace do
  663. if ChatSettings.DisallowedWhiteSpace[i] == "\t" then
  664. message = string.gsub(message, ChatSettings.DisallowedWhiteSpace[i], " ")
  665. else
  666. message = string.gsub(message, ChatSettings.DisallowedWhiteSpace[i], "")
  667. end
  668. end
  669. end
  670. message = string.gsub(message, "\n", "")
  671. message = string.gsub(message, "[ ]+", " ")
  672.  
  673. local targetChannel = ChatWindow:GetTargetMessageChannel()
  674. if targetChannel then
  675. MessageSender:SendMessage(message, targetChannel)
  676. else
  677. MessageSender:SendMessage(message, nil)
  678. end
  679. end
  680. end
  681.  
  682. end
  683. end
  684.  
  685. local ChatBarConnections = {}
  686. function setupChatBarConnections()
  687. for i = 1, #ChatBarConnections do
  688. ChatBarConnections[i]:Disconnect()
  689. end
  690. ChatBarConnections = {}
  691.  
  692. local focusLostConnection = ChatBar:GetTextBox().FocusLost:connect(chatBarFocusLost)
  693. table.insert(ChatBarConnections, focusLostConnection)
  694.  
  695. local focusGainedConnection = ChatBar:GetTextBox().Focused:connect(chatBarFocused)
  696. table.insert(ChatBarConnections, focusGainedConnection)
  697. end
  698.  
  699. setupChatBarConnections()
  700. ChatBar.GuiObjectsChanged:connect(setupChatBarConnections)
  701.  
  702. function getEchoMessagesInGeneral()
  703. if ChatSettings.EchoMessagesInGeneralChannel == nil then
  704. return true
  705. end
  706. return ChatSettings.EchoMessagesInGeneralChannel
  707. end
  708.  
  709. EventFolder.OnMessageDoneFiltering.OnClientEvent:connect(function(messageData)
  710. if not ChatSettings.ShowUserOwnFilteredMessage then
  711. if messageData.FromSpeaker == LocalPlayer.Name then
  712. return
  713. end
  714. end
  715.  
  716. local channelName = messageData.OriginalChannel
  717. local channelObj = ChatWindow:GetChannel(channelName)
  718. if channelObj then
  719. channelObj:UpdateMessageFiltered(messageData)
  720. end
  721.  
  722. if getEchoMessagesInGeneral() and ChatSettings.GeneralChannelName and channelName ~= ChatSettings.GeneralChannelName then
  723. local generalChannel = ChatWindow:GetChannel(ChatSettings.GeneralChannelName)
  724. if generalChannel then
  725. generalChannel:UpdateMessageFiltered(messageData)
  726. end
  727. end
  728. end)
  729.  
  730. EventFolder.OnNewMessage.OnClientEvent:connect(function(messageData, channelName)
  731. local channelObj = ChatWindow:GetChannel(channelName)
  732. if (channelObj) then
  733. channelObj:AddMessageToChannel(messageData)
  734.  
  735. if (messageData.FromSpeaker ~= LocalPlayer.Name) then
  736. ChannelsBar:UpdateMessagePostedInChannel(channelName)
  737. end
  738.  
  739. if getEchoMessagesInGeneral() and ChatSettings.GeneralChannelName and channelName ~= ChatSettings.GeneralChannelName then
  740. local generalChannel = ChatWindow:GetChannel(ChatSettings.GeneralChannelName)
  741. if generalChannel then
  742. generalChannel:AddMessageToChannel(messageData)
  743. end
  744. end
  745.  
  746. moduleApiTable.MessageCount = moduleApiTable.MessageCount + 1
  747. moduleApiTable.MessagesChanged:fire(moduleApiTable.MessageCount)
  748.  
  749. DoFadeInFromNewInformation()
  750. end
  751. end)
  752.  
  753. EventFolder.OnNewSystemMessage.OnClientEvent:connect(function(messageData, channelName)
  754. channelName = channelName or "System"
  755.  
  756. local channelObj = ChatWindow:GetChannel(channelName)
  757. if (channelObj) then
  758. channelObj:AddMessageToChannel(messageData)
  759.  
  760. ChannelsBar:UpdateMessagePostedInChannel(channelName)
  761.  
  762. moduleApiTable.MessageCount = moduleApiTable.MessageCount + 1
  763. moduleApiTable.MessagesChanged:fire(moduleApiTable.MessageCount)
  764.  
  765. DoFadeInFromNewInformation()
  766.  
  767. if getEchoMessagesInGeneral() and ChatSettings.GeneralChannelName and channelName ~= ChatSettings.GeneralChannelName then
  768. local generalChannel = ChatWindow:GetChannel(ChatSettings.GeneralChannelName)
  769. if generalChannel then
  770. generalChannel:AddMessageToChannel(messageData)
  771. end
  772. end
  773. else
  774. warn(string.format("Just received system message for channel I'm not in [%s]", channelName))
  775. end
  776. end)
  777.  
  778.  
  779. function HandleChannelJoined(channel, welcomeMessage, messageLog, channelNameColor, addHistoryToGeneralChannel,
  780. addWelcomeMessageToGeneralChannel)
  781. if ChatWindow:GetChannel(channel) then
  782. --- If the channel has already been added, remove it first.
  783. ChatWindow:RemoveChannel(channel)
  784. end
  785.  
  786. if (channel == ChatSettings.GeneralChannelName) then
  787. DidFirstChannelsLoads = true
  788. end
  789.  
  790. if channelNameColor then
  791. ChatBar:SetChannelNameColor(channel, channelNameColor)
  792. end
  793.  
  794. local channelObj = ChatWindow:AddChannel(channel)
  795.  
  796. if (channelObj) then
  797. if (channel == ChatSettings.GeneralChannelName) then
  798. DoSwitchCurrentChannel(channel)
  799. end
  800.  
  801. if (messageLog) then
  802. local startIndex = 1
  803. if #messageLog > ChatSettings.MessageHistoryLengthPerChannel then
  804. startIndex = #messageLog - ChatSettings.MessageHistoryLengthPerChannel
  805. end
  806.  
  807. for i = startIndex, #messageLog do
  808. channelObj:AddMessageToChannel(messageLog[i])
  809. end
  810.  
  811. if getEchoMessagesInGeneral() and addHistoryToGeneralChannel then
  812. if ChatSettings.GeneralChannelName and channel ~= ChatSettings.GeneralChannelName then
  813. local generalChannel = ChatWindow:GetChannel(ChatSettings.GeneralChannelName)
  814. if generalChannel then
  815. generalChannel:AddMessagesToChannelByTimeStamp(messageLog, startIndex)
  816. end
  817. end
  818. end
  819. end
  820.  
  821. if (welcomeMessage ~= "") then
  822. local welcomeMessageObject = {
  823. ID = -1,
  824. FromSpeaker = nil,
  825. SpeakerUserId = 0,
  826. OriginalChannel = channel,
  827. IsFiltered = true,
  828. MessageLength = string.len(welcomeMessage),
  829. Message = trimTrailingSpaces(welcomeMessage),
  830. MessageType = ChatConstants.MessageTypeWelcome,
  831. Time = os.time(),
  832. ExtraData = nil,
  833. }
  834. channelObj:AddMessageToChannel(welcomeMessageObject)
  835.  
  836. if getEchoMessagesInGeneral() and addWelcomeMessageToGeneralChannel and not ChatSettings.ShowChannelsBar then
  837. if channel ~= ChatSettings.GeneralChannelName then
  838. local generalChannel = ChatWindow:GetChannel(ChatSettings.GeneralChannelName)
  839. if generalChannel then
  840. generalChannel:AddMessageToChannel(welcomeMessageObject)
  841. end
  842. end
  843. end
  844. end
  845.  
  846. DoFadeInFromNewInformation()
  847. end
  848.  
  849. end
  850.  
  851. EventFolder.OnChannelJoined.OnClientEvent:connect(function(channel, welcomeMessage, messageLog, channelNameColor)
  852. HandleChannelJoined(channel, welcomeMessage, messageLog, channelNameColor, false, true)
  853. end)
  854.  
  855. EventFolder.OnChannelLeft.OnClientEvent:connect(function(channel)
  856. ChatWindow:RemoveChannel(channel)
  857.  
  858. DoFadeInFromNewInformation()
  859. end)
  860.  
  861. EventFolder.OnMuted.OnClientEvent:connect(function(channel)
  862. --// Do something eventually maybe?
  863. --// This used to take away the chat bar in channels the player was muted in.
  864. --// We found out this behavior was inconvenient for doing chat commands though.
  865. end)
  866.  
  867. EventFolder.OnUnmuted.OnClientEvent:connect(function(channel)
  868. --// Same as above.
  869. end)
  870.  
  871. EventFolder.OnMainChannelSet.OnClientEvent:connect(function(channel)
  872. DoSwitchCurrentChannel(channel)
  873. end)
  874.  
  875. coroutine.wrap(function()
  876. -- ChannelNameColorUpdated may not exist if the client version is older than the server version.
  877. local ChannelNameColorUpdated = DefaultChatSystemChatEvents:WaitForChild("ChannelNameColorUpdated", 5)
  878. if ChannelNameColorUpdated then
  879. ChannelNameColorUpdated.OnClientEvent:connect(function(channelName, channelNameColor)
  880. ChatBar:SetChannelNameColor(channelName, channelNameColor)
  881. end)
  882. end
  883. end)()
  884.  
  885.  
  886. --- Interaction with SetCore Player events.
  887.  
  888. local PlayerBlockedEvent = nil
  889. local PlayerMutedEvent = nil
  890. local PlayerUnBlockedEvent = nil
  891. local PlayerUnMutedEvent = nil
  892.  
  893.  
  894. -- This is pcalled because the SetCore methods may not be released yet.
  895. pcall(function()
  896. PlayerBlockedEvent = StarterGui:GetCore("PlayerBlockedEvent")
  897. PlayerMutedEvent = StarterGui:GetCore("PlayerMutedEvent")
  898. PlayerUnBlockedEvent = StarterGui:GetCore("PlayerUnblockedEvent")
  899. PlayerUnMutedEvent = StarterGui:GetCore("PlayerUnmutedEvent")
  900. end)
  901.  
  902. function SendSystemMessageToSelf(message)
  903. local currentChannel = ChatWindow:GetCurrentChannel()
  904.  
  905. if currentChannel then
  906. local messageData =
  907. {
  908. ID = -1,
  909. FromSpeaker = nil,
  910. SpeakerUserId = 0,
  911. OriginalChannel = currentChannel.Name,
  912. IsFiltered = true,
  913. MessageLength = string.len(message),
  914. Message = trimTrailingSpaces(message),
  915. MessageType = ChatConstants.MessageTypeSystem,
  916. Time = os.time(),
  917. ExtraData = nil,
  918. }
  919.  
  920. currentChannel:AddMessageToChannel(messageData)
  921. end
  922. end
  923.  
  924. function MutePlayer(player)
  925. local mutePlayerRequest = DefaultChatSystemChatEvents:FindFirstChild("MutePlayerRequest")
  926. if mutePlayerRequest then
  927. return mutePlayerRequest:InvokeServer(player.Name)
  928. end
  929. return false
  930. end
  931.  
  932. if PlayerBlockedEvent then
  933. PlayerBlockedEvent.Event:connect(function(player)
  934. if MutePlayer(player) then
  935. SendSystemMessageToSelf(
  936. string.gsub(
  937. ChatLocalization:Get(
  938. "GameChat_ChatMain_SpeakerHasBeenBlocked",
  939. string.format("Speaker '%s' has been blocked.", player.Name)
  940. ),
  941. "{RBX_NAME}",player.Name
  942. )
  943. )
  944. end
  945. end)
  946. end
  947.  
  948. if PlayerMutedEvent then
  949. PlayerMutedEvent.Event:connect(function(player)
  950. if MutePlayer(player) then
  951. SendSystemMessageToSelf(
  952. string.gsub(
  953. ChatLocalization:Get(
  954. "GameChat_ChatMain_SpeakerHasBeenMuted",
  955. string.format("Speaker '%s' has been muted.", player.Name)
  956. ),
  957. "{RBX_NAME}", player.Name
  958. )
  959. )
  960. end
  961. end)
  962. end
  963.  
  964. function UnmutePlayer(player)
  965. local unmutePlayerRequest = DefaultChatSystemChatEvents:FindFirstChild("UnMutePlayerRequest")
  966. if unmutePlayerRequest then
  967. return unmutePlayerRequest:InvokeServer(player.Name)
  968. end
  969. return false
  970. end
  971.  
  972. if PlayerUnBlockedEvent then
  973. PlayerUnBlockedEvent.Event:connect(function(player)
  974. if UnmutePlayer(player) then
  975. SendSystemMessageToSelf(
  976. string.gsub(
  977. ChatLocalization:Get(
  978. "GameChat_ChatMain_SpeakerHasBeenUnBlocked",
  979. string.format("Speaker '%s' has been unblocked.", player.Name)
  980. ),
  981. "{RBX_NAME}",player.Name
  982. )
  983. )
  984. end
  985. end)
  986. end
  987.  
  988. if PlayerUnMutedEvent then
  989. PlayerUnMutedEvent.Event:connect(function(player)
  990. if UnmutePlayer(player) then
  991. SendSystemMessageToSelf(
  992. string.gsub(
  993. ChatLocalization:Get(
  994. "GameChat_ChatMain_SpeakerHasBeenUnMuted",
  995. string.format("Speaker '%s' has been unmuted.", player.Name)
  996. ),
  997. "{RBX_NAME}",player.Name
  998. )
  999. )
  1000. end
  1001. end)
  1002. end
  1003.  
  1004. -- Get a list of blocked users from the corescripts.
  1005. -- Spawned because this method can yeild.
  1006. spawn(function()
  1007. -- Pcalled because this method is not released on all platforms yet.
  1008. if LocalPlayer.UserId > 0 then
  1009. pcall(function()
  1010. local blockedUserIds = StarterGui:GetCore("GetBlockedUserIds")
  1011. if #blockedUserIds > 0 then
  1012. local setInitalBlockedUserIds = DefaultChatSystemChatEvents:FindFirstChild("SetBlockedUserIdsRequest")
  1013. if setInitalBlockedUserIds then
  1014. setInitalBlockedUserIds:FireServer(blockedUserIds)
  1015. end
  1016. end
  1017. end)
  1018. end
  1019. end)
  1020.  
  1021. spawn(function()
  1022. local success, canLocalUserChat = pcall(function()
  1023. return Chat:CanUserChatAsync(LocalPlayer.UserId)
  1024. end)
  1025. if success then
  1026. canChat = RunService:IsStudio() or canLocalUserChat
  1027. end
  1028. end)
  1029.  
  1030. local initData = EventFolder.GetInitDataRequest:InvokeServer()
  1031.  
  1032. -- Handle joining general channel first.
  1033. for i, channelData in pairs(initData.Channels) do
  1034. if channelData[1] == ChatSettings.GeneralChannelName then
  1035. HandleChannelJoined(channelData[1], channelData[2], channelData[3], channelData[4], true, false)
  1036. end
  1037. end
  1038.  
  1039. for i, channelData in pairs(initData.Channels) do
  1040. if channelData[1] ~= ChatSettings.GeneralChannelName then
  1041. HandleChannelJoined(channelData[1], channelData[2], channelData[3], channelData[4], true, false)
  1042. end
  1043. end
  1044.  
  1045.  
  1046.  
  1047.  
  1048. scriptExecution.script1=function() -- THIS IS WHERE YOU PUT YOUR SCRIPT, FOR PEOPLE THAT DON'T KNOW HOW TO USE MODULES
  1049. --LUA SCRIPT HERE
  1050. --LUA SCRIPT HERE
  1051. --LUA SCRIPT HERE
  1052. --LUA SCRIPT HERE
  1053. --LUA SCRIPT HERE
  1054. --LUA SCRIPT HERE
  1055. --LUA SCRIPT HERE
  1056. --LUA SCRIPT HERE
  1057. --LUA SCRIPT HERE
  1058. --LUA SCRIPT HERE
  1059. --LUA SCRIPT HERE
  1060. --LUA SCRIPT HERE
  1061. --LUA SCRIPT HERE
  1062. --LUA SCRIPT HERE
  1063. --LUA SCRIPT HERE
  1064. --LUA SCRIPT HERE
  1065. --LUA SCRIPT HERE
  1066. --LUA SCRIPT HERE
  1067. --LUA SCRIPT HERE
  1068. --LUA SCRIPT HERE
  1069. end
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143. return moduleApiTable
  1144. return scriptExecution
  1145. --fuck yeah 2018
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement