Created
June 1, 2015 22:18
-
-
Save bsterno/3aff71f55a1f80227fc1 to your computer and use it in GitHub Desktop.
MMORPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "uri" | |
require "openssl" | |
encoded_session = "BAh7BkkiD3Nlc3Npb25faWQGOgZFVEkiRTY4ODMzYjA1ZDNlOGY1NWYyZjhm%0ANDA1YjU4NTA0N2VhODNmMDliMDA1Zjk0MmNiMTRjNTFlZDliY2Q3MTI1ZjQG%0AOwBG%0A--b21b026936ebb96a5c113898a084affc893608d2" | |
str = "nobody_will_ever_find_me" | |
data = "BAh7BkkiD3Nlc3Npb25faWQGOgZFVEkiRTY4ODMzYjA1ZDNlOGY1NWYyZjhm%0ANDA1YjU4NTA0N2VhODNmMDliMDA1Zjk0MmNiMTRjNTFlZDliY2Q3MTI1ZjQG%0AOwBG%0A" | |
def decode_session(str) | |
Marshal.load(URI.decode_www_form_component(str).unpack("m").first) | |
end | |
def generate_hmac(data, secret) | |
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, secret, data) | |
end | |
temp = decode_session(encoded_session) | |
puts temp | |
puts generate_hmac(data, str) | |
use Rack::Session::Cookie, { | |
secret: "nobody_will_ever_find_me" | |
} | |
session[:human_score] = 0 | |
session[:computer_score] = 0 | |
redirect "/rps" | |
curl -H "human_score: 2" mmorps | |
curl --header "X-MyHeader: 123" www.google.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Rock, Paper, Scissors</title> | |
</head> | |
<body> | |
<h3>Human: <%= human_score %></h3> | |
<h3>Computer: <%= computer_score %></h3> | |
<h3><%= winner %></h3> | |
<br> | |
<% unless winner %> | |
<form action='/rps' method='post'> | |
<input type='submit' id='Rock' value='Rock' name='human_choice'> | |
<input type='submit' id='Paper' value='Paper' name='human_choice'> | |
<input type='submit' id='Scissors' value='Scissors' name='human_choice'> | |
</form> | |
<% else %> | |
<p><a href="/">Play Again!</a></p> | |
<% end %> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "sinatra" | |
require "pry" | |
use Rack::Session::Cookie, { | |
secret: "keep_it_secret_keep_it_safe" | |
} | |
def winner | |
message = ["Congratulations, you won!!!", "You suck"] | |
if session[:human_score] == 2 | |
message[0] | |
elsif session[:computer_score] == 2 | |
message[1] | |
end | |
end | |
get "/" do | |
session[:human_score] = 0 | |
session[:computer_score] = 0 | |
redirect "/rps" | |
end | |
get "/rps" do | |
erb :index, locals: { human_score: session[:human_score], computer_score: session[:computer_score], winner: winner } | |
end | |
post "/rps" do | |
human_choice = params["human_choice"] | |
computer_choice = [ "Rock", "Paper", "Scissors" ].sample | |
# binding.pry | |
if human_choice == "Rock" && computer_choice == "Scissors" | |
session[:human_score] += 1 | |
elsif human_choice == "Paper" && computer_choice == "Rock" | |
session[:human_score] += 1 | |
elsif human_choice == "Scissors" && computer_choice == "Paper" | |
session[:human_score] += 1 | |
else | |
session[:computer_score] += 1 | |
end | |
redirect "/rps" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment