Upload & Download Files with Rgss

Upload & Download Files with Rgss
Version: 2.1
By: Berka


Introduction
Now, your crazy project is able to download and upload files on ftp or http servers.

Features
  • No external files/libs, only Apis
  • Fast transfers
  • ProgressBars...
  • Ftp and http support

Screenshots
Image

Demo
RMVX
RMXP

Script
RMVX ! Show
The Net module:
  1. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2. #                             Download & Upload Files with RGSS
  3. #   par berka                                v 2.1                           rgss 2
  4. #                                      http://www.rpgmakervx-fr.com                                                        
  5. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  6. # thanks to: http://www.66rpg.com for documentation on wininet
  7. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  8. # ! do not use ftp which contains privates data
  9. # ! this scripts need ftp account information !
  10. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  11. # Ftp :
  12. #      â €“ ¼ receive :
  13. #                Net::Ftp.download("dir_on_ftp/file.zip","./Graphics")
  14. #      â €“ ¼ send :
  15. #                Net::Ftp.upload("./Graphics/file.zip","Â §dir_on_ftp/file.zip")
  16. #      â €“ ¼ make directory :
  17. #                Net::Ftp.mkdir("/dir_on_ftp")
  18. # Http :
  19. #      â €“ ¼ receive :
  20. #                Net::Http.download("url","./Graphics")
  21. #      â €“ ¼ total octets downloaded :
  22. #                Net::HTTP.dloaded
  23. #      â €“ ¼ size of file :
  24. #                Net::HTTP.size("test.zip")
  25. #      â €“ ¼ % dl progress :
  26. #                Net::HTTP.progress("test.zip")
  27. #      â €“ ¼ transfer time:
  28. #                Net::HTTP.temps("test.zip")
  29. #      â €“ ¼ list files :
  30. #                Net::HTTP.transfers
  31. #      â €“ ¼ file loaded? :
  32. #                Net::HTTP.loaded?("test.zip")
  33. #      â €“ ¼ octets transfered :
  34. #                Net::HTTP.transfered
  35. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  36. module Berka
  37.   module NetError
  38.      ErrConIn="Unable to connect to Internet"
  39.      ErrConFtp="Unable to connect to Ftp"
  40.      ErrConHttp="Unable to connect to the Server"
  41.      ErrNoFFtpIn="The file to be download doesn't exist"
  42.      ErrNoFFtpEx="The file to be upload doesn't exist"
  43.      ErrTranHttp="Http Download is failed"
  44.      ErrDownFtp="Ftp Download is failed"
  45.      ErrUpFtp="Ftp Upload is failed"
  46.      ErrNoFile="No file to be download"
  47.      ErrMkdir="Unable to create a new directory"
  48.   end
  49. end
  50. include Berka::NetError
  51. module Net
  52.   W='wininet'
  53.   SPC=Win32API.new('kernel32','SetPriorityClass','pi','i').call(-1,128)
  54.   IOA=Win32API.new(W,'InternetOpenA','plppl','l').call('',0,'','',0)
  55.   IC=Win32API.new(W,'InternetConnectA','lplpplll','l')
  56.   print(ErrConIn)if IOA==0
  57.   module FTP
  58.      FSCD=Win32API.new(W,'FtpSetCurrentDirectoryA','lp','l')
  59.      FGF=Win32API.new(W,'FtpGetFileA','lppllll','l')
  60.      FPF=Win32API.new(W,'FtpPutFile','lppll','l')
  61.      FCD=Win32API.new(W,'FtpCreateDirectoryA','lp','l')
  62.      module_function 
  63.      def init
  64.         #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  65.         ftp="ftp.server.com"            #
  66.         port=21                                  #   Modify !
  67.         identifiant="user"                  #
  68.         motdepasse="password"          #
  69.         #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  70.         @fb=IC.call(IOA,ftp,port,identifiant,motdepasse,1,0,0)
  71.         ftp,port,identifiant,motdepasse=[nil]*4 # clear ftp ids !
  72.         (print(ErrConFtp))if @fb==0
  73.      end
  74.      def download(ext,int='./')
  75.         init if @fb.nil?  
  76.         c=ext.split('/').pop
  77.         if FSCD.call(@fb,ext.gsub(c,''))!=0
  78.            print(ErrDownFtp)if FGF.call(@fb,c,"#{int}/#{c}",0,32,2,0)==0
  79.         else
  80.            print(ErrNoFFtpIn)
  81.         end
  82.      end
  83.      def mkdir(rep)
  84.         init if @fb.nil?
  85.         print(ErrMkdir)if FCD.call(@fb,rep)==0
  86.      end
  87.      def upload(int,ext)
  88.         init if @fb.nil?
  89.         if FSCD.call(@fb,ext)&&File.exist?(int)
  90.            print(ErrUpFtp)if FPF.call(@fb,int,ext,2,0)==0
  91.         else
  92.            print(ErrNoFFtpEx)
  93.         end
  94.      end
  95.   end
  96.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  97.   module HTTP
  98.      IOU=Win32API.new(W,'InternetOpenUrl','lppllp','l')
  99.      IRF=Win32API.new(W,'InternetReadFile','lpip','l')
  100.      ICH=Win32API.new(W,'InternetCloseHandle','l','l')
  101.      HQI=Win32API.new(W,'HttpQueryInfo','llppp','i')
  102.      module_function
  103.      def sizeloaded(i=0);@read[i];end
  104.      def transfered;@dloaded;end
  105.      def transfers;@dls;end
  106.      def progress(i=0);(@read[i].to_f/@size[i]*100);end
  107.      def loaded?(i=0);@read[i]>=@size[i];end
  108.      def temps(i=0);@tps[i];end
  109.      def size(i=0);@size[i];end
  110.      def download(url,int='./')
  111.         @dloaded||=0;@dls||={};@i||=-1;@size||={};@read||={};@tps={}
  112.         a=url.split('/');serv,root,fich=a[2],a[3..a.size].join('/'),a[-1]
  113.         print(ErrNoFile)if fich.nil?
  114.         @dls[fich]=Thread.start(url,int){|url,int|txt='';t=Time.now
  115.         ErrConHttp if(e=IC.call(IOA,serv,80,'','',3,1,0))==0   
  116.         f=IOU.call(IOA,url,nil,0,0,0)
  117.         HQI.call(f,5,k="\0"*1024,[k.size-1].pack('l'),nil)
  118.         @read[fich],@size[fich]=0,k.delete!("\0").to_i
  119.         loop do
  120.            buf,n=' '*1024,0
  121.            r=IRF.call(f,buf,1024,o=[n].pack('i!'))
  122.            n=o.unpack('i!')[0]
  123.            break if r&&n==0
  124.            @read[fich]=(txt<<buf[0,n]).size
  125.         end
  126.         (File.open(int+fich,'wb')<<txt).close
  127.         @dloaded+=@read[fich]
  128.         ICH.call(f)
  129.         @tps[fich]=Time.now-t
  130.         sleep(0.001)}
  131.      end
  132.   end
  133. end
  134.  
Expand to see the code.

Scene Example:
  1. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2. #                              Download & Upload Files with RGSS
  3. #   par berka                                 v 2.1                               rgss 2
  4. #                                       www.rpgmakervx-fr.com                                                               
  5. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  6. #                  EXAMPLES !
  7. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  8. class Window_Barre<Window_Base
  9.   Col1=Color.new(255,0,0)
  10.   Col2=Color.new(0,255,0)
  11.   def initialize
  12.      super(100,50,344,316)
  13.      @dls=Net::HTTP.transfers
  14.      refresh
  15.   end
  16.   def refresh
  17.      i=0
  18.      self.contents.clear
  19.      self.contents.font.size=22
  20.      self.contents.draw_text(-16,0,self.width,WLH,"Http: Downloads",1)
  21.      self.contents.font.size=20
  22.      @dls.each_key{|file|
  23.      self.contents.draw_text(0,56*(i+=1),200,WLH,"--> #{file}")
  24.      self.contents.fill_rect(131,56*i+25,152,10,Color.new(0,0,0,150))
  25.      self.contents.font.size=14
  26.      rat="#{Net::HTTP.sizeloaded(file)/1024}/#{Net::HTTP.size(file)/1024} ko"
  27.      self.contents.draw_text(132,56*i+32,150,WLH,rat,1)
  28.      s=Net::HTTP.temps(file)
  29.      self.contents.draw_text(20,56*i+20,self.width,WLH,"OK:#{s} secs")if Net::HTTP.loaded?(file)
  30.      pr=Net::HTTP.progress(file)/100
  31.      self.contents.draw_text(272,56*i,self.width,WLH,"#{(pr*100).to_i}%")rescue nil
  32.      self.contents.gradient_fill_rect(132,56*i+26,pr*150,8,Col1,Col2)
  33.      self.contents.font.size=20}
  34.   end
  35. end
  36. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  37. class Download<Scene_Base
  38.   def start
  39.      super
  40.      @fond=Spriteset_Map.new
  41.      Net::HTTP.download('http://download59.mediafire.com/313lzxpdytpg/gyok0vgmm2m/hero+creator.zip')
  42.      Net::HTTP.download('http://www.google.fr/intl/fr_fr/images/logo.gif')
  43.      Net::HTTP.download('http://www.rpgrevolution.com/forums/banner3.gif')
  44.      Net::HTTP.download('http://i42.servimg.com/u/f42/12/32/03/86/bannie11.jpg')
  45.      @barre=Window_Barre.new
  46.   end
  47.   def terminate
  48.      super
  49.      @barre.dispose
  50.      @fond.dispose
  51.   end
  52.   def update
  53.      super
  54.      @barre.refresh
  55.   end
  56. end
  57.  
  58. def telecharger
  59.   Net::HTTP.download('http://download59.mediafire.com/313lzxpdytpg/gyok0vgmm2m/hero+creator.zip')
  60.   Net::HTTP.download('http://www.google.fr/intl/fr_fr/images/logo.gif')
  61.   Net::HTTP.download('http://www.rpgrevolution.com/forums/banner3.gif')
  62.   Net::HTTP.download('http://i42.servimg.com/u/f42/12/32/03/86/bannie11.jpg')
  63. end
  64.  
Expand to see the code.

RMXP ! Show
The Net module
  1. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2. #                            Download & Upload Files with RGSS
  3. #   par berka                                 v 2.1                           rgss 1
  4. #                                     http://www.rpgmakervx-fr.com&nbsp;&nbsp;                                                      
  5. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  6. # thanks to: http://www.66rpg.com for documentation on wininet
  7. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  8. # ! do not use ftp which contains privates data
  9. # ! this scripts need ftp account information !
  10. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  11. # Ftp :
  12. #      Ã¢ €“ ¼ receive :
  13. #               Net::Ftp.download("dir_on_ftp/file.zip","./Graphics")
  14. #      Ã¢ €“ ¼ send :
  15. #               Net::Ftp.upload("./Graphics/file.zip","Â §dir_on_ftp/file.zip")
  16. #      Ã¢ €“ ¼ make directory :
  17. #               Net::Ftp.mkdir("/dir_on_ftp")
  18. # Http :
  19. #      Ã¢ €“ ¼ receive :
  20. #               Net::Http.download("url","./Graphics")
  21. #      Ã¢ €“ ¼ total octets downloaded :
  22. #               Net::HTTP.dloaded
  23. #      Ã¢ €“ ¼ size of file :
  24. #               Net::HTTP.size("test.zip")
  25. #      Ã¢ €“ ¼ % dl progress :
  26. #               Net::HTTP.progress("test.zip")
  27. #      Ã¢ €“ ¼ transfer time:
  28. #               Net::HTTP.temps("test.zip")
  29. #      Ã¢ €“ ¼ list files :
  30. #               Net::HTTP.transfers
  31. #      Ã¢ €“ ¼ file loaded? :
  32. #               Net::HTTP.loaded?("test.zip")
  33. #      Ã¢ €“ ¼ octets transfered :
  34. #               Net::HTTP.transfered
  35. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  36. module Berka
  37.   module NetError
  38.      ErrConIn="Unable to connect to Internet"
  39.      ErrConFtp="Unable to connect to Ftp"
  40.      ErrConHttp="Unable to connect to the Server"
  41.      ErrNoFFtpIn="The file to be download doesn't exist"
  42.      ErrNoFFtpEx="The file to be upload doesn't exist"
  43.      ErrTranHttp="Http Download is failed"
  44.      ErrDownFtp="Ftp Download is failed"
  45.      ErrUpFtp="Ftp Upload is failed"
  46.      ErrNoFile="No file to be download"
  47.      ErrMkdir="Unable to create a new directory"
  48.   end
  49. end
  50. module Net
  51.   W='wininet'
  52.   SPC=Win32API.new('kernel32','SetPriorityClass','pi','i').call(-1,128)
  53.   IOA=Win32API.new(W,'InternetOpenA','plppl','l').call('',0,'','',0)
  54.   IC=Win32API.new(W,'InternetConnectA','lplpplll','l')
  55.   print(Berka::NetErrorErr::ConIn)if IOA==0
  56.   module FTP
  57.      FSCD=Win32API.new(W,'FtpSetCurrentDirectoryA','lp','l')
  58.      FGF=Win32API.new(W,'FtpGetFileA','lppllll','l')
  59.      FPF=Win32API.new(W,'FtpPutFile','lppll','l')
  60.      FCD=Win32API.new(W,'FtpCreateDirectoryA','lp','l')
  61.      module_function      
  62.      def init
  63.         #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  64.         ftp="ftp.server.com"               #
  65.         port=21                                 #   A modifier !
  66.         identifiant="user"                  #
  67.         motdepasse="password"            #
  68.         #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  69.         @fb=IC.call(IOA,ftp,port,identifiant,motdepasse,1,0,0)
  70.         ftp,port,identifiant,motdepasse=[nil]*4 # efface les ids par sécurité
  71.         (print(Berka::NetError::ErrConFtp))if @fb==0
  72.      end
  73.      def download(ext,int='./')
  74.         init if @fb.nil?      
  75.         c=ext.split('/').pop
  76.         if FSCD.call(@fb,ext.gsub(c,''))!=0
  77.            print(Berka::NetErrorErr::ErrDownFtp)if FGF.call(@fb,c,"#{int}/#{c}",0,32,2,0)==0
  78.         else
  79.            print(Berka::NetErrorErr::ErrNoFFtpIn)
  80.         end
  81.      end
  82.      def mkdir(rep)
  83.         init if @fb.nil?
  84.         print(Berka::NetErrorErr::ErrMkdir)if FCD.call(@fb,rep)==0
  85.      end
  86.      def upload(int,ext)
  87.         init if @fb.nil?
  88.         if FSCD.call(@fb,ext)&&File.exist?(int)
  89.            print(Berka::NetErrorErr::ErrUpFtp)if FPF.call(@fb,int,ext,2,0)==0
  90.         else
  91.            print(Berka::NetErrorErr::ErrNoFFtpEx)
  92.         end
  93.      end
  94.   end
  95.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  96.   module HTTP
  97.      IOU=Win32API.new(W,'InternetOpenUrl','lppllp','l')
  98.      IRF=Win32API.new(W,'InternetReadFile','lpip','l')
  99.      ICH=Win32API.new(W,'InternetCloseHandle','l','l')
  100.      HQI=Win32API.new(W,'HttpQueryInfo','llppp','i')
  101.      module_function
  102.      def sizeloaded(i='');@read[i];end
  103.      def transfered;@dloaded;end
  104.      def transfers;@dls;end
  105.      def progress(i='');(@read[i].to_f/@size[i]*100);end
  106.      def loaded?(i='');@read[i]>=@size[i]rescue nil;end
  107.      def temps(i='');@tps[i]if loaded?(i);end
  108.      def size(i='');@size[i];end
  109.      def download(url,int='./')
  110.         @dloaded||=0;@dls||={};@i||=-1;@size||={};@read||={};@tps={}
  111.         a=url.split('/');serv,root,fich=a[2],a[3..a.size].join('/'),a[-1]
  112.         print(Berka::NetErrorErr::ErrNoFile)if fich.nil?
  113.         @dls[fich]=Thread.start(url,int){|url,int|txt='';t=Time.now
  114.         Berka::NetErrorErr::ErrConHttp if(e=IC.call(IOA,serv,80,'','',3,1,0))==0   
  115.         f=IOU.call(IOA,url,nil,0,0,0)
  116.         HQI.call(f,5,k="\0"*1024,[k.size-1].pack('l'),nil)
  117.         @read[fich],@size[fich]=0,k.delete!("\0").to_i
  118.         loop do
  119.            buf,n=' '*1024,0
  120.            r=IRF.call(f,buf,1024,o=[n].pack('i!'))
  121.            n=o.unpack('i!')[0]
  122.            break if r&&n==0
  123.            txt << buf[0,n]
  124.            @read[fich]=txt.size
  125.         end
  126.         (File.open(int+fich,'wb')<<txt).close
  127.         @dloaded+=@read[fich]
  128.         ICH.call(f);sleep(0.01)
  129.         @tps[fich]=Time.now-t}
  130.      end
  131.   end
  132. end
Expand to see the code.

The Scene Example:
  1. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2. #                              Téléchargement de fichiers en Rgss
  3. #   par berka                                 v 2.1                               rgss 1
  4. #                                       www.rpgmakervx-fr.com                                                               
  5. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  6. #                  EXEMPLES !
  7. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  8. class Window_Barre<Window_Base
  9.   def initialize
  10.      super(100,50,440,380)
  11.      self.contents=Bitmap.new(width-32,height-32)
  12.      self.contents.font.name=$fontface
  13.      self.contents.font.size=$fontsize
  14.      # on initialise un tableau de téléchargement
  15.      @dls=Net::HTTP.transfers
  16.      refresh
  17.   end
  18.   def refresh
  19.      i=0
  20.      self.contents.clear
  21.      self.contents.font.size=22
  22.      self.contents.draw_text(-16,0,self.width,24,"Http: Gestionnaire de téléchargement",1)
  23.      self.contents.font.size=20
  24.      # pour chaque téléchargement
  25.      @dls.each_key{|file|
  26.      self.contents.draw_text(0,56*(i+=1),200,24,"--> #{file}")
  27.      self.contents.fill_rect(131,56*i+25,202,10,Color.new(0,0,0,150))
  28.      self.contents.font.size=14
  29.      # on récupere le pourcentage du téléchargement
  30.      pr=Net::HTTP.progress(file)/100
  31.      # on écrit le rapport: octets téléchargés / taille totale
  32.      rat="#{Net::HTTP.sizeloaded(file)/1024}/#{Net::HTTP.size(file)/1024} ko"
  33.      self.contents.draw_text(132,56*i+32,150,24,rat,1)
  34.      # on récupère le temps de téléchargement du fichier
  35.      s=Net::HTTP.temps(file)
  36.      # on l'écrit
  37.      self.contents.draw_text(20,56*i+20,self.width,24,"Fait en #{s} secs")
  38.      # on écrit le pourcentage de progression
  39.      self.contents.draw_text(342,56*i+26,self.width,24,"#{(pr*100).to_i}%")rescue nil
  40.      # et on trace la barre
  41.      self.contents.fill_rect(132,56*i+26,pr*200,8,Color.new(0,255,0))
  42.      self.contents.font.size=20}
  43.   end
  44. end
  45. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  46. class Scene_Download
  47.   def main
  48.      @fond=Spriteset_Map.new
  49.      # chargement des fichiers
  50.      Net::HTTP.download('http://download59.mediafire.com/313lzxpdytpg/gyok0vgmm2m/hero+creator.zip')
  51.      Net::HTTP.download('http://www.google.fr/intl/fr_fr/images/logo.gif')
  52.      Net::HTTP.download('http://www.rpgrevolution.com/forums/banner3.gif')
  53.      Net::HTTP.download('http://i42.servimg.com/u/f42/12/32/03/86/bannie11.jpg')
  54.      #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  55.      @barre=Window_Barre.new
  56.      Graphics.transition
  57.      loop do
  58.         Input.update
  59.         Graphics.update
  60.         update
  61.         break if $scene != self
  62.      end
  63.      Graphics.freeze
  64.      @fond.dispose
  65.      @barre.dispose
  66.   end
  67.   def update
  68.      @barre.refresh
  69.      $scene=Scene_Map.new if Input.trigger?(Input::B)
  70.   end
  71. end
  72.  
Expand to see the code.


Instructions
Quote:
Ftp :
receive : Net::FTP.download("file_on_ftp","./Graphics")
send : Net::FTP.upload("file_in_project","dir_on_ftp")
Http :
receive : Net::HTTP.download("url","./Graphics")

The downloaded file has the same name of the original

FAQ
Paste this script above main

Compatibility
No Problem I think !

Credits and Thanks
Msdn, my best friend ^^
http://www.66rpg.com for parts of scripts !

Author's Notes
next feature:
evaluate the size of the file: done.
evaluate if the file exists: done.

Terms and Conditions
Free for using, but I need credits. Do not post this script anywhere without my permission !

enjoy,
berka
Will ther be an XP version? Or will it already work with XP?
amazing just freakin amazing@!
Thanks !
I'll made a rmxp version !

berka
Thanks, I like this.
New version !
only for rmvx but xp's coming soon !

berka
One day we will be able to make games that weight just 1KB, all Info/Graphics will be downloaded from the web. that would be cool! the "Loading" Screen Era will come to RPG Maker
I get an error with #example.

script '#example' line 29 : FloatDomainError
Infinity
This is very cool, and would be definitely do-able with sites such as 110mb.com, this would be awesome for people who don't want to clog their system with large games
I have one more thing: How do I use the files I download with this?
Fallen wrote:
One day we will be able to make games that weight just 1KB, all Info/Graphics will be downloaded from the web. that would be cool! the "Loading" Screen Era will come to RPG Maker

I think this script would work better for patch system or something around that line. :D
Man, no for XP??? THIS IS AN AWESOME SCRIPT!!!!
berka wrote:
only for rmvx but xp's coming soon !

thanks !


berka
Near wrote:
I get an error with #example.

script '#example' line 29 : FloatDomainError
Infinity


Same for me in the VX version.
ok I'll fix it !
thanks
berka

Edit: I've posted all the scripts ! 😉
berka wrote:
ok I'll fix it !
thanks
berka

Edit: I've posted all the scripts ! 😉


Now the game freezes when I talk to the guy.
how long does it freeze ?
Does it crash ?
Which version are you using ?
I'll put rgss dll files into the rar

berka
It freezes until I close the game, and I'm using the original demo, with the new example scene script.
Really nice, and also it will come in handy for one of my projects which need to be updated.
its nice looking.. but i havent gotten to try it yet.. I get the error as well. also when I try to download the rmxp version.. it corrupts.. I havent tried vx yet.. but I am now

EDIT: nope same error corrupt zip file. I would like to use this script in my particle engine, allowing users to upload and download particles, graphics, movement paths, etc.. It will allow me to update a file on an ftp server so they just turn on the game and bam new junk XD
This is fantastic, really though while I was reading through this post I started to wonder, this script makes it easy to release updates and thats cool. Though is it possible to make it so that players can report a problem within the game?

I'm not by any means requesting something like that just wondering if something like it would be possible.

In case you don't know what I mean say someones playing your demo they find a TON of TERRIBLE TERRIBLE grammar... 😀 ... they can send you a message right in the game... say by pressing a F key or something and typing the problem within the window. Could something along those lines be done?

Lets face it I've played a few games were there where a few issues, but when I tried to report it I really didn't care enough to remember the details, while I rated the game.

EDIT 😀

Sorry I was looking around a little more and noticed

InputBox Script Version: 1.3
By: Rafidelis

http://www.hbgames.org/forums/viewtopic.php?f=11&t=63074

Something like this type of input box but when you submit it sends the info to an e-mail inbox.
Really interesting and handy script indeed... The game design half in me wonders if games need that at all really, because I figure only a handful will be fitting for an updating feature, but the customization side wants to update my games with new graphics and scripts :]

I think the script is a little messy... also, naming modules 'berka' isn't any practical at all tbh. Other than that, well done, so keep up the good work.
I fixed the xp version, there were errors with the error display XD, but here it is

  1. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2. #                            Download & Upload Files with RGSS
  3. #   par berka                                 v 2.1                           rgss 1
  4. #                                     http://www.rpgmakervx-fr.com&nbsp;&nbsp;                                        # azirht001 bug fixes             
  5. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  6. # thanks to: http://www.66rpg.com for documentation on wininet
  7. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  8. # ! do not use ftp which contains privates data
  9. # ! this scripts need ftp account information !
  10. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  11. # Ftp :
  12. #      Ã¢ €“ ¼ receive :
  13. #               Net::FTP.download("dir_on_ftp/file.zip","./Graphics")
  14. #      Ã¢ €“ ¼ send :
  15. #               Net::FTP.upload("./directoryinfolder/file.exe","directoryonftp newfilename.exe")
  16. #      Ã¢ €“ ¼ make directory :
  17. #               Net::FTP.mkdir("/dir_on_ftp")
  18. # Http :
  19. #      Ã¢ €“ ¼ receive :
  20. #               Net::HTTP.download("url","./Graphics")
  21. #      Ã¢ €“ ¼ total octets downloaded :
  22. #               Net::HTTP.dloaded
  23. #      Ã¢ €“ ¼ size of file :
  24. #               Net::HTTP.size("test.zip")
  25. #      Ã¢ €“ ¼ % dl progress :
  26. #               Net::HTTP.progress("test.zip")
  27. #      Ã¢ €“ ¼ transfer time:
  28. #               Net::HTTP.temps("test.zip")
  29. #      Ã¢ €“ ¼ list files :
  30. #               Net::HTTP.transfers
  31. #      Ã¢ €“ ¼ file loaded? :
  32. #               Net::HTTP.loaded?("test.zip")
  33. #      Ã¢ €“ ¼ octets transfered :
  34. #               Net::HTTP.transfered
  35. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  36. module Berka
  37.   module NetError
  38.      ErrConIn="Unable to connect to Internet"
  39.      ErrConFtp="Unable to connect to Ftp"
  40.      ErrConHttp="Unable to connect to the Server"
  41.      ErrNoFFtpIn="The file to be download doesn't exist"
  42.      ErrNoFFtpEx="The file to be upload doesn't exist"
  43.      ErrTranHttp="Http Download is failed"
  44.      ErrDownFtp="Ftp Download is failed"
  45.      ErrUpFtp="Ftp Upload is failed"
  46.      ErrNoFile="No file to be download"
  47.      ErrMkdir="Unable to create a new directory"
  48.   end
  49. end
  50. module Net
  51.   W='wininet'
  52.   SPC=Win32API.new('kernel32','SetPriorityClass','pi','i').call(-1,128)
  53.   IOA=Win32API.new(W,'InternetOpenA','plppl','l').call('',0,'','',0)
  54.   IC=Win32API.new(W,'InternetConnectA','lplpplll','l')
  55.   print(Berka::NetError::ConIn)if IOA==0
  56.   module FTP
  57.      FSCD=Win32API.new(W,'FtpSetCurrentDirectoryA','lp','l')
  58.      FGF=Win32API.new(W,'FtpGetFileA','lppllll','l')
  59.      FPF=Win32API.new(W,'FtpPutFile','lppll','l')
  60.      FCD=Win32API.new(W,'FtpCreateDirectoryA','lp','l')
  61.      module_function      
  62.      def init
  63.         #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  64.         ftp="ftp.host.com"               #
  65.         port=21                                 #   A modifier ! 21 is default
  66.         identifiant="username"                  #
  67.         motdepasse="password"            #
  68.         #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  69.         @fb=IC.call(IOA,ftp,port,identifiant,motdepasse,1,0,0)
  70.         ftp,port,identifiant,motdepasse=[nil]*4 # efface les ids par sécurité
  71.         (print(Berka::NetError::ErrConFtp))if @fb==0
  72.      end
  73.      def download(ext,int='./')
  74.         init if @fb.nil?      
  75.         c=ext.split('/').pop
  76.         if FSCD.call(@fb,ext.gsub(c,''))!=0
  77.            print(Berka::NetError::ErrDownFtp)if FGF.call(@fb,c,"#{int}/#{c}",0,32,2,0)==0
  78.         else
  79.            print(Berka::NetError::ErrNoFFtpIn)
  80.         end
  81.      end
  82.      def mkdir(rep)
  83.         init if @fb.nil?
  84.         print(Berka::NetError::ErrMkdir)if FCD.call(@fb,rep)==0
  85.      end
  86.      def upload(int,ext)
  87.         init if @fb.nil?
  88.         if FSCD.call(@fb,ext)&&File.exist?(int)
  89.            print(Berka::NetError::ErrUpFtp) if FPF.call(@fb,int,ext,2,0)==0
  90.         else
  91.            print(Berka::NetError::ErrNoFFtpEx)
  92.         end
  93.      end
  94.   end
  95.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  96.   module HTTP
  97.      IOU=Win32API.new(W,'InternetOpenUrl','lppllp','l')
  98.      IRF=Win32API.new(W,'InternetReadFile','lpip','l')
  99.      ICH=Win32API.new(W,'InternetCloseHandle','l','l')
  100.      HQI=Win32API.new(W,'HttpQueryInfo','llppp','i')
  101.      module_function
  102.      def sizeloaded(i='');@read[i];end
  103.      def transfered;@dloaded;end
  104.      def transfers;@dls;end
  105.      def progress(i='');(@read[i].to_f/@size[i]*100);end
  106.      def loaded?(i='');@read[i]>=@size[i]rescue nil;end
  107.      def temps(i='');@tps[i]if loaded?(i);end
  108.      def size(i='');@size[i];end
  109.      def download(url,int='./')
  110.         @dloaded||=0;@dls||={};@i||=-1;@size||={};@read||={};@tps={}
  111.         a=url.split('/');serv,root,fich=a[2],a[3..a.size].join('/'),a[-1]
  112.         print(Berka::NetError::ErrNoFile)if fich.nil?
  113.         @dls[fich]=Thread.start(url,int){|url,int|txt='';t=Time.now
  114.         Berka::NetError::ErrConHttp if(e=IC.call(IOA,serv,80,'','',3,1,0))==0   
  115.         f=IOU.call(IOA,url,nil,0,0,0)
  116.         HQI.call(f,5,k="\0"*1024,[k.size-1].pack('l'),nil)
  117.         @read[fich],@size[fich]=0,k.delete!("\0").to_i
  118.         loop do
  119.            buf,n=' '*1024,0
  120.            r=IRF.call(f,buf,1024,o=[n].pack('i!'))
  121.            n=o.unpack('i!')[0]
  122.            break if r&&n==0
  123.            txt << buf[0,n]
  124.            @read[fich]=txt.size
  125.         end
  126.         (File.open(int+fich,'wb')<<txt).close
  127.         @dloaded+=@read[fich]
  128.         ICH.call(f);sleep(0.01)
  129.         @tps[fich]=Time.now-t}
  130.      end
  131.   end
  132. end
Expand to see the code.
Works fantasicly well Berka, great job. One question though how come the scene showing the download progress doesn't show up 100% of the time? I called it like you did in your XP demo, however it doesn't always show the bars which is quite odd. Any ideas?
@BlueScope : yeah, my script is quite messy, but I chose this very ugly programming to accelerate the implementation process
@Desecration : this maybe an issue about float numbers rounded.
Or, because of each trame has 1024 octets, maybe your file is too small !

thanks all !

berka
Ahh right, that makes sense. Thanks for the reply.
This sounds very useful. I'm getting the freezing problem too when play-testing the XP demo. It happens when downloading the .zip file.
Once again, how do I use the files obtained through this script?
What type file do you want to download ?
If you receive *.rxdata files... you have to restart your game to reload the datas.
If you have zip files... you have to unzip them manually.

regards

berka

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=63165