The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.

Reply
 
Thread Tools
  #1    
Old February 13th, 2012 (07:32 PM).
Ho-oh 112's Avatar
Ho-oh 112
Advance Scripter
 
Join Date: Feb 2011
Age: 18
Gender: Male
Nature: Hasty
Alright, so I've been looking up on a safer way to use SQL servers with essentials, and I think I found one, Desbrina indirectly gave me the idea.

This is a discussion over how we can do this.

It's designed for php scripts to send a socket with a gifts attributes (game code, code, message) but wasn't tested.
Right so I've developed a sample:
Code:
def pbGiftRequest(host, request, filename=nil, depth=0)
  if depth>10
    raise "Redirection level too deep"
  end
  socket=::TCPSocket.new(host, 80)
  time=Time.now.to_i
  begin
    socket.send(request)
    info=socket.accept # accepts incomming sockets
    info.listen("Gift") # Waits for the socket
    result=info.read(64)# When a socket comes in it reads it's first 64 chars...
    data=""
    # Get the HTTP result
    if result[/^HTTP\/1\.[01] (\d+).*/]
      errorcode=$1.to_i
      if errorcode>=400 && errorcode<500
        raise "HTTP Error #{errorcode}"
      end
      headers={}
      # Get the response headers
      while true
        result=socket.gets.sub(/\r$/,"")
        break if result==""
        if result[/^([^:]+):\s*(.*)/]
          headers[$1]=$2
        end
      end
      length=-1
      chunked=false
      if headers["Content-Length"]
        length=headers["Content-Length"].to_i
      end
      if headers["Transfer-Encoding"]=="chunked"
        chunked=true
      end
      if headers["Location"] && errorcode >= 300 && errorcode < 400
        socket.close rescue socket=nil
        return pbDownloadData(headers["Location"],filename,depth+1)
      end
      if chunked==true
        # Chunked content
        while true
          lengthline=socket.gets.sub(/\r$/,"")
          length=lengthline.to_i(16)
          break if length==0
          while Time.now.to_i-time>=5 || socket.select(10)==0
            time=Time.now.to_i
            Graphics.update
          end
          data+=socket.recv(length)
          socket.gets
        end
      elsif length==-1
        # No content length specified
        while true
          if socket.select(500)==0
            break
          else
            while Time.now.to_i-time>=5 || socket.select(10)==0
              time=Time.now.to_i
              Graphics.update
            end
            data+=socket.recv(1)
          end
        end
      else
        # Content length specified
        while length>0
          chunk=[length,4096].min
          while Time.now.to_i-time>=5 || socket.select(10)==0
            time=Time.now.to_i
            Graphics.update
          end
          data+=socket.recv(chunk)
          length-=chunk
        end
      end
    end
    if filename
      File.open(filename,"wb"){|f|
         f.write(data)
      }
    else
      return data
    end
    ensure
    socket.close rescue socket=nil
  end
  return ""
end
 
def pbCheckGift(url, filename=nil, depth=0)
  userAgent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.14) Gecko/2009082707 Firefox/3.0.14"
  if depth>10
    raise "Redirection level too deep"
  end
  if url[/^http:\/\/([^\/]+)(.*)$/]
    host=$1
    path=$2
    path="/" if path.length==0
    request="GET #{path} HTTP/1.1\nUser-Agent: #{userAgent}\nPragma: no-cache\nHost: #{host}\nProxy-Connection: Close\n\n"
    return pbGiftRequest(host, request, filename, depth)
  end
  return ""
end
this sample is to show people how you could possiblly receive sockets, it's not tested but, I guess it's a matter of trail & error.

I was testing it for mySQL mystery gift, but I remembered I have no actual site to test a .php file on which this script is made for....

Anyone with an idea can post it here.
__________________
Scripting Level: Advance

RMXP Poke-Essentials MySQL Trading System Link:
http://www.pokecommunity.com/showthr...62#post7077162

RMXP Poke-Essentials Mystery Gift Link:
http://www.pokecommunity.com/showthread.php?t=270687

RMXP Poke-Essentials Award System Link:
http://www.pokecommunity.com/showthread.php?p=7111566
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 06:45 AM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.