m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/curling.rb
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-08-27 21:21:26 -0700
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-08-27 21:21:26 -0700
commit2d129fffd7278ce292dbb76d7b7ad493811ee22d (patch)
treea881d4905ae5818a3971d8999374d8e53d8130cf /curling.rb
parent8d2eae318e541965f031a1acaf88f14234cc2fe8 (diff)
Handle invalid checksums
Diffstat (limited to 'curling.rb')
-rw-r--r--curling.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/curling.rb b/curling.rb
index 4b03e8d..e688a01 100644
--- a/curling.rb
+++ b/curling.rb
@@ -61,7 +61,16 @@ To restart the game, run `rm k` to remove the cookie that stores your game state
end
get '/:command' do |command|
- engine = Hex.new cookies.to_h
+ begin
+ engine = Hex.new cookies.to_h
+ rescue InvalidChecksumError
+ halt 422, <<~MSG
+ Invalid state, checksum does not match!
+ If you lost your last valid game state, you'll have to remove your current
+ cookie and start over.
+ MSG
+ end
+
engine.step command
engine.state_h.each_pair do |key, value|
cookies[key] = value