Added client side hooks for drawing, playing, and reaping cards
This commit is contained in:
parent
736f6e6354
commit
3fd5773a14
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user