Need help with a script - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help with a script

Geoff084Geoff084 Posts: 1Member
When i run this code (through NETBEANS - with ruby addon) it does not function correctly.
It doesn't login correctly and I'm not sure whats wrong.
Im am still in the process of learning ruby, and any help would be greatly appreciated.
[hr]
#!/usr/bin/ruby
require 'open-uri'

#E-Mail and Password... replace /'s with %2f
email = "hotmail@hotmail.com"
password = "****************"

#Whatever the file name is that you're using... Mining is view.fcgi (if I remember, chatbox is comm.fcgi etc.)
file_name = "view.fcgi"

#What it says in the address bar besides the email and password. Make sure a & precedes every variable
uri = "&step=pit&do=2&lvl=13"

#Don't change this...
referer = "http://a3.alienaa.com/cgi-bin/#{file_name}"
url = "http://a3.alienaa.com/cgi-bin/#{file_name}?&email=#{email}&pass=#{password}"
user_agent = "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"

#Amount of veins to mine
veins = -1
to_mine = 200

#Final URL to use in open()
goto = "#{url}#{uri}"

#Previous direction that was gone. options are: n (north), e (east), s (south), w (west)
prev_dir = ""

#Method for when it gets stuck with only one option (going east, only option west, so it can't move)
def stuck line, prev_dir
if (prev_dir == "e" || prev_dir == "w")
if (!(/&go=s>/ =~ line) && (!(/&go=n>/ =~ line)))
return true
end
elsif (prev_dir == "s" || prev_dir == "n")
if (!(/&go=w>/ =~ line) && (!(/&go=e>/ =~ line)))
return true
end
end
end

#method for finding out which to map to
def prev dir
if (dir == "e")
return "w"
elsif (dir == "w")
return "e"
elsif (dir == "s")
return "n"
elsif (dir == "n")
return "s"
end
end


#timer vars, to change up the directions (so it doesn't get into a pattern)
set_arr = ['e','s','w','n']
rand_arr = []
trail = []
trail_moves = 0
moves = 0

def track_back prev_dir
case prev_dir
when "e"
return "w"
when "w"
return "e"
when "n"
return "s"
when "s"
return "n"
end
end

while (veins < to_mine)
#1 second sleep for one connection a second
sleep(0.10);
goto = "#{url}#{uri}"
open( goto, "Referer"=>referer, "User-Agent"=>user_agent ) do |site|
line = site.read
if (/&step=pit&mine=1/ =~ line)
if (/&step=pit&mine=1&shovel=1/ =~ line)
uri = "&step=pit&mine=1&shovel=1"
puts "Shoveled for extra ore! Sweet!"
#veins += 1
else
uri = "&step=pit&mine=1"
puts "Mined"
#veins += 1
end
break
elsif ((/&leave=1/ =~ line || /&next=1/ =~ line) && (prev_dir == "" || prev_dir == "leave"))
if (/&leave=1/ =~ line)
uri = "&step=pit&leave=1"
prev_dir = "leave"
elsif (/&next=1/ =~ line)
uri = "&step=pit&next=1"
prev_dir = "next"
trail = []
trail_moves = 0
end
break
else
if (prev_dir == "leave") #Check to see if on the wrong level
break
end
puts prev_dir if (trail_moves <= 150)
moves += 1
if (moves > 40 )
while (!(set_arr.empty?))
rand_arr.push(set_arr.delete_at(rand(set_arr.size)))
end
set_arr = rand_arr
rand_arr = []
puts "Directions Randomized!"
moves = 0
end
if (trail_moves > 50) #Maximum amount of steps, traces back
trace_pop = trail.pop
uri = "&step=pit&go=#{trace_pop}"
print "trace"
puts trace_pop
if (trail.empty? or /&do=1&lvl=13/ =~ line)
if (/&do=1&lvl=13/ =~ line)
uri = "&step=pit&do=2&lvl=13"
end
trail_moves = 0
trail = []
prev_dir = ""
end
moves = 0
break
end
if (/&do=1&lvl=13/ =~ line) #Check to see if you died during the pit
uri = "&step=pit&do=2&lvl=13"
prev_dir = ""
puts "Dead, restarting"
trail_moves = 0
trail = []
moves = 0
break
end
if (prev_dir == "" || prev_dir == "next")
uri = "&step=pit&go=s"
prev_dir = "s"
trail.push("n")
trail_moves += 1
break
elsif (/&go=#{prev_dir}>/ =~ line)
uri = "&step=pit&go=#{prev_dir}"
trail.push(track_back(prev_dir))
trail_moves += 1
break
elsif ((/&go=#{set_arr[0]}>/ =~ line) && (prev_dir != prev(set_arr[0]) || stuck(line, prev_dir)))
uri = "&step=pit&go=#{set_arr[0]}"
prev_dir = "#{set_arr[0]}"
trail.push(track_back(prev_dir))
trail_moves += 1
break
elsif ((/&go=#{set_arr[1]}>/ =~ line) && (prev_dir != prev(set_arr[1]) || stuck(line, prev_dir)))
uri = "&step=pit&go=#{set_arr[1]}"
prev_dir = "#{set_arr[1]}"
trail.push(track_back(prev_dir))
trail_moves += 1
break
elsif ((/&go=#{set_arr[2]}>/ =~ line) && (prev_dir != prev(set_arr[2]) || stuck(line, prev_dir)))
uri = "&step=pit&go=#{set_arr[2]}"
prev_dir = "#{set_arr[2]}"
trail.push(track_back(prev_dir))
trail_moves += 1
break
elsif ((/&go=#{set_arr[3]}>/ =~ line) && (prev_dir != prev(set_arr[3]) || stuck(line, prev_dir)))
uri = "&step=pit&go=#{set_arr[3]}"
prev_dir = "#{set_arr[3]}"
trail.push(track_back(prev_dir))
trail_moves += 1
break
end
end
end
end
[hr]
Sign In or Register to comment.