A simple web based die roller I made to learn Ruby, and emulate the defunct Invisible Castle.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#!/usr/bin/ruby
|
|
|
|
require "cgi"
|
|
|
|
require "./db"
|
|
|
|
cgi = CGI.new
|
|
|
|
clause = ""
|
|
|
|
emptyclause = 0
|
|
|
|
if cgi.has_key?("user")
|
|
|
|
unless cgi.params["user"][0]==""
|
|
|
|
clause = " WHERE user='" + cgi.params["user"][0] +"'"
|
|
|
|
emptyclause = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if cgi.has_key?("game")
|
|
|
|
unless cgi.params["game"][0]==""
|
|
|
|
if emptyclause == 1
|
|
|
|
clause = clause + " AND "
|
|
|
|
else
|
|
|
|
clause = " WHERE "
|
|
|
|
end
|
|
|
|
clause = clause + "game ='" + cgi.params['game'][0] + "'"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print '<html>'
|
|
|
|
print ' <form action="display.rb" method="post">'
|
|
|
|
print ' User<input type="text" name="user" />'
|
|
|
|
print ' Game<input type="text" name="game" />'
|
|
|
|
print ' <input type="submit" value="Display Rolls" />'
|
|
|
|
print ' </form>'
|
|
|
|
|
|
|
|
statement = $my.prepare("SELECT * from rolls" + clause)
|
|
|
|
result = statement.execute
|
|
|
|
result.num_rows.times do
|
|
|
|
puts result.fetch.join("\s") + "<br />"
|
|
|
|
end
|
|
|
|
print '</html>'
|
|
|
|
$my.close
|