euchre-live

Euchre web-app for the socially distant family
git clone git://git.alexkarle.com/euchre-live.git
Log | Files | Refs | README | LICENSE

commit 47619cb8ccf098a6071b8a66fbbe4a126bd253a4 (patch)
parent 7e72b194bd4f1a01a99010d7d8c9e1d21c60af21
Author: Alex Karle <alex@karle.co>
Date:   Tue, 14 Apr 2020 23:25:20 -0400

Euchre::Dealer: Validate suit being ordered

We know the trump nominee; we know the suit you're requesting; we know
how many times it's passed. Might as well yell at you if you're
misbehaving! (The Dealer is getting awfully good at that these days...
so much for the laid back "if you say so" Dealer :) )

Also adds a <select> element to debug.html to test this nonsense.

Diffstat:
Mlib/Euchre/Dealer.pm | 15++++++++++++++-
Mpublic/debug.html | 9++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm @@ -307,7 +307,20 @@ sub order { broadcast_gamestate($game); } } elsif ($msg->{vote}) { - # TODO: add hand/suit validation? + # Validate its an OK vote + if ($game->{pass_count} < 4) { + if ($game->{trump_nominee} !~ /$msg->{vote}/) { + send_error($p, "Must vote on kitty card's suit"); + return; + } + } else { + if ($game->{trump_nominee} =~ /$msg->{vote}/) { + send_error($p, "Can't vote for kitty card suit after turned down"); + return; + } + } + + # Accept the vote... $game->{trump} = $msg->{vote}; $game->{caller} = $p->{seat}; $game->{phase} = 'play'; diff --git a/public/debug.html b/public/debug.html @@ -31,7 +31,6 @@ if (typeof msg.game.trump_nominee !== 'undefined') { gameState += 'Trump Nominee: ' + '<img class="card" src="cards/' + msg.game.trump_nominee + '.svg"><br>' - order_suit = msg.game.trump_nominee.substring(1,2); } document.getElementById('hand').innerHTML = 'HAND: <br>' @@ -78,6 +77,8 @@ ws.send(JSON.stringify({action:'start_game', start_seat: seat})) } function vote(a) { + order_suit = document.getElementById('order_suit').value; + console.log(order_suit); ws.send(JSON.stringify({action:'order', vote: order_suit, loner: a})) } function pass() { @@ -115,6 +116,12 @@ <div id="hand">No cards in hand</div> <br> <button onclick="vote(0)">Order</button> + <select id="order_suit"> + <option value="H">Hearts</option> + <option value="D">Diamonds</option> + <option value="S">Spades</option> + <option value="C">Clubs</option> + </select> <button onclick="vote(1)">Loner</button> <button onclick="pass()">Pass</button> <br><br>