Advertisement
Guest User

Dodgy code

a guest
Oct 20th, 2015
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function SplitStringEvery(str, count)
  2.     local tab = {}
  3.     for x in string.gmatch( str, string.rep( ".", count - 1 ) .. "?.?" ) do
  4.         table.insert( tab, x )
  5.     end
  6.     return tab
  7. end
  8.  
  9. local function MaterialData( txt, format )
  10.     return Material( "../data/" .. mat .. "\n."..format )  
  11. end
  12.  
  13. if ( SERVER ) then
  14.  
  15.     util.AddNetworkString( 'ClientSendPicture' )
  16.     util.AddNetworkString( 'ServerRedirectPicture' )
  17.    
  18.     net.Receive( 'ClientSendPicture', function( len, ply )
  19.         local int = net.ReadFloat()
  20.         net.Start( 'ServerRedirectPicture' )
  21.         net.WriteFloat( int )
  22.         for i = 1, int do
  23.             local len = net.ReadFloat()
  24.             local str = net.ReadData( len )
  25.             net.WriteFloat( len )
  26.             net.WriteData( str, len )
  27.         end
  28.         net.Send( ply )
  29.     end )
  30.    
  31. end
  32.  
  33. if ( CLIENT ) then
  34.  
  35.     net.Receive( 'ServerRedirectPicture', function()
  36.         local int = net.ReadFloat()
  37.         local tab = {}
  38.         local str = ''
  39.         for i = 1, int do
  40.         local len = net.ReadFloat()
  41.         table.insert( tab, net.ReadData( len ) )
  42.         end
  43.         for k,v in pairs( tab ) do file.Append( 'tmp.txt', v ) end
  44.         local mat = MaterialData( 'tmp.txt', 'jpg' )
  45.         local Base = vgui.Create( 'DFrame' )
  46.         Base:SetSize( 200, 200 )
  47.         Base:Center()
  48.         Base:SetSizable( true )
  49.         Base:MakePopup()
  50.         Base.Paint = function( self, w, h )
  51.             surface.SetDrawColor( 255, 255, 255, 255 )
  52.             surface.SetMaterial( mat )
  53.             surface.DrawTexturedRect( 0, 0, w, h )
  54.         end
  55.         file.Delete( 'tmp.txt' )
  56.     end )
  57.  
  58.     concommand.Add( 'SendPictureTest', function()
  59.         local imagedata = file.Read( 'screenshots/classthing0000.jpg', 'MOD' )
  60.         local imgtbl = SplitStringEvery( imagedata, 1024 )
  61.         net.Start( 'ClientSendPicture' )
  62.         net.WriteFloat( #imgtbl )
  63.         for k, v in pairs( imgtbl ) do net.WriteFloat( #v ) net.WriteData( v, #v ) end
  64.         net.SendToServer()
  65.     end )
  66.    
  67. end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement