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 1fdb96c02657873f775da31e5867eefd0a5e13a7 (patch)
parent 747b0ccf4086f761d6d5784d57074745026c83ed
Author: Alex Karle <alex@karle.co>
Date:   Wed, 13 May 2020 22:01:08 -0400

Euchre::Host: Convert list_tables to a GET request

We want to allow people to view games in progress without getting a
websocket first.

This is preferable because the websockets are one of the few resources
we have a hard limit on. We can change it, but the default was probably
set for a reason.

Diffstat:
Mgloat.pl | 5+++++
Mlib/Euchre/Host.pm | 21+++++++++++++--------
2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gloat.pl b/gloat.pl @@ -18,6 +18,11 @@ get '/' => sub { $c->reply->static('index.html'); }; +get '/tables' => sub { + my $c = shift; + $c->render(json => list_tables); +}; + get '/debug' => sub { my $c = shift; $c->reply->static('debug.html'); diff --git a/lib/Euchre/Host.pm b/lib/Euchre/Host.pm @@ -18,6 +18,7 @@ our @EXPORT = qw( register_player gloaters_never_win prune_tables + list_tables stats ); @@ -74,7 +75,6 @@ sub handle_msg { ping => \&pong, join_table => \&join_table, leave_table => \&leave_table, - list_tables => \&list_tables, ); my $p = $PLAYERS{$cid}; @@ -176,13 +176,18 @@ sub leave_table { } sub list_tables { - my ($p) = @_; - - # TODO: send more... - $p->send({ - msg_type => 'list', - tables => [map { $_->name } values %DEALERS], - }); + my $json = { games => [] }; + for my $k (keys %DEALERS) { + my $d = $DEALERS{$k}; + push @{$json->{games}}, { + name => $k, + phase => $d->game->phase, + has_password => $d->password ? 1 : 0, + players => $d->player_names, + spectators => [map { $_->name } @{$d->spectators}], + }; + } + return $json; }