From 3fd5773a14e590e0b66eb73cd756521531d78fbf Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Mon, 14 Sep 2020 15:10:19 -0600 Subject: [PATCH] Added client side hooks for drawing, playing, and reaping cards --- Server/server.pl | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Server/server.pl b/Server/server.pl index 642e5d9..dbdb023 100755 --- a/Server/server.pl +++ b/Server/server.pl @@ -129,7 +129,7 @@ sub addPool { sub delPool { my ($sessionID,$poolID) = @_; - my @reapedCards = splice($sessions{$sessionID}{"pools"}{$poolID}{cards}); + my @reapedCards = splice(@{$sessions{$sessionID}{"pools"}{$poolID}{cards}}); delete($sessions{$sessionID}{"pools"}{$poolID}); return @reapedCards; } @@ -189,7 +189,7 @@ sub addHand { sub delHand { my ($sessionID, $userID, $handID) = @_; - my @leftoverCards = splice($sessions{$sessionID}{"users"}{$userID}->{hands}{$handID}->{cards}); + my @leftoverCards = splice(@{$sessions{$sessionID}{"users"}{$userID}->{hands}{$handID}->{cards}}); delete($sessions{$sessionID}{"users"}{$userID}{hands}{$handID}); return @leftoverCards; } @@ -239,7 +239,7 @@ sub delUser { sub getDeckSize { my ($sessionID, $deckID) = @_; - return length $sessions{$sessionID}{"decks"}{$deckID}->{cards}; + return scalar @{$sessions{$sessionID}{"decks"}{$deckID}->{cards}}; } sub getPoolTop { @@ -332,7 +332,7 @@ my $server = Net::WebSocket::Server->new( } $current->send_utf8('{"pools":'.to_json(\%poolStats).'}'); # Users Hands - my @hands = getHands($sessionID,$conn->{user}); + my @hands = getHands($sessionID,$_->{user}); my %handStats = (); for (@hands) { $handStats{$_}{name} = $_; @@ -342,7 +342,7 @@ my $server = Net::WebSocket::Server->new( # for each hand for (@hands) { my $handID = $_; - my @hand = @{$sessions{$sessionID}{"users"}{$conn->{user}}{hands}{$handID}{cards}}; + my @hand = @{$sessions{$sessionID}{"users"}{$current->{user}}{hands}{$handID}{cards}}; # each card (so we scale better) if (@hand) { for (@hand) { my $card = $_; @@ -350,6 +350,20 @@ my $server = Net::WebSocket::Server->new( }} } }}} + if ($messageData->{action} =~ /draw/) { + drawCard($conn->{session},$messageData->{deck},$conn->{user},$messageData->{hand}); + $conn->send_utf8('{"info":"card drawn", "request":"update"}'); + } + if ($messageData->{action} =~ /play/) { + playCard($conn->{session},$conn->{user},$messageData->{hand},$messageData->{cardID},$messageData->{pool}); + $conn->send_utf8('{"info":"card played", "request":"update"}'); + } + if ($messageData->{action} =~ /clear/) { + my @cards = delPool($conn->{session},$messageData->{pool}); + addCards($conn->{session},$messageData->{deck},\@cards); + addPool($conn->{session},$messageData->{pool}); + $conn->send_utf8('{"info":"pool cleared", "request":"update"}'); + } } }, disconnect => sub {