From 1fdb96c02657873f775da31e5867eefd0a5e13a7 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Wed, 13 May 2020 22:01:08 -0400 Subject: [PATCH] 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. --- gloat.pl | 5 +++++ lib/Euchre/Host.pm | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gloat.pl b/gloat.pl index 8edb1f7..088e95e 100755 --- 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 index fd9c904..b6451c1 100644 --- 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; } -- libgit2 1.1.1