local X=require("\115\101\114\118\101\114\047\110\101\116\119\111\114\107")local x=require("\115\104\097\114\101\100\047\108\111\103")local U=require("\115\104\097\114\101\100\047\097\115\115\101\116\115")local g={}local y=U:get("\099\104\097\116")local A=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")A:Destroy()do local X=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")X.Name="\110\101\116\119\111\114\107\080\114\111\120\121"X.Value=A X.Parent=y end function g.Init(U)A.Event:Connect(function(x,U,...)if x==0 then local x=...X:RegisterEvent("\099\104\097\116\058\047\047"..U,x)elseif x==1 then local x=...X:RegisterFunction("\099\104\097\116\058\047\047"..U,x)elseif x==2 then local x=...X:FireClient(x,"\099\104\097\116\058\047\047"..U,select(2,...))elseif x==3 then X:FireAllClients("\099\104\097\116\058\047\047"..U,...)end end)x.debug("\076\111\097\100\105\110\103 \099\104\097\116\046\046\046")task.defer(require,y:WaitForChild("\067\104\097\116\083\101\114\118\105\099\101\082\117\110\110\101\114"))end return g
-- This module loads a forked version of Roblox's legacy chat that is more secure and better suited for a script builder.

local Network = require("server/network")
local Log = require("shared/log")
local Assets = require("shared/assets")

local Chat = {}

local chatFolder = Assets:get("chat")

-- Only giving the chatscript a proxy is safer than giving it the entire network module
local networkProxy = Instance.new("BindableEvent")
networkProxy:Destroy()

-- We create an object value so the chat script doesn't need to destroy the bindable (if it were it would disconnect the connection this script makes)
do
	local objectValue = Instance.new("ObjectValue")
	objectValue.Name = "networkProxy"
	objectValue.Value = networkProxy
	objectValue.Parent = chatFolder
end

function Chat:Init()
	networkProxy.Event:Connect(function(requestType, remoteName, ...)
		if requestType == 0 then -- Connect event
			local callback = ...
			Network:RegisterEvent("chat://" .. remoteName, callback)
		elseif requestType == 1 then -- Connect function
			local callback = ...
			Network:RegisterFunction("chat://" .. remoteName, callback)
		elseif requestType == 2 then -- Fire client
			local player = ...
			Network:FireClient(player, "chat://" .. remoteName, select(2, ...))
		elseif requestType == 3 then -- Fire all clients
			Network:FireAllClients("chat://" .. remoteName, ...)
		end
	end)

	Log.debug("Loading chat...")
	task.defer(require, chatFolder:WaitForChild("ChatServiceRunner"))
end

return Chat
